#include <bits/stdc++.h>
using namespace std;
int a[200010], sqt, tp2, b[1000010];
long long ans, c[200010];
struct node {
  int l, r, i;
};
node v[200010], tp;
void add(int i) {
  tp2 = a[i];
  ans -= (long long)b[tp2] * (long long)b[tp2] * (long long)tp2;
  b[tp2]++;
  ans += (long long)b[tp2] * (long long)b[tp2] * (long long)tp2;
  return;
}
void remove(int i) {
  tp2 = a[i];
  ans -= (long long)b[tp2] * (long long)b[tp2] * (long long)tp2;
  b[tp2]--;
  ans += (long long)b[tp2] * (long long)b[tp2] * (long long)tp2;
  return;
}
bool cmp(node w, node e) {
  if (w.l / sqt != e.l / sqt) return w.l / sqt < e.l / sqt;
  return w.r < e.r;
}
int main() {
  int q, n, i, l, r, L, R;
  scanf("%d%d", &n, &q);
  sqt = 1000;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 0; i < q; i++) {
    scanf("%d%d", &v[i].l, &v[i].r);
    v[i].i = i;
  }
  sort(v, v + q, cmp);
  l = 1;
  r = 1;
  ans = a[1];
  b[a[1]] = 1;
  for (i = 0; i < q; i++) {
    tp = v[i];
    L = tp.l;
    R = tp.r;
    while (l < L) {
      remove(l);
      l++;
    }
    while (l > L) {
      add(l - 1);
      l--;
    }
    while (r < R) {
      add(r + 1);
      r++;
    }
    while (r > R) {
      remove(r);
      r--;
    }
    c[tp.i] = ans;
  }
  for (i = 0; i < q; i++) printf("%I64d\n", c[i]);
  return 0;
}
