#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
const int base = 500;
long long res[maxn];
int A[maxn];
int B[1000010];
int lnk[maxn];
int son[maxn / base + 10];
int que[maxn];
pair<int, int> g[maxn];
int n, m;
bool cmp(const int a, const int b) { return g[a].second < g[b].second; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &g[i].first, &g[i].second);
    g[i].first--;
    g[i].second--;
    int t = g[i].first / base;
    lnk[i] = son[t];
    son[t] = i;
  }
  for (int i, ii = 0; ii <= (n - 1) / base; ii++) {
    int t = 0;
    for (int j = son[ii]; j; j = lnk[j]) que[t++] = j;
    sort(que, que + t, cmp);
    i = ii * base;
    long long s = 0;
    for (int j = i, k = 0; j <= n; j++) {
      s += (long long)A[j] * (2 * B[A[j]] + 1);
      B[A[j]]++;
      while (k < t && g[que[k]].second == j) {
        for (int jj = i; jj < g[que[k]].first; jj++) {
          s += (long long)A[jj] * (1 - 2 * B[A[jj]]);
          B[A[jj]]--;
        }
        res[que[k]] = s;
        for (int jj = i; jj < g[que[k]].first; jj++) {
          s += (long long)A[jj] * (1 + 2 * B[A[jj]]);
          B[A[jj]]++;
        }
        k++;
      }
    }
    for (int j = i, k = 0; j <= n; j++) B[A[j]] = 0;
  }
  for (int i = 1; i <= m; i++) printf("%I64d\n", res[i]);
}
