9 10
6 2 3 1 4 8 5 9 8
3 9
6 6
9 9
9 9
9 9
2 3
3 9
3 8
6 9
5 6
 10 10
5 10 9 2 9 3 5 5 6 5
5 10
2 2
3 10
4 8
1 3
1 5
5 5
10 10
8 9
6 10
 8 10
100 100 100 100 100 100 100 100
1 8
2 8
3 8
4 8
5 8
6 8
7 8
8 8
1 1
1 5
 5 15
103 45 103 67 45
1 1
1 2
1 3
1 4
1 5
2 2
2 3
2 4
2 5
3 3
3 4
3 5
4 4
4 5
5 5
 1 1
1000000
1 1
 10 5
10 9 8 7 6 5 4 3 2 1
4 8
1 10
3 9
2 2
5 10
 9 10
5 3 10 2 4 8 7 5 1
6 9
1 8
3 3
2 7
3 5
4 6
9 9
8 8
1 9
5 6
 9 10
10 2 6 2 4 6 6 4 1
4 8
8 9
2 3
8 9
9 9
4 5
1 7
6 6
6 8
1 1
 20 8
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2
4 15
1 2
2 20
7 7
13 18
7 7
3 19
3 8
 1 2
1
1 1
1 1
 8 10
5 7 3 1 4 2 1 1
5 7
3 8
2 7
4 8
4 5
2 8
4 6
1 2
4 7
3 5

54
8
8
8
8
5
54
30
46
12
 63
10
92
34
24
53
9
5
11
54
 6400
4900
3600
2500
1600
900
400
100
100
2500
 103
148
457
524
659
45
148
215
350
103
170
215
67
112
45
 1000000
 25
55
35
9
21
 21
54
10
34
16
14
1
5
55
12
 42
5
8
5
1
6
76
6
28
10
 108
3
281
1
27
1
209
27
 1
1
 7
18
20
15
5
25
7
12
10
8



import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

import static java.lang.Math.*;

public class ProblemD_Yandex_Round_2_2010_2011 implements Runnable{
	
	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");
	
	void init() throws FileNotFoundException{
		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}
	
	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(in.readLine());
			}catch (Exception e){
				return null;
			}
		}
		return tok.nextToken();
	}
	
	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}
	
	long readLong() throws IOException{
		return Long.parseLong(readString());
	}
	
	double readDouble() throws IOException{
		return Double.parseDouble(readString());
	}
	
	public static void main(String[] args){
		new Thread(null, new ProblemD_Yandex_Round_2_2010_2011(), "", 128 * (1L << 20)).start();
	}
	
	long timeBegin, timeEnd;

	void time(){
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}
	
	long memoryTotal, memoryFree;
	

	void memory(){
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
	}
	
	void debug(Object... objects){
		if (DEBUG){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}
	
	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			memoryTotal = Runtime.getRuntime().freeMemory();
			init();
			solve();
			out.close();
			time();
			memory();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}
	
	boolean DEBUG = false;
	
	class Query implements Comparable<Query>{
		
		int l, r;
		int index;
		
		public Query(int l, int r, int index) {
			super();
			this.l = l;
			this.r = r;
			this.index = index;
		}

		@Override
		public int compareTo(Query q) {
			return l - q.l;
		}
		
		
	}
	
	int MAX_N = 1000 * 1000 + 1;
	
	void solve() throws IOException{
		int n = readInt();
		int t = readInt();
		
		int[] a = new int[n];
		
		int[] ids = new int[MAX_N];
		Arrays.fill(ids, -1);
		int curIndex = 0;
		
		int[] values = new int[n];
		Arrays.fill(values, -1);
		
		for (int i = 0; i < n; ++i){
			int value = readInt();
			
			if (ids[value] == -1){
				ids[value] = curIndex;
				values[curIndex++] = value;
			}
			
			a[i] = ids[value];
		}
		
		
		int len = (int) floor(sqrt(n)) + 1;
		int[] sizes = new int[len+1];
		sizes[0] = 0;
		for (int i = 1; i < sizes.length; ++i){
			sizes[i] = sizes[i-1] + len;
		}
		
		List<Query>[] lists = new List[len+1];
		for (int i = 0; i <= len; ++i){
			lists[i] = new ArrayList<ProblemD_Yandex_Round_2_2010_2011.Query>();
		}
		
		for (int i = 0; i < t; ++i){
			int l = readInt() - 1;
			int r = readInt() - 1;
			
			int queryLen = (r - l + 1);
			int queryIndex = queryLen / len;
			
			lists[queryIndex].add(new Query(l, r, i));
		}
		
		long[] ans = new long[t];
		
		int[] counts = new int[n];
		Arrays.fill(counts, 0);
//		Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
		
		for (int i = 0; i <= len; ++i){
			int size = sizes[i];
			
			List<Query> list = lists[i];
			if (list.size() == 0){
				continue;
			}
			
			Collections.sort(list);
			
			long curAns = 0;
			Arrays.fill(counts, 0);
			for (int j = 0; j < min(n, size); ++j){
//				long oldCount = add(a[j], counts);
				
				long oldCount = counts[a[j]];
				++counts[a[j]];
				
				curAns += (2 * oldCount + 1) * values[a[j]];
			}
			
			int curQuery = 0;
			int curL = list.get(curQuery).l;
			
		it:	for (int l = 0; l <= n - size; ++l){
				while (l == curL){
					Query q = list.get(curQuery);
					
					int index = q.index;
					ans[index] = curAns;
					
					int r = q.r;
					
					for (int j = l + size; j <= r; ++j){
//						long oldCount = add(a[j], counts);
						
						long oldCount = counts[a[j]];
						++counts[a[j]];
						
						ans[index] += (2 * oldCount + 1) * values[a[j]];
					}
					
					for (int j = r; j >= l + size; --j){
//						remove(a[j], counts);
						--counts[a[j]];
					}
					
					++curQuery;
					
					if (curQuery == list.size()){
						break it;
					}else{
						curL = list.get(curQuery).l;
					}
				}
				
				if (i > 0){
//					long oldCount = remove(a[l], counts);
					long oldCount = counts[a[l]];
					--counts[a[l]];
					
					curAns += (-2 * oldCount + 1) * values[a[l]];
					

					if (l + size < n) {
//						oldCount = add(a[l+size], counts);
						
						oldCount = counts[a[l+size]];
						++counts[a[l+size]];
						
						curAns += (2 * oldCount + 1) * values[a[l+size]];
					} 
				}
			}
		}
		
		
		for (int i = 0; i < t; ++i){
			out.println(ans[i]);
		}
	}
}

