#include <bits/stdc++.h>
using namespace std;
const int M = 200005;
struct Query {
  int L, R, id;
} q[M];
int s, col[M];
long long ans[M];
int cnt[M * 10];
bool cmp(Query a, Query b) {
  if (a.L / s == b.L / s) return a.R < b.R;
  return a.L / s < b.L / s;
}
inline void rd(int& res) {
  res = 0;
  char c;
  while (c = getchar(), c < 48)
    ;
  do res = res * 10 + (c ^ 48);
  while (c = getchar(), c > 47);
}
void print(long long x) {
  if (!x) return;
  print(x / 10);
  putchar(x % 10 ^ 48);
}
inline void sc(long long x) {
  if (x == 0)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  s = (int)sqrt(n);
  for (int i = 1; i <= n; i++) rd(col[i]);
  for (int i = 0; i < m; i++) {
    int a, b;
    rd(a);
    rd(b);
    q[i] = (Query){a, b, i};
  }
  sort(q, q + m, cmp);
  int L = 1, R = 0;
  long long res = 0;
  for (int i = 0; i < m; i++) {
    while (R < q[i].R) {
      R++;
      res += (long long)col[R] * (cnt[col[R]] + 1) * (cnt[col[R]] + 1) -
             (long long)col[R] * cnt[col[R]] * cnt[col[R]];
      cnt[col[R]]++;
    }
    while (L < q[i].L) {
      res -= (long long)col[L] * cnt[col[L]] * cnt[col[L]] -
             (long long)col[L] * (cnt[col[L]] - 1) * (cnt[col[L]] - 1);
      cnt[col[L]]--;
      L++;
    }
    while (R > q[i].R) {
      res -= (long long)col[R] * cnt[col[R]] * cnt[col[R]] -
             (long long)col[R] * (cnt[col[R]] - 1) * (cnt[col[R]] - 1);
      cnt[col[R]]--;
      R--;
    }
    while (L > q[i].L) {
      L--;
      res += (long long)col[L] * (cnt[col[L]] + 1) * (cnt[col[L]] + 1) -
             (long long)col[L] * cnt[col[L]] * cnt[col[L]];
      cnt[col[L]]++;
    }
    ans[q[i].id] = res;
  }
  for (int i = 0; i < m; i++) sc(ans[i]);
  return 0;
}
