#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
const int LEN = 300;
int n;
int m;
pair<pair<pair<int, int>, pair<int, int> >, int> v[200000];
int cnt[1000001];
int l, r;
long long sum;
int x[200000];
long long res[200000];
int go(int p, int q) {
  while (r < q) {
    r++;
    sum += (long long)(cnt[x[r]] * 2 + 1) * x[r];
    cnt[x[r]]++;
  }
  while (l > p) {
    l--;
    sum += (long long)(cnt[x[l]] * 2 + 1) * x[l];
    cnt[x[l]]++;
  }
  while (r > q) {
    cnt[x[r]]--;
    sum -= (long long)(cnt[x[r]] * 2 + 1) * x[r];
    r--;
  }
  while (l < p) {
    cnt[x[l]]--;
    sum -= (long long)(cnt[x[l]] * 2 + 1) * x[l];
    l++;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &v[i].first.second.first, &v[i].first.second.second);
    v[i].first.second.first--;
    v[i].first.second.second--;
    v[i].first.first.first = v[i].first.second.first / LEN;
    v[i].first.first.second = v[i].first.second.second;
    v[i].second = i;
  }
  sort(v, v + m);
  l = r = 0;
  sum = x[0];
  cnt[x[0]]++;
  for (int i = 0; i < m; i++) {
    go(v[i].first.second.first, v[i].first.second.second);
    res[v[i].second] = sum;
  }
  for (int i = 0; i < m; i++) printf("%I64d\n", res[i]);
  return 0;
}
