#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 1e6 + 10;
int a[N], cnt[M];
long long ans[N], res;
struct Q {
  int l, r, b, id;
  Q(){};
  bool operator<(const Q& rhs) const {
    if (b == rhs.b) return r < rhs.r;
    return b < rhs.b;
  }
} q[N];
int L, R, first;
long long cal1(int l, int r) {
  long long res = 0;
  for (int i = l; i <= r; i++) {
    res += 1LL * a[i] * (2 * cnt[a[i]] + 1);
    cnt[a[i]]++;
  }
  return res;
}
long long cal2(int l, int r) {
  long long res = 0;
  for (int i = l; i <= r; i++) {
    cnt[a[i]]--;
    res -= 1LL * a[i] * (2 * cnt[a[i]] + 1);
  }
  return res;
}
long long query(int x, int y) {
  if (first) {
    first = 0;
    res = cal1(x, y);
  } else {
    res += cal1(x, L - 1);
    res += cal2(L, x - 1);
    res += cal1(R + 1, y);
    res += cal2(y + 1, R);
  }
  L = x, R = y;
  return res;
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int block_size = sqrt(n + 0.5);
  for (int i = 0; i < t; i++) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].b = q[i].l / block_size, q[i].id = i;
  }
  sort(q, q + t);
  memset(cnt, 0, sizeof(cnt));
  first = 1;
  res = 0;
  for (int i = 0; i < t; i++) ans[q[i].id] = query(q[i].l, q[i].r);
  for (int i = 0; i < t; i++) printf("%lld\n", ans[i]);
  return 0;
}
