func_code_string: #include <bits/stdc++.h>   using namespace std;   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};   void file() {}   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);   }   const int N = 2e5 + 9;   int arr[N], qi[N], qs[N], qe[N];   long long qans[N], cnt;   int fre[N / 2 * 10 + 9];   long long calc(int num) { return 1LL * fre[num] * fre[num] * num; }   void add(int num) {     cnt -= calc(num);     fre[num]++;     cnt += calc(num);   }   void remove(int num) {     cnt -= calc(num);     fre[num]--;     cnt += calc(num);   }   int main() {     file();     fast();     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < q; i++) {       qi[i] = i;       cin >> qs[i] >> qe[i];       qs[i]--, qe[i]--;     }     int sq = sqrt(n);     sort(qi, qi + q, [sq](int a, int b) {       return make_pair(qs[a] / sq, qe[a]) < make_pair(qs[b] / sq, qe[b]);     });     int s = 0, e = 0;     for (int i = 0; i < q; i++) {       int idx = qi[i];       while (e <= qe[idx]) add(arr[e++]);       while (s > qs[idx]) add(arr[--s]);       while (e > qe[idx] + 1) remove(arr[--e]);       while (s < qs[idx]) remove(arr[s++]);       qans[idx] = cnt;     }     for (int i = 0; i < q; i++) cout << qans[i] <<   n ;     return 0;   }   