func_code_string: #include <bits/stdc++.h>   using namespace std;   const int L = 2e5 + 7;   long long out[L], a[L], counter[1000001], szs = 900;   struct node {     long long l, r, q;   };   bool comp(node x, node y) {     long long xx = x.l / szs, yy = y.l / szs;     if (xx == yy) return x.r < y.r;     return x.l < y.l;   }   long long ans = 0;   void add(int idx) {     counter[a[idx]]++;     ans += ((counter[a[idx]]) * (counter[a[idx]]) * a[idx] -             (counter[a[idx]] - 1) * (counter[a[idx]] - 1) * a[idx]);   }   void remove(int idx) {     counter[a[idx]]--;     ans += ((counter[a[idx]]) * (counter[a[idx]]) * a[idx] -             (counter[a[idx]] + 1) * (counter[a[idx]] + 1) * a[idx]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int curl, curr, n, m, cur = 0, l, r, b, k;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> a[i];     std::vector<node> v(m);     node temp;     for (int i = 0; i < m; ++i) {       cin >> l >> r;       l--, r--;       v[i].l = l, v[i].r = r, v[i].q = i;     }     sort(v.begin(), v.end(), comp);     l = 0, r = -1;     for (int i = 0; i < m; ++i) {       curl = v[i].l, curr = v[i].r;       while (r < curr) {         ++r;         add(r);       }       while (r > curr) {         remove(r);         --r;       }       while (l < curl) {         remove(l);         l++;       }       while (l > curl) {         --l;         add(l);       }       out[v[i].q] = ans;     }     for (int i = 0; i < m; ++i) cout << out[i] <<   n ;     return 0;   }   