#include <bits/stdc++.h>
const double PI = 3.141592653589793238460;
using namespace std;
int fre[1000001], ar[200001];
long long int ans[200001];
long long int power = 0;
struct query {
  int l;
  int r;
  int i;
};
query Q[200001];
bool comp(query a, query b) {
  if (a.l / 500 != b.l / 500) return a.l / 500 < b.l / 500;
  return a.r < b.r;
}
void add(int pos) {
  long long int cnt = fre[ar[pos]];
  fre[ar[pos]]++;
  power -= (cnt * cnt) * ar[pos], cnt++;
  power += (cnt * cnt) * ar[pos];
}
void remove(int pos) {
  long long int cnt = fre[ar[pos]];
  fre[ar[pos]]--;
  power -= (cnt * cnt) * ar[pos], cnt--;
  power += (cnt * cnt) * ar[pos];
}
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> ar[i - 1];
  for (int 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);
  int ML = 0, MR = -1;
  for (int i = 0; i < q; i++) {
    int L = Q[i].l;
    int R = Q[i].r;
    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[Q[i].i] = power;
  }
  for (int i = 1; i <= q; i++) cout << ans[i - 1] << '\n';
}
