#include <bits/stdc++.h>
using namespace std;
const long long root = 417, maxn = 2e5 + 3, maxv = 1e6 + 3;
struct qry_ {
  long long idx, L, R;
} qry[maxn];
long long n, v[maxn], ap[maxv];
long long q, ans[maxn];
int main() {
  scanf("%lld %lld", &n, &q);
  for (long long i = 0; i < n; i++) scanf("%lld", &v[i]);
  for (long long i = 0; i < q; i++) {
    scanf("%lld %lld", &qry[i].L, &qry[i].R);
    qry[i].L--;
    qry[i].R--;
    qry[i].idx = i;
  }
  sort(qry, qry + q, [](const qry_ &A, const qry_ &B) {
    if (A.L / root == B.L / root) return A.R < B.R;
    return A.L < B.L;
  });
  long long moL, tot = 0, moR;
  for (long long i = qry[0].L; i <= qry[0].R; i++) {
    tot -= ap[v[i]] * ap[v[i]] * v[i];
    ap[v[i]]++;
    tot += ap[v[i]] * ap[v[i]] * v[i];
  }
  moL = qry[0].L;
  moR = qry[0].R;
  for (long long i = 0; i < q; i++) {
    while (moL < qry[i].L) {
      tot -= ap[v[moL]] * ap[v[moL]] * v[moL];
      ap[v[moL]]--;
      tot += ap[v[moL]] * ap[v[moL]] * v[moL];
      moL++;
    }
    while (moR > qry[i].R) {
      tot -= ap[v[moR]] * ap[v[moR]] * v[moR];
      ap[v[moR]]--;
      tot += ap[v[moR]] * ap[v[moR]] * v[moR];
      moR--;
    }
    while (moL > qry[i].L) {
      moL--;
      tot -= ap[v[moL]] * ap[v[moL]] * v[moL];
      ap[v[moL]]++;
      tot += ap[v[moL]] * ap[v[moL]] * v[moL];
    }
    while (moR < qry[i].R) {
      moR++;
      tot -= ap[v[moR]] * ap[v[moR]] * v[moR];
      ap[v[moR]]++;
      tot += ap[v[moR]] * ap[v[moR]] * v[moR];
    }
    ans[qry[i].idx] = tot;
  }
  for (long long i = 0; i < q; i++) printf("%lld\n", ans[i]);
  return 0;
}
