#include <bits/stdc++.h>
using namespace std;
const long long maxn = 201000;
long long a[maxn], n, t;
long long ans[maxn];
struct node {
  long long l, r;
  long long id;
} p[maxn];
long long cnt[1000010];
bool cmp(node a, node b) {
  long long k = sqrt(n);
  if (a.l / k == b.l / k)
    return a.r < b.r;
  else
    return a.l < b.l;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> t;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= t; i++) {
    cin >> p[i].l >> p[i].r;
    p[i].id = i;
  }
  sort(p + 1, p + 1 + t, cmp);
  long long l = 1, r = 1;
  cnt[a[1]]++;
  long long sum = a[1];
  for (long long i = 1; i <= t; i++) {
    while (l < p[i].l) {
      cnt[a[l]]--;
      sum -= ((2 * cnt[a[l]] + 1) * a[l]);
      l++;
    }
    while (l > p[i].l) {
      cnt[a[--l]]++;
      sum += ((2 * cnt[a[l]] - 1) * a[l]);
    }
    while (r < p[i].r) {
      cnt[a[++r]]++;
      sum += ((2 * cnt[a[r]] - 1) * a[r]);
    }
    while (r > p[i].r) {
      cnt[a[r]]--;
      sum -= ((2 * cnt[a[r]] + 1) * a[r]);
      r--;
    }
    ans[p[i].id] = sum;
  }
  for (long long i = 1; i <= t; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
