#include <bits/stdc++.h>
using namespace std;
struct query {
  int L, R, index;
};
int BLOCK;
bool cmp(query A, query B) {
  if (A.L / BLOCK != B.L / BLOCK) {
    return A.L / BLOCK < B.L / BLOCK;
  }
  return A.R < B.R;
}
query Q[200001];
int Count[1000001], a[200001];
long long ans[200001], answer, Ks, s;
inline void remove(long long position) {
  Count[a[position]]--;
  Ks = Count[a[position]];
  s = a[position];
  answer -= (2 * Ks + 1LL) * s;
}
inline void add(long long position) {
  Count[a[position]]++;
  Ks = Count[a[position]];
  s = a[position];
  answer += (2 * Ks - 1LL) * s;
}
int main() {
  int n, i, q, L, R, currL, currR;
  scanf("%d %d", &n, &q);
  answer = 0;
  BLOCK = 450;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < q; i++) {
    scanf("%d %d", &L, &R);
    Q[i].L = L - 1;
    Q[i].R = R - 1;
    Q[i].index = i;
  }
  sort(Q, Q + q, cmp);
  currR = currL = 0;
  for (i = 0; i < q; i++) {
    L = Q[i].L;
    R = Q[i].R;
    while (currL < L) {
      remove(currL);
      currL++;
    }
    while (currL > L) {
      currL--;
      add(currL);
    }
    while (currR <= R) {
      add(currR);
      currR++;
    }
    while (currR > R + 1) {
      remove(currR - 1);
      currR--;
    }
    ans[Q[i].index] = answer;
  }
  for (i = 0; i < q; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
