#include <bits/stdc++.h>
long long v[200005], n, f[1000005], curans, bl, m, ans[200005];
inline void upd(long long x, long long ty) {
  curans += v[x] + 2 * f[v[x]] * v[x] * ty;
  f[v[x]] += ty;
}
struct Node {
  long long l, r, id;
  bool operator<(const Node& x) const {
    if (l / bl == x.l / bl) return r < x.r;
    return l / bl < x.l / bl;
  }
} q[200005];
inline void solve() {
  bl = (long long)pow(n, 0.5);
  std::sort(q + 1, q + m + 1);
  long long l = 1, r = 1;
  for (long long i = 1; i <= m; ++i) {
    while (l > q[i].l) upd(--l, 1);
    while (r < q[i].r) upd(r++, 1);
    while (l < q[i].l) upd(l++, -1);
    while (r > q[i].r) upd(--r, -1);
    ans[q[i].id] = curans;
  }
}
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; ++i) scanf("%lld", &v[i]);
  for (long long i = 1; i <= m; ++i)
    scanf("%lld%lld", &q[i].l, &q[i].r), ++q[i].r, q[i].id = i;
  solve();
  for (long long i = 1; i <= m; ++i) printf("%lld\n", ans[i]);
}
