#include <bits/stdc++.h>
using namespace std;
typedef struct query {
  int x, y, id;
} query;
int oc[1000001];
int root;
bool cmp(query A, query B) {
  if (A.x / root == B.x / root) return A.y < B.y;
  return A.x / root < B.x / root;
}
int main() {
  int N, T;
  scanf("%d%d", &N, &T);
  int vet[N + 1];
  for (int i = 0; i < N; i++) {
    scanf("%d", &vet[i]);
  }
  root = sqrt(N);
  long long resps[T];
  query q[T];
  for (int i = 0; i < T; i++) {
    scanf("%d%d", &q[i].x, &q[i].y);
    q[i].x--;
    q[i].y--;
    q[i].id = i;
  }
  sort(q, q + T, cmp);
  int x, y;
  long long resp = 0;
  x = q[0].x;
  y = q[0].y;
  for (int i = x; i <= y; i++) {
    resp -= ((((long long)oc[vet[i]]) * oc[vet[i]]) * (vet[i]));
    oc[vet[i]]++;
    resp += ((((long long)oc[vet[i]]) * oc[vet[i]]) * (vet[i]));
  }
  resps[q[0].id] = resp;
  for (int a = 1; a < T; a++) {
    while (q[a].x > x) {
      resp -= ((((long long)oc[vet[x]]) * oc[vet[x]]) * (vet[x]));
      oc[vet[x]]--;
      resp += ((((long long)oc[vet[x]]) * oc[vet[x]]) * (vet[x]));
      x++;
    }
    while (x > q[a].x) {
      x--;
      resp -= ((((long long)oc[vet[x]]) * oc[vet[x]]) * (vet[x]));
      oc[vet[x]]++;
      resp += ((((long long)oc[vet[x]]) * oc[vet[x]]) * (vet[x]));
    }
    while (q[a].y > y) {
      y++;
      resp -= ((((long long)oc[vet[y]]) * oc[vet[y]]) * (vet[y]));
      oc[vet[y]]++;
      resp += ((((long long)oc[vet[y]]) * oc[vet[y]]) * (vet[y]));
    }
    while (y > q[a].y) {
      resp -= ((((long long)oc[vet[y]]) * oc[vet[y]]) * (vet[y]));
      oc[vet[y]]--;
      resp += ((((long long)oc[vet[y]]) * oc[vet[y]]) * (vet[y]));
      y--;
    }
    resps[q[a].id] = resp;
  }
  for (int i = 0; i < T; i++) cout << resps[i] << endl;
  return 0;
}
