#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 69;
const long long MAXA = 1e6 + 69;
const long long S = 1e3 + 69;
struct vl {
  long long l, r, i;
  bool operator<(const vl &t) const {
    if (l / S == t.l / S) return r < t.r;
    return l / S < t.l / S;
  }
};
long long n, t;
long long a[MAXN];
long long cnt[MAXA];
vl q[MAXN];
long long ans[MAXN];
long long L = 1, R = 0;
long long res;
void update(long long i, long long v) {
  res -= i * cnt[i] * cnt[i];
  cnt[i] += v;
  res += i * cnt[i] * cnt[i];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> t;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1, l, r; i <= t; i++) {
    cin >> l >> r;
    q[i] = {l, r, i};
  }
  sort(q + 1, q + 1 + t);
  for (long long i = 1; i <= t; i++) {
    long long l = q[i].l, r = q[i].r;
    while (L - 1 >= l) L--, update(a[L], 1);
    while (R + 1 <= r) R++, update(a[R], 1);
    while (L + 1 <= l) update(a[L], -1), L++;
    while (R - 1 >= r) update(a[R], -1), R--;
    ans[q[i].i] = res;
  }
  for (long long i = 1; i <= t; i++) cout << ans[i] << '\n';
}
