#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto const &vv : V) os << vv << ",";
  os << "]";
  return os;
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  os << "(" << P.first << "," << P.second << ")";
  return os;
}
template <typename T>
inline void print_128(T num) {
  if (!num) return;
  print_128(num / 10);
  cout.put((num % 10) + '0');
}
inline int fstoi(const string &str) {
  auto it = str.begin();
  bool neg = 0;
  int num = 0;
  if (*it == '-')
    neg = 1;
  else
    num = *it - '0';
  ++it;
  while (it < str.end()) num = num * 10 + (*it++ - '0');
  if (neg) num *= -1;
  return num;
}
inline void getch(char &x) {
  while (x = getchar_unlocked(), x < 33) {
    ;
  }
}
inline void getstr(string &str) {
  str.clear();
  char cur;
  while (cur = getchar_unlocked(), cur < 33) {
    ;
  }
  while (cur > 32) {
    str += cur;
    cur = getchar_unlocked();
  }
}
template <typename... Args>
inline void getstr(string &str, Args &...arg) {
  str.clear();
  char cur;
  while (cur = getchar_unlocked(), cur < 33) {
    ;
  }
  while (cur > 32) {
    str += cur;
    cur = getchar_unlocked();
  }
  getstr(arg...);
}
template <typename T>
inline bool sc(T &num) {
  bool neg = 0;
  int c;
  num = 0;
  while (c = getchar_unlocked(), c < 33) {
    if (c == EOF) return false;
  }
  if (c == '-') {
    neg = 1;
    c = getchar_unlocked();
  }
  for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;
  if (neg) num *= -1;
  return true;
}
template <typename T, typename... Args>
inline void sc(T &num, Args &...args) {
  bool neg = 0;
  int c;
  num = 0;
  while (c = getchar_unlocked(), c < 33) {
    ;
  }
  if (c == '-') {
    neg = 1;
    c = getchar_unlocked();
  }
  for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;
  if (neg) num *= -1;
  sc(args...);
}
int res[1000001];
long long pows[200001];
long long ans;
inline void inc(int num) {
  ans -= pows[res[num]] * num;
  ++res[num];
  ans += pows[res[num]] * num;
}
inline void dec(int num) {
  ans -= pows[res[num]] * num;
  --res[num];
  ans += pows[res[num]] * num;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (long long i = 1; i < 200001; ++i) pows[i] = i * i;
  int n, t;
  sc(n, t);
  int in[n];
  for (auto &i : (in)) sc(i);
  const int S = 447;
  long long answer[t];
  struct qu {
    int l;
    int r;
    int id;
  };
  qu query[t];
  for (int i = (0); i < int((t)); ++i) {
    sc(query[i].l, query[i].r);
    --query[i].l;
    query[i].id = i;
  }
  sort(query, query + t, [&](qu &f, qu &s) {
    if (f.l / S != s.l / S) return f.l < s.l;
    return bool((f.r < s.r) ^ ((f.l / S) & 1));
  });
  int curl = 0, curr = 0;
  for (auto &i : query) {
    int L = i.l, R = i.r;
    while (curl < L) {
      dec(in[curl++]);
    }
    while (L < curl) {
      inc(in[--curl]);
    }
    while (curr < R) {
      inc(in[curr++]);
    }
    while (R < curr) {
      dec(in[--curr]);
    }
    answer[i.id] = ans;
  }
  for (auto &i : answer) cout << i << '\n';
}
