#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10, mod = 1e9 + 7, INF = 1e18, lg = 20, SQRT = 400;
int a[maxn], cnt[maxn * 5];
long long ans, res[maxn];
pair<pair<int, int>, int> test[maxn];
pair<int, int> quer[maxn];
inline void add(int k) {
  ans -= cnt[k] * 1ll * cnt[k] * k;
  cnt[k]++;
  ans += cnt[k] * 1ll * cnt[k] * k;
}
inline void remove(int k) {
  ans -= cnt[k] * 1ll * cnt[k] * k;
  cnt[k]--;
  ans += cnt[k] * 1ll * cnt[k] * k;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, t;
  cin >> n >> t;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < t; ++i) {
    int l, r;
    cin >> l >> r;
    l--;
    test[i] = {{l / SQRT, r}, i};
    quer[i] = {l, r};
  }
  sort(test, test + t);
  int p1, p2;
  p1 = p2 = 0;
  for (int i = 0; i < t; ++i) {
    int idx = test[i].second;
    int l = quer[idx].first, r = quer[idx].second;
    while (p1 < l) {
      remove(a[p1++]);
    }
    while (p2 > r) {
      remove(a[--p2]);
    }
    while (p1 > l) {
      add(a[--p1]);
    }
    while (p2 < r) {
      add(a[p2++]);
    }
    res[idx] = ans;
  }
  for (int i = 0; i < t; ++i) {
    cout << res[i] << '\n';
  }
}
