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.math.*;
public class hc {
	InputStream is;
	PrintWriter out;
	long mod=pow(10,9)+7;
	static int block;
	static boolean prime[];
	void solve()
	{
		int n=ni();
		int q=ni();
		block=(int)Math.sqrt(n);
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=ni();
		Query p[]=new Query[q];
		for(int i=0;i<q;i++)
			p[i]=new Query(ni()-1,ni()-1,i);
		Arrays.sort(p);
		long count=0;
		long freq[]=new long[1000000+1];
		int curl=0,curr=-1;
		long ans[]=new long[q];
		for(int i=0;i<q;i++)
		{
			int l=p[i].l;
			int r=p[i].r;
			while(curl<l)
			{
				count-=(freq[a[curl]]+freq[a[curl]]-1)*a[curl];
				freq[a[curl]]--;
				curl++;
			}
			while(curl>l)
			{
				curl--;
				count+=(freq[a[curl]]+freq[a[curl]]+1)*a[curl];
				freq[a[curl]]++;
			}
			while(curr>r)
			{
				count-=(freq[a[curr]]+freq[a[curr]]-1)*a[curr];
				freq[a[curr]]--;
				curr--;
			}
			while(curr<r)
			{
				curr++;
				count+=(freq[a[curr]]+freq[a[curr]]+1)*a[curr];
				freq[a[curr]]++;
			}
			ans[p[i].in]=count;
		}
		for(int i=0;i<q;i++)
			out.println(ans[i]+" ");
	}
	public static void prime(int n)
	{
		prime=new boolean[n+1];
		int count=0;
		for(int i=2;i*i<=n;i++)
		{
			if(prime[i])
				continue;
			for(int j=i;j*i<=n;j++)
			{
				prime[i*j]=true;
			}
		}
	}
	static class Query implements Comparable<Query>
	{
		private int l,r,in,size;	
		public Query(int l, int r,int in) 
		{ 
			this.l = l;
			this.r = r;
			this.in=in;
			this.size=l/block;
		}
		@Override
		public int compareTo(Query o) 
		{
			// TODO Auto-generated method stub
			if(this.size!=o.size)
				return this.size-o.size;
			else
				return this.r-o.r;
		}
	}
	static class Pair implements Comparable<Pair>{
		 
        int x,y,k,i;
        
	Pair (int x,int y,int i){
		this.x=x;
		this.y=y;
		this.i=i;
	}
        
	public int compareTo(Pair o) {
			if(this.x!=o.x)
				return	this.x/block-o.x/block;
			else
				return 	this.y-o.y;
	}
 
        public boolean equals(Object o) {
            if (o instanceof Pair) {
                Pair p = (Pair)o;
                return p.x == x && p.y == y && p.k==k;
            }
            return false;
        }
           
 
        @Override
        public String toString() {
            return  "("+x + " " + y +" "+k+" "+i+" )";
        }
    
    } 
	public static int count(int num)
	{
		int count=0;
		while(num!=0)
		{
			num=num&(num-1);
			count++;
		}
		return count;
	}
	/*static long d, x, y;
	void extendedEuclid(long A, long B) {
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	long modInverse(long A,long M) //A and M are coprime
	{
	    extendedEuclid(A,M);
	    return (x%M+M)%M;    //x may be negative
	}*/
	public static void mergeSort(int[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(int arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		int left[] = new int[n1];
		int right[] = new int[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	public static void mergeSort(long[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(long arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		long left[] = new long[n1];
		long right[] = new long[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	    
	    public static boolean isPal(String s){
	        for(int i=0, j=s.length()-1;i<=j;i++,j--){
	                if(s.charAt(i)!=s.charAt(j)) return false;
	        }
	        return true;
	    }
	    public static String rev(String s){
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
	    }
	    
	    public static long gcd(long x,long y){
		if(x%y==0)
			return y;
		else
			return gcd(y,x%y);
	    }
	    
	    public static int gcd(int x,int y){
		if(x%y==0)
			return y;
		else 
			return gcd(y,x%y);
	    }
	    
	    public static long gcdExtended(long a,long b,long[] x){
	        
	        if(a==0){
	            x[0]=0;
	            x[1]=1;
	            return b;
	        }
	        long[] y=new long[2];
	        long gcd=gcdExtended(b%a, a, y);
	        
	        x[0]=y[1]-(b/a)*y[0];
	        x[1]=y[0];
	        
	        return gcd;
	    }
	    
	    public static int abs(int a,int b){
		return (int)Math.abs(a-b);
	    }
	 
	    public static long abs(long a,long b){
		return (long)Math.abs(a-b);
	    }
	    
	    public static int max(int a,int b){
		if(a>b)
			return a;
		else
			return b;
	    }
	 
	    public static int min(int a,int b){
		if(a>b)
			return b;
		else 
			return a;
	    }
	    
	    public static long max(long a,long b){
		if(a>b)
			return a;
		else
			return b;
	    }
	 
	    public static long min(long a,long b){
		if(a>b)
			return b;
		else 
			return a;
	    }
	 
	    public static long pow(long n,long p,long m){
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	    }
	    
	    public static long pow(long n,long p){
		long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;	    
		    p >>=1;
		    n*=n;	    
		}
		return result;
	    }
	    public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
	    void run() throws Exception {
			is = System.in;
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		}
	   
	    public static void main(String[] args) throws Exception {
			new Thread(null, new Runnable() {
				public void run() {
					try {
						new hc().run();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "1", 1 << 26).start();
		}
	    private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;
	 
		private int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}
	 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
	 
		private int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b));
			return b;
		}
	 
		private double nd() {
			return Double.parseDouble(ns());
		}
	 
		private char nc() {
			return (char) skip();
		}
	 
		private String ns() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
	 
		private char[] ns(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}
	 
		private char[][] nm(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = ns(m);
			return map;
		}
	 
		private int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = ni();
			return a;
		}
	 
		private int ni() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}
	 
			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}
	 
		private long nl() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}
	 
			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}
	 
}