#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2e5 + 11;
const int Amax = 1e6 + 11;
const int block = 507;
int n, t, a[Nmax], cnt[Amax];
long long cur, res[Nmax];
struct query {
  int l, r, id;
} q[Nmax];
bool cmp(query a, query b) {
  if (a.l / block == b.l / block)
    return a.r < b.r;
  else
    return a.l < b.l;
}
void upd(int l, int r, int v) {
  for (int i = (int)l; i <= (int)r; ++i) {
    cur -= 1LL * cnt[a[i]] * cnt[a[i]] * a[i];
    cnt[a[i]] += v;
    cur += 1LL * cnt[a[i]] * cnt[a[i]] * a[i];
  }
}
int main() {
  scanf("%d %d", &n, &t);
  for (int i = (int)1; i <= (int)n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = (int)1; i <= (int)t; ++i) {
    scanf("%d %d", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + t + 1, cmp);
  for (int i = (int)1; i <= (int)t; ++i) {
    if (q[i - 1].l < q[i].l)
      upd(q[i - 1].l, q[i].l - 1, -1);
    else
      upd(q[i].l, q[i - 1].l - 1, 1);
    if (q[i - 1].r < q[i].r)
      upd(q[i - 1].r + 1, q[i].r, 1);
    else
      upd(q[i].r + 1, q[i - 1].r, -1);
    res[q[i].id] = cur;
  }
  for (int i = (int)1; i <= (int)t; ++i) {
    cout << res[i] << '\n';
  }
}
