#include <bits/stdc++.h>
using namespace std;
const int MXN = 2 * 1e5 + 5;
int n, t;
int sqrtn, a[MXN];
int freq[MXN * 10];
pair<int, pair<int, int> > Q[MXN];
unsigned long long answers[MXN];
unsigned long long ans = 0;
bool comp(pair<int, pair<int, int> >& p1, pair<int, pair<int, int> >& p2) {
  int block1 = p1.first / sqrtn;
  int block2 = p2.first / sqrtn;
  if (block1 != block2) return block1 < block2;
  return p1.second.first < p2.second.first;
}
inline void add(int ind) {
  ans += (unsigned long long)a[ind] * (2 * freq[a[ind]] + 1);
  freq[a[ind]]++;
}
inline void remove(int ind) {
  freq[a[ind]]--;
  ans -= (unsigned long long)a[ind] * (2 * freq[a[ind]] + 1);
}
int main() {
  scanf("%d%d", &n, &t);
  sqrtn = sqrt(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < t; i++) {
    scanf("%d%d", &Q[i].first, &Q[i].second.first);
    Q[i].first--;
    Q[i].second.first--;
    Q[i].second.second = i;
  }
  sort(Q, Q + t, comp);
  int l = Q[0].first;
  int r = Q[0].second.first;
  for (int i = l; i <= r; i++) add(i);
  answers[Q[0].second.second] = ans;
  for (int i = 1; i < t; i++) {
    int new_l = Q[i].first;
    int new_r = Q[i].second.first;
    while (l < new_l) remove(l++);
    while (l > new_l) add(--l);
    while (r < new_r) add(++r);
    while (r > new_r) remove(r--);
    answers[Q[i].second.second] = ans;
  }
  for (int i = 0; i < t; i++) printf("%lld\n", answers[i]);
  return 0;
}
