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.util.function.Function;
import java.util.stream.Collectors;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.math.*;



public class Main
{
	static StringBuilder sb;
	static dsu dsu;
	static long fact[];
	static long mod=(long)(1e8);
	static ArrayList<Integer>adj[];
	static ArrayList<Integer>prime;
	static int n,len;
	static int A[];
	static int s[];
	static int fre[];
	static long Ans[];
	static int cnt,ml,mr;
	static long power;
	static query q[];
	
	
	
	static void add(int el)
	{
		int pref=fre[el];
		power=(long)power-(long)pref*pref*el;
		fre[el]++;
		power+=(long)fre[el]*fre[el]*el;
	}
	static void remove(int el)
	{
		int pref=fre[el];
		power=(long)power-(long)pref*pref*el;
		fre[el]--;
		power+=(long)fre[el]*fre[el]*el;
		
		
		
	}
	static class query implements Comparable<query>
	{
		int l;int r; int ind;
		query(int l, int r, int ind)
		{
			this.l=l;this.r=r;this.ind=ind;
		}
		public int compareTo(query o)
		{
			int x=l/len;
			int y=o.l/len;
			if(x==y)
			{
				return Integer.compare(r,o.r);
			}
			else
				return Integer.compare(x,y);
		}
	}
	 
	
	
