#include <bits/stdc++.h>
using namespace std;
const int NMAX = 200005;
const int VALMAX = 1000005;
int v[NMAX];
struct Query {
  int st, dr;
  int bucket;
  int poz;
};
Query q[NMAX];
long long vf[VALMAX];
long long sol[NMAX];
long long solt = 0;
bool cmp(Query first, Query second) {
  if (first.bucket == second.bucket) {
    return first.dr < second.dr;
  }
  return first.bucket < second.bucket;
}
void add(int nr, int val) {
  solt = solt - vf[nr] * vf[nr] * (long long)nr;
  vf[nr] += val;
  solt = solt + vf[nr] * vf[nr] * (long long)nr;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
  }
  int rad = (int)sqrt((double)n);
  rad++;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &q[i].st, &q[i].dr);
    q[i].bucket = q[i].st / rad;
    q[i].poz = i;
  }
  sort(q + 1, q + m + 1, cmp);
  int st = 1, dr = 0;
  for (int i = 1; i <= m; i++) {
    while (dr < q[i].dr) {
      dr++;
      add(v[dr], 1);
    }
    while (dr > q[i].dr) {
      add(v[dr], -1);
      dr--;
    }
    while (st < q[i].st) {
      add(v[st], -1);
      st++;
    }
    while (st > q[i].st) {
      st--;
      add(v[st], 1);
    }
    sol[q[i].poz] = solt;
  }
  for (int i = 1; i <= m; i++) {
    printf("%lld\n", sol[i]);
  }
  return 0;
}
