#include<bits/stdc++.h>
#define MAXN 200010
#define MAXX 1000010
using namespace std;
int block;
long long arr[MAXN+1],freq[MAXX+1],sol[MAXN+1];
struct query{
int l,r,i;
}qry[MAXN+1];
bool comp(query q1,query q2){
if(q1.l!=q2.l)
return (q1.l/block)<(q2.l/block);
return q1.r<q2.r;
}
int main(){
ios::sync_with_stdio(false);
int n,t,l,r,lx,rx;
long long x=0;
cin>>n>>t;
block=sqrt(n);
for(int i=0;i<n;i++)
cin>>arr[i];
for(int i=0;i<t;i++){
cin>>qry[i].l>>qry[i].r;
qry[i].l--;
qry[i].r--;
qry[i].i=i;
}
sort(qry,qry+t,comp);
l=0;
r=-1;
for(int i=0;i<t;i++){
lx=qry[i].l;
rx=qry[i].r;
while(l>lx){
l--;
x+=(((2LL*freq[arr[l]])+1)*arr[l]);
freq[arr[l]]++;
}
while(l<lx){
x-=(((2LL*freq[arr[l]])-1)*arr[l]);
freq[arr[l]]--;
l++;
}
while(r<=rx){
x+=(((2LL*freq[arr[r]])+1)*arr[r]);
freq[arr[r]]++;
r++;
}
while(r>(rx+1)){
r--;
x-=(((2LL*freq[arr[r]])-1)*arr[r]);
freq[arr[r]]--;
}
sol[qry[i].i]=x;
}
for(int i=0;i<t;i++)
cout<<sol[i]<<"\n";
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBNQVhOIDIwMDAxMAojZGVmaW5lIE1BWFggMTAwMDAxMAp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgYmxvY2s7CmxvbmcgbG9uZyBhcnJbTUFYTisxXSxmcmVxW01BWFgrMV0sc29sW01BWE4rMV07CnN0cnVjdCBxdWVyeXsKCWludCBsLHIsaTsKfXFyeVtNQVhOKzFdOwpib29sIGNvbXAocXVlcnkgcTEscXVlcnkgcTIpewoJaWYocTEubCE9cTIubCkKCQlyZXR1cm4gKHExLmwvYmxvY2spPChxMi5sL2Jsb2NrKTsKCXJldHVybiBxMS5yPHEyLnI7Cn0KaW50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