#include <bits/stdc++.h>
using namespace std;
int n, t, a[300000], cnt[1100000];
long long res[300000];
struct query {
  int l, r, id, p;
  bool operator<(const query &x) const {
    return p < x.p || (p == x.p && r < x.r);
  }
} b[300000];
signed main() {
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  int chunk = floor(sqrt(n) + .5);
  for (int i = 0; i < t; i++) {
    scanf("%d%d", &b[i].l, &b[i].r);
    b[i].id = i;
    b[i].p = b[i].l / chunk;
  }
  sort(b, b + t);
  int l = 1, r = 0;
  long long ans = 0;
  for (int i = 0; i < t; i++) {
    while (r < b[i].r) {
      r++;
      ans += ((cnt[a[r]]++ << 1) + 1ll) * a[r];
    }
    while (r > b[i].r) {
      ans -= ((cnt[a[r]]-- << 1) - 1ll) * a[r];
      r--;
    }
    while (l < b[i].l) {
      ans -= ((cnt[a[l]]-- << 1) - 1ll) * a[l];
      l++;
    }
    while (l > b[i].l) {
      l--;
      ans += ((cnt[a[l]]++ << 1) + 1ll) * a[l];
    }
    res[b[i].id] = ans;
  }
  for (int i = 0; i < t; i++) printf("%I64d\n", res[i]);
  return 0;
}
