#include <bits/stdc++.h>
int rad;
int N, T;
long long int A[200000];
long long int cnt[1000005];
std::pair<int, int> Q[200000];
long long int idx[200000], ans[200000];
bool cmp(const int& i, const int& j) {
  std::pair<int, int> a = Q[i], b = Q[j];
  if (a.first / rad == b.first / rad) return a.second < b.second;
  return a.first / rad < b.first / rad;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  std::cin >> N >> T;
  for (int i = 0; i < N; i++) std::cin >> A[i];
  for (rad = 0; rad * rad <= N; rad++)
    ;
  --rad;
  for (int i = 0; i < T; i++) {
    std::cin >> Q[i].first >> Q[i].second;
    idx[i] = i;
    --Q[i].first;
    --Q[i].second;
  }
  std::sort(idx, idx + T, cmp);
  int L = Q[idx[0]].first;
  int R = L - 1;
  long long int cur = 0;
  for (int i = 0; i < T; i++) {
    int l = Q[idx[i]].first, r = Q[idx[i]].second;
    while (R < r) {
      R++;
      cur -= (cnt[A[R]] * cnt[A[R]] * A[R]);
      cnt[A[R]]++;
      cur += (cnt[A[R]] * cnt[A[R]] * A[R]);
    }
    while (R > r) {
      cur -= (cnt[A[R]] * cnt[A[R]] * A[R]);
      cnt[A[R]]--;
      cur += (cnt[A[R]] * cnt[A[R]] * A[R]);
      R--;
    }
    while (L > l) {
      L--;
      cur -= (cnt[A[L]] * cnt[A[L]] * A[L]);
      cnt[A[L]]++;
      cur += (cnt[A[L]] * cnt[A[L]] * A[L]);
    }
    while (L < l) {
      cur -= (cnt[A[L]] * cnt[A[L]] * A[L]);
      cnt[A[L]]--;
      cur += (cnt[A[L]] * cnt[A[L]] * A[L]);
      L++;
    }
    ans[idx[i]] = cur;
  }
  for (int i = 0; i < T; i++) std::cout << ans[i] << "\n";
  return 0;
}
