#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 200010;
long long a[maxn] = {};
int SQ = 600;
int counts[1000010];
struct query {
  int l, r, num;
  long long ans;
  query() {}
  query(int l, int r, int num) : l(l), r(r), num(num) {}
  bool operator<(const query &oth) const {
    return make_pair(l / SQ, r) < make_pair(oth.l / SQ, oth.r);
  }
};
query qq[maxn];
bool cmp(query &q1, query &q2) { return q1.num < q2.num; }
int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; ++i) scanf("%I64d", &a[i]);
  for (int i = 0; i < t; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    qq[i] = query(l, r, i);
  }
  sort(qq, qq + t);
  int curl = 0;
  int curr = -1;
  long long s = 0;
  for (int curq = 0; curq < t; ++curq) {
    while (curr > qq[curq].r) {
      s += a[curr] * (1 - 2 * counts[a[curr]]);
      counts[a[curr]]--;
      curr--;
    }
    while (curr < qq[curq].r) {
      curr++;
      s += a[curr] * (1 + 2 * counts[a[curr]]);
      counts[a[curr]]++;
    }
    while (curl > qq[curq].l) {
      curl--;
      s += a[curl] * (1 + 2 * counts[a[curl]]);
      counts[a[curl]]++;
    }
    while (curl < qq[curq].l) {
      s += a[curl] * (1 - 2 * counts[a[curl]]);
      counts[a[curl]]--;
      curl++;
    }
    qq[curq].ans = s;
  }
  sort(qq, qq + t, cmp);
  for (int i = 0; i < t; ++i) {
    printf("%I64d\n", qq[i].ans);
  }
  return 0;
}
