#include <bits/stdc++.h>
const int N = 2e5 + 10;
using namespace std;
int n, t;
int pos[N], a[N], s[N * 10];
long long f, ans[N];
struct node {
  int l, r, id;
} q[N];
bool cmp(node a, node b) {
  return pos[a.l] < pos[b.l] || pos[a.l] == pos[b.l] && a.r < b.r;
}
void add(long long x) {
  int& k = s[x];
  k++;
  f += x * (k * k - (k - 1) * (k - 1));
}
void sub(long long x) {
  int& k = s[x];
  f -= x * (k * k - (k - 1) * (k - 1));
  k--;
}
int main() {
  scanf("%d%d", &n, &t);
  double dis = sqrt(1. * n);
  for (int i = 1, _ = n + 1; i < _; ++i) scanf("%d", a + i), pos[i] = i / dis;
  for (int i = 0, _ = t; i < _; ++i)
    scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
  sort(q, q + t, cmp);
  int L = 1, R = 0;
  f = 0;
  for (int i = 0, _ = t; i < _; ++i) {
    while (R < q[i].r) add(a[++R]);
    while (R > q[i].r) sub(a[R--]);
    while (L < q[i].l) sub(a[L++]);
    while (L > q[i].l) add(a[--L]);
    ans[q[i].id] = f;
  }
  for (int i = 0, _ = t; i < _; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
