#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int sq = 450;
long long arr[1000005];
vector<pair<pair<long long, long long>, int> > q[450];
long long an[1000005], freq[1000005];
long long ans = 0;
void add(long long x) {
  x = arr[x];
  ans -= freq[x] * freq[x] * x;
  freq[x]++;
  ans += freq[x] * freq[x] * x;
}
void rmv(long long x) {
  x = arr[x];
  ans -= freq[x] * freq[x] * x;
  freq[x]--;
  ans += freq[x] * freq[x] * x;
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, t;
  cin >> n >> t;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  long long l, r;
  for (int i = 1; i <= t; i++) {
    cin >> l >> r;
    int z = l / sq;
    q[z].push_back({{r, l}, i});
  }
  for (int i = 0; i < sq; i++) {
    sort(q[i].begin(), q[i].end());
  }
  long long lf, rt;
  l = q[0][0].first.second;
  r = l;
  freq[arr[l]]++;
  ans = arr[l];
  for (int i = 0; i < sq; i++) {
    for (auto j : q[i]) {
      lf = j.first.second;
      rt = j.first.first;
      while (lf < l) {
        l--;
        add(l);
      }
      while (r < rt) {
        r++;
        add(r);
      }
      while (l < lf) {
        rmv(l);
        l++;
      }
      while (rt < r) {
        rmv(r);
        r--;
      }
      an[j.second] = ans;
    }
  }
  for (int i = 1; i <= t; i++) {
    cout << an[i] << '\n';
  }
  return 0;
}
