Discrete Fourier Transform - 2#5906

Discrete Fourier Transform - 2

0.5 seconds
64 megabytes
Medium

In this problem, you are required to perform the Discrete Fourier Transform (DFT) of a polynomial. Recall that the Discrete Fourier Transform is the vector

y = (y_0, y_1, \ldots, y_{n-1}),

where the coefficients are calculated by the following formula:

For simplicity, let us assume that a_0 = X, and for k \geq 1, the following holds: a_k = (Y a_{k-1} + Z) \mod T, where , , , are given numbers, and \mod denotes the remainder after division.

Input

The first line of input contains five integers: , , , , (1 \leq n \leq 10^7, 1 \leq X, Y, Z, T \leq 10^6).

Output

Print a single number with a relative or absolute error not exceeding 10^{-6}, where denotes the real part, and denotes the imaginary part.

Examples

Example 1

Loading
Loading