AT_abc438_g [ABC438G] Sum of Min
Description
You are given integers $ N,M,K $ , a length- $ N $ integer sequence $ A=(A_0,A_1,\ldots,A_{N-1}) $ , and a length- $ M $ integer sequence $ B=(B_0,B_1,\ldots,B_{M-1}) $ . Note that the indices start from $ 0 $ .
Find $ \displaystyle\sum_{i=0}^{K-1} \min(A_{i\bmod N}, B_{i \bmod M}) $ , modulo $ 998244353 $ .
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ M $ $ K $ $ A_0 $ $ A_1 $ $ \ldots $ $ A_{N-1} $ $ B_0 $ $ B_1 $ $ \ldots $ $ B_{M-1} $
Output Format
Output $ \displaystyle\sum_{i=0}^{K-1} \min(A_{i\bmod N}, B_{i \bmod M}) $ , modulo $ 998244353 $ .
Explanation/Hint
### Sample Explanation 1
The desired value is $ \min(3,1)+\min(1,5)+\min(4,1)+\min(3,5)+\min(1,1)=7 $ .
### Sample Explanation 3
Compute modulo $ 998244353 $ .
### Constraints
- $ 1\le N,M\le 2\times 10^5 $
- $ 1\le K\le 10^{18} $
- $ 1\le A_i,B_i\le 10^9 $
- All input values are integers.