#include <bits/stdc++.h>
using namespace std;
int n, m, a[200005], S, cnt[200005 * 10];
long long res[200005], ans;
struct A {
  int l, r, id;
} b[200005];
bool cmp(A a, A b) {
  if (a.r / S != b.r / S) return a.r < b.r;
  return a.l < b.l;
}
void add(int x) {
  cnt[x]++;
  ans += 1ll * (2 * cnt[x] - 1) * x;
}
void sub(int x) {
  cnt[x]--;
  ans -= 1ll * (2 * cnt[x] + 1) * x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  S = sqrt(n);
  for (int i = 1; i <= m; i++) {
    cin >> b[i].l >> b[i].r;
    b[i].id = i;
  }
  sort(b + 1, b + m + 1, cmp);
  int L = 1, R = 0;
  for (int i = 1; i <= m; i++) {
    int l = b[i].l, r = b[i].r;
    while (R < r) add(a[++R]);
    while (L > l) add(a[--L]);
    while (L < l) sub(a[L++]);
    while (R > r) sub(a[R--]);
    res[b[i].id] = ans;
  }
  for (int i = 1; i <= m; i++) cout << res[i] << '\n';
  return 0;
}
