#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], bl[N];
struct Query {
  int l, r, id;
} q[N];
int l = 1, r = 0, cnt[N * 10];
long long now = 0;
long long Ans[N];
void add(int x) {
  now -= 1ll * cnt[a[x]] * cnt[a[x]] * a[x];
  cnt[a[x]]++;
  now += 1ll * cnt[a[x]] * cnt[a[x]] * a[x];
}
void del(int x) {
  now -= 1ll * cnt[a[x]] * cnt[a[x]] * a[x];
  cnt[a[x]]--;
  now += 1ll * cnt[a[x]] * cnt[a[x]] * a[x];
}
bool cmp(Query a, Query b) {
  return (bl[a.l] ^ bl[b.l]) ? bl[a.l] < bl[b.l]
                             : ((bl[a.l] & 1) ? a.r < b.r : a.r > b.r);
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int unt = sqrt(n);
  for (int i = 1; i <= n; i++) bl[i] = (i - 1) / unt + 1;
  for (int i = 1; i <= t; i++) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + t + 1, cmp);
  for (int i = 1; i <= t; i++) {
    while (l < q[i].l) del(l++);
    while (l > q[i].l) add(--l);
    while (r < q[i].r) add(++r);
    while (r > q[i].r) del(r--);
    Ans[q[i].id] = now;
  }
  for (int i = 1; i <= t; i++) printf("%lld\n", Ans[i]);
  return 0;
}
