#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c;
  while (!isdigit(c = getchar()))
    ;
  do {
    x = x * 10 + c - '0';
  } while (isdigit(c = getchar()));
}
template <typename T>
inline void write(T x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
int n, t;
int a[maxn];
long long cnt[5 * maxn];
long long res[maxn];
struct Query {
  int l, r, id;
} q[maxn];
bool cmp(Query A, Query B) {
  int S = sqrt(n);
  if (A.l / S != B.l / S) return A.l / S < B.l / S;
  return A.r < B.r;
}
int main() {
  cin >> n >> t;
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i <= t; i++) {
    read(q[i].l);
    read(q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + t + 1, cmp);
  long long ans = 0;
  a[0] = 0;
  int left = 1, right = 0;
  for (int i = 1; i <= t; i++) {
    while (left < q[i].l) {
      cnt[a[left]]--;
      ans -= (cnt[a[left]] * 2 + 1) * a[left];
      left++;
    }
    while (left > q[i].l) {
      left--;
      ans += (cnt[a[left]] * 2 + 1) * a[left];
      cnt[a[left]]++;
    }
    while (right < q[i].r) {
      right++;
      ans += (cnt[a[right]] * 2 + 1) * a[right];
      cnt[a[right]]++;
    }
    while (right > q[i].r) {
      cnt[a[right]]--;
      ans -= (cnt[a[right]] * 2 + 1) * a[right];
      right--;
    }
    res[q[i].id] = ans;
  }
  for (int i = 1; i <= t; i++) {
    write(res[i]);
    putchar('\n');
  }
}
