#include <bits/stdc++.h>
using namespace std;
struct data {
  long long l, r, cs, f;
} b[200010];
long long n, q, a[200010], part, cnt[1000010], res, p[200010];
bool cmp(data a, data b) {
  if (a.f == b.f) return a.r < b.r;
  return a.f < b.f;
}
void add(long long u) { res += (1 + 2 * cnt[a[u]]++) * a[u]; }
void del(long long u) { res -= (-1 + 2 * cnt[a[u]]--) * a[u]; }
int main() {
  ios::sync_with_stdio(0);
  scanf("%I64d %I64d", &n, &q);
  for (long long i = (1), _b = (n); i <= _b; i++) scanf("%I64d", &a[i]);
  long long k = long(sqrt(n));
  part = n / k + (n % k > 0);
  for (long long i = (1), _b = (q); i <= _b; i++) {
    scanf("%I64d %I64d", &b[i].l, &b[i].r);
    b[i].cs = i;
    b[i].f = b[i].l / part - (b[i].l % part == 0);
  }
  sort(b + 1, b + q + 1, cmp);
  long long currL = 1;
  long long currR = 1;
  res = a[1];
  cnt[a[1]]++;
  for (long long i = (1), _b = (q); i <= _b; i++) {
    while (currR > b[i].r) del(currR--);
    while (currR < b[i].r) add(++currR);
    while (currL < b[i].l) del(currL++);
    while (currL > b[i].l) add(--currL);
    p[b[i].cs] = res;
  }
  for (long long i = (1), _b = (q); i <= _b; i++) printf("%I64d\n", p[i]);
  return 0;
}
