func_code_string: #include <bits/stdc++.h>   using namespace std;   int a[1000006], BLOCK;   long long ans[200005], answer = 0;   int asdf[1000006];   struct Node {     int L, R, ind;   } q[200005];   bool cmp(Node x, Node y) {     if (x.L / BLOCK != y.L / BLOCK)       return x.L / BLOCK < y.L / BLOCK;     else       return x.R < y.R;   }   void add(int pos) {     answer -= 1ll * asdf[a[pos]] * asdf[a[pos]] * a[pos];     asdf[a[pos]]++;     answer += 1ll * asdf[a[pos]] * asdf[a[pos]] * a[pos];   }   void remove(int pos) {     answer -= 1ll * asdf[a[pos]] * asdf[a[pos]] * a[pos];     asdf[a[pos]]--;     answer += 1ll * asdf[a[pos]] * asdf[a[pos]] * a[pos];   }   int main() {     int n, t;     cin >> n >> t;     BLOCK = sqrt(n);     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= t; i++) {       q[i].ind = i;       cin >> q[i].L >> q[i].R;     }     sort(q + 1, q + t + 1, cmp);     int curL = 0, curR = 0;     for (int i = 1; i <= t; i++) {       while (curL < q[i].L) {         remove(curL);         curL++;       }       while (curL > q[i].L) {         add(curL - 1);         curL--;       }       while (curR > q[i].R + 1) {         remove(curR - 1);         curR--;       }       while (curR <= q[i].R) {         add(curR);         curR++;       }       ans[q[i].ind] = answer;     }     for (int i = 1; i <= t; i++) cout << ans[i] <<   n ;   }   