#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200009;
const int MAXNN = 1000009;
int sq = 500;
long long answer = 0;
long long a[MAXN], summ[MAXNN], res[MAXNN];
struct tst {
  long long first, second, pos, ans;
};
tst test[MAXNN];
bool comp(tst x, tst y) {
  if (x.first / sq == y.first / sq)
    return x.second < y.second;
  else
    return x.first < y.first;
}
void sum(int first, int second, long long d) {
  if (first <= second)
    for (int i = first; i <= second; i++) {
      answer -= (summ[a[i]] * summ[a[i]] * a[i]);
      summ[a[i]] += d;
      answer += (summ[a[i]] * summ[a[i]] * a[i]);
    }
}
int main() {
  int n, t;
  scanf("%d %d", &n, &t);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < t; i++) {
    scanf("%I64d %I64d\n", &test[i].first, &test[i].second);
    test[i].pos = i;
  }
  sort(test, test + t, comp);
  sum(test[0].first, test[0].second, 1);
  test[0].ans = answer;
  for (int i = 1; i < t; i++) {
    if (test[i - 1].first < test[i].first)
      sum(test[i - 1].first, test[i].first - 1, -1);
    else
      sum(test[i].first, test[i - 1].first - 1, 1);
    if (test[i - 1].second < test[i].second)
      sum(test[i - 1].second + 1, test[i].second, 1);
    else
      sum(test[i].second + 1, test[i - 1].second, -1);
    test[i].ans = answer;
  }
  for (int i = 0; i < t; i++) res[test[i].pos] = test[i].ans;
  for (int i = 0; i < t; i++) printf("%I64d\n", res[i]);
  return 0;
}
