Problem10659--Sona

10659: Sona

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

Sona , Maven of the Strings . Of cause, she can play the zither. Sona can't speak but she can make fancy music. Her music can attack, heal, encourage and enchant.There're an ancient score. But because it's too long, Sona can't play it in a short moment. So Sona decide to just play a part of it and revise it. A score is composed of notes. There are $10^9$ kinds of notes and a score has $10^5$ notes at most.To diversify Sona's own score, she have to select several parts of it. The energy of each part is calculated like that:Count the number of times that each notes appear. Sum each of the number of times' cube together. And the sum is the energy.You should help Sona to calculate out the energy of each part.

Input

This problem contains several cases. And this problem provides 2 seconds to run. 
The first line of each case is an integer $N\ (1 ≤ N ≤ 10^5)$, indicates the number of notes. 
Then $N$ numbers followed. Each number is a kind of note. $(1 ≤ \text{note} ≤ 10^9)$ 
Next line is an integer $Q\ (1 ≤ Q ≤ 10^5)$, indicates the number of parts. 
Next $Q$ parts followed. Each part contains $2$ integers $L_i$ and $R_i$, indicates the left side of the part and the right side of the part.

Output

For each part, you should output the energy of that part.

Sample 1 Input

8
1 1 3 1 3 1 3 3
4
1 8
3 8
5 6
5 5

Sample 1 Output

128
72
2
1

Source/Category

莫队