#include <bits/stdc++.h>
using namespace std;
const int MAXV = 1000000, MAXN = 200000, MAXB = 450;
vector<int> w[MAXV + 10];
int c[MAXN + 10];
long long cnt[MAXN + 10];
int MX;
void add(int a, int v) {
  while (a <= MX) {
    cnt[a] += v;
    a += (a & (-a));
  }
}
long long get(int a) {
  long long res = 0LL;
  while (a > 0) {
    res += cnt[a];
    a -= (a & (-a));
  }
  return res;
}
vector<pair<int, int> > pyt[MAXN + 10];
long long res[MAXN + 10];
vector<int> big;
int main(void) {
  int n, Q;
  scanf("%d%d", &n, &Q);
  for (int i = 0; i < (n); ++i) {
    scanf("%d", &c[i]);
    w[c[i]].push_back(i);
  }
  for (int i = 1; i <= MAXV; ++i) {
    if (((int)((w[i]).size())) > MAXB) {
      big.push_back(i);
    }
  }
  for (int i = 0; i < (Q); ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    --l;
    --r;
    for (__typeof((big).begin()) it = (big).begin(); it != (big).end(); ++it) {
      int b = *it;
      int z = upper_bound((w[b]).begin(), (w[b]).end(), r) -
              lower_bound((w[b]).begin(), (w[b]).end(), l);
      res[i] += (long long)z * z * b;
    }
    pyt[r].push_back(make_pair(i, l));
  }
  MX = n + 2;
  for (int i = 0; i < (n); ++i) {
    int b = c[i];
    if (((int)((w[b]).size())) <= MAXB) {
      for (__typeof((w[b]).begin()) it = (w[b]).begin(); it != (w[b]).end();
           ++it) {
        int g = *it;
        if (g == i) {
          break;
        }
        add(n + 1 - g, b * 2);
      }
      add(n + 1 - i, b);
    }
    for (__typeof((pyt[i]).begin()) it = (pyt[i]).begin(); it != (pyt[i]).end();
         ++it) {
      res[it->first] += get(n + 1 - it->second);
    }
  }
  for (int i = 0; i < (Q); ++i) {
    printf("%I64d\n", res[i]);
  }
  return 0;
}
