#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<pair<int, int>, pair<int, pair<int, int> > > x,
         pair<pair<int, int>, pair<int, pair<int, int> > > y) {
  pair<int, int> ax = x.first;
  pair<int, int> by = y.first;
  return (ax.first == by.first) ? (ax.second < by.second)
                                : (ax.first < by.first);
}
int cnt[2000008], n, cl, cr, m, l, r, i, s, b, d, p, ar[2000008];
long long int otp[2000008];
long long int ans;
void add(long long int p) {
  if (p >= 1 && p <= n) {
    cnt[ar[p]]++;
    ans += (long long int)(cnt[ar[p]] * 2 - 1) * (long long int)(ar[p]);
  }
}
void remove(long long int p) {
  if (p >= 1 && p <= n) {
    ans -= (long long int)(cnt[ar[p]] * 2 - 1) * (long long int)(ar[p]);
    cnt[ar[p]]--;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> ar[i];
  s = ceil(sqrt(n));
  vector<pair<pair<int, int>, pair<int, pair<int, int> > > > adj;
  for (i = 1; i <= m; i++) {
    cin >> l >> r;
    b = (l / s) + 1;
    d = (r / s) + 1;
    adj.push_back(pair<pair<int, int>, pair<int, pair<int, int> > >(
        pair<int, int>(b, d),
        pair<int, pair<int, int> >(i, pair<int, int>(l, r))));
  }
  sort(adj.begin(), adj.end(), cmp);
  cl = 0;
  cr = 0;
  ans = 0;
  for (i = 0; i < adj.size(); i++) {
    l = ((adj[i].second).second).first;
    r = ((adj[i].second).second).second;
    p = (adj[i].second).first;
    while (cl > l) add(--cl);
    while (cl < l) remove(cl++);
    while (cr > r) remove(cr--);
    while (cr < r) add(++cr);
    otp[p] = ans;
  }
  for (i = 1; i <= m; i++) cout << otp[i] << "\n";
  return 0;
}
