#include <bits/stdc++.h>
using namespace std;
const int S = 447;
struct Query {
  int i;
  int l;
  int r;
};
struct Mos {
  long long int ans = 0;
  vector<long long int> cnts;
  void add(long long int x) {
    ans -= cnts[x] * cnts[x] * x;
    cnts[x]++;
    ans += cnts[x] * cnts[x] * x;
  }
  void remove(long long int x) {
    ans -= cnts[x] * cnts[x] * x;
    cnts[x]--;
    ans += cnts[x] * cnts[x] * x;
  }
};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<long long int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<Query> queries(m);
  for (int i = 0; i < m; i++) {
    cin >> queries[i].l >> queries[i].r;
    queries[i].l--;
    queries[i].r--;
    queries[i].i = i;
  }
  sort(queries.begin(), queries.end(), [](Query a, Query b) {
    if (a.l / S != b.l / S) return a.l < b.l;
    return ((a.l / S) & 1 ? a.r < b.r : a.r > b.r);
  });
  Mos ans;
  ans.cnts.resize(1e6 + 1);
  vector<long long int> anses(m);
  int l = 0, r = -1;
  for (Query q : queries) {
    while (l > q.l) {
      l--;
      ans.add(arr[l]);
    }
    while (r < q.r) {
      r++;
      ans.add(arr[r]);
    }
    while (l < q.l) {
      ans.remove(arr[l]);
      l++;
    }
    while (r > q.r) {
      ans.remove(arr[r]);
      r--;
    }
    anses[q.i] = ans.ans;
  }
  for (long long int x : anses) cout << x << "\n";
  cerr << "Run time: " << fixed << setprecision(3)
       << (double)clock() / CLOCKS_PER_SEC << "s" << endl;
  return 0;
}
