#include <bits/stdc++.h>
using namespace std;
const int maxn = 220000;
int unit;
int num[1111111], a[maxn];
long long tmp, ans[maxn];
struct node {
  int i, l, r;
} query[maxn];
int cmp(node l1, node l2) {
  if (l1.l / unit == l2.l / unit) return l1.r < l2.r;
  return l1.l / unit < l2.l / unit;
}
void insert(long long x) {
  tmp -= x * num[x] * num[x];
  ++num[x];
  tmp += x * num[x] * num[x];
}
void remove(long long x) {
  tmp -= x * num[x] * num[x];
  --num[x];
  tmp += x * num[x] * num[x];
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  unit = (int)sqrt((double)n);
  for (int i = 0; i < t; ++i) {
    query[i].i = i;
    scanf("%d%d", &query[i].l, &query[i].r);
  }
  sort(query, query + t, cmp);
  int l = 1, r = 0;
  for (int i = 0; i < t; ++i) {
    while (l < query[i].l) remove(a[l++]);
    while (l > query[i].l) insert(a[--l]);
    while (r > query[i].r) remove(a[r--]);
    while (r < query[i].r) insert(a[++r]);
    ans[query[i].i] = tmp;
  }
  for (int i = 0; i < t; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
