#include <bits/stdc++.h>
using namespace std;
long long cnt[1000009], a[200009], ans[200009], answer = 0;
struct node {
  long long L, R, i;
} q[200009];
bool cmp(node x, node y) {
  if (x.L / 1000 != y.L / 1000) {
    return x.L / 1000 < y.L / 1000;
  }
  return x.R < y.R;
}
void add(long long position) {
  long long aa;
  aa = 0;
  if (cnt[a[position]] >= 1) {
    aa = cnt[a[position]];
  }
  cnt[a[position]]++;
  if (cnt[a[position]] >= 1) {
    answer = answer + ((cnt[a[position]] * cnt[a[position]]) * a[position]) -
             (aa * aa * a[position]);
  }
}
void remove(long long position) {
  long long aa;
  aa = 0;
  aa = cnt[a[position]];
  cnt[a[position]]--;
  if (cnt[a[position]] >= 0) {
    answer = answer - (aa * aa * a[position]) +
             (cnt[a[position]] * cnt[a[position]] * a[position]);
  }
}
int main() {
  long long n;
  long long m;
  scanf("%I64d", &n);
  scanf("%I64d", &m);
  for (long long i = 0; i < n; i++) scanf("%I64d", &a[i]);
  for (long long i = 0; i < m; i++) {
    scanf("%I64d%I64d", &q[i].L, &q[i].R);
    q[i].L--;
    q[i].R--;
    q[i].i = i;
  }
  sort(q, q + m, cmp);
  long long currentL = 0, currentR = 0;
  for (long long i = 0; i < m; i++) {
    long long L = q[i].L, R = q[i].R;
    while (currentL < L) {
      remove(currentL);
      currentL++;
    }
    while (currentL > L) {
      add(currentL - 1);
      currentL--;
    }
    while (currentR <= R) {
      add(currentR);
      currentR++;
    }
    while (currentR > R + 1) {
      remove(currentR - 1);
      currentR--;
    }
    long long sum = 0;
    ans[q[i].i] = answer;
  }
  for (long long i = 0; i < m; i++) printf("%I64d\n", ans[i]);
}
