#include <bits/stdc++.h>
using namespace std;
int n, m, arr[200005], sz, fq[1000005];
pair<pair<int, int>, int> q[200005];
long long sq[200005], ans[200005], ca;
bool cmp(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {
  int nx = x.first.first / sz;
  int ny = y.first.first / sz;
  if (nx != ny) return ny > nx;
  return y.first.second > x.first.second;
}
int add(int x) {
  ca -= (sq[fq[x]] * x);
  fq[x]++;
  ca += (sq[fq[x]] * x);
}
int rem(int x) {
  ca -= (sq[fq[x]] * x);
  fq[x]--;
  ca += (sq[fq[x]] * x);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  for (long long i = 0; i <= 200000; i++) sq[i] = i * i;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &q[i].first.first, &q[i].first.second);
    q[i].first.first--;
    q[i].first.second--;
    q[i].second = i;
  }
  sz = sqrt(n);
  sort(q, q + m, cmp);
  int ml = 0, mr = -1;
  for (int i = 0; i < m; i++) {
    int l = q[i].first.first;
    int r = q[i].first.second;
    while (mr < r) {
      mr++;
      add(arr[mr]);
    }
    while (mr > r) {
      rem(arr[mr]);
      mr--;
    }
    while (ml < l) {
      rem(arr[ml]);
      ml++;
    }
    while (ml > l) {
      ml--;
      add(arr[ml]);
    }
    ans[q[i].second] = ca;
  }
  for (int i = 0; i < m; i++) printf("%I64d\n", ans[i]);
}
