#include <bits/stdc++.h>
using namespace std;
struct query {
  int l, r, ind, bl;
  query() {
    l = 0;
    r = 0;
    ind = 0;
    bl = 0;
  }
  query(int a, int b, int c) {
    l = a;
    r = b;
    ind = c;
    bl = l / 500;
  }
  bool operator<(const query a) {
    if (bl != a.bl) return bl < a.bl;
    if (r != a.r)
      return r < a.r;
    else
      return l < a.l;
  }
};
int n;
vector<int> a;
vector<int> d;
vector<query> q;
vector<long long> aq;
bool comp(query a, query b) { return a < b; }
int main() {
  int t;
  scanf("%d%d", &n, &t);
  a.assign(n + 10, 0);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  d.assign(1005000, 0);
  aq.assign(t + 10, 0);
  if (t <= 0) return 0;
  for (int i = 0; i < t; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    q.push_back(query(l, r, i));
  }
  sort(q.begin(), q.end(), comp);
  long long ans = 0;
  for (int i = q[0].l; i <= q[0].r; i++) {
    ans -= (1LL * d[a[i]] * d[a[i]] * a[i]);
    d[a[i]]++;
    ans += (1LL * d[a[i]] * d[a[i]] * a[i]);
  }
  aq[q[0].ind] = ans;
  int ul = q[0].l, ur = q[0].r;
  for (int i = 1; i < t; i++) {
    for (int u = ul; u < q[i].l; u++) {
      ans -= (1LL * d[a[u]] * d[a[u]] * a[u]);
      d[a[u]]--;
      ans += (1LL * d[a[u]] * d[a[u]] * a[u]);
    }
    for (int u = q[i].l; u < ul; u++) {
      ans -= (1LL * d[a[u]] * d[a[u]] * a[u]);
      d[a[u]]++;
      ans += (1LL * d[a[u]] * d[a[u]] * a[u]);
    }
    ul = q[i].l;
    for (int u = ur + 1; u <= q[i].r; u++) {
      ans -= (1LL * d[a[u]] * d[a[u]] * a[u]);
      d[a[u]]++;
      ans += (1LL * d[a[u]] * d[a[u]] * a[u]);
    }
    for (int u = q[i].r + 1; u <= ur; u++) {
      ans -= (1LL * d[a[u]] * d[a[u]] * a[u]);
      d[a[u]]--;
      ans += (1LL * d[a[u]] * d[a[u]] * a[u]);
    }
    ur = q[i].r;
    aq[q[i].ind] = ans;
  }
  for (int i = 0; i < t; i++) printf("%I64d\n", aq[i]);
  return 0;
}
