#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
std::pair<int, int> DR[] = {{-1, 0}, {0, 1},   {1, 0}, {0, -1},
                            {-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug& operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug& operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
int gcd(int a, int b) {
  if (b) return gcd(b, a % b);
  return a;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int l[1 << 18], r[1 << 18], L, occ[1 << 20], a[1 << 18], n, t;
vector<int> vec;
long long sum, ans[1 << 18];
inline void rem(int val) {
  sum -= 1ll * occ[val] * occ[val] * val;
  occ[val]--;
  sum += 1ll * occ[val] * occ[val] * val;
}
inline void add(int val) {
  sum -= 1ll * occ[val] * occ[val] * val;
  occ[val]++;
  sum += 1ll * occ[val] * occ[val] * val;
}
bool comp(int a, int b) {
  if (l[a] / L != l[b] / L) return (l[a] / L) < (l[b] / L);
  return r[a] < r[b];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n >> t;
  L = sqrt(n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= t; i++) {
    cin >> l[i] >> r[i];
    vec.push_back(i);
  }
  sort(vec.begin(), vec.end(), comp);
  int pointa = 1;
  int pointb = 1;
  add(a[1]);
  for (auto it : vec) {
    while (pointb != r[it]) {
      if (pointb > r[it])
        rem(a[pointb--]);
      else
        add(a[++pointb]);
    }
    while (pointa != l[it]) {
      if (pointa > l[it])
        add(a[--pointa]);
      else
        rem(a[pointa++]);
    }
    ans[it] = sum;
  }
  for (int i = 1; i <= t; i++) cout << ans[i] << '\n';
  return 0;
}
