#include <bits/stdc++.h>
using namespace std;
struct name {
  int l, r, ind;
};
bool comp(name a, name b) { return a.r < b.r; }
int n, Q;
vector<name> q[1002];
int mp[1000002] = {0};
long long ans[200002] = {0};
int a[200002] = {0};
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  int k = sqrt(n * 1.00);
  for (int i = 0; i < Q; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    int t = l / k;
    name x;
    x.l = l;
    x.r = r + 1;
    x.ind = i;
    q[t].push_back(x);
  }
  k = n / k;
  for (int i = 0; i <= k + 1; ++i) {
    if (!q[i].size()) continue;
    sort(q[i].begin(), q[i].end(), comp);
    long long s = 0;
    int l = q[i][0].l;
    int r = q[i][0].r;
    int ind = q[i][0].ind;
    for (int j = l; j < r; ++j) {
      int x = (int)a[j];
      s -= a[j] * 1LL * mp[x] * mp[x] * 1LL;
      mp[x]++;
      s += a[j] * 1LL * mp[x] * mp[x] * 1LL;
    }
    ans[ind] = s;
    int L = l;
    int R = r;
    for (int j1 = 1; j1 < q[i].size(); ++j1) {
      l = q[i][j1].l;
      r = q[i][j1].r;
      ind = q[i][j1].ind;
      for (int j = R; j < r; ++j) {
        int x = (int)a[j];
        s -= a[j] * 1LL * mp[x] * mp[x] * 1LL;
        mp[x]++;
        s += a[j] * 1LL * mp[x] * mp[x] * 1LL;
      }
      for (int j = L; j < l; ++j) {
        int x = (int)a[j];
        s -= a[j] * 1LL * mp[x] * mp[x] * 1LL;
        mp[x]--;
        s += a[j] * 1LL * mp[x] * mp[x] * 1LL;
      }
      for (int j = l; j < L; ++j) {
        int x = (int)a[j];
        s -= a[j] * 1LL * mp[x] * mp[x] * 1LL;
        mp[x]++;
        s += a[j] * 1LL * mp[x] * mp[x] * 1LL;
      }
      L = l;
      R = r;
      ans[ind] = s;
    }
    for (int y = 0; y < 1000002; ++y) mp[y] = 0;
  }
  for (int i = 0; i < Q; ++i) printf("%I64d\n", ans[i]);
  return 0;
}
