#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double PI = acos(-1);
const long long MOD = 1000000007;
const long long FMOD = 998244353;
const long double eps = 1e-9;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
void solve();
signed main() {
  cout << fixed << setprecision(10);
  long long t = 1;
  for (long long testcase = 1; testcase < t + 1; testcase++) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
const long long MAXN = 1e6 + 10;
long long n, m, blk_sz, freq[MAXN], curans;
vector<long long> arr, ans;
vector<pair<pair<long long, long long>, long long> > queries;
bool cmp(pair<pair<long long, long long>, long long> a,
         pair<pair<long long, long long>, long long> b) {
  if (a.first.first / blk_sz == b.first.first / blk_sz)
    return a.first.second < b.first.second;
  return a.first.first / blk_sz < b.first.first / blk_sz;
}
void add(long long x) {
  curans -= freq[x] * freq[x] * x;
  freq[x]++;
  curans += freq[x] * freq[x] * x;
}
void remove(long long x) {
  curans -= freq[x] * freq[x] * x;
  freq[x]--;
  curans += freq[x] * freq[x] * x;
}
void solve() {
  scanf("%lld%lld", &n, &m);
  blk_sz = sqrt(n) + 1;
  arr.resize(n + 1);
  ans.resize(m);
  queries.resize(m);
  memset(freq, 0, sizeof freq);
  curans = 0;
  for (long long i = 1; i <= n; i++) scanf("%lld", &arr[i]);
  for (long long i = 0; i < m; i++) {
    scanf("%lld%lld", &queries[i].first.first, &queries[i].first.second);
    queries[i].second = i;
  }
  sort(queries.begin(), queries.end(), cmp);
  long long l = 1, r = 1;
  for (long long i = 0; i < m; i++) {
    while (l < queries[i].first.first) remove(arr[l++]);
    while (l > queries[i].first.first) add(arr[--l]);
    while (r <= queries[i].first.second) add(arr[r++]);
    while (r > queries[i].first.second + 1) remove(arr[--r]);
    ans[queries[i].second] = curans;
  }
  for (auto u : ans) printf("%lld\n", u);
}
