Description

海獅覺得 $\text{\color{black}{o}\color{red}{wl}}$ APCS才三級分 TOI在建電墊底 演算法能力實在是太差了
於是決定每天出一題讓 $\text{\color{black}{o}\color{red}{wl}}$ 增進演算法能力
但是因為 $\text{\color{black}{o}\color{red}{wl}}$ 能力不佳
所以只能選擇一段連續的時間(至少一天)每天寫題目
而且這段時間還不能太長
請判斷 $\text{\color{black}{o}\color{red}{wl}}$ 最多可以精進多少演算法能力

Input Format

由於數字太大 IO 很慢 請你自己生測資

第一行有兩個整數 $n(1 \leq n \leq 10^7)$ 和 $k(1 \leq k \leq n)$ 代表海獅出題出了幾天以及 $\text{\color{black}{o}\color{red}{wl}}$ 最長可以連續寫幾天題目

你要自己生成包含$n$個整數的序列$E$
第$i$個數$E_i$ 代表第$i$題能增進多少 $\text{\color{black}{o}\color{red}{wl}}$ 的演算法能力
其中有時候 $\text{\color{black}{o}\color{red}{wl}}$ 會覺得海獅的題目太爛導致 $\text{\color{black}{o}\color{red}{wl}}$ 的演算法能力下降 ( $E_i < 0$ )

第二行有四個整數 $x$ $a$ $b$ $c$ $ (1 \leq x, a, b, c \leq 10^9)$
我們令 $E_1 = x$
$E_i = (a \cdot E_{i-1} + b) \bmod c - \lfloor c / 2 \rfloor$ for $i = 2, 3, \dots, n$
(假設模運算恆正)

Output Format

一個整數代表 $\text{\color{black}{o}\color{red}{wl}}$ 最多增進多少演算法能力

Sample Input 1

5 2
3 2 1 100

Sample Output 1

13

Hints

Problem Source

$\text{\color{black}{o}\color{red}{wl}}$ 不要再裝弱了

TopCoder

User's AC Ratio

100.0% (2/2)

Tags

Problem Setter

Created by roychuang

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 262144 65536
1 1000 262144 65536
2 1000 262144 65536
3 1000 262144 65536
4 1000 262144 65536
5 1000 262144 65536
6 1000 262144 65536
7 1000 262144 65536
8 1000 262144 65536
9 1000 262144 65536
10 1000 262144 65536
11 1000 262144 65536
12 1000 262144 65536
13 1000 262144 65536
14 1000 262144 65536
15 1000 262144 65536
16 1000 262144 65536
17 1000 262144 65536
18 1000 262144 65536
19 1000 262144 65536
20 1000 262144 65536