#include <bits/stdc++.h>
const int BLOCK_SIZE = 450;
const int MaxN = 2e5 + 1;
const int MaxA = 1e6 + 1;
using namespace std;
int arr[MaxN];
int cnt[MaxA] = {0};
long long res[MaxN];
struct query {
  int index;
  int l;
  int r;
  query() {
    index = 0;
    l = 0;
    r = 0;
  }
  query(int xIndex, int xL, int xR) {
    index = xIndex;
    l = xL;
    r = xR;
  }
  bool operator<(const query o) const {
    if (l / BLOCK_SIZE == o.l / BLOCK_SIZE) {
      return r < o.r;
    } else {
      return l < o.l;
    }
  }
};
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, q, l, r;
  cin >> n >> q;
  query lQuery[q + 1];
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
  }
  for (int i = 1; i <= q; ++i) {
    cin >> l >> r;
    lQuery[i] = query(i, l, r);
  }
  sort(lQuery + 1, lQuery + q + 1);
  l = 1, r = 0;
  long long ans = 0;
  for (int i = 1; i <= q; ++i) {
    while (lQuery[i].l < l) {
      --l;
      ans -= (long long)cnt[arr[l]] * cnt[arr[l]] * arr[l];
      ++cnt[arr[l]];
      ans += (long long)cnt[arr[l]] * cnt[arr[l]] * arr[l];
    }
    while (lQuery[i].l > l) {
      ans -= (long long)cnt[arr[l]] * cnt[arr[l]] * arr[l];
      --cnt[arr[l]];
      ans += (long long)cnt[arr[l]] * cnt[arr[l]] * arr[l];
      ++l;
    }
    while (lQuery[i].r < r) {
      ans -= (long long)cnt[arr[r]] * cnt[arr[r]] * arr[r];
      --cnt[arr[r]];
      ans += (long long)cnt[arr[r]] * cnt[arr[r]] * arr[r];
      --r;
    }
    while (lQuery[i].r > r) {
      ++r;
      ans -= (long long)cnt[arr[r]] * cnt[arr[r]] * arr[r];
      ++cnt[arr[r]];
      ans += (long long)cnt[arr[r]] * cnt[arr[r]] * arr[r];
    }
    res[lQuery[i].index] = ans;
  }
  for (int i = 1; i <= q; ++i) {
    cout << res[i] << "\n";
  }
  return 0;
}
