#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 200010;
const int M = 1000010;
long long cnt[M];
int arr[N];
long long ans[N];
int unit;
struct info {
  int l, r;
  int d;
  int b;
  bool operator<(const info &t) const {
    if (b == t.b) return r < t.r;
    return b < t.b;
  }
};
info node[N];
int Scan() {
  int res = 0, ch, flag = 0;
  if ((ch = getchar()) == '-')
    flag = 1;
  else if (ch >= '0' && ch <= '9')
    res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';
  return flag ? -res : res;
}
int main(void) {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  getchar();
  unit = (int)sqrt(n + 0.5);
  for (i = 1; i <= n; ++i) arr[i] = Scan();
  for (i = 0; i < m; ++i) {
    node[i].l = Scan();
    node[i].r = Scan();
    node[i].d = i;
    node[i].b = node[i].l / unit;
  }
  sort(node, node + m);
  int L = node[0].l;
  int R = L - 1;
  long long power = 0;
  for (i = 0; i < m; ++i) {
    while (L > node[i].l) {
      --L;
      power = power + arr[L] * ((cnt[arr[L]] << 1) + 1);
      ++cnt[arr[L]];
    }
    while (L < node[i].l) {
      --cnt[arr[L]];
      power = power - arr[L] * ((cnt[arr[L]] << 1) + 1);
      ++L;
    }
    while (R > node[i].r) {
      --cnt[arr[R]];
      power = power - arr[R] * ((cnt[arr[R]] << 1) + 1);
      --R;
    }
    while (R < node[i].r) {
      ++R;
      power = power + arr[R] * ((cnt[arr[R]] << 1) + 1);
      ++cnt[arr[R]];
    }
    ans[node[i].d] = power;
  }
  for (i = 0; i < m; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
