#include <bits/stdc++.h>
using namespace std;
int block_size = 300;
int a[200005];
long long ans[200005];
int c[1000005] = {0};
struct Q {
  int l, r, i;
};
Q q[200005];
bool sortby(Q a, Q b) {
  int x = a.l / block_size;
  int y = b.l / block_size;
  if (x != y) return x < y;
  return a.r < b.r;
}
int main() {
  int n, t;
  cin >> n >> t;
  int i;
  block_size = ceil(sqrt(n));
  for (i = 0; i < n; i++) cin >> a[i];
  int l, r;
  for (i = 0; i < t; i++) {
    cin >> l >> r;
    l--, r--;
    q[i].l = l;
    q[i].r = r;
    q[i].i = i;
  }
  sort(q, q + t, sortby);
  int ml, mr;
  l = 0, r = -1;
  long long s = 0;
  for (i = 0; i < t; i++) {
    ml = q[i].l, mr = q[i].r;
    while (mr > r) {
      r++;
      c[a[r]]++;
      s += (2 * c[a[r]] - 1) * a[r];
    }
    while (ml > l) {
      c[a[l]]--;
      s -= (2 * c[a[l]] + 1) * a[l];
      l++;
    }
    while (mr < r) {
      c[a[r]]--;
      s -= (2 * c[a[r]] + 1) * a[r];
      r--;
    }
    while (ml < l) {
      l--;
      c[a[l]]++;
      s += (2 * c[a[l]] - 1) * a[l];
    }
    ans[q[i].i] = s;
  }
  for (i = 0; i < t; i++) cout << ans[i] << endl;
  return 0;
}
