#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = atan(1.0);
#define readFile freopen("input","r",stdin);
#define writeFile freopen("output","w",stdout);
#define fastIO ios::sync_with_stdio(0);
typedef pair<int,int> ii;
typedef unsigned long long ULL;
const int N = 200001;
int arr[N];
int bsize;
struct query{
long long ord,bucket,l,r;
query(){}
query(int ord,int l,int r){
this->ord = ord;
this->l = l;
this->r = r;
this->bucket = ord/bsize;
if (!this->bucket) this->bucket++;
}
}queries[N];
struct cmp{
bool operator () (query q1,query q2){
if (q1.bucket!=q2.bucket) return q1.r<q2.r;
return q1.bucket<q2.bucket;
}
};
int main(){
#ifndef ONLINE_JUDGE
readFile;
#endif
fastIO;
long long n,q; cin>>n>>q;
bsize = sqrt(N);
long long res[N];
for(int i=0;i<n;i++) cin>>arr[i];
for(int i=0;i<q;i++){
long long a,b; cin>>a>>b;
a--;
queries[i] = query(i,a,b);
}
sort(queries,queries+q,cmp());
long long l=queries[0].l,r=l=queries[0].l;
unsigned long long ans = 0;
long long rep[1000001];
memset(rep,0,sizeof(rep));
for(int i=0;i<q;i++){
long long ll=queries[i].l,rr = queries[i].r;
while (l<ll){
long long t = rep[arr[l]]--;
ans-=(t*t-(t-1)*(t-1))*arr[l];
l++;
}
while (l>ll){
long long t = ++rep[arr[l-1]];
ans+=(t*t-(t-1)*(t-1))*arr[l-1];
l--;
}
while (r>rr){
long long t = rep[arr[r-1]]--;
ans-=(t*t-(t-1)*(t-1))*arr[r-1];
r--;
}
while (r<rr){
long long t = ++rep[arr[r]];
ans+=(t*t-(t-1)*(t-1))*arr[r];
r++;
}
res[queries[i].ord] = ans;
}
for(int i=0;i<q;i++) cout<<res[i]<<"\n";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGxvbmcgbG9uZyBtb2QgPSAxZTkgKyA3Owpjb25zdCBkb3VibGUgZXBzID0gMWUtOTsKY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47aSsrKSBjaW4+PmFycltpXTsKICAgIGZvcihpbnQgaT0wO2k8cTtpKyspewogICAgICAgIGxvbmcgbG9uZyBhLGI7IGNpbj4+YT4+YjsKICAgICAgICBhLS07CiAgICAgICAgcXVlcmllc1tpXSA9IHF1ZXJ5KGksYSxiKTsKICAgIH0KICAgIHNvcnQocXVlcmllcyxxdWVyaWVzK3EsY21wKCkpOwogICAgbG9uZyBsb25nIGw9cXVlcmllc1swXS5sLHI9bD1xdWVyaWVzWzBdLmw7CiAgICB1bnNpZ25lZCBsb25nIGxvbmcgYW5zID0gMDsKICAgIGxvbmcgbG9uZyByZXBbMTAwMDAwMV07CiAgICBtZW1zZXQocmVwLDAsc2l6ZW9mKHJlcCkpOwogICAgZm9yKGludCBpPTA7aTxxO2krKyl7CiAgICAgICAgbG9uZyBsb25nIGxsPXF1ZXJpZXNbaV0ubCxyciA9IHF1ZXJpZXNbaV0ucjsKICAgICAgICB3aGlsZSAobDxsbCl7CiAgICAgICAgICAgIGxvbmcgbG9uZyB0ID0gcmVwW2FycltsXV0tLTsKICAgICAgICAgICAgYW5zLT0odCp0LSh0LTEpKih0LTEpKSphcnJbbF07CiAgICAgICAgICAgIGwrKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKGw+bGwpewogICAgICAgICAgICBsb25nIGxvbmcgdCA9ICsrcmVwW2FycltsLTFdXTsKICAgICAgICAgICAgYW5zKz0odCp0LSh0LTEpKih0LTEpKSphcnJbbC0xXTsKICAgICAgICAgICAgbC0tOwogICAgICAgIH0gICAgCiAgICAgICAgd2hpbGUgKHI+cnIpewogICAgICAgICAgICBsb25nIGxvbmcgdCA9IHJlcFthcnJbci0xXV0tLTsKICAgICAgICAgICAgYW5zLT0odCp0LSh0LTEpKih0LTEpKSphcnJbci0xXTsKICAgICAgICAgICAgci0tOwogICAgICAgIH0KICAgICAgICB3aGlsZSAocjxycil7CiAgICAgICAgICAgIGxvbmcgbG9uZyB0ID0gKytyZXBbYXJyW3JdXTsKICAgICAgICAgICAgYW5zKz0odCp0LSh0LTEpKih0LTEpKSphcnJbcl07CiAgICAgICAgICAgIHIrKzsKICAgICAgICB9CiAgICAgICAgcmVzW3F1ZXJpZXNbaV0ub3JkXSA9IGFuczsKICAgIH0KICAgIGZvcihpbnQgaT0wO2k8cTtpKyspIGNvdXQ8PHJlc1tpXTw8IlxuIjsKfQ==