#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "no-stack-protector")
using namespace std;
int n, q, k, a[200005], cnt[1000005];
long long power, ans[200005];
vector<pair<pair<long long, long long>, int>> que;
bool cmp(pair<pair<long long, long long>, int> x,
         pair<pair<long long, long long>, int> y) {
  if (x.first.first / k != y.first.first / k)
    return x.first.first / k < y.first.first / k;
  return x.first.second < y.first.second;
}
void add(int pos) {
  power += 1LL * a[pos] * (2 * cnt[a[pos]] + 1);
  cnt[a[pos]]++;
}
void sub(int pos) {
  power -= 1LL * a[pos] * (2 * cnt[a[pos]] - 1);
  cnt[a[pos]]--;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  k = sqrt(n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0, x, y; i < q; i++) {
    cin >> x >> y;
    que.push_back({{x, y}, i});
  }
  sort(que.begin(), que.end(), cmp);
  int l = 1, r = 0;
  for (int i = 0; i < q; i++) {
    while (l > que[i].first.first) add(--l);
    while (l < que[i].first.first) sub(l++);
    while (r > que[i].first.second) sub(r--);
    while (r < que[i].first.second) add(++r);
    ans[que[i].second] = power;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
  return 0;
}
