P10886 [MX-S3-T2] "FeOI Round 1" Journey
Background
Original link: 。
---

Description
Little W has recently been learning a programming language.
This programming language has a statement as follows:
```
range(a,b,c)
```
This statement represents a sequence, and the sequence is:
$$
[a,a+c,a+2c,\cdots,a+kc]
$$
Here, $k$ is the largest non-negative integer $k$ such that $a+kc
Input Format
To speed up input, we use the following input method.
The input consists of one line with five non-negative integers $n, A, B, C, g_n$.
Here, $n$ is the length of the sequence $g$, $A, B, C$ are parameters for generating the data, and $g_n$ is the $n$-th term of the sequence $g$.
For the $i$-th term of the sequence $g$ ($1\leq i < n$), it satisfies $g_i \equiv Ag_{i+1}^2+Bg_{i+1}+C \pmod {10^9 + 7}$.
Output Format
Output one line with one non-negative integer, which is the required answer in the problem.
Explanation/Hint
**Sample Explanation #1**
$g=[2,1]$ (indexed starting from $1$).
Let $ans=\sum\limits_{i\in \mathrm{range}(a,b,c)} g_i$.
When $a=1,b=2,c=1$, $ans=2$.
When $a=1,b=2,c=2$, $ans=2$.
When $a=1,b=3,c=1$, $ans=2+1=3$.
When $a=1,b=3,c=2$, $ans=2$.
When $a=2,b=3,c=1$, $ans=1$.
When $a=2,b=3,c=2$, $ans=1$.
The answer is $\sum ans=2+2+3+2+1+1=11$.
**Sample Explanation #2**
This sample satisfies Special Property A.
**Constraints**
For $100\%$ of the testdata: $1\leq n\leq 2\times 10^7$, $0\leq A,B,C,g_n