#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
int n, t, r;
int arr[N];
struct node {
  int L, R, idx;
  node() { L = R = idx = 0; }
  node(int a, int b, int c) { L = a, R = b, idx = c; }
  bool operator<(const node &a) const {
    if (L / r != a.L / r) return L / r < a.L / r;
    return R < a.R;
  }
} q[N];
int cnt[N * 10];
long long ans, res[N];
void add(int v) {
  ans -= 1ll * cnt[v] * cnt[v] * v;
  cnt[v]++;
  ans += 1ll * cnt[v] * cnt[v] * v;
}
void remove(int v) {
  ans -= 1ll * cnt[v] * cnt[v] * v;
  cnt[v]--;
  ans += 1ll * cnt[v] * cnt[v] * v;
}
int main(int argc, char *args[]) {
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; ++i) scanf("%d", arr + i);
  for (int x, y, i = 0; i < t; ++i) {
    scanf("%d%d", &x, &y);
    x--, y--;
    q[i] = node(x, y, i);
  }
  r = n / (int)sqrt(t) + 1;
  sort(q, q + t);
  int curL = 0, curR = 0;
  ans = arr[0];
  cnt[arr[0]]++;
  for (int i = 0; i < t; ++i) {
    int L = q[i].L, R = q[i].R;
    while (curR < R) add(arr[++curR]);
    while (curL > L) add(arr[--curL]);
    while (L > curL) remove(arr[curL++]);
    while (R < curR) remove(arr[curR--]);
    res[q[i].idx] = ans;
  }
  for (int i = 0; i < t; ++i) printf("%lld\n", res[i]);
  return 0;
}
