#include <bits/stdc++.h>
using namespace std;
const long long BLK = 700;
struct query {
  long long l;
  long long r;
  long long idx;
};
query q[200001];
long long ans[200001];
long long ar[200001];
long long freq[1000001];
long long power = 0;
bool compare(query a, query b) {
  if (a.l / BLK != b.l / BLK) {
    return a.l / BLK < b.l / BLK;
  }
  return (a.l / BLK & 1) ? a.r < b.r : a.r > b.r;
}
void add(long long pos) {
  long long count = freq[ar[pos]];
  freq[ar[pos]]++;
  power -= (count * count) * ar[pos];
  count++;
  power += (count * count) * ar[pos];
}
void remove(long long pos) {
  long long count = freq[ar[pos]];
  freq[ar[pos]]--;
  power -= (count * count) * ar[pos];
  count--;
  power += (count * count) * ar[pos];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, nq;
  cin >> n >> nq;
  for (long long i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (long long i = 0; i < nq; i++) {
    cin >> q[i].l >> q[i].r;
    q[i].l--;
    q[i].r--;
    q[i].idx = i;
  }
  sort(q, q + nq, compare);
  long long ML = 0, MR = -1;
  for (long long i = 0; i < nq; i++) {
    long long l = q[i].l;
    long long 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].idx] = power;
  }
  for (long long i = 0; i < nq; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
