#include <bits/stdc++.h>
using namespace std;
static const int MAXN = 1e6 + 10;
static const int OO = 0x3fffffff;
inline int read() {
  int ret = 0, f = 1;
  char c;
  while (c = getchar(), !isdigit(c)) f = c == 45 ? -1 : 1;
  while (isdigit(c)) {
    ret = (ret << 3) + (ret << 1);
    ret += c - 48;
    c = getchar();
  }
  return f * ret;
}
template <class T>
inline bool scan_d(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
struct Node {
  int l, r, id;
} q[MAXN];
int n, m;
int cnt[MAXN];
int belong[MAXN], block;
long long ans;
int arr[MAXN];
long long out[MAXN];
bool cmp(Node a, Node b) {
  if (a.l / block != b.l / block) {
    return a.l / block < b.l / block;
  }
  return a.r < b.r;
}
inline void build() {
  block = sqrt(n);
  sort(q + 1, q + 1 + m, cmp);
}
inline void remove(int x) {
  ans -= 1ll * cnt[x] * cnt[x] * x;
  --cnt[x];
  ans += 1ll * cnt[x] * cnt[x] * x;
}
inline void add(int x) {
  ans -= 1ll * cnt[x] * cnt[x] * x;
  ++cnt[x];
  ans += 1ll * cnt[x] * cnt[x] * x;
}
void mo() {
  int l = 1, r = 1;
  cnt[arr[l]] = 1;
  ans = arr[l];
  for (register int i = 1; i <= m; ++i) {
    while (l < q[i].l) {
      remove(arr[l]);
      ++l;
    }
    while (l > q[i].l) {
      --l;
      add(arr[l]);
    }
    while (r > q[i].r) {
      remove(arr[r]);
      --r;
    }
    while (r < q[i].r) {
      ++r;
      add(arr[r]);
    }
    out[q[i].id] = ans;
  }
}
inline void print(long long x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
int main() {
  n = read();
  m = read();
  for (register int i = 1; i <= n; ++i) {
    arr[i] = read();
  }
  for (register int i = 1; i <= m; ++i) {
    q[i].l = read();
    q[i].r = read();
    q[i].id = i;
  }
  build();
  mo();
  for (register int i = 1; i <= m; ++i) {
    print(out[i]);
    puts("");
  }
}
