#include <bits/stdc++.h>
using namespace std;
long long int paw(long long int a, long long int b);
struct q {
  int l, r, in;
} quer[210000];
int arr[210000], coun[1100000], bl;
long long int sol[210000], ans = 0;
bool comp(const q& a, const q& b) {
  if (a.l / bl == b.l / bl) return a.r < b.r;
  return a.l / bl < b.l / bl;
}
int add(int ai) {
  ans -= (long long int)((long long int)coun[arr[ai]] *
                         (long long int)coun[arr[ai]] * (long long int)arr[ai]);
  coun[arr[ai]]++;
  ans += (long long int)((long long int)coun[arr[ai]] *
                         (long long int)coun[arr[ai]] * (long long int)arr[ai]);
  return 0;
}
int remove(int ai) {
  ans -= (long long int)((long long int)coun[arr[ai]] *
                         (long long int)coun[arr[ai]] * (long long int)arr[ai]);
  coun[arr[ai]]--;
  ans += (long long int)((long long int)coun[arr[ai]] *
                         (long long int)coun[arr[ai]] * (long long int)arr[ai]);
  return 0;
}
int main() {
  int n, d, i, sq, cl, cr;
  scanf("%d %d", &n, &d);
  for (i = 0; i < n; i++) scanf("%d", &arr[i]);
  bl = (int)sqrt(n);
  for (i = 0; i < d; i++) {
    scanf("%d %d", &quer[i].l, &quer[i].r);
    quer[i].l--;
    quer[i].r--;
    quer[i].in = i;
  }
  sort(quer, quer + d, comp);
  cl = 0;
  cr = 0;
  for (i = 0; i < d; i++) {
    while (cl < quer[i].l) {
      remove(cl);
      cl++;
    }
    while (cl > quer[i].l) {
      cl--;
      add(cl);
    }
    while (cr < quer[i].r + 1) {
      add(cr);
      cr++;
    }
    while (cr > quer[i].r + 1) {
      cr--;
      remove(cr);
    }
    sol[quer[i].in] = ans;
  }
  for (i = 0; i < d; i++) printf("%lld\n", sol[i]);
  return 0;
}
long long int paw(long long int a, long long int b) {
  long long int x = ((a) % 1000000007), ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * x) % 1000000007;
    x = (x * x) % 1000000007;
    b >>= 1;
  }
  return ans;
}
