#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 7;
int arr[M], s_sz, cnt[M], cnt1[M];
long long cur_ans, answers[M];
struct query {
  int l, r, idx;
};
query qry[M];
bool way(const query &a, const query &b) {
  int seg1 = a.l / s_sz, seg2 = b.l / s_sz;
  if (seg1 == seg2)
    return a.r < b.r;
  else
    return seg1 < seg2;
}
void add(int x) {
  cur_ans -= 1ll * cnt[x] * cnt[x] * x;
  cnt[x]++;
  cur_ans += 1ll * cnt[x] * cnt[x] * x;
}
void remov(int x) {
  cur_ans -= 1ll * cnt[x] * cnt[x] * x;
  cnt[x]--;
  cur_ans += 1ll * cnt[x] * cnt[x] * x;
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  s_sz = ceil(sqrt(n));
  for (int i = 0; i < n; i++) scanf("%d", arr + i);
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--, r--;
    qry[i].l = l;
    qry[i].r = r;
    qry[i].idx = i;
  }
  sort(qry, qry + q, way);
  int mo_left = 0, mo_right = -1;
  for (int i = 0; i < q; i++) {
    int left = qry[i].l;
    int right = qry[i].r;
    while (mo_right < right) {
      mo_right++;
      add(arr[mo_right]);
    }
    while (mo_right > right) {
      remov(arr[mo_right]);
      mo_right--;
    }
    while (mo_left < left) {
      remov(arr[mo_left]);
      mo_left++;
    }
    while (mo_left > left) {
      mo_left--;
      add(arr[mo_left]);
    }
    answers[qry[i].idx] = cur_ans;
  }
  for (int i = 0; i < q; i++) {
    printf("%I64d\n", answers[i]);
  }
  return 0;
}
