#include <bits/stdc++.h>
using namespace std;
inline void fastRead(int *a) {
  register char c = 0;
  while (c < 33) c = getchar();
  *a = 0;
  while (c > 33) {
    *a = *a * 10 + c - '0';
    c = getchar();
  }
}
inline void fastWrite(long long int a) {
  char snum[20];
  int i = 0;
  do {
    snum[i++] = a % 10 + 48;
    a = a / 10;
  } while (a != 0);
  i = i - 1;
  while (i >= 0) putchar(snum[i--]);
  putchar('\n');
}
int n, block;
int arr[200005];
long long int ans[200005];
int num[1000005];
long long int sum;
bool cmp(pair<pair<int, int>, int> p1, pair<pair<int, int>, int> p2) {
  if (p1.first.first / block == p2.first.first / block)
    return p1.first.second / block < p2.first.second / block;
  return p1.first.first / block < p2.first.first / block;
}
void add(int pos) {
  int nn = arr[pos];
  sum -= (1LL * num[nn] * num[nn]) * 1LL * nn;
  num[arr[pos]]++;
  sum += (1LL * num[nn] * num[nn]) * 1LL * nn;
}
void remove(int pos) {
  long long int nn = arr[pos];
  sum -= (1LL * num[nn] * num[nn]) * 1LL * nn;
  num[arr[pos]]--;
  sum += (1LL * num[nn] * num[nn]) * 1LL * nn;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<pair<pair<int, int>, int> > v;
  block = sqrt(n);
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    v.push_back(make_pair(make_pair(a, b), i));
  }
  sort(v.begin(), v.end(), cmp);
  int l = 0, r = -1;
  for (int i = 0; i < v.size(); i++) {
    int id = v[i].second;
    int l1 = v[i].first.first;
    int r1 = v[i].first.second;
    while (l < l1) {
      remove(l);
      l++;
    }
    while (l > l1) {
      add(l - 1);
      l--;
    }
    while (r < r1) {
      add(r + 1);
      r++;
    }
    while (r > r1) {
      remove(r);
      r--;
    }
    ans[id] = sum;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << '\n';
  ;
  return 0;
}
