#include <bits/stdc++.h>
using namespace std;
int nodes, q, arr[200005], total[1000005] = {}, blok, batas1, batas2, kiri,
                           kanan;
unsigned long long jawaban = 0, ans[200005];
struct apapun1 {
  int kiri, kanan, indeks;
  friend bool operator<(apapun1 a, apapun1 b) {
    if (a.kiri / blok == b.kiri / blok) return (a.kanan < b.kanan);
    return (a.kiri / blok < b.kiri / blok);
  }
} coba1, temp1;
vector<apapun1> query;
void pairing1(int kiri, int kanan, int indeks) {
  coba1.kiri = kiri;
  coba1.kanan = kanan;
  coba1.indeks = indeks;
}
void add(int indeks) {
  jawaban -= (long long)total[arr[indeks]] * total[arr[indeks]] * arr[indeks];
  total[arr[indeks]]++;
  jawaban += (long long)total[arr[indeks]] * total[arr[indeks]] * arr[indeks];
}
void remove(int indeks) {
  jawaban -= (long long)total[arr[indeks]] * total[arr[indeks]] * arr[indeks];
  total[arr[indeks]]--;
  jawaban += (long long)total[arr[indeks]] * total[arr[indeks]] * arr[indeks];
}
int main() {
  scanf("%d%d", &nodes, &q);
  blok = ceil(sqrt(nodes));
  for (int i = 1; i <= nodes; i++) {
    scanf("%d", &arr[i]);
  }
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &batas1, &batas2);
    pairing1(batas1, batas2, i);
    query.push_back(coba1);
  }
  sort(query.begin(), query.end());
  kiri = 1;
  kanan = 1;
  add(1);
  for (int i = 0; i < q; i++) {
    temp1 = query[i];
    while (kiri < temp1.kiri) {
      remove(kiri);
      kiri++;
    }
    while (kiri > temp1.kiri) {
      kiri--;
      add(kiri);
    }
    while (kanan < temp1.kanan) {
      kanan++;
      add(kanan);
    }
    while (kanan > temp1.kanan) {
      remove(kanan);
      kanan--;
    }
    ans[temp1.indeks] = jawaban;
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] << endl;
  }
}
