#include <bits/stdc++.h>
using namespace std;
long long n, m, k, ks, f[1000039], s[200039], q[200039], tot, pus, a[200039],
    l = 1, r = 0, ans[200039];
struct yyy {
  int x, y, num;
} sf[200039];
inline bool cmp(yyy x, yyy y) {
  return (s[x.x] ^ s[y.x]) ? (x.x < y.x)
                           : ((s[x.x] & 1) ? x.y < y.y : x.y > y.y);
}
int main() {
  register int i, j;
  scanf("%lld%lld", &n, &m);
  ks = sqrt(n);
  for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (i = 1; i <= ks; i++) s[i] = 1;
  for (i = ks + 1; i <= n; i++) s[i] = s[i - ks] + 1;
  for (i = 1; i <= m; i++) {
    scanf("%lld%lld", &sf[i].x, &sf[i].y);
    sf[i].num = i;
  }
  sort(sf + 1, sf + m + 1, cmp);
  for (i = 1; i <= m; i++) {
    while (sf[i].x < l) l--, tot += (f[a[l]] * 2 + 1) * a[l], f[a[l]]++;
    while (sf[i].x > l) tot -= (f[a[l]] * 2 - 1) * a[l], f[a[l]]--, l++;
    while (sf[i].y < r) tot -= (f[a[r]] * 2 - 1) * a[r], f[a[r]]--, r--;
    while (sf[i].y > r) r++, tot += (f[a[r]] * 2 + 1) * a[r], f[a[r]]++;
    ans[sf[i].num] = tot;
  }
  for (i = 1; i <= m; i++) printf("%lld\n", ans[i]);
}
