#include <bits/stdc++.h>
using namespace std;
int block = 900;
int a[200001];
vector<long long int> freq(1000001, 0);
vector<pair<pair<int, int>, int> > v(200001);
vector<long long int> answer(200001, 0);
bool hello(pair<pair<int, int>, int> p1, pair<pair<int, int>, int> p2) {
  if ((p1.first.first) / block != (p2.first.first) / block) {
    return (p1.first.first) / block < (p2.first.first) / block;
  } else
    return (p1.first.second) < (p2.first.second);
}
long long int ans = 0;
void add(int idx) {
  freq[a[idx]]++;
  ans += ((freq[a[idx]]) * (freq[a[idx]]) * a[idx] -
          (freq[a[idx]] - 1) * (freq[a[idx]] - 1) * a[idx]);
}
void remove(int idx) {
  freq[a[idx]]--;
  ans += ((freq[a[idx]]) * (freq[a[idx]]) * a[idx] -
          (freq[a[idx]] + 1) * (freq[a[idx]] + 1) * a[idx]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> a[i];
  int l, r;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    --l, --r;
    v[i] = make_pair(make_pair(l, r), i);
  }
  sort(v.begin(), v.begin() + q, hello);
  l = 0, r = -1;
  int curl, curr;
  for (int i = 0; i < q; i++) {
    curl = v[i].first.first;
    curr = v[i].first.second;
    while (r < curr) {
      ++r;
      add(r);
    }
    while (r > curr) {
      remove(r);
      --r;
    }
    while (l < curl) {
      remove(l);
      l++;
    }
    while (l > curl) {
      --l;
      add(l);
    }
    answer[v[i].second] = ans;
  }
  for (int i = 0; i < q; ++i) {
    cout << answer[i] << "\n";
  }
  return 0;
}
