#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, pos;
} q[200010];
int arr[200010], cnt[200010 * 10], cl, cr, le, ri, blk;
long long int ans, res[200010];
bool cmp(node a, node b) {
  if ((a.l / blk) == (b.l / blk)) return a.r < b.r;
  return (a.l / blk) < (b.l / blk);
}
inline void add(int ind) {
  ans -= ((long long)cnt[arr[ind]] * (long long)cnt[arr[ind]] *
          (long long)arr[ind]);
  cnt[arr[ind]]++;
  ans += ((long long)cnt[arr[ind]] * (long long)cnt[arr[ind]] *
          (long long)arr[ind]);
}
inline void remove(int ind) {
  ans -= ((long long)cnt[arr[ind]] * (long long)cnt[arr[ind]] *
          (long long)arr[ind]);
  cnt[arr[ind]]--;
  ans += ((long long)cnt[arr[ind]] * (long long)cnt[arr[ind]] *
          (long long)arr[ind]);
}
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 0; i < t; i++) {
    cin >> q[i].l >> q[i].r;
    q[i].pos = i;
  }
  blk = sqrt(n);
  sort(q, q + t, cmp);
  cl = 0;
  cr = -1;
  for (int i = 0; i < t; i++) {
    le = q[i].l - 1;
    ri = q[i].r - 1;
    while (cl < le) {
      remove(cl);
      cl++;
    }
    while (cl > le) {
      cl--;
      add(cl);
    }
    while (cr < ri) {
      cr++;
      add(cr);
    }
    while (cr > ri) {
      remove(cr);
      cr--;
    }
    res[q[i].pos] = ans;
  }
  for (int i = 0; i < t; i++) {
    printf("%I64d\n", res[i]);
  }
  return 0;
}
