#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
inline void bugp(const pair<T, V> &x) {
  cerr << '{' << x.first << ", " << x.second << "}\n";
}
template <typename T, typename U, typename V>
inline void bugpp(const pair<T, pair<U, V> > &x) {
  cerr << '{' << x.first << ", {" << x.second.first << ", " << x.second.second
       << "}}\n";
}
const int N = 200002, Q = 200002, MAX = 1000001, bs = 800;
int n, q, arr[N], chk[MAX];
long long sum = 0, ans[Q];
struct query {
  int L, R, id;
  bool operator<(const query &qq) const {
    if ((L - 1) / bs != (qq.L - 1) / bs) return L < qq.L;
    return ((L - 1) / bs) & 1 ? (R > qq.R) : (R < qq.R);
  }
} que[Q];
inline void add(const int &pos) {
  int old = chk[arr[pos]]++;
  sum += 2LL * old * arr[pos] + arr[pos];
}
inline void rem(const int &pos) {
  if (!pos || !chk[arr[pos]]) return;
  int old = chk[arr[pos]]--;
  sum -= (2LL * old * arr[pos] - arr[pos]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  scanf("%d %d", &n, &q);
  for (int i = 1, _n = (n); i <= _n; ++i) scanf("%d", &arr[i]);
  for (int i = 1, _n = (q); i <= _n; ++i) {
    scanf("%d %d", &que[i].L, &que[i].R);
    que[i].id = i;
  }
  sort(que + 1, que + q + 1);
  int l = 0, r = 0;
  for (int i = 1, _n = (q); i <= _n; ++i) {
    while (l > que[i].L) add(--l);
    while (r > que[i].R) rem(r--);
    while (r < que[i].R) add(++r);
    while (l < que[i].L) rem(l++);
    ans[que[i].id] = sum;
  }
  for (int i = 1, _n = (q); i <= _n; ++i) cout << ans[i] << '\n';
  return 0;
}
