P5686 [CSP-S 2019 Jiangxi] Sum of Product of Sums.
Background
JXCSP-S T2
Description
Given two sequences $a_i, b_i$ indexed from $1$ to $n$, define the function $S(l, r)$ $(1 \le l \le r \le n)$ as:
$$\sum_{i=l}^r a_i \times \sum_{i=l}^r b_i$$
Please compute the value of the following expression:
$$\sum_{l=1}^n \sum_{r=l}^n S(l,r)$$
Since the answer may be very large, you only need to output the result modulo $10^9 + 7$.
Input Format
The first line contains a positive integer $n$ indicating the length of the sequences.
The second line contains $n$ positive integers representing $a_i$.
The third line contains $n$ positive integers representing $b_i$.
Output Format
Output a single integer, the result modulo $10^9 + 7$.
Explanation/Hint
Constraints
For $20\%$ of the testdata: $n \le 10$, $a_i, b_i \le 10$.
For $40\%$ of the testdata: $n \le 200$, $a_i, b_i \le 100$.
For $70\%$ of the testdata: $n \le 3000$, $a_i, b_i \le 10^5$.
For $100\%$ of the testdata: $3 \le n \le 5 \times 10^5$, $1 \le a_i, b_i \le 10^9$.
Translated by ChatGPT 5