Mail.Ru Cup 2018 Round 1
H
Epic Convolution
Codeforces
3500
原题
← G→
翻译中…

You are given two arrays $a_0, a_1, \ldots, a_{n - 1}$ and $b_0, b_1, \ldots, b_{m-1}$, and an integer $c$.

翻译中…

Compute the following sum:

翻译中…

$$\sum_{i=0}^{n-1} \sum_{j=0}^{m-1} a_i b_j c^{i^2\,j^3}$$

翻译中…

Since it's value can be really large, print it modulo $490019$.

翻译中…

Input

翻译中…

First line contains three integers $n$, $m$ and $c$ ($1 \le n, m \le 100\,000$, $1 \le c \lt 490019$).

翻译中…

Next line contains exactly $n$ integers $a_i$ and defines the array $a$ ($0 \le a_i \le 1000$).

翻译中…

Last line contains exactly $m$ integers $b_i$ and defines the array $b$ ($0 \le b_i \le 1000$).

翻译中…

Output

翻译中…

Print one integer — value of the sum modulo $490019$.

翻译中…

Note

翻译中…

In the first example, the only non-zero summand corresponds to $i = 1$, $j = 1$ and is equal to $1 \cdot 1 \cdot 3^1 = 3$.

翻译中…

In the second example, all summands are equal to $1$.

翻译中…

样例

Input #1
2 2 3
0 1
0 1
Output #1
3
InputCopy OutputCopy
Input #2
3 4 1
1 1 1
1 1 1 1
Output #2
12
InputCopy OutputCopy
Input #3
2 3 3
1 2
3 4 5
Output #3
65652
InputCopy OutputCopy
题目信息
题号
1054H
时间限制
4 s
内存限制
256 MB
标签
中国剩余定理
FFT
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。