#include <bits/stdc++.h>
using namespace std;
int n, t, len;
bool mos(pair<pair<int, int>, int> &a, pair<pair<int, int>, int> &b) {
  int pa = a.first.first / len;
  int push_back = b.first.first / len;
  if (pa != push_back) return pa < push_back;
  return a.first.second < b.first.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> t;
  len = max((long long)sqrt(n), 1LL);
  vector<int> v(n);
  for (int i = 0; i < (int)n; ++i) cin >> v[i];
  vector<pair<pair<int, int>, int>> q(t);
  for (int i = 0; i < (int)t; ++i) {
    cin >> q[i].first.first >> q[i].first.second;
    q[i].second = i;
  }
  sort(q.begin(), q.end(), mos);
  vector<long long> ans(t);
  vector<int> cnt(1000005, 0);
  int l, r;
  l = r = 0;
  long long num = v[0];
  ++cnt[v[0]];
  for (int i = 0; i < (int)t; ++i) {
    int lg = q[i].first.first;
    int rg = q[i].first.second;
    --lg, --rg;
    while (r < rg) {
      ++r, num += (2LL * cnt[v[r]]++ + 1) * v[r];
    }
    while (r > rg) {
      num -= (2LL * --cnt[v[r]] + 1) * v[r];
      r--;
    }
    while (l < lg) {
      num -= (2LL * --cnt[v[l]] + 1) * v[l];
      l++;
    }
    while (l > lg) {
      --l, num += (2LL * cnt[v[l]]++ + 1) * v[l];
    }
    ans[q[i].second] = num;
  }
  for (int i = 0; i < (int)t; ++i) {
    cout << ans[i] << '\n';
  }
}
