#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long arr[200005], ans[200005], freq[1000005];
long long BLK = 450, cnt = 0;
struct query {
  int l;
  int r;
  int i;
};
query qr[200005];
bool comp(query a, query b) {
  if (a.l / BLK != b.l / BLK) return a.l / BLK < b.l / BLK;
  return a.r < b.r;
}
void add(long long pos) {
  long long temp = arr[pos];
  long long fre = freq[temp];
  freq[temp]++;
  cnt -= fre * fre * temp;
  fre++;
  cnt += fre * fre * temp;
}
void remove(long long pos) {
  long long temp = arr[pos];
  long long fre = freq[temp];
  freq[temp]--;
  cnt -= fre * fre * temp;
  fre--;
  cnt += fre * fre * temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i <= q; i++) {
    cin >> qr[i].l >> qr[i].r;
    qr[i].i = i;
  }
  sort(qr + 1, qr + q + 1, comp);
  long long MR = 0, ML = 1, L, R;
  for (int i = 1; i <= q; i++) {
    L = qr[i].l, R = qr[i].r;
    while (ML > L) ML--, add(ML);
    while (ML < L) remove(ML), ML++;
    while (MR > R) remove(MR), MR--;
    while (MR < R) MR++, add(MR);
    ans[qr[i].i] = cnt;
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
  return 0;
}
