← Back to Problems
Make the Number
Easy optimization Martingales & Stopping
Time limit: 2 s per test  ·  Memory: 256 MB

A trader has x_0 chips and needs N chips by the end of the session to keep the desk funded. The session has T rounds. In each round the trader chooses an integer stake s (any amount from 0 up to their current wealth), then wins s chips with probability p or loses s chips with probability 1 - p, independently. The game is losing: p < 1/2. Play stops early if the wealth reaches N or hits 0.

Submit a full staking policy: your stake as a function of the current wealth and the number of rounds remaining.

Input

Four values p, x_0, N and Tp with at most 6 digits after the decimal point, the rest integers.

Output

T lines, each with N - 1 integers. The x-th integer on the t-th line is your stake at wealth x with t rounds remaining. Every stake must satisfy 0 <= s <= x.

Scoring

The judge computes your policy's exact success probability P (no simulation) by dynamic programming, and the best achievable success probability P*. Your score on a case is P / P*, averaged over cases and scaled to the problem's points. An invalid policy (wrong shape, non-integers, a stake exceeding the wealth) scores 0 on that case.

Constraints

0.25 <= p <= 0.49

1 <= x_0 < N <= 64

10 <= T <= 60

Examples

input
0.4 11 32 20
possible output
0 1 1 3 2 5 1 7 9 7 9 0 8 6 11 13 12 5 1 3 3 12 4 3 5 16 26 15 4 24 24
1 2 1 3 0 0 0 2 0 2 4 4 1 8 3 1 3 14 10 10 16 21 22 14 5 4 27 2 24 10 3
1 1 1 4 0 4 1 4 7 5 11 6 0 7 13 2 11 4 2 4 18 9 3 22 17 13 14 18 1 4 0
0 0 1 0 2 0 7 4 7 5 6 1 11 0 2 6 12 6 18 12 8 19 18 13 25 10 12 11 1 5 11
0 2 0 1 2 1 5 3 3 6 6 3 0 7 1 3 0 0 17 19 16 16 16 3 18 11 8 7 4 14 25
0 0 0 0 5 1 1 6 3 6 6 1 0 2 12 3 10 10 8 17 4 17 18 4 22 7 6 7 1 2 17
1 2 2 0 3 5 5 2 5 3 0 11 3 7 4 9 14 9 15 14 9 17 15 17 19 13 23 13 16 26 4
0 2 1 4 5 0 1 1 3 3 3 9 12 11 1 8 5 15 14 13 9 2 10 14 14 22 8 15 4 3 20
1 1 2 0 3 5 7 5 4 3 3 12 7 2 11 9 13 7 18 9 16 20 1 5 9 4 25 4 6 4 11
0 1 3 3 4 1 4 1 8 5 2 1 13 6 9 16 8 3 4 18 16 12 1 12 18 14 20 14 17 15 6
0 2 3 3 0 2 1 3 7 1 10 10 8 6 15 4 5 11 0 2 8 10 1 2 17 26 10 5 0 20 22
0 1 0 3 3 0 0 1 3 1 3 9 3 3 1 12 1 3 3 9 0 2 19 16 21 25 25 21 21 7 16
1 1 1 1 5 5 5 7 9 6 10 11 13 6 10 14 11 18 6 14 13 20 15 0 16 26 26 4 14 1 11
0 0 3 0 3 0 1 0 4 10 8 8 6 3 15 0 7 10 11 3 12 2 4 0 16 19 2 20 3 27 27
0 2 0 1 5 5 1 8 8 6 8 0 5 11 10 11 9 13 17 0 14 2 0 19 0 1 0 13 8 8 19
0 1 3 2 0 0 6 4 4 5 1 5 0 12 6 3 13 10 11 18 14 9 3 15 11 16 5 28 3 14 27
1 1 1 1 5 4 4 4 7 10 6 1 5 5 9 3 16 16 14 17 15 8 21 12 24 12 27 1 0 20 0
0 1 1 2 4 5 5 2 8 9 8 7 6 9 0 8 7 17 10 9 19 22 0 18 16 5 1 9 22 27 8
0 1 2 2 1 5 3 0 1 4 4 2 9 7 1 5 2 12 9 17 19 4 16 20 11 24 2 11 19 14 23
0 2 3 4 0 6 1 2 2 7 6 4 5 4 1 12 4 14 19 18 18 11 10 22 18 0 4 26 7 28 11
This output receives a score of 0.59.
input
0.3 3 4 10
possible output
1 1 2
0 2 2
1 2 1
1 1 0
1 0 2
1 1 0
0 0 1
1 2 1
0 0 3
1 1 3
This output receives a score of 0.59.
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2