#include <bits/stdc++.h>
using namespace std;
long long int ans = 0, s;
const int maxn = 1e6 + 1;
long long int cnt[maxn], v[maxn];
inline bool cmp(pair<pair<int, int>, int> p1, pair<pair<int, int>, int> p2) {
  if (p1.first.first / s == p2.first.first / s)
    return (p1.first.second < p2.first.second);
  else
    return (p1.first.first < p2.first.first);
}
inline void add(long long int x) {
  x = v[x];
  ans -= cnt[x] * cnt[x] * x;
  cnt[x]++;
  ans += cnt[x] * cnt[x] * x;
}
inline void remov(long long int x) {
  x = v[x];
  ans -= cnt[x] * cnt[x] * x;
  cnt[x]--;
  ans += cnt[x] * cnt[x] * x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n, q;
    cin >> n >> q;
    s = sqrt(n);
    v[0] = 0;
    for (int i = 1; i < n + 1; i++) cin >> v[i];
    vector<pair<pair<int, int>, int> > query(q);
    for (int i = 0; i < q; i++) {
      cin >> query[i].first.first >> query[i].first.second;
      query[i].second = i;
    }
    sort(query.begin(), query.end(), cmp);
    int l = 0, r = 0;
    int l1, r1;
    vector<long long int> u(q);
    for (auto p : query) {
      l1 = p.first.first, r1 = p.first.second;
      while (l > l1) {
        add(l - 1);
        l--;
      }
      while (r < r1) {
        add(r + 1);
        r++;
      }
      while (l < l1) {
        remov(l);
        l++;
      }
      while (r > r1) {
        remov(r);
        r--;
      }
      u[p.second] = ans;
    }
    for (int i = 0; i < q; i++) cout << u[i] << '\n';
  }
  return 0;
}
