#include <bits/stdc++.h>
using namespace std;
//
const int mx = 2e5 + 5;
const int maxa = 1e6 + 5;
const int S = 450;
//
struct query
{
    int l, r, id;
    //
    bool operator < (const query &other)
    {
        if (l / S != other.l / S)
            return l < other.l;
        return l / S & 1 ? r < other.r : r > other.r;
    }
};
//
int n, t, a[mx];
int cnt[maxa];
long long ans[mx];
query Q[mx];
//
void calc (void)
{
    int l = 0, r = 0;
    long long sum = 0;
    //
    for (int i = 1; i <= t; ++i)
    {
        while (l < Q[i].l)
        {
            --cnt[a[l]];
            sum -= (cnt[a[l]] << 1 | 1LL) * a[l];
            ++l;
        }
        while (l > Q[i].l)
        {
            --l;
            sum += (cnt[a[l]] << 1 | 1LL) * a[l];
            ++cnt[a[l]];
        }
        while (r < Q[i].r)
        {
            ++r;
            sum += (cnt[a[r]] << 1 | 1LL) * a[r];
            ++cnt[a[r]];
        }
        while (r > Q[i].r)
        {
            --cnt[a[r]];
            sum -= (cnt[a[r]] << 1 | 1LL) * a[r];
            --r;
        }
        ans[Q[i].id] = sum;
    }
}
//
void process (void)
{
    cin >> n >> t;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= t; ++i)
        cin >> Q[i].l >> Q[i].r,
        Q[i].id = i;

    sort(Q + 1, Q + t + 1);
    calc();

    for (int i = 1; i <= t; ++i)
        cout << ans[i] << '\n';
}
//
signed main (void)
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    process();
}