#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";
}