#include <bits/stdc++.h>
using namespace std;
long long sl[1000001];
long long l, r, L, R, res = 0, m, n;
long long a[1000001];
long long S;
struct data {
  long long first;
  long long second;
  long long stt;
  long long res;
};
data make_data(long long first, long long second, long long stt,
               long long res) {
  data a;
  a.first = first;
  a.second = second;
  a.stt = stt;
  a.res = res;
  return a;
}
vector<data> b;
bool operator<(data x, data y) {
  if (x.second / S != y.second / S) return (x.second / S) < (y.second / S);
  return x.first < y.first;
}
bool cmp2(data x, data y) { return x.stt < y.stt; }
void add(long long x) {
  res = res - sl[x] * sl[x] * x;
  sl[x]++;
  res = res + sl[x] * sl[x] * x;
}
void del(long long x) {
  res = res - sl[x] * sl[x] * x;
  sl[x]--;
  res = res + sl[x] * sl[x] * x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> n >> m;
  S = sqrt(n);
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= m; i++) {
    cin >> l >> r;
    b.push_back(make_data(l, r, i, 0));
  }
  sort(b.begin(), b.end());
  L = 0;
  R = 0;
  for (long long i = 0; i < b.size(); i++) {
    l = b[i].first;
    r = b[i].second;
    while (R < r) {
      R++;
      add(a[R]);
    }
    while (L > l) {
      L--;
      add(a[L]);
    }
    while (R > r) {
      del(a[R]);
      R--;
    }
    while (L < l) {
      del(a[L]);
      L++;
    }
    b[i].res = res;
  }
  sort(b.begin(), b.end(), cmp2);
  for (long long i = 0; i < b.size(); i++) cout << b[i].res << "\n";
  return 0;
}
