func_code_string: #include <bits/stdc++.h>   using namespace std;   struct Node {     int l, r, b, No;     bool operator<(const Node &t) const {       if (b != t.b) return b < t.b;       return r < t.r;     }   };   const int N = 200005;   const int M = 1000005;   int n, Q;   int seq[N];   Node q[N];   int cnt[M];   long long ans[N];   long long &cal(int x, int &l, int &r, long long &ret) {     int L = q[x].l, R = q[x].r;     while (l > L) {       --l;       int t = seq[l];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     while (r < R) {       ++r;       int t = seq[r];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     while (l < L) {       int t = seq[l];       ret += -2LL * cnt[t] * t + t;       ++l;       cnt[t]--;     }     while (r > R) {       int t = seq[r];       ret += -2LL * cnt[t] * t + t;       --r;       cnt[t]--;     }     return ret;   }   void solve() {     int B = (int)sqrt(1.0 * n);     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= Q; ++i) {       scanf( %d %d , &q[i].l, &q[i].r);       q[i].b = q[i].l / B;       q[i].No = i;     }     sort(q + 1, q + 1 + Q);     int l = q[1].l, r = q[1].r;     long long ret = 0;     for (int i = l; i <= r; ++i) {       int t = seq[i];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     ans[q[1].No] = ret;     for (int i = 2; i <= Q; ++i) {       ans[q[i].No] = cal(i, l, r, ret);     }     for (int i = 1; i <= Q; ++i) {       printf( %I64d n , ans[i]);     }   }   int main() {     while (scanf( %d %d , &n, &Q) != EOF) {       for (int i = 1; i <= n; ++i) {         scanf( %d , &seq[i]);       }       solve();     }     return 0;   }   