#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
long long B;
typedef struct query {
  int l, r, id;
} qry;
bool cmp(qry a, qry b) {
  if (a.l / B != b.l / B)
    return (a.l < b.l);
  else
    return (a.r < b.r);
}
int freq[1000055] = {0};
long long add(long long a[], long long n, long long id) {
  long long res = 0;
  freq[a[id]]++;
  res = ((2 * freq[a[id]]) - 1) * a[id];
  return (res);
}
long long remov(long long a[], long long n, long long id) {
  long long res = 0;
  res = (2 * freq[a[id]] - 1) * a[id];
  freq[a[id]]--;
  return res;
}
void solve(long long a[], long long n, qry q[], long long t, long long ans[]) {
  long long st = 0, end = 0, i, j, k, cnt = 0;
  for (i = 0; i < t; i++) {
    j = q[i].l;
    k = q[i].r;
    while (st > j) {
      cnt += add(a, n, st - 1);
      st--;
    }
    while (st < j) {
      cnt -= remov(a, n, st);
      st++;
    }
    while (end <= k) {
      cnt += add(a, n, end);
      end++;
    }
    while (end > k + 1) {
      cnt -= remov(a, n, end - 1);
      end--;
    }
    ans[q[i].id] = cnt;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t, n, i, j, k, x, y;
  cin >> n >> t;
  B = sqrt(n);
  long long a[n], ans[t];
  qry q[t];
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < t; i++) {
    cin >> q[i].l >> q[i].r;
    q[i].l--;
    q[i].r--;
    q[i].id = i;
  }
  sort(q, q + t, cmp);
  solve(a, n, q, t, ans);
  for (i = 0; i < t; i++) cout << ans[i] << endl;
  return 0;
}
