#include <bits/stdc++.h>
using namespace std;
struct MO {
  int l, r, idx;
} Q[200005];
long long ans, answer[200005], a[200005], freq[1000005], B;
bool MO_COMP(const MO &lhs, const MO &rhs) {
  if (lhs.l / B != rhs.l / B) return lhs.l / B < rhs.l / B;
  return lhs.r < rhs.r;
}
void add(int pos) {
  ans += a[pos] * (2 * freq[a[pos]] + 1);
  freq[a[pos]]++;
}
void remove(int pos) {
  ans += a[pos] * (-2 * freq[a[pos]] + 1);
  freq[a[pos]]--;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  B = sqrt(n) + 1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d", &Q[i].l, &Q[i].r);
    Q[i].idx = i;
  }
  sort(Q + 1, Q + m + 1, MO_COMP);
  int curL = 1, curR = 1;
  for (int i = 1; i <= m; ++i) {
    int L = Q[i].l, R = Q[i].r;
    while (curL < L) {
      remove(curL);
      curL++;
    }
    while (curL > L) {
      add(curL - 1);
      curL--;
    }
    while (curR <= R) {
      add(curR);
      curR++;
    }
    while (curR > R + 1) {
      remove(curR - 1);
      curR--;
    }
    answer[Q[i].idx] = ans;
  }
  for (int i = 1; i <= m; ++i) {
    printf("%lld\n", answer[i]);
  }
  return 0;
}
