#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 0;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  if (f) return x;
  return 0 - x;
}
const int maxn = 1 << 20;
int n, m, k, col[maxn], block, suf[maxn];
struct node {
  int l, r, id;
  bool operator<(const node &x) const {
    if (((l - 1) / block + 1) == ((x.l - 1) / block + 1)) return r < x.r;
    return l < x.l;
  }
} q[maxn];
long long cur = 0, ans[maxn], cnt[maxn];
void add(int x) {
  x = col[x];
  cur -= 1ll * x * cnt[x] * cnt[x];
  cnt[x]++;
  cur += 1ll * x * cnt[x] * cnt[x];
}
void del(int x) {
  x = col[x];
  cur -= 1ll * x * cnt[x] * cnt[x];
  cnt[x]--;
  cur += 1ll * x * cnt[x] * cnt[x];
}
int main() {
  n = read(), m = read();
  block = pow(n, 7.0 / 12);
  for (int i = 1; i <= n; i++) {
    col[i] = read();
  }
  for (int i = 1, l, r; i <= m; i++) {
    l = read(), r = read();
    q[i] = node{l, r, i};
  }
  sort(q + 1, q + m + 1);
  int l = 1, r = 0;
  for (int i = 1; i <= m; i++) {
    while (l < q[i].l) del(l), l++;
    while (l > q[i].l) l--, add(l);
    while (r < q[i].r) r++, add(r);
    while (r > q[i].r) del(r), r--;
    ans[q[i].id] = cur;
  }
  for (int i = 1; i <= m; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
