#include<bits/stdc++.h>
#define sc scanf
#define pf printf
#define ll long long int
using namespace std;
int m;
struct qwery{
    int l,h,i;
    qwery(int a=0,int b=0,int e=0){
        l=a;
        h=b;
        i=e;
    }
}q[200005];
bool cmp(qwery a,qwery b){
    if((a.l/m)==(b.l/m))return a.h<b.h;
    else return a.l<b.l;
}
int ar[200005];
ll ans[200005];
int st[1000006];
int main(){
    int n,qr;
    while(sc("%d %d",&n,&qr)==2){
        for(int i=0;i<n;i++)sc("%d",&ar[i]);
        m=sqrt(n);
        for(int i=0;i<qr;i++){
            int l,h;
            sc("%d %d",&l,&h);
            q[i]=qwery(l-1,h-1,i);
        }
        sort(q,q+qr,cmp);
        int lh=0,rh=-1;
        ll cnt=0;
        memset(st,0,sizeof(st));
        for(int i=0;i<qr;i++){
            qwery f=q[i];
            int rf,lf;
            rf=0;lf=0;
            //cout<<" "<<f.l<<" "<<f.h<<endl;
            while(rh<f.h){
                rh++;
                cnt-=(ll)((ll)st[ar[rh]]*(ll)st[ar[rh]]*(ll)ar[rh]);
                st[ar[rh]]++;
                cnt+=(ll)((ll)st[ar[rh]]*(ll)st[ar[rh]]*(ll)ar[rh]);
                rf=1;
            }
            while(lh>f.l){
                lh--;
                cnt-=(ll)((ll)st[ar[lh]]*(ll)st[ar[lh]]*(ll)ar[lh]);
                st[ar[lh]]++;
                cnt+=(ll)((ll)st[ar[lh]]*(ll)st[ar[lh]]*(ll)ar[lh]);
                lf=1;
            }
            while(lh<f.l and lf==0){
                cnt-=(ll)((ll)st[ar[lh]]*(ll)st[ar[lh]]*(ll)ar[lh]);
                st[ar[lh]]--;
                cnt+=(ll)((ll)st[ar[lh]]*(ll)st[ar[lh]]*(ll)ar[lh]);
                lh++;
            }
            while(rh>f.h and rf==0){
                cnt-=(ll)((ll)st[ar[rh]]*(ll)st[ar[rh]]*(ll)ar[rh]);
                st[ar[rh]]--;
                cnt+=(ll)((ll)st[ar[rh]]*(ll)st[ar[rh]]*(ll)ar[rh]);
                rh--;
            }
            ans[q[i].i]=cnt;
            //cout<<cnt<<endl;
        }
        for(ll i=0;i<qr;i++){
            pf("%I64d\n",ans[i]);
        }
    }
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200002
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000002];
lli rslt[mx];
struct query{
   int l, r, p;
}q[mx];
bool cmp(query x, query y){
   return (x.l/m==y.l/m)?(x.r<y.r):(x.l<y.l);
}
int main()
{
   //cin>>n>>t;
   scanf("%d %d", &n, &t);
   m=sqrt(n+1);
   for(int i=0; i<n; i++) scanf("%d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; //q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      /*if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }*/

      while(r>q[i].r){
         r--;
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]--;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
      }
      while(r<=q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]++;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r++;
      }
      while(l<q[i].l){
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]--;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         l++;
      }
      while(l>q[i].l){
         l--;
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]++;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200001
using namespace std;
typedef long long lli;
int n, t, m; lli a[mx], k[1000001];
lli rslt[mx];
struct query{
   int l, r, p;
}q[mx];
bool cmp(query x, query y){
   if(x.l/m==y.l/m) return x.r<y.r;
   return x.l<y.l;
}
int main()
{
   scanf("%d %d", &n, &t);
   m=sqrt(n);
   for(int i=0; i<n; i++) scanf("%I64d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      while(r>q[i].r){
         r--;
         ans+=(-2LL*k[a[r]]+1)*a[r];
         k[a[r]]--;
      }
      while(r<=q[i].r){
         ans+=(2LL*k[a[r]]+1)*a[r];
         k[a[r]]++;
         r++;
      }
      while(l<q[i].l){
         ans+=(-2LL*k[a[l]]+1)*a[l];
         k[a[l]]--;
         l++;
      }
      while(l>q[i].l){
         l--;
         ans+=(2LL*k[a[l]]+1)*a[l];
         k[a[l]]++;
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200001
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000001];
lli rslt[mx];
struct query{
   int l, r, p;
}q[mx];
bool cmp(query x, query y){
   if(x.l/m==y.l/m) return x.r<y.r;
   return x.l<y.l;
}
int main()
{
   //cin>>n>>t;
   scanf("%d %d", &n, &t);
   m=sqrt(n);
   for(int i=0; i<n; i++) scanf("%d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; //q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      /*if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }*/

      while(r>q[i].r){
         r--;
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]--;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
      }
      while(r<=q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]++;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r++;
      }
      while(l<q[i].l){
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]--;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         l++;
      }
      while(l>q[i].l){
         l--;
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]++;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200001
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000001];
lli rslt[mx];
struct query{
   int l, r, p;
}q[mx];
bool cmp(query x, query y){
   if(x.l/m==y.l/m) return x.r<y.r;
   return x.l<y.l;
}
int main()
{
   scanf("%d %d", &n, &t);
   m=sqrt(n);
   for(int i=0; i<n; i++) scanf("%d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; //q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      /*if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }*/

      while(r>q[i].r){
         r--;
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]--;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
      }
      while(r<=q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]++;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r++;
      }
      while(l<q[i].l){
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]--;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         l++;
      }
      while(l>q[i].l){
         l--;
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]++;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200001
using namespace std;
typedef long long lli;
int n, t, m; lli a[mx], k[1000001];
lli rslt[mx];
struct query{
   int l, r, p, bl;
}q[mx];
bool cmp(query x, query y){
   if(x.bl==y.bl) return x.r<y.r;
   return x.bl<y.bl;
}
int main()
{
   //cin>>n>>t;
   scanf("%d %d", &n, &t);
   m=sqrt(n);
   for(int i=0; i<n; i++) scanf("%I64d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }
/*
      while(r>q[i].r){
         r--;
         ans+=(-2LL*k[a[r]]+1)*a[r];
         k[a[r]]--;
      }*/
      while(r<=q[i].r){
         ans+=(2LL*k[a[r]]+1)*a[r];
         k[a[r]]++;
         r++;
      }
      while(l<q[i].l){
         ans+=(-2LL*k[a[l]]+1)*a[l];
         k[a[l]]--;
         l++;
      }
      while(l>q[i].l){
         l--;
         ans+=(2LL*k[a[l]]+1)*a[l];
         k[a[l]]++;
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200002
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000002];
lli rslt[mx];
struct query{
   int l, r, p;
}q[mx];
bool cmp(query x, query y){
   return (x.l/m==y.l/m)?(x.r<y.r):(x.l/m<y.l/m);
}
int main()
{
   cin>>n>>t;
   m=sqrt(n+1);
   for(int i=0; i<n; i++) scanf("%d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; //q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      /*if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }*/

      while(r>q[i].r){
         r--;
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]--;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
      }
      while(r<=q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]++;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r++;
      }
      while(l<q[i].l){
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]--;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         l++;
      }
      while(l>q[i].l){
         l--;
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]++;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200001
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000001];
lli rslt[mx];
struct query{
   int l, r, p;
}q[mx];
bool cmp(query x, query y){
   if(x.l/m==y.l/m) return x.r<y.r;
   return x.l<y.l;
}
int main()
{
   scanf("%d %d", &n, &t);
   m=sqrt(n);
   for(int i=0; i<n; i++) scanf("%I64d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      while(r>q[i].r){
         r--;
         ans+=(lli)(-2LL*k[a[r]]+1)*(lli)a[r];
         k[a[r]]--;
      }
      while(r<=q[i].r){
         ans+=(lli)(2LL*k[a[r]]+1)*(lli)a[r];
         k[a[r]]++;
         r++;
      }
      while(l<q[i].l){
         ans+=(lli)(-2LL*k[a[l]]+1)*(lli)a[l];
         k[a[l]]--;
         l++;
      }
      while(l>q[i].l){
         l--;
         ans+=(lli)(2LL*k[a[l]]+1)*(lli)a[l];
         k[a[l]]++;
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200002
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000002];
lli rslt[mx];
struct query{
   int l, r, bl, p;
}q[mx];
bool cmp(query x, query y){
   return (x.bl==y.bl)?(x.r<y.r):(x.bl<y.bl);
}
int main()
{
   cin>>n>>t;
   m=sqrt(n+1);
   for(int i=0; i<n; i++) scanf("%d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);

   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      /*if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }*/
      while(r>q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]--;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r--;
      }
      while(r<=q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]++;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r++;
      }
      while(l<q[i].l){
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]--;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         l++;
      }
      while(l>q[i].l){
         l--;
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]++;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200001
using namespace std;
typedef long long lli;
int n, t, m; lli a[mx], k[1000001];
lli rslt[mx];
struct query{
   int l, r, p;
}q[mx];
bool cmp(query x, query y){
   if(x.l/m==y.l/m) return x.r<y.r;
   return x.l<y.l;
}
int main()
{
   //cin>>n>>t;
   scanf("%d %d", &n, &t);
   m=sqrt(n);
   for(int i=0; i<n; i++) scanf("%I64d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; //q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      /*if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }*/

      while(r>q[i].r){
         r--;
         ans+=(-2LL*k[a[r]]+1)*a[r];
         k[a[r]]--;
      }
      while(r<=q[i].r){
         ans+=(2LL*k[a[r]]+1)*a[r];
         k[a[r]]++;
         r++;
      }
      while(l<q[i].l){
         ans+=(-2LL*k[a[l]]+1)*a[l];
         k[a[l]]--;
         l++;
      }
      while(l>q[i].l){
         l--;
         ans+=(2LL*k[a[l]]+1)*a[l];
         k[a[l]]++;
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;

const int MAXN=200000+10;

int n,m;
int a[MAXN],b[MAXN*5];
int pos[MAXN];
long long ans=0;
long long ANS[MAXN];
struct Node{
	int x,y,id;
}q[MAXN];

bool operator<(const Node& a,const Node& b){
	if(pos[a.x]==pos[b.x]) return a.y<b.y;
	return pos[a.x]<pos[b.x];
}

void Update(int x,int y){
	ans-=(long long)b[a[x]]*(long long)b[a[x]]*a[x];
	b[a[x]]+=y;
	ans+=(long long)b[a[x]]*(long long)b[a[x]]*a[x];
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&q[i].x,&q[i].y);
		q[i].id=i;
	}
	int T=(int)sqrt(n*1.00);
	for(int i=1;i<=n;i++)
		pos[i]=i/T+1;
	sort(q+1,q+m+1);
	for(int i=1,l=1,r=0;i<=m;i++){
		int L=q[i].x,R=q[i].y;
		for(;r<R;r++)
			Update(r+1,1);
		for(;r>R;r--)
			Update(r,-1);
		for(;l<L;l++)
			Update(l,-1);
		for(;l>L;l--)
			Update(l-1,1);
		ANS[q[i].id]=ans;
	}
	for(int i=1;i<=m;i++)
		printf("%I64d\n",ANS[i]);
	return 0;
}


//BISMILLAHIR RAHMANIR RAHIM
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<queue>
#include<set>
#include <iostream>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#define N 1000000
#define sn scanf
#define pf printf
#define pb push_back
#define mp make_pair

const double PI=2.0*acos(0);

typedef long long int ll;
using namespace std;
struct T{
int a,b,block,d;
}qry[1000000];

bool cmp(T x,T y)
{
    if(x.block!=y.block)
        return x.a<y.a;
        return x.b<y.b;
}
ll ans[1000005],cnt[1000006];
int ar[1000000];
int main()
{
    int i,j,k,l,t,cs=1,r=1,s,m,n,a,b,c,d,e,f,g,h,u,v;

    //freopen(".txt","r",stdin);
    sn("%d %d",&n,&m);
    for(i=0;i<n;i++)
    {
        sn("%d",&ar[i]);
    }
    memset(cnt,0,sizeof(cnt));
    u=sqrt(n);
    for(i=0;i<m;i++)
    {
        sn("%d %d",&qry[i].a,&qry[i].b);
        qry[i].a--;qry[i].b--;
        qry[i].block=qry[i].a/u;
        qry[i].d=i;
    }
    sort(qry,qry+m,cmp);
    ll result=0,Lf=0,Rh=0;
    for(i=0;i<m;i++)
    {
        while(Lf<qry[i].a)
        {
            cnt[ar[Lf]]--;
            result-=(2*cnt[ar[Lf]]+1)*ar[Lf];
            Lf++;
        }
        while(Lf>qry[i].a)
        {
            Lf--;
            cnt[ar[Lf]]++;
            result+=(2*cnt[ar[Lf]]-1)*ar[Lf];
        }
        while(Rh<=qry[i].b)
        {
            cnt[ar[Rh]]++;
            result+=(2*cnt[ar[Rh]]-1)*ar[Rh];
            Rh++;
        }
        while(Rh>1+qry[i].b)
        {
            Rh--;
            cnt[ar[Rh]]--;
            result-=(2*cnt[ar[Rh]]+1)*ar[Rh];
        }
        ans[qry[i].d]=result;
    }
    for(i=0;i<m;i++)
    {
        pf("%I64d\n",ans[i]);
    }
    return 0;

}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200002
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000002];
lli rslt[mx];
struct query{
   int l, r, bl, p;
}q[mx];
bool cmp(query x, query y){
   return (x.bl==y.bl)?(x.r<y.r):(x.bl<y.bl);
}
int main()
{
   cin>>n>>t;
   m=sqrt(n+1);
   for(int i=0; i<n; i++) scanf("%d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);

   int l, r; lli ans;
   for(int i=0; i<t; i++){
      if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }
      while(r<=q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]++;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r++;
      }
      while(l<q[i].l){
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]--;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         l++;
      }
      while(l>q[i].l){
         l--;
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]++;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200002
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000002];
lli rslt[mx];
struct query{
   int l, r, bl, p;
}q[mx];
bool cmp(query x, query y){
   return (x.bl==y.bl)?(x.r<y.r):(x.bl<y.bl);
}
int main()
{
   cin>>n>>t;
   m=sqrt(n+1);
   for(int i=0; i<n; i++) scanf("%d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      /*if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }*/

      while(r>q[i].r){
         r--;
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]--;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
      }
      while(r<=q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]++;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r++;
      }
      while(l<q[i].l){
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]--;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         l++;
      }
      while(l>q[i].l){
         l--;
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]++;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#define mx 200002
using namespace std;
typedef long long lli;
int n, t, m, a[mx], k[1000002];
lli rslt[mx];
struct query{
   int l, r, p;
}q[mx];
bool cmp(query x, query y){
   return (x.l/m==y.l/m)?(x.r<y.r):(x.l<y.l);
}
int main()
{
   //cin>>n>>t;
   scanf("%d %d", &n, &t);
   m=sqrt(n);
   for(int i=0; i<n; i++) scanf("%d", a+i);
   for(int i=0; i<t; i++){
      scanf("%d %d", &q[i].l, &q[i].r);
      q[i].l--; q[i].r--;
      q[i].p=i; //q[i].bl=q[i].l/m;
   }
   sort(q, q+t, cmp);
   int l=0, r=0; lli ans=0;
   for(int i=0; i<t; i++){
      /*if(!i or q[i].bl!=q[i-1].bl){
         l=0, r=0, ans=0LL;
         memset(k, 0, sizeof k);
      }*/

      while(r>q[i].r){
         r--;
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]--;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
      }
      while(r<=q[i].r){
         ans-=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         k[a[r]]++;
         ans+=(lli)k[a[r]]*(lli)k[a[r]]*(lli)a[r];
         r++;
      }
      while(l<q[i].l){
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]--;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         l++;
      }
      while(l>q[i].l){
         l--;
         ans-=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
         k[a[l]]++;
         ans+=(lli)k[a[l]]*(lli)k[a[l]]*(lli)a[l];
      }
      rslt[q[i].p]=ans;
   }
   for(int i=0; i<t; i++) printf("%I64d\n", rslt[i]);
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return a.r<b.r;
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)sqrt(n)+1;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        int pos;
        while(curl<l){pos=curl;   cnt[a[pos]]--;answer-=(2*cnt[a[pos]]+1)*a[pos];curl++; }// pr(answer);
        while(curl>l){pos=curl-1; cnt[a[pos]]++;answer+=(2*cnt[a[pos]]-1)*a[pos];curl--; } //pr(answer);
        while(curr<r){pos=curr; cnt[a[pos]]++;answer+=(2*cnt[a[pos]]-1)*a[pos];curr++;}// pr(answer);
        while(curr>r){pos=curr-1; cnt[a[pos]]--;answer-=(2*cnt[a[pos]]+1)*a[pos];curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return a.r<b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=sqrt(n)+1;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl);curl--; }
        while(curr<=r){ add(curr);curr++;}
        while(curr>r+1){ remov(curr);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return a.r<b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=sqrt(n)+1;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        while(curl<l){ remov(curl);curl++; }// pr(answer);
        while(curl>l){ add(curl-1);curl--; } //pr(answer);
        while(curr<r){ add(curr);curr++;}// pr(answer);
        while(curr>r){ remov(curr-1);curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l<b.l;
    return a.r<b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    int aa=(int)(a.l/block);
    return (aa&1)?a.r<b.r:a.r>b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        while(curl<l){ remov(curl);curl++; }// pr(answer);
        while(curl>l){ add(curl-1);curl--; } //pr(answer);
        while(curr<r){ add(curr);curr++;}// pr(answer);
        while(curr>r){ remov(curr-1);curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return ((int)(a.l/block)&1)?a.r<b.r:a.r>b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        while(curl<l){ remov(curl);curl++; }// pr(answer);
        while(curl>l){ add(curl-1);curl--; } //pr(answer);
        while(curr<r){ add(curr);curr++;}// pr(answer);
        while(curr>r){ remov(curr-1);curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (ax%2)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(sqrt(t)+1);
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l)remov(curl),curl++;
        while(curl>l)add(curl-1),curl--;
        while(curr<r)add(curr),curr++;
        while(curr>r)remov(curr-1),curr--;
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    int aa=(int)(a.l/block);
    return (aa&1)?a.r<b.r:a.r>b.r;
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        int pos;
        while(curl<l){pos=curl;   cnt[a[pos]]--;answer-=(2*cnt[a[pos]]+1)*a[pos];curl++; }// pr(answer);
        while(curl>l){pos=curl-1; cnt[a[pos]]++;answer+=(2*cnt[a[pos]]-1)*a[pos];curl--; } //pr(answer);
        while(curr<r){pos=curr; cnt[a[pos]]++;answer+=(2*cnt[a[pos]]-1)*a[pos];curr++;}// pr(answer);
        while(curr>r){pos=curr-1; cnt[a[pos]]--;answer-=(2*cnt[a[pos]]+1)*a[pos];curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return a.r<b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=sqrt(n)+1;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp2(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (ax%2)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return a.r<b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=sqrt(n)+1;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l<b.l;
    return ((a.l/block)%2)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (ax%2)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (ax&1)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (ax%2)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(sqrt(t));;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l)remov(curl),curl++;
        while(curl>l)add(curl-1),curl--;
        while(curr<r)add(curr),curr++;
        while(curr>r)remov(curr-1),curr--;
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return a.r<b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        while(curl<l){ remov(curl);curl++; }// pr(answer);
        while(curl>l){ add(curl-1);curl--; } //pr(answer);
        while(curr<r){ add(curr);curr++;}// pr(answer);
        while(curr>r){ remov(curr-1);curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (ax&1)?a.r<b.r:a.r>b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//God & me
//I have agreed about this: "God can do anything" :-"
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
using namespace std;
template<class T,class L>bool smax(T&x,L y){return x<y?(x=y,1):0;}template<class T,class L>bool smin(T&x,L y){return x>y?(x=y,1):0;}
char OUTBUF[20],INBUF,*IT;
#define in(x) while((INBUF=getchar())<'0');for(x=INBUF-'0';(INBUF=getchar())>='0';x=x*10+INBUF-'0');
#define out(x) OUTBUF[0]=x%10;x/=10;for(IT=OUTBUF+1;x;)*IT++=x%10,x/=10;for(;IT!=OUTBUF;)putchar(*--IT+48);putchar('\n');
typedef pair<int,int> pii;
const int maxn=2e5+17,sq=448,maxv=1e6+17;
struct Q{
  int l,r,idx;
}q[maxn];
int n,a[maxn],qn,cnt[maxv];
long long cur,ans[maxn];
void add(int x,int v){
  x=a[x];
  cur-=(long long)cnt[x]*cnt[x]*x;
  cnt[x]+=v;
  cur+=(long long)cnt[x]*cnt[x]*x;
}
main(){
  in(n);in(qn);
  for(int i=0;i<n;i++){
    in(a[i]);
  }
  for(int i=0;i<qn;i++){
    in(q[i].l);in(q[i].r);q[i].l--,q[i].idx=i;
  }
  sort(q,q+qn,[](Q& a,Q& b){
      if(a.l/sq!=b.l/sq)
	return a.l<b.l;
      return bool((a.r<b.r));
    });
  int l=0,r=0;
  for(int i=0;i<qn;i++){
    int nxl=q[i].l,nxr=q[i].r;
    while(r<nxr)
      add(r++,1);
    while(l>nxl)
      add(--l,1);
    while(r>nxr)
      add(--r,-1);
    while(l<nxl)
      add(l++,-1);
    ans[q[i].idx]=cur;
  }
  for(int i=0;i<qn;i++){
    out(ans[i]);
  }
  return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l<b.l;
    return ((a.l/block)&1)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl);curl++; }
        while(curl>l){ add(curl-1);curl--; }
        while(curr<r){ add(curr);curr++;}
        while(curr>r){ remov(curr-1);curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (ax%2)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(1.514*sqrt(t)+1);;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l){ remov(curl),curl++; }
        while(curl>l){ add(curl-1),curl--; }
        while(curr<r){ add(curr),curr++;}
        while(curr>r){ remov(curr-1),curr--;}
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


// by shik
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N 200010
#define S 1000010
using namespace std;
typedef long long LL;
LL ans[N];
struct Q {
	int id,L,R;
	void read( int _id ) { id=_id; scanf("%d%d",&L,&R); }
} q[N];
int n,m,num[N],tmt;
bool cp( Q a, Q b ) {
	int ax=a.L/tmt,bx=b.L/tmt;
	if ( ax!=bx ) return ax<bx;
	return (ax&1)?a.R<b.R:a.R>b.R;
}
void input() {
	scanf("%d%d",&n,&m);
	for ( int i=1; i<=n; i++ ) scanf("%d",num+i);
	for ( int i=0; i<m; i++ ) q[i].read(i);
	tmt=(int)(1.514*sqrt(m)+1);
	sort(q,q+m,cp);
}
int st,ed,app[S]; LL now;
LL go( int L, int R ) {
	while ( st<L ) { now-=num[st]*(1+2*--app[num[st]]); st++; }
	while ( ed>R ) { now-=num[ed]*(1+2*--app[num[ed]]); ed--; }
	while ( st>L ) { st--; now+=num[st]*(1+2*app[num[st]]++); }
	while ( ed<R ) { ed++; now+=num[ed]*(1+2*app[num[ed]]++); }
	return now;
}
void solve() {
	st=ed=1; app[num[1]]++; now=num[1];
	for ( int i=0; i<m; i++ ) ans[q[i].id]=go(q[i].L,q[i].R);
	for ( int i=0; i<m; i++ ) printf("%I64d\n",ans[i]);
}
int main()
{
	input();
	solve();
	return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return ((int)(a.l/block)&1)?a.r<b.r:a.r>b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=sqrt(n)+1);
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        while(curl<l){ remov(curl);curl++; }// pr(answer);
        while(curl>l){ add(curl-1);curl--; } //pr(answer);
        while(curr<r){ add(curr);curr++;}// pr(answer);
        while(curr>r){ remov(curr-1);curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return a.r<b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=sqrt(n)+1;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        while(curl<l){ remov(curl);curl++; }// pr(answer);
        while(curl>l){ add(curl-1);curl--; } //pr(answer);
        while(curr<r){ add(curr);curr++;}// pr(answer);
        while(curr>r){ remov(curr-1);curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return ((int)(a.l/block)&1)?a.r<b.r:a.r>b.r;
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=sqrt(n)+1;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        while(curl<l){ remov(curl);curl++; }// pr(answer);
        while(curl>l){ add(curl-1);curl--; } //pr(answer);
        while(curr<r){ add(curr);curr++;}// pr(answer);
        while(curr>r){ remov(curr-1);curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


// by shik
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N 200010
#define S 1000010
using namespace std;
typedef long long LL;
LL ans[N];
struct Q {
	int id,L,R;
	void read( int _id ) { id=_id; scanf("%d%d",&L,&R); }
} q[N];
int n,m,num[N],tmt;
bool cp( Q a, Q b ) {
	int ax=a.L/tmt,bx=b.L/tmt;
	if ( ax!=bx ) return ax<bx;
	return a.R<b.R;
}
void input() {
	scanf("%d%d",&n,&m);
	for ( int i=1; i<=n; i++ ) scanf("%d",num+i);
	for ( int i=0; i<m; i++ ) q[i].read(i);
	tmt=(int)(1.514*sqrt(m)+1);
	sort(q,q+m,cp);
}
int st,ed,app[S]; LL now;
LL go( int L, int R ) {
	while ( st<L ) { now-=num[st]*(1+2*--app[num[st]]); st++; }
	while ( ed>R ) { now-=num[ed]*(1+2*--app[num[ed]]); ed--; }
	while ( st>L ) { st--; now+=num[st]*(1+2*app[num[st]]++); }
	while ( ed<R ) { ed++; now+=num[ed]*(1+2*app[num[ed]]++); }
	return now;
}
void solve() {
	st=ed=1; app[num[1]]++; now=num[1];
	for ( int i=0; i<m; i++ ) ans[q[i].id]=go(q[i].L,q[i].R);
	for ( int i=0; i<m; i++ ) printf("%I64d\n",ans[i]);
}
int main()
{
	input();
	solve();
	return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block,a[200005];
ll answer;
ll ans[200005];
int cnt[1000004];
struct query
{
    int l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    int ax=a.l/block,bx=b.l/block;
    if(ax!=bx)
        return ax<bx;
    return (ax%2)^(a.r<b.r);
}
void remov(int pos)
{
    cnt[a[pos]]--;
    answer-=(2*cnt[a[pos]]+1)*a[pos];
}
void add(int pos)
{
    cnt[a[pos]]++;
    answer+=(2*cnt[a[pos]]-1)*a[pos];
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%d%d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=(int)(sqrt(t));
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    int l,r;
    FOR(i,0,t-1)
    {
        l=q[i].l;
        r=q[i].r+1;
        while(curl<l)remov(curl),curl++;
        while(curl>l)add(curl-1),curl--;
        while(curr<r)add(curr),curr++;
        while(curr>r)remov(curr-1),curr--;
        ans[q[i].i]=answer;
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);
    return 0;
}


//Abinash Ghosh(Om)
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
using  namespace  std;

#define PI acos(-1.0)
#define MAX 10000007
#define EPS 1e-9
#define mem(a,b) memset(a,b,sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define Sort(x) sort(x.begin(),x.end())
#define FOR(i, b, e) for(int i = b; i <= e; i++)
#define FORR(i, b, e) for(int i = b; i >= e; i--)
#define pr(x) cout<<x<<"\n"
#define pr2(x,y) cout<<x<<" "<<y<<"\n"
#define pr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

typedef  long long ll;
typedef  pair <int, int> pii;
typedef  pair <double , double> pdd;
typedef  pair <ll , ll > pll;
typedef  vector <int> vi;
typedef  vector <pii> vpii;
typedef  vector <ll > vl;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};
//int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int n,t,block;
ll answer;
ll a[200005],ans[200005];
int cnt[1000004];
struct query
{
    ll l,r,i;
}q[200005];
bool cmp(query a,query b)
{
    if(a.l/block!=b.l/block)
        return a.l/block<b.l/block;
    return a.r<b.r;
}
int main()
{
    //READ("inA.txt");
    //WRITE("outA.txt");
    scanf("%d%d",&n,&t);
    FOR(i,0,n-1)
    {
        scanf("%I64d",&a[i]);
    }
    FOR(i,0,t-1)
    {
        scanf("%I64d%I64d",&q[i].l,&q[i].r);
        q[i].l--,q[i].r--,q[i].i=i;
    }
    block=sqrt(n)+1;
    sort(q,q+t,cmp);
    int curl=0,curr=0;
    answer=0;
    FOR(i,0,t-1)
    {
        int l=q[i].l;
        int r=q[i].r+1;
       // pr2(l,r);
        int pos;
        while(curl<l){pos=curl;   cnt[a[pos]]--;answer-=(2*cnt[a[pos]]+1)*a[pos];curl++; }// pr(answer);
        while(curl>l){pos=curl-1; cnt[a[pos]]++;answer+=(2*cnt[a[pos]]-1)*a[pos];curl--; } //pr(answer);
        while(curr<r){pos=curr; cnt[a[pos]]++;answer+=(2*cnt[a[pos]]-1)*a[pos];curr++;}// pr(answer);
        while(curr>r){pos=curr-1; cnt[a[pos]]--;answer-=(2*cnt[a[pos]]+1)*a[pos];curr--;}// pr(answer);
        ans[q[i].i]=answer;
       // pr("\n");
    }
    FOR(i,0,t-1)
    printf("%I64d\n",ans[i]);

    return 0;
}
/*
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
*/


// by shik
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N 200010
#define S 1000010
using namespace std;
typedef long long LL;
LL ans[N];
struct Q {
	int id,L,R;
	void read( int _id ) { id=_id; scanf("%d%d",&L,&R); }
} q[N];
int n,m,num[N],tmt;
bool cp( Q a, Q b ) {
	int ax=a.L/tmt,bx=b.L/tmt;
	if ( ax!=bx ) return ax<bx;
	return a.R<b.R;
}
void input() {
	scanf("%d%d",&n,&m);
	for ( int i=1; i<=n; i++ ) scanf("%d",num+i);
	for ( int i=0; i<m; i++ ) q[i].read(i);
	tmt=(int)sqrt(n)+1;
	sort(q,q+m,cp);
}
int st,ed,app[S]; LL now;
LL go( int L, int R ) {
	while ( st<L ) { now-=num[st]*(1+2*--app[num[st]]); st++; }
	while ( ed>R ) { now-=num[ed]*(1+2*--app[num[ed]]); ed--; }
	while ( st>L ) { st--; now+=num[st]*(1+2*app[num[st]]++); }
	while ( ed<R ) { ed++; now+=num[ed]*(1+2*app[num[ed]]++); }
	return now;
}
void solve() {
	st=ed=1; app[num[1]]++; now=num[1];
	for ( int i=0; i<m; i++ ) ans[q[i].id]=go(q[i].L,q[i].R);
	for ( int i=0; i<m; i++ ) printf("%I64d\n",ans[i]);
}
int main()
{
	input();
	solve();
	return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

typedef pair<int,int> ii;
typedef long long int Lint;

const int MAXN = 200010;

int N,Q,K;

Lint ans;

int ar[MAXN];

Lint cnt[1000010];

Lint out[MAXN];

struct node{

	int l,r,g,pos;

	friend bool operator < ( const node &a , const node &b ){
		if ( a.g == b.g )	return a.r < b.r;
		return a.g < b.g;
	}

}q[MAXN];

void increase( int i ){

	ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

	cnt[ ar[i] ] += 1LL;

	ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

}

void decrease( int i ){

	ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

	cnt[ ar[i] ] -= 1LL;

	ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

}

int main(){

	scanf(" %d %d",&N,&Q);

	K = sqrt(N);

	for ( int i=1 ; i<=N ; i++ )
		scanf(" %d",&ar[i]);

	for ( int i=1 ; i<=Q ; i++ ){
		scanf(" %d %d",&q[i].l,&q[i].r);

		q[i].g = q[i].l/K - (q[i].l%K==0);

		q[i].pos = i;
	}

	sort( q+1 , q+Q+1 );

	int L = q[1].l , R = q[1].r;

	for ( int i=L ; i<=R ; i++ )
	 	increase(i);

	for ( int i=1 ; i<=Q ; i++ ){

		if ( R < q[i].r ){

			for ( int j=R+1 ; j<=q[i].r ; j++ )
				increase(j);

		}else{

			for ( int j=R ; j>q[i].r ; j-- )
				decrease(j);

		}

		if ( L < q[i].l ){

			for ( int j=L ; j<q[i].l ; j++ )
				decrease(j);

		}else{

			for ( int j=q[i].l ; j<L ; j++ )
				increase(j);

		}

		L = q[i].l;
		R = q[i].r;

		out[ q[i].pos ] = ans;

	}

	for ( int i=1 ; i<=Q ; i++ )
		printf("%I64d\n",out[i]);

	return 0;

}


#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

typedef pair<int,int> ii;
typedef long long int Lint;

const int MAXN = 200010;

int N,Q,K;

Lint ans;

int ar[MAXN];

Lint cnt[1000010];

Lint out[MAXN];

struct node{

	int l,r,g,pos;

}q[MAXN];

int comp( const node &a , const node &b ){
	if ( a.g != b.g )	return a.g < b.g;
	if ( a.r != b.r ) a.r < b.r;
	return a.l < b.l;
}

int main(){

	scanf(" %d %d",&N,&Q);

	K = sqrt(N);

	for ( int i=1 ; i<=N ; i++ )
		scanf(" %d",&ar[i]);

	for ( int i=1 ; i<=Q ; i++ ){
		scanf(" %d %d",&q[i].l,&q[i].r);

		q[i].g = (q[i].l-1)/K;

		q[i].pos = i;
	}

	sort( q+1 , q+Q+1 , comp );

	int L = q[1].l , R = q[1].r;

	for ( int i=L ; i<=R ; i++ ){
		ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];
		cnt[ ar[i] ] += 1LL;
		ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];
	}

	for ( int i=1 ; i<=Q ; i++ ){

		if ( R < q[i].r ){

			for ( int j=R+1 ; j<=q[i].r ; j++ ){
				ans -= cnt[ ar[j] ] * cnt[ ar[j] ] * ar[j];
				cnt[ ar[j] ] += 1LL;
				ans += cnt[ ar[j] ] * cnt[ ar[j] ] * ar[j];
			}

		}else{

			for ( int j=R ; j>q[i].r ; j-- ){
				ans -= cnt[ ar[j] ] * cnt[ ar[j] ] * ar[j];
				cnt[ ar[j] ] -= 1LL;
				ans += cnt[ ar[j] ] * cnt[ ar[j] ] * ar[j];
			}

		}

		if ( L < q[i].l ){

			for ( int j=L ; j<q[i].l ; j++ ){
				ans -= cnt[ ar[j] ] * cnt[ ar[j] ] * ar[j];
				cnt[ ar[j] ] -= 1LL;
				ans += cnt[ ar[j] ] * cnt[ ar[j] ] * ar[j];
			}

		}else{

			for ( int j=q[i].l ; j<L ; j++ ){
				ans -= cnt[ ar[j] ] * cnt[ ar[j] ] * ar[j];
				cnt[ ar[j] ] += 1LL;
				ans += cnt[ ar[j] ] * cnt[ ar[j] ] * ar[j];
			}

		}

		L = q[i].l;
		R = q[i].r;

		out[ q[i].pos ] = ans;

	}

	for ( int i=1 ; i<=Q ; i++ )
		printf("%I64d\n",out[i]);

	return 0;

}


#include <bits/stdc++.h>
#define se first.second
#define fi second.first

using namespace std;

typedef long long int lint;
typedef pair<lint,lint> ii;
typedef pair<ii,ii> iiii;
const lint MAXN = 201000;

lint N,M,K,ar[MAXN],er[MAXN*5],ans,out[MAXN*5];
iiii qu[MAXN];

int main(){
	scanf(" %I64d %I64d",&N,&M); K=sqrt(N)+1;
	for(lint i=1;i<=N;i++)
		scanf(" %I64d",&ar[i]);
	for(lint i=1,a,b;i<=M;i++){
		scanf(" %I64d %I64d",&a,&b);
		qu[i]=iiii(ii(a/K+1,b),ii(a,i));
	}
	sort(qu+1,qu+M+1);
	lint l=0,r=0;
	for(lint i=1;i<=M;i++){
		while(r<qu[i].se){
			r++;
			ans-=ar[r]*er[ar[r]]*er[ar[r]];
			er[ar[r]]++;
			ans+=ar[r]*er[ar[r]]*er[ar[r]];
		}
		while(r>qu[i].se){
			ans-=ar[r]*er[ar[r]];
			er[ar[r]]--;
			ans+=ar[r]*er[ar[r]];
			r--;
		}
		while(l<qu[i].fi){
			ans-=ar[l]*er[ar[l]]*er[ar[l]];
			er[ar[l]]--;
			ans+=ar[l]*er[ar[l]]*er[ar[l]];
			l++;
		}
		while(l>qu[i].fi){
			l--;
			ans-=ar[l]*er[ar[l]]*er[ar[l]];
			er[ar[l]]++;
			ans+=ar[l]*er[ar[l]]*er[ar[l]];
		}
		out[qu[i].second.second]=ans;
	}
	for(int i=1;i<=M;i++)
		printf("%I64d\n",out[i]);
	return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

typedef pair<int,int> ii;
typedef long long int Lint;

const int MAXN = 200010;

int N,Q,K;

Lint ans;

int ar[MAXN];

Lint cnt[1000010];

Lint out[MAXN];

struct node{

	int l,r,g,pos;

}q[MAXN];

int comp( const node &a , const node &b ){
	if ( a.g != b.g )	return a.g < b.g;
	if ( a.r != b.r ) return a.r < b.r;
	return a.l < b.l;
}

int main(){

	scanf(" %d %d",&N,&Q);

	K = sqrt(N);

	for ( int i=1 ; i<=N ; i++ )
		scanf(" %d",&ar[i]);

	for ( int i=1 ; i<=Q ; i++ ){
		scanf(" %d %d",&q[i].l,&q[i].r);

		q[i].g = (q[i].l-1)/K;

		q[i].pos = i;
	}

	sort( q+1 , q+Q+1 , comp );

	int L = q[1].l , R = q[1].r;

	for ( int i=L ; i<=R ; i++ ){
		ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];
		cnt[ ar[i] ] += 1LL;
		ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];
	}

	for ( int i=1 ; i<=Q ; i++ ){

		while ( R < q[i].r ){
			R++;
			ans -= cnt[ ar[R] ] * cnt[ ar[R] ] * ar[R];
			cnt[ ar[R] ] += 1LL;
			ans += cnt[ ar[R] ] * cnt[ ar[R] ] * ar[R];
		}

		while ( R > q[i].r ){
			ans -= cnt[ ar[R] ] * cnt[ ar[R] ] * ar[R];
			cnt[ ar[R] ] -= 1LL;
			ans += cnt[ ar[R] ] * cnt[ ar[R] ] * ar[R];
			R--;
		}

		while ( L < q[i].l ){
			ans -= cnt[ ar[L] ] * cnt[ ar[L] ] * ar[L];
			cnt[ ar[L] ] -= 1LL;
			ans += cnt[ ar[L] ] * cnt[ ar[L] ] * ar[L];
			L++;
		}

		while ( L > q[i].l ){
			L--;
			ans -= cnt[ ar[L] ] * cnt[ ar[L] ] * ar[L];
			cnt[ ar[L] ] += 1LL;
			ans += cnt[ ar[L] ] * cnt[ ar[L] ] * ar[L];
		}

		out[ q[i].pos ] = ans;

	}

	for ( int i=1 ; i<=Q ; i++ )
		printf("%I64d\n",out[i]);

	return 0;

}


#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

typedef pair<int,int> ii;
typedef long long int Lint;

const int MAXN = 200010;

int N,Q,K;

Lint ans;

int ar[MAXN];

Lint cnt[1000010];

struct node{

	int l,r,g;

	friend bool operator < ( const node &a , const node &b ){
		if ( a.g == b.g )	return a.r < b.r;
		return a.g < b.g;
	}

}q[MAXN];

void increase( int i ){

	ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

	cnt[ ar[i] ] += 1LL;

	ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

}

void decrease( int i ){

	ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

	cnt[ ar[i] ] -= 1LL;

	ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

}

int main(){

	scanf(" %d %d",&N,&Q);

	K = sqrt(N);

	for ( int i=1 ; i<=N ; i++ )
		scanf(" %d",&ar[i]);

	for ( int i=1 ; i<=Q ; i++ ){
		scanf(" %d %d",&q[i].l,&q[i].r);
		q[i].g = q[i].l/K - (q[i].l%K==0);
	}

	sort( q+1 , q+Q+1 );

	int L = q[1].l , R = q[1].r;

	for ( int i=L ; i<=R ; i++ )
	 	increase(i);

	cout << ans << endl;

	int last_group = -1;

	for ( int i=2 ; i<=Q ; i++ ){

		if ( R < q[i].r ){

			for ( int j=R+1 ; j<=q[i].r ; j++ )
				increase(j);

		}else{

			for ( int j=R ; j>q[i].r ; j-- )
				decrease(j);

		}

		if ( L < q[i].l ){

			for ( int j=L ; j<q[i].l ; j++ )
				decrease(j);

		}else{

			for ( int j=q[i].l ; j<L ; j++ )
				increase(j);

		}

		cout << ans << endl;

	}

	return 0;

}


#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

typedef pair<int,int> ii;
typedef long long int Lint;

const int MAXN = 200010;

int N,Q,K;

Lint ans;

int ar[MAXN];

Lint cnt[1000010];

struct node{

	int l,r,g;

	friend bool operator < ( const node &a , const node &b ){
		if ( a.g == b.g )	return a.r < b.r;
		return a.g < b.g;
	}

}q[MAXN];

void increase( int i ){

	ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

	cnt[ ar[i] ] += 1LL;

	ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

}

void decrease( int i ){

	ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

	cnt[ ar[i] ] -= 1LL;

	ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i];

}

int main(){

	scanf(" %d %d",&N,&Q);

	K = sqrt(N);

	for ( int i=1 ; i<=N ; i++ )
		scanf(" %d",&ar[i]);

	for ( int i=1 ; i<=Q ; i++ ){
		scanf(" %d %d",&q[i].l,&q[i].r);
		q[i].g = q[i].l/K - (q[i].l%K==0);
	}

	sort( q+1 , q+Q+1 );

	int L = q[1].l , R = q[1].r;

	for ( int i=L ; i<=R ; i++ )
	 	increase(i);

	int last_group = -1;

	for ( int i=1 ; i<=Q ; i++ ){

		if ( R < q[i].r ){

			for ( int j=R+1 ; j<=q[i].r ; j++ )
				increase(j);

		}else{

			for ( int j=R ; j>q[i].r ; j-- )
				decrease(j);

		}

		if ( L < q[i].l ){

			for ( int j=L ; j<q[i].l ; j++ )
				decrease(j);

		}else{

			for ( int j=q[i].l ; j<L ; j++ )
				increase(j);

		}

		cout << ans << endl;

	}

	return 0;

}


#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

typedef pair<int,int> ii;
typedef long long int Lint;

const int MAXN = 200010;

int N,Q,K;

Lint ans;

int ar[MAXN];

int cnt[1000010];

Lint out[MAXN];

struct node{

	int l,r,g,pos;

	friend bool operator < ( const node &a , const node &b ){
		if ( a.g == b.g )	return a.r < b.r;
		return a.g < b.g;
	}

}q[MAXN];

inline void increase( int i ){

	ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i] * 1LL;

	cnt[ ar[i] ] += 1LL;

	ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i] * 1LL;

}

inline void decrease( int i ){

	ans -= cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i] * 1LL;

	cnt[ ar[i] ] -= 1LL;

	ans += cnt[ ar[i] ] * cnt[ ar[i] ] * ar[i] * 1LL;

}

int main(){

	scanf(" %d %d",&N,&Q);

	K = sqrt(N);

	for ( int i=1 ; i<=N ; i++ )
		scanf(" %d",&ar[i]);

	for ( int i=1 ; i<=Q ; i++ ){
		scanf(" %d %d",&q[i].l,&q[i].r);

		q[i].g = q[i].l/K - (q[i].l%K==0);

		q[i].pos = i;
	}

	sort( q+1 , q+Q+1 );

	int L = q[1].l , R = q[1].r;

	for ( int i=L ; i<=R ; i++ )
	 	increase(i);

	for ( int i=1 ; i<=Q ; i++ ){

		if ( R < q[i].r ){

			for ( int j=R+1 ; j<=q[i].r ; j++ )
				increase(j);

		}else{

			for ( int j=R ; j>q[i].r ; j-- )
				decrease(j);

		}

		if ( L < q[i].l ){

			for ( int j=L ; j<q[i].l ; j++ )
				decrease(j);

		}else{

			for ( int j=q[i].l ; j<L ; j++ )
				increase(j);

		}

		L = q[i].l;
		R = q[i].r;

		out[ q[i].pos ] = ans;

	}

	for ( int i=1 ; i<=Q ; i++ )
		printf("%I64d\n",out[i]);

	return 0;

}