#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
int a, b, ar[maxn], K;
long long yu[maxn * 5], ans[maxn], sq[maxn];
pair<pair<int, int>, int> bs[maxn];
bool cmp(const pair<pair<int, int>, int> &a,
         const pair<pair<int, int>, int> &b) {
  if ((a.first.first >> 9) != (b.first.first >> 9))
    return (a.first.first >> 9) < (b.first.first >> 9);
  if (a.first.second == b.first.second) return a.first.first < b.first.first;
  return a.first.second < b.first.second;
}
int main() {
  scanf("%d %d", &a, &b);
  K = sqrt(a) + 1;
  for (int i = 1; i <= a; i++) scanf("%d", &ar[i]), sq[i] = (long long)i * i;
  for (int i = 0, j, k; i < b; i++) {
    scanf("%d %d", &bs[i].first.first, &bs[i].first.second);
    bs[i].second = i;
  }
  sort(bs, bs + b, cmp);
  int l = 0, r = 0;
  long long res = 0;
  for (int i = 0; i < b; i++) {
    while (r < bs[i].first.second)
      r++, res -= sq[yu[ar[r]]] * ar[r], yu[ar[r]]++,
          res += sq[yu[ar[r]]] * ar[r];
    while (r > bs[i].first.second)
      res -= sq[yu[ar[r]]] * ar[r], yu[ar[r]]--, res += sq[yu[ar[r]]] * ar[r],
          r--;
    while (l < bs[i].first.first)
      res -= sq[yu[ar[l]]] * ar[l], yu[ar[l]]--, res += sq[yu[ar[l]]] * ar[l],
          l++;
    while (l > bs[i].first.first)
      l--, res -= sq[yu[ar[l]]] * ar[l], yu[ar[l]]++,
          res += sq[yu[ar[l]]] * ar[l];
    ans[bs[i].second] = res;
  }
  for (int i = 0; i < b; i++) printf("%I64d\n", ans[i]);
  return 0;
}
