#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e2 * 2;
const int TMXN = 1048576;
const long long INF = 1e9 + 7;
const long long INFL = 1e18;
struct query {
  int l, r, id;
};
int n;
int a[TMXN];
long long ans[TMXN];
long long res;
int cnt[TMXN];
int m, k;
query q[TMXN];
bool cmp(query a, query b) {
  if (a.l / 447 != b.l / 447) return (a.l / 447 < b.l / 447);
  return a.r < b.r;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].l;
    q[i].id = i;
  }
  int L = 0, R = -1;
  sort(q + 1, q + m + 1, cmp);
  for (int i = 1; i <= m; i++) {
    while (q[i].r > R) {
      R++;
      res += (((cnt[a[R]] + 1) * (cnt[a[R]] + 1) * a[R])) -
             ((cnt[a[R]] * cnt[a[R]]) * a[R]);
      cnt[a[R]]++;
    }
    while (q[i].l < L) {
      L--;
      res += (((cnt[a[L]] + 1) * (cnt[a[L]] + 1) * a[L])) -
             ((cnt[a[L]] * cnt[a[L]]) * a[L]);
      cnt[a[L]]++;
    }
    while (q[i].r < R) {
      res -= ((cnt[a[R]] * cnt[a[R]]) * a[R]) -
             (((cnt[a[R]] - 1) * (cnt[a[R]] - 1) * a[R]));
      cnt[a[R]]--;
      R--;
    }
    while (q[i].l > L) {
      res -= ((cnt[a[L]] * cnt[a[L]]) * a[L]) -
             (((cnt[a[L]] - 1) * (cnt[a[L]] - 1) * a[L]));
      cnt[a[L]]--;
      L++;
    }
    ans[q[i].id] = res;
  }
  for (int i = 1; i <= m; i++) printf("%I64d\n", ans[i]);
  return 0;
}
