#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
long long umap[1000001] = {0};
long long ans = 0;
void add(long long i) {
  long long val = umap[a[i]];
  umap[a[i]]++;
  ans += (2LL * val + 1) * a[i];
}
void del(long long i) {
  long long val = umap[a[i]];
  umap[a[i]]--;
  ans += (-2LL * val + 1) * a[i];
}
long long sq;
long long prevL, prevR;
void compute(long long l, long long r) {
  while (prevL < l) {
    del(prevL);
    prevL++;
  }
  while (l < prevL) {
    prevL--;
    add(prevL);
  }
  while (prevR < r) {
    prevR++;
    add(prevR);
  }
  while (r < prevR) {
    del(prevR);
    prevR--;
  }
}
bool comp(pair<pair<long long, long long>, long long> a,
          pair<pair<long long, long long>, long long> b) {
  long long val1 = a.first.first / sq;
  long long val2 = b.first.first / sq;
  if (val1 == val2) {
    return a.first.second < b.first.second;
  }
  return val1 < val2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, t;
  cin >> n >> t;
  a.resize(n + 1);
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<pair<pair<long long, long long>, long long> > query(t);
  sq = sqrt(n) + 1;
  for (long long i = 0; i < t; i++) {
    long long l, r;
    cin >> l >> r;
    query[i] = {{l, r}, i};
  }
  sort(query.begin(), query.end(), comp);
  prevL = 0;
  prevR = 0;
  ans = 0;
  vector<long long> res(t);
  for (long long i = 0; i < t; i++) {
    long long l = query[i].first.first;
    long long r = query[i].first.second;
    long long idx = query[i].second;
    compute(l, r);
    res[idx] = ans;
  }
  for (long long i = 0; i < t; i++) {
    cout << res[i] << endl;
  }
  cout << endl;
}
