#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
int n, m, block, l = 1, r;
long long sum;
long long a[2000010], cnt[2000010], ans[2000010];
struct query {
  int l, r, id, pos;
} q[2000010];
bool cmp(query a, query b) {
  return a.pos == b.pos ? (a.pos & 1 ? a.r < b.r : a.r > b.r) : a.pos < b.pos;
}
void update(long long x, int p) {
  x = a[x];
  sum -= cnt[x] * cnt[x] * x;
  cnt[x] += p;
  sum += cnt[x] * cnt[x] * x;
}
int main() {
  read(n), read(m);
  block = sqrt(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  for (int i = 1; i <= m; ++i) {
    read(q[i].l), read(q[i].r);
    q[i].id = i, q[i].pos = q[i].l / block;
  }
  sort(q + 1, q + m + 1, cmp);
  for (int i = 1; i <= m; ++i) {
    int ql = q[i].l, qr = q[i].r, id = q[i].id;
    while (l < ql) update(l++, -1);
    while (r > qr) update(r--, -1);
    while (l > ql) update(--l, 1);
    while (r < qr) update(++r, 1);
    ans[id] = sum;
  }
  for (int i = 1; i <= m; ++i) printf("%lld\n", ans[i]);
  return 0;
}
