Module: Mo algorithm


Problem

2 /4


powerful array

Problem

There is an array of natural numbers a1, a2, ..., an. Consider some of its subarrays al, al + 1, ..., ar, where 1 ≤ l ≤ r ≤ n, and for each natural number s denote by Ks the number of occurrences of the number s in this subarray. Let's call the cardinality of a subarray the sum of the products Ks·Ks·s over all distinct integers s. Since the number of different numbers in the array is finite, the sum contains only a finite number of non-zero terms.

It is necessary to calculate the cardinalities of each of the t given subarrays.

Input
The first line contains two integers n and t (1 ≤ n, t ≤ 200000) — the length of the array and the number of requests, respectively.
The second line contains n natural numbers ai (1 ≤ ai ≤ 106) — array elements.
The next t lines contain two positive integers l and r (1 ≤ l ≤ r ≤ n) — indexes of the left and right ends of the corresponding subarray.

Imprint
Print t lines, where the i-th line contains the only natural number — cardinality of the i-th query subarray.

Examples:
 
Input Output
3 2
1 2 1
1 2
1 3
3
6
8 3
1 1 2 2 1 3 1 1
27
16
27
20
20
20