#include <bits/stdc++.h>
int a[200005], cnt[1000005], n, m, siz;
long long ans[200005];
struct que {
  int l, r, id;
  inline bool operator<(const que& rhs) const {
    return (l / siz != rhs.l / siz ? l < rhs.l : r < rhs.r);
  }
} q[200005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  siz = n / sqrt(m) + 1;
  for (int i = 1; i <= m; ++i) scanf("%d%d", &q[i].l, &q[q[i].id = i].r);
  std::sort(q + 1, q + m + 1);
  long long now = 0;
  for (int l = 1, r = 0, i = 1; i <= m; ++i) {
    while (r < q[i].r) {
      ++r;
      now += a[r] * (1LL + 2 * cnt[a[r]]);
      ++cnt[a[r]];
    }
    while (l > q[i].l) {
      --l;
      now += a[l] * (1LL + 2 * cnt[a[l]]);
      ++cnt[a[l]];
    }
    while (r > q[i].r) {
      --cnt[a[r]];
      now -= a[r] * (1LL + 2 * cnt[a[r]]);
      --r;
    }
    while (l < q[i].l) {
      --cnt[a[l]];
      now -= a[l] * (1LL + 2 * cnt[a[l]]);
      ++l;
    }
    ans[q[i].id] = now;
  }
  for (int i = 1; i <= m; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
