#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];
inline void add(long long &val, int &one) {
  val = val + one * (cnt[one] << 1) + one;
  ++cnt[one];
}
inline void del(long long &val, int &one) {
  val = val - one * (cnt[one] << 1) + one;
  --cnt[one];
}
int main(void) {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  unit = (int)sqrt(n + 0.5);
  for (i = 1; i <= n; ++i) scanf("%d", &arr[i]);
  for (i = 0; i < m; ++i) {
    scanf("%d%d", &node[i].l, &node[i].r);
    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) del(power, arr[L++]);
    while (L > node[i].l) add(power, arr[--L]);
    while (R < node[i].r) add(power, arr[++R]);
    while (R > node[i].r) del(power, arr[R--]);
    ans[node[i].d] = power;
  }
  for (i = 0; i < m; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
