#include <bits/stdc++.h>
using namespace std;
struct query {
  long long l;
  long long r;
  long long i;
};
query Q[200001];
long long ar[200001];
long long ans[200001];
long long freq[1000001];
long long power = 0;
bool comp(query a, query b) {
  if (a.l / 555 != b.l / 555) return a.l / 555 < b.l / 555;
  return a.r / 555 < b.r / 555;
}
void add(long long pos) {
  long long ele = ar[pos];
  long long cur = freq[ele];
  freq[ele]++;
  long long curF = freq[ele];
  power -= (cur * cur * ele);
  power += (curF * curF * ele);
}
void remove(long long pos) {
  long long ele = ar[pos];
  long long cur = freq[ele];
  freq[ele]--;
  long long curF = freq[ele];
  power -= (cur * cur * ele);
  power += (curF * curF * ele);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, q;
  cin >> n >> q;
  for (long long i = 0; i < n; i++) cin >> ar[i];
  for (long long i = 0; i < q; i++) {
    cin >> Q[i].l >> Q[i].r;
    Q[i].i = i, Q[i].l--, Q[i].r--;
  }
  sort(Q, Q + q, comp);
  long long ML = 0, MR = -1;
  for (int i = 0; i < q; i++) {
    long long L = Q[i].l;
    long long R = Q[i].r;
    int idx = Q[i].i;
    while (ML > L) ML--, add(ML);
    while (MR < R) MR++, add(MR);
    while (ML < L) remove(ML), ML++;
    while (MR > R) remove(MR), MR--;
    ans[idx] = power;
  }
  for (long long i = 0; i < q; i++) cout << ans[i] << '\n';
}
