PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000012. Sức mạnh của đoạn mảng (Powerful array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Sức mạnh của đoạn mảng (Powerful array)

Powerful array

Source: Codeforces Version: Phuoc Hung OJ Extended

Problem Statement

For a range [l,r][l,r], let fxf_x be the frequency of value xx in that range. Its power is ∑xx⋅fx2\sum_x x\cdot f_x^2 over all values present. Compute the power of every queried range. Answers may require a 64-bit integer.

Input

The first line contains N,QN,Q. The second line has NN positive integers aia_i. The next QQ lines contain l,rl,r.

Output

Print QQ lines, one answer per query in the original order.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301\le N\le 30; 1≤Q≤301\le Q\le 30; 1≤ai≤10000001\le a_i\le 1000000; 1≤l≤r≤N1\le l\le r\le N.
  • Subtask 2 (30 points): 1≤N≤22001\le N\le 2200; 1≤Q≤22001\le Q\le 2200; 1≤ai≤10000001\le a_i\le 1000000; 1≤l≤r≤N1\le l\le r\le N.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤Q≤2000001\le Q\le 200000; 1≤ai≤10000001\le a_i\le 1000000; 1≤l≤r≤N1\le l\le r\le N.

Examples

Input

3 2
1 2 1
1 2
1 3

Output

3
6

Explanation

Range [1,3][1,3] has f1=2f_1=2, f2=1f_2=1. Its power is 1⋅22+2⋅12=61\cdot 2^2+2\cdot 1^2=6.