#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T>
void _print(deque<T> deq) {
  cerr << "[ ";
  for (T i : deq) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.first);
  cerr << ",";
  _print(p.second);
  cerr << "}";
}
template <class T>
void _print(vector<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
void _print(long long a[], long long n) {
  cerr << "[ ";
  for (long long i = 0; i < n; i++) {
    _print(a[i]);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(set<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T>
void _print(multiset<T> v) {
  cerr << "[ ";
  for (T i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v) {
  cerr << "[ ";
  for (auto i : v) {
    _print(i);
    cerr << " ";
  }
  cerr << "]";
}
long long power(long long x, long long y, long long M) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % M;
    y >>= 1;
    x = (x * x) % M;
  }
  return res % M;
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y >>= 1;
    x = (x * x);
  }
  return res;
}
const long long mxn = 1e6 + 6, mod = 1e9 + 7, inf = 1e18;
long long t, casee = 1;
long long sz;
long long a[mxn];
long long ans_queries[200010];
long long queries;
long long ans = 0;
long long n;
long long freq[mxn];
struct query {
  long long l, r, id;
  bool operator<(const query &aa) const {
    long long x = l / sz;
    long long y = aa.l / sz;
    if (x == y) return r < aa.r;
    return x < y;
  }
} q[200010];
void add(long long val) {
  long long ks = freq[val];
  ans += val * (2 * ks + 1);
  freq[val]++;
}
void remove(long long val) {
  long long ks = freq[val];
  ans -= val * (2 * ks - 1);
  freq[val]--;
}
void mos_algo() {
  sort(q, q + queries);
  long long l = 0;
  long long r = -1;
  for (long long i = 0; i < queries; i++) {
    while (l < q[i].l) remove(a[l++]);
    while (l > q[i].l) add(a[--l]);
    while (r < q[i].r) add(a[++r]);
    while (r > q[i].r) remove(a[r--]);
    ans_queries[q[i].id] = ans;
  }
}
void test_case() {
  cin >> n >> queries;
  sz = sqrt(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < queries; i++) {
    long long l, r;
    cin >> l >> r;
    l--;
    r--;
    q[i].l = l;
    q[i].r = r;
    q[i].id = i;
  }
  mos_algo();
  for (long long i = 0; i < queries; i++) {
    cout << ans_queries[i] << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  t = 1;
  while (t--) {
    test_case();
    casee++;
  }
  return 0;
}
