func_code_string: #include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9, PI = acos(-1.);   const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;   const int N = 2e5 + 5, SQ = 500;   int n, q, a[N], l[N], r[N], p[N];   long long ans[N], c[1000005], s;   void add(int x) {     int v = a[x];     s -= c[v] * c[v] * v;     c[v]++;     s += c[v] * c[v] * v;   }   void rem(int x) {     int v = a[x];     s -= c[v] * c[v] * v;     c[v]--;     s += c[v] * c[v] * v;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < q; ++i) scanf( %d%d , &l[i], &r[i]), p[i] = i;     sort(p, p + q, [](int a, int b) {       return l[a] / SQ == l[b] / SQ ? r[a] < r[b] : l[a] < l[b];     });     int cl = 0, cr = 0;     for (int i = 0; i < q; ++i) {       int cur = p[i];       while (cl < l[cur]) rem(cl++);       while (cl > l[cur]) add(--cl);       while (cr < r[cur]) add(++cr);       while (cr > r[cur]) rem(cr--);       ans[cur] = s;     }     for (int i = 0; i < q; ++i) printf( %lld n , ans[i]);     return 0;   }   