#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int MAX_N = 1e6 + 1;
long long f[MAX_N];
vector<pair<pair<int, int>, int>> v;
int sq;
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  a.first.first /= sq;
  b.first.first /= sq;
  return a < b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int n, t;
  cin >> n >> t;
  long long a[n + 1];
  long long ans[t + 1];
  sq = ceil(sqrt(n));
  for (int i = 1; i <= n; i++) cin >> a[i];
  int l, r;
  for (int i = 0; i < t; i++) {
    cin >> l >> r;
    v.push_back({{l, r}, i});
  }
  sort(v.begin(), v.end(), cmp);
  pair<int, int> p = v[0].first;
  l = p.first, r = p.first;
  f[a[l]]++;
  long long curr_ans = a[l];
  for (int i = 0; i < t; i++) {
    p = v[i].first;
    while (p.first < l) {
      l--;
      curr_ans -= a[l] * (f[a[l]] * f[a[l]]);
      f[a[l]]++;
      curr_ans += a[l] * (f[a[l]] * f[a[l]]);
    }
    while (p.first > l) {
      curr_ans -= a[l] * (f[a[l]] * f[a[l]]);
      f[a[l]]--;
      curr_ans += a[l] * (f[a[l]] * f[a[l]]);
      l++;
    }
    while (p.second < r) {
      curr_ans -= a[r] * (f[a[r]] * f[a[r]]);
      f[a[r]]--;
      curr_ans += a[r] * (f[a[r]] * f[a[r]]);
      r--;
    }
    while (p.second > r) {
      r++;
      curr_ans -= a[r] * (f[a[r]] * f[a[r]]);
      f[a[r]]++;
      curr_ans += a[r] * (f[a[r]] * f[a[r]]);
    }
    int c = v[i].second;
    ans[c] = curr_ans;
  }
  for (int i = 0; i < t; i++) {
    cout << ans[i] << '\n';
  }
}
