← Back to Problems
Tail Hedge
Easy standard Martingales & Stopping Probability & Statistics
Time limit: 2 s per test  ·  Memory: 256 MB

A tail-hedge book bleeds by design. Its NAV starts at X_0 = 1 and follows the disclosed model: each day, independently of the past,

X_{t+1} = X_t * U   with probability p
X_{t+1} = X_t * d   with probability 1 - p

where 0 < d < 1 < U. The values d and U are given for every case; p is chosen so that the NAV is a martingale.

For each case you see the daily history X_1 .. X_N and a horizon h. Output two numbers: m = E[X_{N+h} | history] and q = P(X_{N+h} > X_N).

Input

The first line contains the integer T, the number of cases. Each case consists of two lines: a line d U h N (d with 4 decimals, U with 2 decimals, h and N integers), and a line with the N reals X_1 .. X_N.

Output

T lines. Line i: m q for case i, separated by a space.

Constraints

1 <= T <= 200

0.96 <= d <= 0.999

2 <= U <= 40

20 <= h <= 500

100 <= N <= 400

Scoring

This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.

Numeric answers are accepted if they are within an absolute tolerance of 1e-12 or a relative tolerance of 1e-09 of the expected value.

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