#include <bits/stdc++.h>
using namespace std;
const int maxa = 2e5 + 10;
int a[maxa];
int chunk[maxa];
int sum[1000009];
struct node {
  int l, r;
  int id;
  long long ans;
} nn[maxa];
bool cmp1(node a, node b) {
  if (chunk[a.l] == chunk[b.l]) return a.r < b.r;
  return chunk[a.l] < chunk[b.l];
}
int main() {
  int n, m;
  register int i, j;
  scanf("%d%d", &n, &m);
  int block = sqrt(n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    chunk[i] = (i - 1) / block + 1;
  }
  for (i = 0; i < m; i++) {
    scanf("%d%d", &nn[i].l, &nn[i].r);
    nn[i].id = i;
  }
  sort(nn, nn + m, cmp1);
  int x = 1;
  int y = 0;
  long long ans = 0;
  for (i = 0; i < m; i++) {
    while (x < nn[i].l) {
      ans = ans - 1ll * sum[a[x]] * sum[a[x]] * a[x];
      sum[a[x]]--;
      ans = ans + 1ll * sum[a[x]] * sum[a[x]] * a[x];
      x++;
    }
    while (x > nn[i].l) {
      x--;
      ans = ans - 1ll * sum[a[x]] * sum[a[x]] * a[x];
      sum[a[x]]++;
      ans = ans + 1ll * sum[a[x]] * sum[a[x]] * a[x];
    }
    while (y < nn[i].r) {
      y++;
      ans = ans - 1ll * sum[a[y]] * sum[a[y]] * a[y];
      sum[a[y]]++;
      ans = ans + 1ll * sum[a[y]] * sum[a[y]] * a[y];
    }
    while (y > nn[i].r) {
      ans = ans - 1ll * sum[a[y]] * sum[a[y]] * a[y];
      sum[a[y]]--;
      ans = ans + 1ll * sum[a[y]] * sum[a[y]] * a[y];
      y--;
    }
    nn[nn[i].id].ans = ans;
  }
  for (i = 0; i < m; i++) printf("%lld\n", nn[i].ans);
  return 0;
}
