#include <bits/stdc++.h>
using namespace std;
template <typename t>
ostream& operator,(ostream& os, t x) {
  return os << ' ' << x;
}
struct data {
  int l, r, pos;
  data(int _l = 0, int _r = 0, int _pos = 0) : l(_l), r(_r), pos(_pos){};
};
int n, m, sz;
int cnt[1000005];
int a[1000005];
vector<data> query;
long long ans_to_query[1000005];
long long ans = 0;
bool operator<(data x, data y) {
  if (x.r / sz != y.r / sz) return x.r < y.r;
  return x.l < y.l;
}
void add(int x) {
  ans -= cnt[x] * 1LL * cnt[x] * x;
  cnt[x]++;
  ans += cnt[x] * 1LL * cnt[x] * x;
}
void sub(int x) {
  ans -= cnt[x] * 1LL * cnt[x] * x;
  cnt[x]--;
  ans += cnt[x] * 1LL * cnt[x] * x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  sz = sqrt(n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r;
    query.push_back(data(l, r, i));
  }
  sort(query.begin(), query.end());
  int L = 0, R = 0;
  for (int i = 0; i < query.size(); i++) {
    int l = query[i].l, r = query[i].r, pos = query[i].pos;
    while (R < r) {
      R++;
      add(a[R]);
    }
    while (R > r) {
      sub(a[R]);
      R--;
    }
    while (L > l) {
      L--;
      add(a[L]);
    }
    while (L < l) {
      sub(a[L]);
      L++;
    }
    ans_to_query[pos] = ans;
  }
  for (int i = 1; i <= m; i++) cout << ans_to_query[i] << '\n';
}
