Time limit: 0.55sMemory limit: 256MBInput: Output:
Consider a sequence of integers a1,...,ak. We call the value of a1,...,ak, which we denote by (a1,...,ak), the maximal integer 2x=x times2×...×2 such that 2x divides a1+...+ak. For example, if k=3 and a1=8,a2=3,a3=1 then a1+a2+a3=12 and the value of the sequence is 4.
You are given a sequence of n positive integers a1,...,an. Calculate the remainder sum of the value of all the contiguous subsequences of a1,...,an when divided by 109+7, which is equal to S(a1,...,an)=i=1∑nj=i∑n(ai,...,aj)(mod 109+7)
In other words, S(a1,...,an) is the remainder of the sum of (ai,...,aj) for 1≤i≤j≤n when divided by 109+7.
Input data
The first line of the input contains the integer n. The second line of the inputs contains the integers a1,...,an, separated by white space.
Output data
The output must contain a single line, which contains the integer S(a1,...,an).
Restrictions
1≤n≤200000.
1≤ai≤1000000.
a1+...+an≤1000000.
Subtask 1 (13 points)
ai=1,n≤200
Subtask 2 (16 points)
a1+...+an≤200
Subtask 3 (5 points)
n≤200
Subtask 4 (20 points)
n≤5000
Subtask 5 (21 points)
a1+...+an≤200000
Subtask 6 (25 points)
No further restrictions
Examples
stdin
3
1 2 3
stdout
8
stdin
5
2 4 1 2 4
stdout
25
stdin
20
1 2 3 1 2 3 4 5 6 2 3 3 1 2 3 7 5 1 2 3 2
stdout
728
Explanations
First example: The values of all the contiguous subsequences are:
(1)=1
(1,2)=1
(1,2,3)=2
(2)=2
(2,3)=1
(3)=1
Thus S(1,2,3) is the remainder of sum of these values when divided by 109+7 i.e. 8.
Second example: The values of all the contiguous subsequences are:
(2)=2
(2,4)=2
(2,4,1)=1
(2,4,1,2)=1
(2,4,1,2,4)=1
(4)=4
(4,1)=1
(4,1,2)=1
(4,1,2,4)=1
(1)=1
(1,2)=1
(1,2,4)=1
(2)=2
(2,4)=2
(4)=4
Thus S(2,4,1,2,4) is the remainder of the sum of these values when divided by 109+7 i.e. 25.