Under construction

Still being built. Things may change

Period Sequence

Time limit6sMemory limit256 MB

Summary
Given a periodic-plus-growing sequence built from n integers, compute the sum over all subarrays inside index range [a, b] of sum of x times count of x squared, modulo 1e9+7.
Level

Hard9 of 10

Topics
Math, Segment tree, Combinatorics
Solved
No attempts yet

Statement

Chiaki has nn integers s0,s1,…,sn−1s_0, s_1, \dots, s_{n-1}. She defines an infinite sequence SS as follows.

Sk=sk mod n+n⋅⌊kn⌋S_k = s_{k \bmod n} + n \cdot \left\lfloor \frac{k}{n} \right\rfloor

Here kk is a zero-based index.

For a contiguous subsequence S[l..r]S[l..r], let cntxcnt_x be the number of occurrences of xx in S[l..r]S[l..r]. The value of S[l..r]S[l..r] is

f(l,r)=∑xx⋅cntx2f(l,r)=\sum_{x} x \cdot cnt_x^2

For two integers aa and bb (a≤ba \le b), find the value of

(∑a≤l≤r≤bf(l,r)) mod (109+7)\left(\sum_{a \le l \le r \le b} f(l,r)\right) \bmod (10^9+7)

Input

There are multiple test cases. The first line contains an integer TT, the number of test cases. Each test case is as follows.

The first line contains three integers nn, aa, and bb (1≤n≤20001 \le n \le 2000, 0≤a≤b≤10180 \le a \le b \le 10^{18}).

The second line contains nn integers s0,s1,…,sn−1s_0, s_1, \dots, s_{n-1} (0≤si≤1090 \le s_i \le 10^9).

The sum of all nn does not exceed 2⋅1042 \cdot 10^4.

Output

For each test case, print one integer: the answer.

Examples1

  1. Example 1

    Input
    4
    3 2 6
    2 1 3
    5 2 7
    2 1 5 1 2
    4 4 8
    2 1 5 17
    3 5 9
    2 5 2
    
    Expected output
    179
    268
    369
    437