#include <bits/stdc++.h>
using namespace std;
struct node_qry {
  int l, r, indx, bucket_indx;
  long long res;
};
node_qry qry[200005];
long long a[200005], cnt[1000005], ans;
int bucket_size, n, q;
bool comp1(node_qry na, node_qry nb) {
  if (na.bucket_indx == nb.bucket_indx) return (na.r < nb.r);
  return (na.bucket_indx < nb.bucket_indx);
}
bool comp2(node_qry na, node_qry nb) { return (na.indx < nb.indx); }
void ADD(long long x) {
  long long temp = cnt[x] * cnt[x];
  temp *= x;
  ans -= temp;
  cnt[x]++;
  temp = cnt[x] * cnt[x];
  temp *= x;
  ans += temp;
  return;
}
void REMOVE(long long x) {
  long long temp = cnt[x] * cnt[x];
  temp *= x;
  ans -= temp;
  cnt[x]--;
  temp = cnt[x] * cnt[x];
  temp *= x;
  ans += temp;
  return;
}
void MO_s_algo() {
  sort(qry, qry + q, comp1);
  int l = qry[0].l, r = qry[0].r;
  ans = 0;
  for (int i = 0; i < q; i++) {
    while (l < qry[i].l) {
      REMOVE(a[l]);
      l++;
    }
    while (l > qry[i].l) {
      l--;
      ADD(a[l]);
    }
    while (r < qry[i].r) {
      r++;
      ADD(a[r]);
    }
    while (r > qry[i].r) {
      REMOVE(a[r]);
      r--;
    }
    if (i == 0) {
      for (int j = l; j <= r; j++) {
        ADD(a[j]);
      }
    }
    qry[i].res = ans;
  }
  sort(qry, qry + q, comp2);
  return;
}
int main() {
  int i;
  scanf("%d %d", &n, &q);
  for (i = 0; i < n; i++) scanf("%lld", &a[i]);
  bucket_size = sqrt(n);
  for (i = 0; i < q; i++) {
    scanf("%d %d", &qry[i].l, &qry[i].r);
    qry[i].l--;
    qry[i].r--;
    qry[i].indx = i;
    qry[i].bucket_indx = (qry[i].l + 1) / bucket_size;
  }
  MO_s_algo();
  for (i = 0; i < q; i++) printf("%lld\n", qry[i].res);
  return 0;
}
