#include <bits/stdc++.h>
using namespace std;
long long n, x, y, t, a[200005], ans = 0, cnt[1000005], an[200005];
pair<long long, pair<long long, long long>> q[200005];
bool cmp(pair<long long, pair<long long, long long>> a,
         pair<long long, pair<long long, long long>> b) {
  if (a.second.first / 447 != b.second.first / 447) {
    return a.second.first / 447 < b.second.first / 447;
  }
  return a.second.second < b.second.second;
}
int main() {
  scanf("%lld\n", &n);
  scanf("%lld\n", &t);
  for (int i = 1; i <= n; i++) {
    scanf("%lld\n", &a[i]);
  }
  for (int i = 1; i <= t; i++) {
    scanf("%lld\n", &x);
    scanf("%lld\n", &y);
    q[i] = make_pair(i, make_pair(x, y));
  }
  sort(q + 1, q + t + 1, cmp);
  long long l, L = 0, r, R = 0;
  for (int i = 1; i <= t; i++) {
    l = q[i].second.first, r = q[i].second.second;
    while (L < l) {
      cnt[a[L]]--;
      ans -= ((cnt[a[L]] << 1) + 1) * a[L];
      L++;
    }
    while (L > l) {
      L--;
      ans += ((cnt[a[L]] << 1) + 1) * a[L];
      cnt[a[L]]++;
    }
    while (R < r) {
      R++;
      ans += ((cnt[a[R]] << 1) + 1) * a[R];
      cnt[a[R]]++;
    }
    while (R > r) {
      cnt[a[R]]--;
      ans -= ((cnt[a[R]] << 1) + 1) * a[R];
      R--;
    }
    an[q[i].first] = ans;
  }
  for (int i = 1; i <= t; i++) {
    printf("%lld\n", an[i]);
  }
  return 0;
}
