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.io.*;
import java.math.*;
import java.util.*;


/**
 *
 * @author Saju
 *
 */

public class Main {

	private static int dx[] = { 1, 0, -1, 0 };
	private static int dy[] = { 0, -1, 0, 1 };

	private static final long INF = Long.MAX_VALUE;
	private static final int INT_INF = Integer.MAX_VALUE;
	private static final long NEG_INF = Long.MIN_VALUE;
	private static final int NEG_INT_INF = Integer.MIN_VALUE;
	private static final double EPSILON = 1e-10;

	private static final int MAX = 1000007;
	
	private static final long MOD = 1000000007;

	private static final int MAXN = 10000007;
	private static final int MAXA = 10000009;
	private static final int MAXLOG = 22;

	public static void main(String[] args) throws IOException {

		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);

//		 InputReader in = new InputReader(new FileInputStream("src/test.in"));
//		 PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));



/*

9
1 2 3 4 5 6 7 8 9
7
1 4
2 8
3 9
8 9
5 9
5 5
2 3


5
1 1 2 1 3
3
1 5
2 4
3 5


*/
		int n = in.nextInt();
		int q = in.nextInt();
		
		int arr[] = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		
		MO mos = new MO(n, arr, q);
		
		for(int i = 0; i < q; i++) {
			int left = in.nextInt() - 1;
			int right = in.nextInt() - 1;
			mos.addQuery(i, left, right);
		}
		
		String ans = mos.getAns();
		out.println(ans);
		
		out.flush();
		out.close();
		System.exit(0);
	}
	
	private static class MO{
		
		private final int MAXA = 1000007;
		private long answer = 0;
		private final int blockSize;
		
		private int n;
		private int arr[];
		private int q;
		private Query queries[];
		private int frequency[];
		private long ans[];
		private int qC = 0;
		
		
		public MO(int n, int arr[], int q){
			this.n = n;
			this.arr = new int[n];
			for(int i = 0; i < n; i++) {
				this.arr[i] = arr[i];
			}
			this.q = q;
			queries = new Query[q];
			int sz = (int) Math.sqrt(n);
			if(sz * sz != n) {
				sz++;
			}
			blockSize = sz;
			frequency = new int[MAXA];
			ans = new long[q];
		}
		
		public void addQuery(int index, int left, int right) {
			queries[qC++] = new Query(index, left, right);
		}
		
		private void runMOS() {
			Arrays.sort(queries, new Comparator<Query>() {

				@Override
				public int compare(Query q1, Query q2) {
					int q1Block = q1.left / blockSize;
					int q2Block = q2.left / blockSize;
					if(q1Block == q2Block) {
						return q1.right - q2.right;
					}
					return q1Block - q2Block;
				}
			});
			
//			for(Query query : queries) {
//				System.out.println(query.left + " " + query.right);
//			}
			
			int currentLeft = queries[0].left;
			int currentRight = queries[0].left;
			
			add(currentLeft);
			
			for(int i = 0; i < q; i++) {
				Query query = queries[i];
				int left = query.left;
				int right = query.right;
				
				while(currentLeft < left) {
					remove(currentLeft);
					currentLeft++;
				}
				
				while(currentLeft > left) {
					add(currentLeft - 1);
					currentLeft--;
				}
				
				while(currentRight < right) {
					add(currentRight + 1);
					currentRight++;
				}
				while(currentRight > right) {
					remove(currentRight);
					currentRight--;	
				}
//				System.out.println(currentLeft + " " + currentRight);
				ans[query.index] = answer;
			}
		}
		public String getAns() {
			runMOS();
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < q; i++) {
				sb.append(ans[i] + "\n");
			}
			return sb.toString();
		}
		
		
		private void add(int index) {
			int k1 = frequency[arr[index]];
			frequency[arr[index]]++;
			int k2 = k1 + 1;
			
			if(k1 == 0) {
//				answer++;
				answer += arr[index];
			}
			else {
				long extra = arr[index] * ((k2 * k2) - (k1 * k1));
				answer += extra;
			}
		}

		private void remove(int index) {
			int k1 = frequency[arr[index]];
			frequency[arr[index]]--;
			int k2 = k1 - 1;
			if(k2 == 0) {
				answer -= arr[index];
			}
			else {
				long extra = arr[index] * ((k1 * k1) - (k2 * k2));
				answer -= extra;
			}
		}
		
		private class Query{
			int index;
			int left;
			int right;
			
			Query(int index, int left, int right){
				this.index = index;
				this.left = left;
				this.right = right;
			}
		}
	}
	
	
	private static long bigMod(long n, long k, long m) {

		long ans = 1;
		while (k > 0) {
			if ((k & 1) == 1) {
				ans = (ans * n) % m;
			}
			n = (n * n) % m;
			k >>= 1;
		}
		return ans;
	}
	
	private static int ceil(int n, int x) {
		int div = n / x;
		if(div * x != n) {
			div++;
		}
		return div;
	}

	private static class Point {
		double x;
		double y;

		Point(double x, double y) {
			this.x = x;
			this.y = y;
		}

		double getDistance(Point p2) {
			Point p1 = this;
			double dx = p1.x - p2.x;
			double dy = p1.y - p2.y;

			return Math.sqrt((dx * dx) + (dy * dy));
		}
	}

	private static int abs(int x) {
		if (x < 0) {
			return -x;
		}
		return x;
	}

	private static long abs(long x) {
		if(x < 0) {
			return -x;
		}
		return x;
	}

	private static int lcm(int a, int b) {
		return (a * b) / gcd(a, b);
	}

	private static int gcd(int a, int b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	private static int log(long x, int base) {
		return (int) (Math.log(x) / Math.log(base));
	}

	private static long min(long a, long b) {
		if (a < b) {
			return a;
		}
		return b;
	}

	private static int min(int a, int b) {
		if (a < b) {
			return a;
		}
		return b;
	}

	private static long max(long a, long b) {
		if (a < b) {
			return b;
		}
		return a;
	}

	private static int max(int a, int b) {
		if (a < b) {
			return b;
		}
		return a;
	}

	private static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public String next() {
			try {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					tokenizer = new StringTokenizer(reader.readLine());

				}
			} catch (IOException e) {
				return null;
			}
			return tokenizer.nextToken();
		}

		public String nextLine() {
			String line = null;
			try {
				tokenizer = null;
				line = reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			return line;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public boolean hasNext() {
			try {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					tokenizer = new StringTokenizer(reader.readLine());
				}
			} catch (Exception e) {
				return false;
			}
			return true;
		}
	}
}