#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
using namespace std;
struct item {
  int l, r, i;
};
const int mxn = 2e5 + 10, MX_N = 1e6 + 5, md = 998244353;
long long T, n, k, q, answer;
long long ans[mxn];
int cnt[MX_N][2];
vector<item> Q;
vector<int> g, v;
bool mark[MX_N];
bool comp(item a, item b) {
  if (a.l / q < b.l / q) {
    return true;
  }
  if (a.l / q > b.l / q) {
    return false;
  }
  if (a.r / q < b.r / q) {
    return true;
  }
  return false;
}
void input() {
  cin >> n >> T;
  int l, r;
  for (int i = 0; i < n; i++) {
    cin >> k;
    g.push_back(k);
  }
  for (int i = 0; i < T; i++) {
    cin >> l >> r;
    --l;
    Q.push_back({l, r, i});
  }
}
void solve() {
  answer = 0, q = ceil(sqrt(n));
  sort(Q.begin(), Q.end(), comp);
  int x = 0, y = 0;
  for (int i = 0; i < Q.size(); i++) {
    int l = Q[i].l;
    int r = Q[i].r;
    while (x < l) {
      cnt[g[x]][1]--;
      v.push_back(g[x]);
      mark[g[x]] = 1;
      x++;
    }
    while (x > l) {
      x--;
      v.push_back(g[x]);
      mark[g[x]] = 1;
      cnt[g[x]][1]++;
    }
    while (y < r) {
      cnt[g[y]][1]++;
      v.push_back(g[y]);
      mark[g[y]] = 1;
      y++;
    }
    while (y > r) {
      y--;
      v.push_back(g[y]);
      mark[g[y]] = 1;
      cnt[g[y]][1]--;
    }
    for (int j = 0; j < v.size(); j++) {
      if (mark[v[j]] == 1) {
        mark[v[j]] = 0;
        answer -= (1LL * cnt[v[j]][0] * cnt[v[j]][0] * v[j]);
        cnt[v[j]][0] += cnt[v[j]][1];
        cnt[v[j]][1] = 0;
        answer += (1LL * cnt[v[j]][0] * cnt[v[j]][0] * v[j]);
      }
    }
    v.clear();
    ans[Q[i].i] = answer;
  }
  for (int i = 0; i < T; i++) {
    cout << ans[i] << " ";
  }
}
int main() {
  ios::sync_with_stdio(false);
  input(), solve();
  return 0;
}
