#include <bits/stdc++.h>
using namespace std;
int a[200005], cnt[5 * 200005];
long long answer, ans[200005];
struct node {
  int l, r, i;
} q[200005];
bool cmp(node x, node y) {
  if (x.l / 448 != y.l / 448) {
    return x.l / 448 < y.l / 448;
  }
  return x.r < y.r;
}
inline void add(int pos) {
  long long temp = cnt[a[pos]];
  answer -= temp * temp * a[pos];
  cnt[a[pos]]++, temp++;
  answer += temp * temp * a[pos];
}
inline void remove(int pos) {
  long long temp = cnt[a[pos]];
  answer -= temp * temp * a[pos];
  cnt[a[pos]]--, temp--;
  answer += temp * temp * a[pos];
}
int main() {
  int n, t;
  scanf("%d %d", &n, &t);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < t; i++) {
    scanf("%d %d", &q[i].l, &q[i].r);
    q[i].l--, q[i].r--;
    q[i].i = i;
  }
  sort(q, q + t, cmp);
  int currentL = 0, currentR = 0;
  for (int i = 0; i < t; i++) {
    int l = q[i].l, r = q[i].r;
    while (currentL < l) {
      remove(currentL);
      currentL++;
    }
    while (currentL > l) {
      add(currentL - 1);
      currentL--;
    }
    while (currentR <= r) {
      add(currentR);
      currentR++;
    }
    while (currentR > r + 1) {
      remove(currentR - 1);
      currentR--;
    }
    ans[q[i].i] = answer;
  }
  for (int i = 0; i < t; i++) {
    printf("%I64d\n", ans[i]);
  }
  return 0;
}
