#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long belong[1000005], s[1000005], a[1000005];
long long n, m, Size, number, ans[1000005], now;
struct Queue {
  long long l, r, id;
} q[1000005];
bool cmp(Queue a, Queue b) {
  return (belong[a.l] ^ belong[b.l])
             ? belong[a.l] < belong[b.l]
             : ((belong[a.l] & 1) ? a.r < b.r : a.r > b.r);
}
signed main() {
  scanf("%lld %lld", &n, &m);
  Size = sqrt(n);
  number = ceil((double)n / Size);
  for (long long i = 1; i <= number; i++) {
    for (long long j = (i - 1) * Size + 1; j <= i * Size; j++) {
      belong[j] = i;
    }
  }
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (long long i = 1; i <= m; i++) {
    scanf("%lld %lld", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + m + 1, cmp);
  long long l = 1, r = 0;
  for (long long i = 1; i <= m; i++) {
    long long ql = q[i].l, qr = q[i].r;
    while (l < ql) now -= (2 * s[a[l]] - 1) * a[l], s[a[l]]--, l++;
    while (l > ql) l--, now += (2 * s[a[l]] + 1) * a[l], s[a[l]]++;
    while (r < qr) r++, now += (2 * s[a[r]] + 1) * a[r], s[a[r]]++;
    while (r > qr) now -= (2 * s[a[r]] - 1) * a[r], s[a[r]]--, r--;
    ans[q[i].id] = now;
  }
  for (long long i = 1; i <= m; i++) printf("%lld\n", ans[i]);
  return 0;
}
