#include <bits/stdc++.h>
void read(int &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
void read(long long &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
using namespace std;
const int S = 500, maxn = 210000;
int n, t, appear[1000010], col[maxn], belong[maxn];
long long sum, ans[maxn];
struct Query {
  int l, r, id;
  bool operator<(const Query &a) const {
    return belong[l] == belong[a.l] ? r < a.r : l < a.l;
  }
} a[maxn];
void add(int x) {
  sum -= 1ll * appear[col[x]] * appear[col[x]] * col[x];
  appear[col[x]]++;
  sum += 1ll * appear[col[x]] * appear[col[x]] * col[x];
}
void del(int x) {
  sum -= 1ll * appear[col[x]] * appear[col[x]] * col[x];
  appear[col[x]]--;
  sum += 1ll * appear[col[x]] * appear[col[x]] * col[x];
}
int main() {
  read(n), read(t);
  for (int i = 0; i <= (int)n / S + 1; i++)
    for (int j = i * S; j <= (int)min((i + 1) * S - 1, n); j++) belong[j] = i;
  for (int i = 1; i <= (int)n; i++) read(col[i]);
  for (int i = 1; i <= (int)t; i++) {
    read(a[i].l), read(a[i].r);
    a[i].id = i;
  }
  sort(a + 1, a + 1 + t);
  int curl = 1, curr = 0;
  for (int i = 1; i <= (int)t; i++) {
    int l = a[i].l, r = a[i].r, id = a[i].id;
    while (curl < l) del(curl++);
    while (curl > l) add(--curl);
    while (curr < r) add(++curr);
    while (curr > r) del(curr--);
    ans[id] = sum;
  }
  for (int i = 1; i <= (int)t; i++) printf("%lld\n", ans[i]);
  return 0;
}
