#include <bits/stdc++.h>
using namespace std;
void TemplateOfMine() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
}
const long long inf = 2e9 + 7;
long long sqrt_size;
struct query {
  long long l, r, i;
};
bool cmp(query a, query b) {
  if (a.l / sqrt_size == b.l / sqrt_size) return a.r < b.r;
  return a.l < b.l;
}
long long a[2000001], x[2000001], n, q, l = 1, r = 1, ans;
vector<query> que;
vector<long long> res;
int main() {
  TemplateOfMine();
  cin >> n >> q;
  sqrt_size = ceil(sqrt(n));
  que.resize(q);
  res.resize(q);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < q; i++) {
    cin >> que[i].l >> que[i].r;
    que[i].i = i;
  }
  ans = a[1];
  x[a[1]]++;
  sort((que).begin(), (que).end(), cmp);
  for (int i = 0; i < q; i++) {
    while (r < que[i].r) {
      r++;
      ans -= x[a[r]] * x[a[r]] * a[r];
      x[a[r]]++;
      ans += x[a[r]] * x[a[r]] * a[r];
    }
    while (l < que[i].l) {
      ans -= x[a[l]] * x[a[l]] * a[l];
      x[a[l]]--;
      ans += x[a[l]] * x[a[l]] * a[l];
      l++;
    }
    while (r > que[i].r) {
      ans -= x[a[r]] * x[a[r]] * a[r];
      x[a[r]]--;
      ans += x[a[r]] * x[a[r]] * a[r];
      r--;
    }
    while (l > que[i].l) {
      l--;
      ans -= x[a[l]] * x[a[l]] * a[l];
      x[a[l]]++;
      ans += x[a[l]] * x[a[l]] * a[l];
    }
    res[que[i].i] = ans;
  }
  for (auto i : res) cout << i << '\n';
  return 0;
}
