#include <bits/stdc++.h>
using namespace std;
const int M4 = 1e4 + 10, M5 = 1e5 + 10, M6 = 1e6 + 10;
const int S = 1500;
int ql[2 * M5], qr[2 * M5], q[M5 * 2];
long long f[M6], ans[M5 * 2], a[M5 * 2], A;
inline void add(int p) {
  A -= (f[a[p]] * f[a[p]] * a[p]);
  f[a[p]]++;
  A += (f[a[p]] * f[a[p]] * a[p]);
}
inline void del(int p) {
  A -= (f[a[p]] * f[a[p]] * a[p]);
  f[a[p]]--;
  A += (f[a[p]] * f[a[p]] * a[p]);
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; i++) scanf("%I64d", a + i);
  for (int i = 0; i < t; i++) scanf("%d%d", ql + i, qr + i), ql[i]--, qr[i]--;
  iota(q, q + t + 1, 0);
  sort(q, q + t, [&](int a, int b) {
    return ql[a] / S == ql[b] / S ? qr[a] < qr[b] : ql[a] / S < ql[b] / S;
  });
  int l = 0, r = -1;
  for (int i = 0; i < t; i++) {
    int R = qr[q[i]], L = ql[q[i]];
    while (r < R) add(++r);
    while (l > L) add(--l);
    while (r > R)
      if (r-- != l) del(r + 1);
    while (l < L)
      if (r != l++) del(l - 1);
    ans[q[i]] = A;
  }
  for (int i = 0; i < t; i++) printf("%I64d\n", ans[i]);
  return 0;
}
