#include <bits/stdc++.h>
using namespace std;
const long long R = 480;
const long long N = 2e6 + 5;
vector<pair<pair<long long, long long>, long long> > q;
long long n, t;
long long cnt[N];
long long a[N];
long long jvb[N];
long long ans = 0;
bool cmp(pair<pair<long long, long long>, long long> q1,
         pair<pair<long long, long long>, long long> q2) {
  long long l1 = q1.first.first;
  long long r1 = q1.first.second;
  long long l2 = q2.first.first;
  long long r2 = q2.first.second;
  if (l1 / R != l2 / R) {
    return l1 / R < l2 / R;
  }
  if ((l1 / R) % 2 == 0) {
    return r1 < r2;
  } else {
    return r2 > r1;
  }
}
void solver(long long l0, long long r0, long long l1, long long r1) {
  for (long long i = r0; i < r1; i++) {
    long long tmp = a[i];
    ans -= cnt[tmp] * cnt[tmp] * tmp;
    cnt[tmp]++;
    ans += cnt[tmp] * cnt[tmp] * tmp;
  }
  for (long long i = l0 - 1; i >= l1; i--) {
    long long tmp = a[i];
    ans -= cnt[tmp] * cnt[tmp] * tmp;
    cnt[tmp]++;
    ans += cnt[tmp] * cnt[tmp] * tmp;
  }
  for (long long i = r0 - 1; i >= r1; i--) {
    long long tmp = a[i];
    ans -= cnt[tmp] * cnt[tmp] * tmp;
    cnt[tmp]--;
    ans += cnt[tmp] * cnt[tmp] * tmp;
  }
  for (long long i = l0; i < l1; i++) {
    long long tmp = a[i];
    ans -= cnt[tmp] * cnt[tmp] * tmp;
    cnt[tmp]--;
    ans += cnt[tmp] * cnt[tmp] * tmp;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> t;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < t; i++) {
    long long l, r;
    cin >> l >> r;
    pair<int, int> tmp = {l, r};
    q.push_back({tmp, i});
  }
  sort(q.begin(), q.end(), cmp);
  long long l = 0;
  long long r = 0;
  for (long long i = 0; i < t; i++) {
    solver(l, r, q[i].first.first - 1, q[i].first.second);
    l = q[i].first.first - 1;
    r = q[i].first.second;
    jvb[q[i].second] = ans;
  }
  for (int i = 0; i < t; i++) {
    cout << jvb[i] << '\n';
  }
}
