#P5686. [CSP-S 2019 江西] 和积和

[CSP-S 2019 江西] 和积和

Background

JXCSP-S T2

Problem Description

Given two sequences ai,bia_i, b_i indexed from 11 to nn, define the function S(l,r)S(l, r) (1lrn)(1 \le l \le r \le n) as:

i=lrai×i=lrbi\sum_{i=l}^r a_i \times \sum_{i=l}^r b_i

Please compute the value of the following expression:

l=1nr=lnS(l,r)\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 109+710^9 + 7.

Input Format

The first line contains a positive integer nn indicating the length of the sequences.
The second line contains nn positive integers representing aia_i.
The third line contains nn positive integers representing bib_i.

Output Format

Output a single integer, the result modulo 109+710^9 + 7.

3
2 3 4
3 4 5
244
5
11 22 33 44 55
12 34 56 78 90
201542

Hint

Constraints
For 20%20\% of the testdata: n10n \le 10, ai,bi10a_i, b_i \le 10.
For 40%40\% of the testdata: n200n \le 200, ai,bi100a_i, b_i \le 100.
For 70%70\% of the testdata: n3000n \le 3000, ai,bi105a_i, b_i \le 10^5.
For 100%100\% of the testdata: 3n5×1053 \le n \le 5 \times 10^5, 1ai,bi1091 \le a_i, b_i \le 10^9.

Translated by ChatGPT 5