	static void solve()
	{
		       n=i();
		       cnt=0;
		       ml=0;
		       mr=-1;
		       power=0;
		       fre=new int[1000000+10];
		       int nq=i();
		     A=new int[n];
		 for(int i=0;i<n;i++)
			 A[i]=i();
		 len=(int)Math.sqrt(n+0.0)+1;
		 
		 q=new query[nq];
		 
		Ans=new long[nq];
		 for(int k=0;k<nq;k++)
		 {
			 int l=i()-1;
			 int r=i()-1;
			 q[k]=new query(l,r,k);
		 }
		 
		 Arrays.sort(q);
		 for(int i=0;i<q.length;i++)
		 {
			 int s=q[i].l;
			 int end=q[i].r;
			 int ansind=q[i].ind;
			 
			 while(mr<end)
			 {
				 mr++;
				 add(A[mr]);
			 }
			 while(ml>s)
			 {
				 ml--;
				 add(A[ml]);
			 }
			 while(ml<s)
			 {
				
				 remove(A[ml]);
				 ml++;
			 }
			 while(mr>end)
			 {
				
				 remove(A[mr]);
				 mr--;
			 }
			 Ans[ansind]=power;
			 }
		 
		 for(int i=0;i<Ans.length;i++)
		 {
			sb.append(Ans[i]);
			sb.append("\n");
		 }
		 
		 
		 
		 
		 
		 
		 
		 
		 
		
		
	}
	
		
		
	
	
	
	public static void main(String[] args)
	 {
		
	         sb=new StringBuilder();
	        int test=1;
	        while(test-->0) 
	        {
	        	solve();
	        }
	         System.out.println(sb);       
	 }
//*******************************************NCR%P*******************************************************	 
	 static long ncr(int n, int r)
	 {
		 if(r>n)
	     return (long)0;
		 long res=fact[n]%mod;
		 
		 res=((long)(res%mod)*(long)(p(fact[r],mod-2)%mod))%mod;
		 res=((long)(res%mod)*(long)(p(fact[n-r],mod-2)%mod))%mod;
		 
		 return res;
	 }
		static long p(long x, long y)//POWER FXN //
		{
			if(y==0)
				return 1;
			
			long res=1;
			while(y>0)
			{
				if(y%2==1)
				{
					res=(res*x)%mod;
					y--;
				}
				
				x=(x*x)%mod;
				y=y/2;
				
				
			}
			return res;
		}
		

//*******************************************   END   ********************************************************//
		static int LowerBound(long a[], long x, int i, int j) 
		{ 
			
			int l=i;int r=j;
			int lb=-1;
			  while(l<=r)
			  {
			    int m=(l+r)/2;
			    
			    if(a[m]>=x) 
			    {
			    	lb=m;
			    	r=m-1;
			    }
			    else l=m+1;
			  }
			  return lb;
		}
		static int UpperBound(long a[], long x, int i, int j) 
		{// x is the key or target value
		    int l=i,r=j;
		    int ans=-1;
		    while(l<=r)
		    {
		       int m=(l+r)/2;
		       
		       if(a[m]<=x) 
		       {
		    	   ans=m;
		    	   l=m+1;
		       }
		       else r=m-1;
		    }
		    return ans;
		 }
		
		
		
		
//*********************************     Disjoint set union    ****************************************************//
	 static class dsu
	 {
		 int parent[];
		 dsu(int n)
		 {
			 parent=new int[n];
			 for(int i=0;i<n;i++)
				 parent[i]=-1;
		 }
		 int find(int a)
		 {
			 if(parent[a]<0)
				 return a;
			 else
			 {
				 int x=find(parent[a]);
				 parent[a]=x;
				 return x;
			 }
		 }
		 void merge(int a,int b)
		 {
			 a=find(a);
			 b=find(b);
			 if(a==b)
				 return;
			 parent[b]=a;
		 }
	 }
	 
	 
	 
//*******************************************PRIME FACTORIZE *****************************************************************************************************//
	 static TreeMap<Integer,Integer> prime(long n)
	 {
		 TreeMap<Integer,Integer>h=new TreeMap<>();
		 long num=n;
		 for(int i=2;i<=Math.sqrt(num);i++)
		 {
			 if(n%i==0)
			 {
				 int nt=0;
				 while(n%i==0) {
					 n=n/i;
					 nt++;
				 }
				 h.put(i, nt);
			 }
		 }
		 if(n!=1)
			 h.put((int)n, 1);
		 return h;
		 
	 }
	 
//*************CLASS PAIR ***********************************************************************************************************************************************
	    static class pair implements Comparable<pair>
	    {
	        long x;
	        long y;
	        pair(long x, long y) 
	        {
	            this.x = x;
	            this.y = y;
	            
	        }
	        public int compareTo(pair o)
	        {
	        	if(Long.compare(x, o.x)==0)
	        	{
	        		return Long.compare(y,o.y);
	        	}
	        	else
	        		return Long.compare(x, o.x);
	        	
	        }
	    }
//*************CLASS PAIR *****************************************************************************************************************************************************
	
	    
	    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int Int() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String String() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return String();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }
    }

    static InputReader in = new InputReader(System.in);
    static OutputWriter out = new OutputWriter(System.out);
   

    public static int[] sort(int[] a) {
        int n = a.length;
        ArrayList<Integer> l = new ArrayList<>();
        for (int i : a)
            l.add(i);
        Collections.sort(l);
        for (int i = 0; i < l.size(); i++)
            a[i] = l.get(i);
        return a;
    }
    public static long[] sort(long[] a) {
        int n = a.length;
        ArrayList<Long> l = new ArrayList<>();
        for (long i : a)
            l.add(i);
        Collections.sort(l);
        for (int i = 0; i < l.size(); i++)
            a[i] = l.get(i);
        return a;
    }

    public static long pow(long x, long y) {
        long res = 1;
        while (y > 0) {
            if (y % 2 != 0) {
                res = (res * x);// % modulus;
                y--;

            }
            x = (x * x);// % modulus;
            y = y / 2;
        }
        return res;
    }
//GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    public static long gcd(long x, long y) {
        if (x == 0)
            return y;
        else
            return gcd(y % x, x);
    }
    //****************LOWEST COMMON MULTIPLE   *************************************************************************************************************************************

    public static long lcm(long x, long y) {
        return (x * (y / gcd(x, y)));
    }
//INPUT PATTERN******************************************************************************************************************************************************************
    public static int i() {
        return in.Int();
    }

    public static long l() {
        String s = in.String();
        return Long.parseLong(s);
    }

    public static String s() {
        return in.String();
    }

    public static int[] readArray(int n) {
        int A[] = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = i();
        }
        return A;
    }

    public static long[] readArray(long n) {
        long A[] = new long[(int) n];
        for (int i = 0; i < n; i++) {
            A[i] = l();
        }
        return A;
    }

}
