#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
struct Query {
  int l, r, id;
  Query() {}
  Query(int l, int r, int id) : l(l), r(r), id(id) {}
};
const int MAX_N = 200010;
const int MAX_Q = 200010;
int SQN = 1000;
bool cmp(const Query& A, const Query& B) {
  if (A.l / SQN != B.l / SQN) return A.l / SQN < B.l / SQN;
  return A.r < B.r;
}
long long a[MAX_N], freq[1000010], ans[MAX_Q], resp = 0;
Query Q[MAX_Q];
void add(int pos) {
  int x = a[pos];
  resp += (2 * freq[x] + 1) * x;
  ++freq[x];
}
void remove(int pos) {
  int x = a[pos];
  --freq[x];
  resp -= (2 * freq[x] + 1) * x;
}
int main() {
  memset(freq, 0, sizeof freq);
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for (int i = 0; i < q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    Q[i] = Query(l - 1, r, i);
  }
  sort(Q, Q + q, cmp);
  int l = 0, r = 0;
  for (int i = 0; i < q; ++i) {
    Query q = Q[i];
    while (l > q.l) add(--l);
    while (r < q.r) add(r++);
    while (l < q.l) remove(l++);
    while (r > q.r) remove(--r);
    ans[q.id] = resp;
  }
  for (int i = 0; i < q; ++i) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
