#include <bits/stdc++.h>
using namespace std;
const int n_max = 200200;
struct Query {
  int left, right;
  int block;
  int id;
  long long ans;
  Query(int l_, int r_, int b_, int i_, long long a_) {
    left = l_;
    right = r_;
    block = b_;
    id = i_;
    ans = a_;
  }
};
int A[n_max], n, q, u, v, S;
vector<Query> Q;
vector<int> Freq(1000010, 0);
long long sum = 0;
bool compareQuery(Query A, Query B) {
  if (A.block != B.block) return A.block < B.block;
  return A.right < B.right;
}
bool by_index(Query A, Query B) { return A.id < B.id; }
void insElement(int value) {
  sum += ((long long)(2 * Freq[value] + 1)) * ((long long)value);
  Freq[value] += 1;
}
void delElement(int value) {
  sum -= ((long long)(2 * Freq[value] - 1)) * ((long long)value);
  Freq[value] -= 1;
}
long long getAns(Query preQ, Query curQ) {
  if (preQ.left <= curQ.left)
    for (int i = preQ.left; i < curQ.left; i++) delElement(A[i]);
  else
    for (int i = curQ.left; i < preQ.left; i++) insElement(A[i]);
  if (preQ.right <= curQ.right)
    for (int i = preQ.right + 1; i <= curQ.right; i++) insElement(A[i]);
  else
    for (int i = curQ.right + 1; i <= preQ.right; i++) delElement(A[i]);
  return sum;
}
int main() {
  cin >> n >> q;
  sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  S = (int)round(sqrt(n) + 1.0);
  for (int i = 0; i < q; i++) {
    cin >> u >> v;
    u--;
    v--;
    Q.push_back(Query(u, v, u / S, i, 0));
  }
  sort(Q.begin(), Q.end(), compareQuery);
  if (Q.size() != 0) {
    for (int i = Q[0].left; i <= Q[0].right; i++) {
      insElement(A[i]);
    }
    Q[0].ans = sum;
    for (int i = 0; i < q - 1; i++) Q[i + 1].ans = getAns(Q[i], Q[i + 1]);
  };
  sort(Q.begin(), Q.end(), by_index);
  for (int i = 0; i < Q.size(); i++) cout << Q[i].ans << endl;
}
