#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
const int B = 450;
int n, m, cnt[200111], a[200111], L = 1, R;
vector<int> c;
long long sum, ans[200111];
void modify(int x, int flag) {
  sum -= 1ll * cnt[a[x]] * cnt[a[x]] * c[a[x]];
  cnt[a[x]] += flag;
  sum += 1ll * cnt[a[x]] * cnt[a[x]] * c[a[x]];
}
void move(int tl, int tr) {
  while (tr > R) modify(++R, 1);
  while (tl < L) modify(--L, 1);
  while (tr < R) modify(R--, -1);
  while (tl > L) modify(L++, -1);
}
struct query {
  int l, r, id;
  bool operator<(const query &tmp) const {
    if (l / B != tmp.l / B)
      return l / B < tmp.l / B;
    else
      return r < tmp.r;
  }
} q[200111];
int main() {
  n = getnum(), m = getnum();
  for (int i = 1; i <= n; i++) a[i] = getnum(), c.push_back(a[i]);
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
  for (int i = 1; i <= n; i++)
    a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
  for (int i = 1; i <= m; i++)
    q[i].l = getnum(), q[i].r = getnum(), q[i].id = i;
  sort(q + 1, q + m + 1);
  for (int i = 1; i <= m; i++) move(q[i].l, q[i].r), ans[q[i].id] = sum;
  for (int i = 1; i <= m; i++) putnum(ans[i]), putendl();
  return 0;
}
