#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const int P = 131;
int block, n, m, a[N];
long long cnt[N], ans[N];
long long sum;
int t;
struct node {
  int l, r, id;
} Q[N];
bool cmp(node &a, struct node &b) {
  if (a.l / block != b.l / block) return a.l < b.l;
  return a.r < b.r;
}
void add(int x) {
  sum -= (long long)cnt[a[x]] * cnt[a[x]] * a[x];
  cnt[a[x]]++;
  sum += (long long)cnt[a[x]] * cnt[a[x]] * a[x];
}
void del(int x) {
  sum -= (long long)cnt[a[x]] * cnt[a[x]] * a[x];
  cnt[a[x]]--;
  sum += (long long)cnt[a[x]] * cnt[a[x]] * a[x];
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &Q[i].l, &Q[i].r);
    Q[i].id = i;
  }
  block = sqrt(1.0 * n);
  sort(Q + 1, Q + 1 + m, cmp);
  int l = 1, r = 0;
  for (int i = 1; i <= m; 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] = sum;
  }
  for (int i = 1; i <= m; i++) printf("%lld\n", ans[i]);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
