#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int N = 200001;
int block = sqrt(N);
pair<pair<int, int>, int> qu[N];
bool comp(pair<pair<int, int>, int> &firs, pair<pair<int, int>, int> &sec) {
  int x = firs.first.first / block;
  int y = sec.first.first / block;
  if (x != y) return x < y;
  return firs.first.second < sec.first.second;
}
long long lans = 0, a[N];
long long cnt[1000001];
inline void add(int x) {
  lans += (2 * cnt[a[x]] + 1) * a[x];
  cnt[a[x]]++;
}
inline void remove(long long x) {
  lans -= (2 * cnt[a[x]] - 1) * a[x];
  cnt[a[x]]--;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    qu[i].first.first = l;
    qu[i].first.second = r;
    qu[i].second = i;
  }
  sort(qu, qu + q, comp);
  int curl = 0, curr = -1;
  long long ans[q + 1];
  for (int i = 0; i < q; i++) {
    int l = qu[i].first.first, r = qu[i].first.second;
    while (curr < r) curr++, add(curr);
    while (curr > r) remove(curr), curr--;
    while (curl < l) remove(curl), curl++;
    while (curl > l) curl--, add(curl);
    ans[qu[i].second] = lans;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
  return 0;
}
