Description
Tingting is a kid who likes matrices. One day she wants to use a computer to generate a huge matrix with n rows and m columns (you do not need to worry about how she stores it). The matrix she generates has a magical property: let F[i,j] denote the element at row i, column j, then F[i,j] satisfies the following recurrence:
$$\begin{aligned}
F[1, 1] &= 1 \\
F[i, j] &=a\times F[i, j-1]+b, &j\neq 1 \\
F[i, 1] &=c\times F[i-1, m]+d, &i\neq 1 \\
\end{aligned}$$
In the recurrence, a,b,c,d are given constants.
Now Tingting wants to know the value of F[n,m]. Please help her. Since the final result can be large, you only need to output the remainder of F[n,m] modulo 109+7.
One line containing six integers n,m,a,b,c,d. The meaning is as described above.
Output a single integer, the value of F[n,m] modulo 109+7.
3 4 1 3 2 6
85
Hint
Explanation for Sample 1.
The matrix in the sample is:
$$\begin{pmatrix}
1 & 4 & 7 & 10 \\
26 & 29 & 32 & 35 \\
76 & 79 & 82 & 85 \\
\end{pmatrix}$$
Constraints
::cute-table{tuack}
| Test point ID |
Constraints |
| 1 |
1≤n,m≤10; 1≤a,b,c,d≤1000 |
| 2 |
1≤n,m≤100; 1≤a,b,c,d≤1000 |
| 3 |
1≤n,m≤103; 1≤a,b,c,d≤109 |
| 4 |
| 5 |
1≤n,m≤109; 1≤a=c≤109; 1≤b=d≤109 |
| 6 |
1≤n,m≤109; a=c=1; 1≤b,d≤109 |
| 7 |
1≤n,m,a,b,c,d≤109 |
| 8 |
| 9 |
| 10 |
| 11 |
1≤n,m≤101000; a=c=1; 1≤b,d≤109 |
| 12 |
1≤n,m≤101000; 1≤a=c≤109; 1≤b=d≤109 |
| 13 |
1≤n,m≤101000; 1≤a,b,c,d≤109 |
| 14 |
| 15 |
1≤n,m≤1020000; 1≤a,b,c,d≤109 |
| 16 |
| 17 |
1≤n,m≤101000000; a=c=1; 1≤b,d≤109 |
| 18 |
1≤n,m≤101000000; 1≤a=c≤109; 1≤b=d≤109 |
| 19 |
1≤n,m≤101000000; 1≤a,b,c,d≤109 |
| 20 |
Translated by ChatGPT 5