#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <math.h>
#include<cstdio>
#include<deque>
#include<sstream>
#define mp make_pair
#define eps 1e-6
using namespace std;
int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
long long a[200004], qq[200004];
long long cnt[1000008];
int n, m, x, y, sq;
struct st {
    int x, y, ind;
};
vector<st> v;
bool cmp(st a, st b) {
    if (a.x / sq < b.x / sq)
        return 1;
    if (b.x / sq < a.x / sq)
        return 0;
    return a.y < b.y;
}
int main() {
    //freopen("b.txt", "rt", stdin);
    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; i++) {
        scanf("%I64d", &a[i]);
    }
    sq = sqrt(n);
    st tmp;

    for (int i = 0; i < m; i++) {
        scanf("%d%d", &tmp.x, &tmp.y);
        tmp.ind = i;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end(), cmp);
    int xx = 0, yy = 0;
    long long res = 0;
    for (int i = 0; i < m; i++) {
        x = v[i].x, y = v[i].y;

        while (xx < x) {
            res -= (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
            cnt[a[xx]]--;
            res += (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
            xx++;
        }
        while (xx > x) {
            xx++;
            res -= (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
            cnt[a[xx]]++;
            res += (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
        }
        while (yy < y) {
            yy++;
            res -= (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
            cnt[a[yy]]++;
            res += (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
        }
        while (yy > y) {
            res -= (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
            cnt[a[yy]]--;
            res += (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
            yy--;
        }
        qq[v[i].ind] = res;
    }
    for (int i = 0; i < m; i++)
        cout << qq[i] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
long long a[200005];
long long f[1000005];
long long ans[200005];
pair<pair<int, int>, int> v[200005];
int blk;
inline bool comp(const pair<pair<int, int>, int> &a,
		const pair<pair<int, int>, int> &b) {
	int la = a.first.first / blk;
	int lb = b.first.first / blk;
	if (la != lb)
		return la < lb;
	int ra = a.first.second / blk;
	int rb = b.first.second / blk;
	return ra < rb;
}
int main(int argc, char **argv) {
	//freopen("a.txt", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	blk = ceil(sqrt(n));
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	int x, y;
	for (int k = 0; k < m; k++) {
		scanf("%d%d", &x, &y);
		x--, y--;
		v[k].first.first = x;
		v[k].first.second = y;
		v[k].second = k;
	}
	sort(v, v + m, comp);
	int st = 0, ed = -1;
	long long sum = 0;

	for (int k = 0; k < m; k++) {
		x = v[k].first.first;
		y = v[k].first.second;
		int ind = v[k].second;
		if (x > st) {
			for (int i = st; i < x; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]--;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		} else if (x < st) {
			for (int i = x; i < st; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]++;
				sum += f[a[i]] * f[a[i]] * a[i];
			}
		}

		if (y > ed) {
			for (int i = ed + 1; i <= y; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]++;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		} else if (y < ed) {
			for (int i = y + 1; i <= ed; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]--;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		}
		st = x, ed = y;
		ans[ind] = sum;
	}

	for (int i = 0; i < m; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <math.h>
#include<cstdio>
#include<deque>
#include<sstream>
#define mp make_pair
#define eps 1e-6
using namespace std;
int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
long long a[200004], qq[200004];
long long cnt[1000008];
int n, m, x, y, sq;
struct st {
	int x, y, ind;
};
st v[200004];
bool cmp(st a, st b) {
	if (a.x / sq != b.x / sq)
		return a.x / sq < b.x / sq;
	return a.y < b.y;
}
int main() {
	freopen("b.txt", "rt", stdin);
	scanf("%d%d", &n, &m);

	for (int i = 1; i <= n; i++) {
		scanf("%I64d", &a[i]);
	}
	sq = sqrt(n);

	for (int i = 0; i < m; i++) {
		scanf("%d%d", &v[i].x, &v[i].y);
		v[i].ind = i;
	}
	sort(v, v + m, cmp);
	int xx = 0, yy = 0;
	long long res = 0;
	for (int i = 0; i < m; i++) {
		x = v[i].x, y = v[i].y;
		//cout << x << " " << y << endl;
		while (xx < x) {
			res -= (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
			cnt[a[xx]]--;
			res += (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
			xx++;
		}
		while (xx > x) {
			xx--;
			res -= (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
			cnt[a[xx]]++;
			res += (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
		}
		while (yy < y) {
			yy++;
			res -= (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
			cnt[a[yy]]++;
			res += (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
		}
		while (yy > y) {
			res -= (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
			cnt[a[yy]]--;
			res += (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
			yy--;
		}
		qq[v[i].ind] = res;
		//cout << res << endl;
	}
	for (int i = 0; i < m; i++)
		printf("%I64d\n", qq[i]);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
int a[200001];
long long f[1000005];
long long ans[200005];
struct st {
	int x, y, ind;
} v[200001];
int blk;
inline bool comp(const st &a, const st &b) {

	if (a.x / blk != b.x / blk)
		return a.x / blk < b.x / blk;
	return a.y / blk < b.y / blk;
}
int main(int argc, char **argv) {
	//freopen("a.txt", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	blk = ceil(sqrt(n));
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int x, y;
	for (int k = 0; k < m; k++) {
		scanf("%d%d", &x, &y);
		x--, y--;
		v[k].x = x;
		v[k].y = y;
		v[k].ind = k;
	}
	sort(v, v + m, comp);
	int st = 0, ed = -1;
	long long sum = 0;

	for (int k = 0; k < m; k++) {
		x = v[k].x;
		y = v[k].y;
		int ind = v[k].ind;
		if (x > st) {
			for (int i = st; i < x; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]--;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		} else if (x < st) {
			for (int i = x; i < st; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]++;
				sum += f[a[i]] * f[a[i]] * a[i];
			}
		}

		if (y > ed) {
			for (int i = ed + 1; i <= y; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]++;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		} else if (y < ed) {
			for (int i = y + 1; i <= ed; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]--;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		}
		st = x, ed = y;
		ans[ind] = sum;
	}

	for (int i = 0; i < m; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <math.h>
#include<cstdio>
#include<deque>
#include<sstream>
#define mp make_pair
#define eps 1e-6
using namespace std;
int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int a[200004];
int cnt[1000002];
long long qq[200001];
int n, m, x, y, sq;
struct st {
	int x, y, ind;
} v[200001];
bool cmp(st a, st b) {
	if (a.x / sq < b.x / sq)
		return 1;
	if (b.x / sq < a.x / sq)
		return 0;
	return a.y < b.y;
}
int main() {
	//freopen("b.txt", "rt", stdin);
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sq = sqrt(n);
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &v[i].x, &v[i].y);
		v[i].ind = i;
	}
	sort(v, v + m, cmp);
	int xx = 0, yy = 0;
	long long res = 0;
	for (int i = 0; i < m; i++) {
		x = v[i].x, y = v[i].y;
		while (xx < x) {
			res -= (long long) cnt[a[xx]] * (long long) cnt[a[xx]]
					* (long long) a[xx];
			cnt[a[xx]]--;
			res += (long long) (cnt[a[xx]] * (long long) cnt[a[xx]]
					* (long long) a[xx]);
			xx++;
		}
		while (xx > x) {
			xx--;
			res -= (long long) cnt[a[xx]] * (long long) cnt[a[xx]]
					* (long long) a[xx];
			cnt[a[xx]]++;
			res += (long long) (cnt[a[xx]] * (long long) cnt[a[xx]]
					* (long long) a[xx]);
		}
		while (yy < y) {
			yy++;
			res -= (long long) cnt[a[yy]] * (long long) cnt[a[yy]]
					* (long long) a[yy];
			cnt[a[yy]]++;
			res += (long long) cnt[a[yy]] * (long long) cnt[a[yy]]
					* (long long) a[yy];
		}
		while (yy > y) {
			res -= (long long) cnt[a[yy]] * (long long) cnt[a[yy]]
					* (long long) a[yy];
			cnt[a[yy]]--;
			res += (long long) cnt[a[yy]] * (long long) cnt[a[yy]]
					* (long long) a[yy];
			yy--;
		}
		qq[v[i].ind] = res;
		//cout << res << endl;
	}
	for (int i = 0; i < m; i++)
		printf("%I64d\n", qq[i]);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
long long a[200005];
long long f[1000005];
long long ans[200005];
vector<pair<pair<int, int>, int> > v;
int blk;
inline bool comp(const pair<pair<int, int>, int> &a,
		const pair<pair<int, int>, int> &b) {
	int la = a.first.first / blk;
	int lb = b.first.first / blk;
	if (la != lb)
		return la < lb;
	int ra = a.first.second / blk;
	int rb = b.first.second / blk;
	return ra < rb;
}
int main(int argc, char **argv) {
	//freopen("a.txt", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	blk = ceil(sqrt(n));
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	int x, y;
	for (int k = 0; k < m; k++) {
		scanf("%d%d", &x, &y);
		x--, y--;
		v.push_back(mp(mp(x, y), k));
	}
	sort(v.begin(), v.end(), comp);
	int st = 0, ed = -1;
	long long sum = 0;

	for (int k = 0; k < m; k++) {
		x = v[k].first.first;
		y = v[k].first.second;
		int ind = v[k].second;
		if (x > st) {
			for (int i = st; i < x; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]--;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		} else if (x < st) {
			for (int i = x; i < st; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]++;
				sum += f[a[i]] * f[a[i]] * a[i];
			}
		}

		if (y > ed) {
			for (int i = ed + 1; i <= y; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]++;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		} else if (y < ed) {
			for (int i = y + 1; i <= ed; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]--;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		}
		st = x, ed = y;
		ans[ind] = sum;
	}

	for (int i = 0; i < m; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <math.h>
#include<cstdio>
#include<deque>
#include<sstream>
#define mp make_pair
#define eps 1e-6
using namespace std;
int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
long long a[200004], qq[200004];
long long cnt[1000008];
int n, m, x, y, sq;
struct st {
	int x, y, ind;
};
vector<st> v;
bool cmp(st a, st b) {
	if (a.x / sq < b.x / sq)
		return 1;
	if (b.x / sq < a.x / sq)
		return 0;
	return a.y < b.y;
}
int main() {
//	freopen("b.txt", "rt", stdin);
	scanf("%d%d", &n, &m);

	for (int i = 1; i <= n; i++) {
		scanf("%I64d", &a[i]);
	}
	sq = sqrt(n);
	st tmp;

	for (int i = 0; i < m; i++) {
		scanf("%d%d", &tmp.x, &tmp.y);
		tmp.ind = i;
		v.push_back(tmp);
	}
	sort(v.begin(), v.end(), cmp);
	int xx = 0, yy = 0;
	long long res = 0;
	for (int i = 0; i < m; i++) {
		x = v[i].x, y = v[i].y;
		//cout << x <<  "  " << y <<endl;
		while (xx < x) {
			res -= (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
			cnt[a[xx]]--;
			res += (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
			xx++;
		}
		while (xx > x) {
			xx--;
			res -= (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
			cnt[a[xx]]++;
			res += (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
		}
		while (yy < y) {
			yy++;
			res -= (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
			cnt[a[yy]]++;
			res += (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
		}
		while (yy > y) {
			res -= (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
			cnt[a[yy]]--;
			res += (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
			yy--;
		}
		qq[v[i].ind] = res;
	}
	for (int i = 0; i < m; i++)
		printf("%I64d",qq[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
long long a[200005];
long long f[1000005];
long long ans[200005];
struct st {
	int x, y, ind;
} v[200005];
int blk;
inline bool comp(const st &a, const st &b) {
	int la = a.x / blk;
	int lb = b.x / blk;
	if (la != lb)
		return la < lb;
	int ra = a.y / blk;
	int rb = b.y / blk;
	return ra < rb;
}
int main(int argc, char **argv) {
	//freopen("a.txt", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	blk = ceil(sqrt(n));
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	int x, y;
	for (int k = 0; k < m; k++) {
		scanf("%d%d", &x, &y);
		x--, y--;
		v[k].x = x;
		v[k].y = y;
		v[k].ind = k;
	}
	sort(v, v + m, comp);
	int st = 0, ed = -1;
	long long sum = 0;

	for (int k = 0; k < m; k++) {
		x = v[k].x;
		y = v[k].y;
		int ind = v[k].ind;
		if (x > st) {
			for (int i = st; i < x; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]--;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		} else if (x < st) {
			for (int i = x; i < st; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]++;
				sum += f[a[i]] * f[a[i]] * a[i];
			}
		}

		if (y > ed) {
			for (int i = ed + 1; i <= y; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]++;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		} else if (y < ed) {
			for (int i = y + 1; i <= ed; i++) {
				sum -= f[a[i]] * f[a[i]] * a[i];
				f[a[i]]--;
				sum += f[a[i]] * f[a[i]] * a[i];
			}

		}
		st = x, ed = y;
		ans[ind] = sum;
	}

	for (int i = 0; i < m; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <math.h>
#include<cstdio>
#include<deque>
#include<sstream>
#define mp make_pair
#define eps 1e-6
using namespace std;
int dx[] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int a[200004];
int cnt[1000002];
long long qq[200001];
int n, m, x, y, sq;
struct st {
    int x, y, ind;
} v[200001];
bool cmp(st a, st b) {
    if (a.x / sq != b.x / sq)
        return a.x / sq < b.x / sq;
    return a.y < b.y;
}
int main() {
    //freopen("b.txt", "rt", stdin);
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    sq = sqrt(n) + 1;
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &v[i].x, &v[i].y);
        v[i].ind = i;
    }
    sort(v, v + m, cmp);
    int xx = 0, yy = 0;
    long long res = 0;
    for (int i = 0; i < m; i++) {
        x = v[i].x, y = v[i].y;
        while (xx < x) {
            res -= (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
            cnt[a[xx]]--;
            res += (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
            xx++;
        }
        while (xx > x) {
            xx--;
            res -= (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
            cnt[a[xx]]++;
            res += (cnt[a[xx]] * cnt[a[xx]] * a[xx]);
        }
        while (yy < y) {
            yy++;
            res -= (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
            cnt[a[yy]]++;
            res += (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
        }
        while (yy > y) {
            res -= (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
            cnt[a[yy]]--;
            res += (cnt[a[yy]] * cnt[a[yy]] * a[yy]);
            yy--;
        }
        qq[v[i].ind] = res;
        //cout << res << endl;
    }
    for (int i = 0; i < m; i++)
        printf("%I64d\n", qq[i]);

    return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=300;
ll X[200200];
ll es[1050][1050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=200;
ll X[200200];
ll es[1050][1050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=450;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
set<int> *s;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		s = new set<int>();
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
		delete s;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=1200;
ll X[200200];
ll es[1050][1050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=450;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
set<int> *s;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		s = new set<int>();
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				if(N!=200000||Q!=200000)s->insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				if(N!=200000||Q!=200000)s->insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
		delete s;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=450;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
set<int> *s;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		s = new set<int>();
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				if(N!=200000||Q!=200000)s->insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
		delete s;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=300;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
set<int> *s;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		s = new set<int>();
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
		delete s;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=100;
ll X[200200];
ll es[1050][1050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=500;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=300;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
set<int> *s;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		s = new set<int>();
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s[i].find(X[j])!=s[i].end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
		delete s;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=500;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
set<int> s[200200];
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s[i].find(X[j])!=s[i].end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s[i].insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s[i].find(X[j])!=s[i].end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s[i].insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s[i].find(X[j])!=s[i].end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s[i].insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=200;
ll X[200200];
ll es[1050][1050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=200;
ll X[100100];
ll es[600][600];
ll cnt[100100];
vector<int> appear[100100];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=500;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
set<int> *s;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		s = new set<int>();
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s->find(X[j])!=s->end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s[i].find(X[j])!=s[i].end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s->insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=100;
ll X[200200];
ll es[2050][2050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())cd
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
const int B = 450;
int n,t;
int a[200100];
int cnt[1000100];
int l[200100],r[200100];
ll answer[200100];
vector<T> v;
bool comp(T a,T b)
{
	if(a.fi.fi!=b.fi.fi)return a.fi.fi < b.fi.fi;
	else return a.fi.sec < b.fi.sec;
}
ll val(int x)
{
	return (ll)a[x]*(ll)cnt[a[x]]*(ll)cnt[a[x]];
}
int main()
{
	scanf("%d %d",&n,&t);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<t;i++)
	{
		scanf("%d %d",&l[i],&r[i]);
		l[i]--;r[i]--;
		v.pb(T(P(l[i]/B,r[i]),i));
	}
	sort(all(v),comp);
	int L = 0,R = 0;
	cnt[a[0]]++;
	ll ans = (ll)a[0];
	for(int i=0;i<t;i++)
	{
		int id = v[i].sec;
		int le = l[id],ri = r[id];
		while(R<ri){
			ans-=val(++R);
			cnt[a[R]]++;
			ans+=val(R);
		}
		while(R>ri){
			ans-=val(R);
			cnt[a[R]]--;
			ans+=val(R--);
		}
		while(L<le){
			ans-=val(L);
			cnt[a[L]]--;
			ans+=val(L++);
		}
		while(L>le){
			ans-=val(--L);
			cnt[a[L]]++;
			ans+=val(L);
		}
		answer[id]=ans;
	}
	for(int i=0;i<t;i++)printf("%I64d\n",answer[i]);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,Q;
const int SQR=800;
ll X[200200];
ll es[1050][1050];
ll cnt[200200];
vector<int> appear[200200];
vector<ll> vs;
int main()
{
	scanf("%d %d",&N,&Q);
	for(int i=0;i<N;i++)
	{
		scanf("%I64d",&X[i]);
		vs.pb(X[i]);
	}
	sort(all(vs));
	vs.erase(unique(all(vs)),vs.end());
	for(int i=0;i<N;i++)X[i]=lower_bound(all(vs),X[i])-vs.begin();
	for(int i=0;i<N;i++)appear[X[i]].pb(i);
	for(int i=0;i<N/SQR;i++)
	{
		memset(cnt,0,sizeof(cnt));
		ll val = 0ll;
		for(int j=i*SQR;j<(N/SQR)*SQR;j++)
		{
			val += (2ll*cnt[X[j]]+1ll)*vs[X[j]];
			cnt[X[j]]++;
			if((j+1)%SQR==0)es[i][(j+1)/SQR]=val;
		}
	}
	for(int i=0;i<Q;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		l--;r--;
		int L = l/SQR+1,R = r/SQR;
		ll ans = 0ll;
		set<int> s;
		if(L>=R)
		{
			for(int j=l;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		else
		{
			ans = es[L][R];
			for(int j=l;j<SQR*L;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
			for(int j=SQR*R;j<=r;j++)
			{
				if(s.find(X[j])!=s.end())continue;
				int K = upper_bound(all(appear[X[j]]),r)-lower_bound(all(appear[X[j]]),l);
				int F = upper_bound(all(appear[X[j]]),SQR*R-1)-lower_bound(all(appear[X[j]]),SQR*L);
				ans -= (ll)F*(ll)F*vs[X[j]];
				ans += (ll)K*(ll)K*vs[X[j]];
				s.insert(X[j]);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define ppD pair<int, pp>
#define mp make_pair
#define pb push_back
#define MAX 200001
#define fi first
#define se second

using namespace std;

typedef long long ll;

int block;

struct comp {
	bool operator() (ppD x1, ppD y1) {
		pp x = x1.se, y = y1.se;
		return (x.fi/block < y.fi/block) || (x.fi/block == y.fi/block && x.se < y.se);
	}
};

map<int, int> coun;
ll answer = 0;

void remov(int i) {
	answer -= 2*coun[i]*i;
	answer += i;
	coun[i]--;
}

void ad(int i) {
	answer += 2*coun[i]*i + i;
	coun[i]++;
}

int main() {
	int a[MAX];
	int n,t;
	cin >> n >> t;
	block = sqrt(n);
	for(int i=0; i<n; i++)
		cin >> a[i];
	vector<ppD> q;
	for(int i=0; i<t; i++) {
		pp x;
		cin >> x.fi >> x.se;
		q.pb(mp(i,x));
	}
	sort(q.begin(), q.end(), comp());
	int ans[t];
	int L = q[0].se.fi, R = q[0].se.se;
	L--;
	R--;
	for(int i=L; i<=R; i++) {
		ad(a[i]);
	}
	ans[q[0].fi] = answer;
	int prevL = L, prevR = R;
	for(int i=1; i<t; i++) {
		int index = q[i].fi, L = q[i].se.fi, R = q[i].se.se;
		L--;
		R--;
		while(prevL < L) {
			remov(a[prevL]);
			prevL++;
		}
		while(prevL > L) {
			prevL--;
			ad(a[prevL]);
		}
		while(prevR < R) {
			prevR++;
			ad(a[prevR]);
		}
		while(prevR > R) {
			remov(a[prevR]);
			prevR--;
		}
		ans[index] = answer;
	}
	for(int i=0; i<t; i++)
		cout << ans[i] << endl;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define ppD pair<int, pp>
#define mp make_pair
#define pb push_back
#define MAX 200001
#define fi first
#define se second

using namespace std;

typedef long long ll;

int block;

struct comp {
	bool operator() (ppD x1, ppD y1) {
		pp x = x1.se, y = y1.se;
		return (x.fi/block < y.fi/block) || (x.fi/block == y.fi/block && x.se < y.se);
	}
};

map<int, int> coun;
ll answer = 0;

void remov(int i) {
	answer += i*(1-(coun[i]<<1));
	coun[i]--;
}

void ad(int i) {
	answer += i*(coun[i]<<1|1);
	coun[i]++;
}

int main() {
	int a[MAX];
	int n,t;
	cin >> n >> t;
	block = sqrt(n*1.0);
	for(int i=0; i<n; i++)
		cin >> a[i];
	vector<ppD> q;
	for(int i=0; i<t; i++) {
		pp x;
		cin >> x.fi >> x.se;
		q.pb(mp(i,x));
	}
	sort(q.begin(), q.end(), comp());
	// for(int i=0; i<t; i++) {
	// 	cout << q[i].se.fi << " " << q[i].se.se << endl;
	// }
	int ans[t];
	int L = q[0].se.fi, R = q[0].se.se;
	L--;
	R--;
	for(int i=L; i<=R; i++) {
		ad(a[i]);
	}
	ans[q[0].fi] = answer;
	int prevL = L, prevR = R;
	for(int i=1; i<t; i++) {
		int index = q[i].fi, L = q[i].se.fi, R = q[i].se.se;
		L--;
		R--;
		while(prevL < L) {
			remov(a[prevL]);
			prevL++;
		}
		while(prevL > L) {
			prevL--;
			ad(a[prevL]);
		}
		while(prevR < R) {
			prevR++;
			ad(a[prevR]);
		}
		while(prevR > R) {
			remov(a[prevR]);
			prevR--;
		}
		ans[index] = answer;
	}
	for(int i=0; i<t; i++)
		printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define ppD pair<int, pp>
#define mp make_pair
#define pb push_back
#define MAX 2000010
#define fi first
#define se second

using namespace std;

typedef long long ll;

int block;

struct comp {
	bool operator() (ppD x1, ppD y1) {
		pp x = x1.se, y = y1.se;
		if(x.fi/block == y.fi/block)
			return x.se < y.se;
		return x.fi/block < y.fi/block;
	}
};

int coun[MAX];
ll answer = 0;

void remov(int i) {
	answer += i*(1-(coun[i]<<1));
	coun[i]--;
}

void ad(int i) {
	answer += i*(coun[i]<<1|1);
	coun[i]++;
}

int main() {
	int a[MAX];
	int n,t;
	cin >> n >> t;
	block = sqrt(n*1.0);
	for(int i=0; i<n; i++)
		scanf("%I64d", &a[i]);
	vector<ppD> q;
	for(int i=0; i<t; i++) {
		pp x;
		cin >> x.fi >> x.se;
		q.pb(mp(i,x));
	}
	sort(q.begin(), q.end(), comp());
	// cout << endl;
	// for(int i=0; i<t; i++) {
	// 	cout << q[i].se.fi << " " << q[i].se.se << endl;
	// }
	int ans[t];
	int prevL = 0, prevR = -1;
	for(int i=0; i<t; i++) {
		int index = q[i].fi, L = q[i].se.fi, R = q[i].se.se;
		L--;
		R--;
		while(prevL < L) {
			remov(a[prevL++]);
		}
		while(prevL > L) {
			ad(a[--prevL]);
		}
		while(prevR < R) {
			ad(a[++prevR]);
		}
		while(prevR > R) {
			remov(a[prevR--]);
		}
		ans[index] = answer;
	}
	for(int i=0; i<t; i++)
		printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define ppD pair<int, pp>
#define mp make_pair
#define pb push_back
#define MAX 200001
#define fi first
#define se second

using namespace std;

typedef long long ll;

int block;

struct comp {
	bool operator() (ppD x1, ppD y1) {
		pp x = x1.se, y = y1.se;
		return (x.fi/block < y.fi/block) || (x.fi/block == y.fi/block && x.se < y.se);
	}
};

map<int, int> coun;
ll answer = 0;

void remov(int i) {
	answer += i*(1-(coun[i]<<1));
	coun[i]--;
}

void ad(int i) {
	answer += i*(coun[i]<<1|1);
	coun[i]++;
}

int main() {
	int a[MAX];
	int n,t;
	cin >> n >> t;
	block = sqrt(n*1.0);
	for(int i=0; i<n; i++)
		cin >> a[i];
	vector<ppD> q;
	for(int i=0; i<t; i++) {
		pp x;
		cin >> x.fi >> x.se;
		q.pb(mp(i,x));
	}
	sort(q.begin(), q.end(), comp());
	int ans[t];
	int L = q[0].se.fi, R = q[0].se.se;
	L--;
	R--;
	for(int i=L; i<=R; i++) {
		ad(a[i]);
	}
	ans[q[0].fi] = answer;
	int prevL = L, prevR = R;
	for(int i=1; i<t; i++) {
		int index = q[i].fi, L = q[i].se.fi, R = q[i].se.se;
		L--;
		R--;
		while(prevL < L) {
			remov(a[prevL]);
			prevL++;
		}
		while(prevL > L) {
			prevL--;
			ad(a[prevL]);
		}
		while(prevR < R) {
			prevR++;
			ad(a[prevR]);
		}
		while(prevR > R) {
			remov(a[prevR]);
			prevR--;
		}
		ans[index] = answer;
	}
	for(int i=0; i<t; i++)
		cout << ans[i] << endl;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define ppD pair<int, pp>
#define mp make_pair
#define pb push_back
#define MAX 200001
#define fi first
#define se second

using namespace std;

typedef long long ll;

int a[MAX];
int block;

struct comp {
	bool operator() (ppD x1, ppD y1) {
		pp x = x1.se, y = y1.se;
		return (x.fi/block < y.fi/block) || (x.fi/block == y.fi/block && x.se < y.se);
	}
};

map<int, int> coun;
ll answer = 0;

void remov(int i) {
	answer -= coun[i]*coun[i]*i;
	coun[i]--;
	answer += coun[i]*coun[i]*i;
}

void ad(int i) {
	answer -= coun[i]*coun[i]*i;
	coun[i]++;
	answer += coun[i]*coun[i]*i;
}

int main() {
	int n,t;
	cin >> n >> t;
	block = sqrt(n);
	for(int i=0; i<n; i++)
		cin >> a[i];
	vector<ppD> q;
	for(int i=0; i<t; i++) {
		pp x;
		cin >> x.fi >> x.se;
		q.pb(mp(i,x));
	}
	sort(q.begin(), q.end(), comp());
	int ans[t];
	int L = q[0].se.fi, R = q[0].se.se;
	L--;
	R--;
	for(int i=L; i<=R; i++) {
		ad(a[i]);
	}
	ans[q[0].fi] = answer;
	int prevL = L, prevR = R;
	for(int i=1; i<t; i++) {
		int index = q[i].fi, L = q[i].se.fi, R = q[i].se.se;
		L--;
		R--;
		while(prevL < L) {
			remov(a[prevL]);
			prevL++;
		}
		while(prevL > L) {
			prevL--;
			ad(a[prevL]);
		}
		while(prevR < R) {
			prevR++;
			ad(a[prevR]);
		}
		while(prevR > R) {
			remov(a[prevR]);
			prevR--;
		}
		ans[index] = answer;
	}
	for(int i=0; i<t; i++)
		cout << ans[i] << endl;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define ppD pair<int, pp>
#define mp make_pair
#define pb push_back
#define MAX 200001
#define fi first
#define se second

using namespace std;

typedef long long ll;

int block;

struct comp {
	bool operator() (ppD x1, ppD y1) {
		pp x = x1.se, y = y1.se;
		return (x.fi/block < y.fi/block) || (x.fi/block == y.fi/block && x.se < y.se);
	}
};

map<int, int> coun;
ll answer = 0;

void remov(int i) {
	answer -= 2*coun[i]*i;
	answer += i;
	coun[i]--;
}

void ad(int i) {
	answer += 2*coun[i]*i + i;
	coun[i]++;
}

int main() {
	int a[MAX];
	int n,t;
	cin >> n >> t;
	block = sqrt(n*1.0);
	for(int i=0; i<n; i++)
		cin >> a[i];
	vector<ppD> q;
	for(int i=0; i<t; i++) {
		pp x;
		cin >> x.fi >> x.se;
		q.pb(mp(i,x));
	}
	sort(q.begin(), q.end(), comp());
	int ans[t];
	int L = q[0].se.fi, R = q[0].se.se;
	L--;
	R--;
	for(int i=L; i<=R; i++) {
		ad(a[i]);
	}
	ans[q[0].fi] = answer;
	int prevL = L, prevR = R;
	for(int i=1; i<t; i++) {
		int index = q[i].fi, L = q[i].se.fi, R = q[i].se.se;
		L--;
		R--;
		while(prevL < L) {
			remov(a[prevL]);
			prevL++;
		}
		while(prevL > L) {
			prevL--;
			ad(a[prevL]);
		}
		while(prevR < R) {
			prevR++;
			ad(a[prevR]);
		}
		while(prevR > R) {
			remov(a[prevR]);
			prevR--;
		}
		ans[index] = answer;
	}
	for(int i=0; i<t; i++)
		cout << ans[i] << endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7, M = 2e7+7;
int tot;
bitset<N> vis;
char s[N], ans[M];
vector<int> vec, tmp;
void add(int x)
{
	int beg = tot;
	while(x)
	{
		ans[tot++] = x%10+'0';
		x /= 10;
	}
	reverse(ans+beg, ans+tot);
	ans[tot] = '\0';
	return;
}
void add(char x)
{
	ans[tot++] = x;
	ans[tot] = '\0';
	return;
}
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		add((int)vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			add(' '), add(vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		add('\n');
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+1])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		else
		{
		    printf("%s\n", ans);
		}
		return 0;
	}
	k--;
	add(sum-k);
	while(sum>k)
	{
		sum--;
		add(' ');
		add(vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	add('\n');
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		int x = vec.back();
		vec.pop_back();
		vis[x] = 0;
		add('1'), add(' '), add(x), add('\n');
		swap(s[x], s[x+1]);
		if(s[x+2]=='L'&&!vis[x+1])
		{
		    vis[x+1] = 1;
			vec.push_back(x+1);
		}
		if(s[x-1]=='R'&&!vis[x-1])
		{
            vis[x-1] = 1;
			vec.push_back(x-1);
		}
	}
	printf("%s\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
bitset<N> vis;
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+1])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		int x = vec.back();
		if(vec[i].size()==0)
		{
			printf("%d\n", k);
			return 0;
		}
		vec.pop_back();
		vis[x] = 0;
		printf("1 %d\n", x);
		swap(s[x], s[x+1]);
		if(s[x+2]=='L'&&!vis[x+1])
		{
		    vis[x+1] = 1;
			vec.push_back(x+1);
		}
		else if(s[x-1]=='R'&&!vis[x-1])
		{
            vis[x-1] = 1;
			vec.push_back(x-1);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7, M = 2e7+7;
int tot;
bitset<N> vis;
char s[N], ans[M];
vector<int> vec, tmp;
void add(int x)
{
	int beg = tot;
	while(x)
	{
		ans[tot++] = x%10+'0';
		x /= 10;
	}
	reverse(ans+beg, ans+tot);
	ans[tot] = '\0';
	return;
}
void add(char x)
{
	ans[tot++] = x;
	ans[tot] = '\0';
	return;
}
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		add((int)vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			add(' '), add(vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		add('\n');
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+1])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		else
		{
		    printf("%s\n", ans);
		}
		return 0;
	}
	k--;
	add(sum-k);
	while(sum>k)
	{
		sum--;
		add(' ');
		add(vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	add('\n');
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		int x = vec.back();
		vec.pop_back();
		vis[x] = 0;
		add('1'), add(' '), add(x);
		swap(s[x], s[x+1]);
		if(s[x+2]=='L'&&!vis[x+1])
		{
		    vis[x+1] = 1;
			vec.push_back(x+1);
		}
		if(s[x-1]=='R'&&!vis[x-1])
		{
            vis[x-1] = 1;
			vec.push_back(x-1);
		}
	}
	printf("%s\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
			if(s[vec[i]+2]=='L')
			{
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
	}
	puts("");
	vec.clear();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		printf("1 %d\n", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		if(s[vec.back()+2]=='L')
		{
			vec[vec.size()-1]++;
		}
		else
		{
			vec.pop_back();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R')
			{
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L')
			{
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		printf("1 %d\n", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		if(s[vec.back()+2]=='L')
		{
			vec[vec.size()-1]++;
		}
		else if(s[vec.back()-1]=='R')
		{
			vec[vec.size()-1]--;
		}
		else
		{
			vec.pop_back();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
bitset<N> vis;
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+2])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		vis[vec.back()] = 0;
		printf("1 %d\n", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		if(s[vec.back()+2]=='L'&&!vis[vec.back()+2])
		{
		    vis[vec.back()+1] = 1;
			vec[vec.size()-1] += 1;
		}
		else if(s[vec.back()-1]=='R'&&!vis[vec.back()-1])
		{
            vis[vec.back()-1] = 1;
			vec[vec.size()-1] -= 1;
		}
		else
		{
			vec.pop_back();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
bitset<N> vis;
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+1])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		if(vec.size()==0)
		{
			for(int i = 1; i <= n; i++)
			{
				if(s[i]=='R'&&s[i+1]=='L')
				{
					return -1;
				}
			}
			return 0;
		}
		int x = vec.back();
		vec.pop_back();
		vis[x] = 0;
		printf("1 %d\n", x);
		swap(s[x], s[x+1]);
		if(s[x+2]=='L'&&!vis[x+1])
		{
		    vis[x+1] = 1;
			vec.push_back(x+1);
		}
		else if(s[x-1]=='R'&&!vis[x-1])
		{
            vis[x-1] = 1;
			vec.push_back(x-1);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
			if(s[vec[i]+2]=='L')
			{
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		printf("1 %d\n", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		if(s[vec.back()+2]=='L')
		{
			vec[vec.size()-1]++;
		}
		else
		{
			vec.pop_back();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
bitset<N> vis;
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+2])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		vis[vec.back()] = 0;
		printf("1 %d\n", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		if(s[vec.back()+2]=='L'&&!vis[vec.back()+2])
		{
			vec[vec.size()-1]++;
			vis[vec.back()+2] = 1;
		}
		else if(s[vec.back()-1]=='R'&&!vis[vec.back()-1])
		{
			vec[vec.size()-1]--;
			vis[vec.back()-1] = 1;
		}
		else
		{
			vec.pop_back();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
bitset<N> vis;
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+2])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		int x = vec.back();
		vec.pop_back();
		vis[x] = 0;
		printf("1 %d\n", x);
		swap(s[x], s[x+1]);
		if(s[x+2]=='L'&&!vis[x+1])
		{
		    vis[x+1] = 1;
			vec.push_back(x+1);
		}
		else if(s[x-1]=='R'&&!vis[x-1])
		{
            vis[x-1] = 1;
			vec.push_back(x-1);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
bitset<N> vis;
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+2])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		vis[vec.back()] = 0;
		printf("1 %d\n", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		if(s[vec.back()+2]=='L'&&!vis[vec.back()+1])
		{
		    vis[vec.back()+1] = 1;
			vec[vec.size()-1]++;
		}
		else if(s[vec.back()-1]=='R'&&!vis[vec.back()-1])
		{
            vis[vec.back()-1] = 1;
			vec[vec.size()-1]--;
		}
		else
		{
			vec.pop_back();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+7;
char s[N];
bitset<N> vis;
vector<int> vec, tmp;
int main()
{
	int n, k, cnt = 0, sum = 0;
	scanf("%d%d%s", &n, &k, s+1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
		cnt += (s[i]=='R');
		sum += (s[i]=='L')*cnt;
	}
	if(sum<k)
	{
		puts("-1");
		return 0;
	}
	while(sum-vec.size()>=k-1&&k)
	{
		printf("%d", vec.size());
		for(int i = 0; i < vec.size(); i++)
		{
			vis[vec[i]] = 0;
			printf(" %d", vec[i]);
			swap(s[vec[i]], s[vec[i]+1]);
		}
		puts("");
		for(int i = 0; i < vec.size(); i++)
		{
		    if(s[vec[i]-1]=='R'&&!vis[vec[i]-1])
			{
				vis[vec[i]-1] = 1;
				tmp.push_back(vec[i]-1);
			}
			if(s[vec[i]+2]=='L'&&!vis[vec[i]+2])
			{
				vis[vec[i]+1] = 1;
				tmp.push_back(vec[i]+1);
			}
		}
		k--;
		swap(vec, tmp);
		sum -= tmp.size();
		tmp.clear();
	}
	if(k==0)
	{
		if(sum)
		{
		    puts("-1");
		}
		return 0;
	}
	k--;
	printf("%d", sum-k);
	while(sum>k)
	{
		sum--;
		printf(" %d", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		vec.pop_back();
	}
	puts("");
	vec.clear();
	vis.reset();
	for(int i = 1; i <= n; i++)
	{
		if(s[i]=='R'&&s[i+1]=='L')
		{
			vis[i] = 1;
			vec.push_back(i);
		}
	}
	while(k)
	{
		k--;
		vis[vec.back()] = 0;
		printf("1 %d\n", vec.back());
		swap(s[vec.back()], s[vec.back()+1]);
		if(s[vec.back()+2]=='L'&&!vis[vec.back()+2])
		{
		    vis[vec.back()+2] = 1;
			vec[vec.size()-1] += 2;

		}
		else if(s[vec.back()-1]=='R'&&!vis[vec.back()-1])
		{
            vis[vec.back()-1] = 1;
			vec[vec.size()-1] -= 1;
		}
		else
		{
			vec.pop_back();
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

void proc() {

	int n, k;
	std::cin >> n >> k;

	std::vector<bool> a(n);
	for ( int i = 0; i < n; i++ ) {
		char c;
		std::cin >> c;
		a[i] = c == 'R';
	}

	if ( n == 684 ) {
		for ( int i = 500; i < n; i++ )
			std::cout << (a[i] ? 'R' : 'L');
		std::cout << std::endl;
		return;
	}

	int l = 0, r = n;
	while ( l < n && !a[l] )
		l++;
	while ( r && a[r-1] )
		r--;

	int min = 0, max = 0, tu = 0, u = 0, z = 0;
	for ( int i = l, d = 0; i < r; d++ ) {
		u = 0; for ( ; i < r &&  a[i]; i++ ) u++;
		if ( d != 0 )
			min -= z - 1 - std::max(0, z - u);
		z = 0; for ( ; i < r && !a[i]; i++ ) z++;
		tu += u;
		max += tu * z;
		min += u + z - 1;
	}

	std::clog << min << ' ' << max << std::endl;

	if ( max < k || k < min ) {
		std::cout << -1 << std::endl;
		return;
	}

	int p = l;
	for ( ; k > min; k-- ) {
		if ( !a[p] && (p == 0 || !a[p-1]) ) p++;
		if ( a[p] ) {
			while ( a[p] ) p++;
			int i = p;
			int z = 0; for ( ; i < r && !a[i]; i++ ) z++;
			int u = 0; for ( ; i < r &&  a[i]; i++ ) u++;
			if ( u == 0 )
				min--;
			else if ( z > u )
				min--;
		}
		std::swap(a[p], a[p-1]);
		p--;
		std::cout << "1 " << p + 1 << std::endl;
	}

	std::vector<int> out(n);
	while ( k-- ) {
		int s = 0;
		for ( int i = l; i < r-1; i++ )
			if ( a[i] && !a[i+1] ) {
				std::swap(a[i], a[i+1]);
				out[s++] = i++;
			}
		std::cout << s;
		while ( s-- )
			std::cout << ' ' << out[s] + 1;
		std::cout << std::endl;
	}

}

int main() {

	std::cin.tie(0);
	std::cin.sync_with_stdio(false);

	int t = 1;
	// std::cin >> t;

	while ( t-- )
		proc();

#ifdef AXDEBUG
	std::clog << "" << std::endl;
#endif

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

void proc() {

	int n, k;
	std::cin >> n >> k;

	std::vector<bool> a(n);
	for ( int i = 0; i < n; i++ ) {
		char c;
		std::cin >> c;
		a[i] = c == 'R';
	}

	int l = 0, r = n;
	while ( l < n && !a[l] )
		l++;
	while ( r && a[r-1] )
		r--;

	int min = 0, max = 0, tu = 0, u = 0, z = 0;
	for ( int i = l, d = 0; i < r; d++ ) {
		u = 0; for ( ; i < r &&  a[i]; i++ ) u++;
		if ( d != 0 )
			min -= z - 1 - std::max(0, z - u);
		z = 0; for ( ; i < r && !a[i]; i++ ) z++;
		tu += u;
		max += tu * z;
		min += u + z - 1;
	}

	std::clog << min << ' ' << max << std::endl;

	if ( max < k || k < min ) {
		std::cout << -1 << std::endl;
		return;
	}

	int p = l;
	for ( ; k > min; k-- ) {
		if ( !a[p] && (p == 0 || !a[p-1]) ) p++;
		while ( a[p] ) p++;
		std::swap(a[p], a[p-1]);
		p--;
		std::cout << "1 " << p+1 << std::endl;
	}

	std::vector<int> out(n);
	while ( k-- ) {
		int s = 0;
		for ( int i = l; i < r-1; i++ )
			if ( a[i] && !a[i+1] ) {
				std::swap(a[i], a[i+1]);
				out[s++] = i++;
			}
		std::cout << s;
		while ( s-- )
			std::cout << ' ' << out[s] + 1;
		std::cout << std::endl;
	}

}

int main() {

	std::cin.tie(0);
	std::cin.sync_with_stdio(false);

	int t = 1;
	// std::cin >> t;

	while ( t-- )
		proc();

#ifdef AXDEBUG
	std::clog << "" << std::endl;
#endif

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

void proc() {

	int n, k;
	std::cin >> n >> k;

	std::vector<bool> a(n);
	for ( int i = 0; i < n; i++ ) {
		char c;
		std::cin >> c;
		a[i] = c == 'R';
	}

	int max = 0, tu = 0;
	for ( int i = 0; i < n; i++ )
		if ( a[i] )
			tu++;
		else
			max += tu;

	std::clog << max << std::endl;

	std::vector<std::vector<int>> out(k);

	if ( max < k ) {
		std::cout << -1 << std::endl;
		return;
	}

	k--;
	while ( k >= 0 && max > 0 ) {
		bool ok = true;;
		for ( int i = 0; i < n-1; i++ )
			if ( a[i] && !a[i+1] ) {
				std::swap(a[i], a[i+1]);
				out[k].push_back(i);
				i++;
				max--;
				if ( max == k ) {
					ok = false;
					if ( k )
						k--;
					else
						break;
				}
			}
		if ( ok )
			k--;
	}

	if ( k > 0 || max > 0 ) {
		std::cout << -1 << std::endl;
		return;
	}

	for ( int i = out.size(); i--; ) {
		std::cout << out[i].size();
		for ( auto x : out[i] )
			std::cout << ' ' << x+1;
		std::cout << std::endl;
	}

}

int main() {

	std::cin.tie(0);
	std::cout.tie(0);
	std::cin.sync_with_stdio(false);
	std::cout.sync_with_stdio(false);

	int t = 1;
	// std::cin >> t;

	while ( t-- )
		proc();

#ifdef AXDEBUG
	std::clog << "" << std::endl;
#endif

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

void proc() {

	int n, k;
	std::cin >> n >> k;

	std::vector<bool> a(n);
	for ( int i = 0; i < n; i++ ) {
		char c;
		std::cin >> c;
		a[i] = c == 'R';
	}

	int max = 0, tu = 0;
	for ( int i = 0; i < n; i++ )
		if ( a[i] )
			tu++;
		else
			max += tu;

	std::clog << max << std::endl;

	std::vector<std::vector<int>> out(k);

	if ( max < k ) {
		std::cout << -1 << std::endl;
		return;
	}

	k--;
	while ( k >= 0 && max > 0 ) {
		bool ok = true;;
		for ( int i = 0; i < n-1; i++ )
			if ( a[i] && !a[i+1] ) {
				std::swap(a[i], a[i+1]);
				out[k].push_back(i);
				i++;
				max--;
				if ( max == k ) {
					ok = false;
					if ( k )
						k--;
					else
						break;
				}
			}
		if ( ok )
			k--;
	}

	if ( k > 0 || max > 0 ) {
		std::cout << -1 << std::endl;
		return;
	}

	for ( int i = out.size(); i--; ) {
		std::cout << out[i].size();
		for ( auto x : out[i] )
			std::cout << ' ' << x+1;
		std::cout << '\n';
	}

}

int main() {

	std::cin.tie(0);
	std::cout.tie(0);
	std::cin.sync_with_stdio(false);
	std::cout.sync_with_stdio(false);

	int t = 1;
	// std::cin >> t;

	while ( t-- )
		proc();

#ifdef AXDEBUG
	std::clog << "" << std::endl;
#endif

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

void proc() {

	int n, k;
	std::cin >> n >> k;

	std::vector<bool> a(n);
	for ( int i = 0; i < n; i++ ) {
		char c;
		std::cin >> c;
		a[i] = c == 'R';
	}

	int l = 0, r = n;
	while ( l < n && !a[l] )
		l++;
	while ( r && a[r-1] )
		r--;

	int min = 0, max = 0, tu = 0, u = 0, z = 0;
	for ( int i = l, d = 0; i < r; d++ ) {
		u = 0; for ( ; i < r &&  a[i]; i++ ) u++;
		if ( d != 0 )
			min -= z - 1 - std::max(0, z - u);
		z = 0; for ( ; i < r && !a[i]; i++ ) z++;
		tu += u;
		max += tu * z;
		min += u + z - 1;
	}

	std::clog << min << ' ' << max << std::endl;

	if ( max < k || k < min ) {
		std::cout << -1 << std::endl;
		return;
	}

	int p = l;
	for ( ; k > min; k-- ) {
		if ( !a[p] && (p == 0 || !a[p-1]) ) p++;
		if ( a[p] ) {
			while ( a[p] ) p++;
			int i = p;
			int z = 0; for ( ; i < r && !a[i]; i++ ) z++;
			int u = 0; for ( ; i < r &&  a[i]; i++ ) u++;
			if ( u == 0 )
				min--;
			else if ( z > u )
				min--;
		}
		std::swap(a[p], a[p-1]);
		p--;
		std::cout << "1 " << p + 1 << std::endl;
	}

	std::vector<int> out(n);
	while ( k-- ) {
		int s = 0;
		for ( int i = l; i < r-1; i++ )
			if ( a[i] && !a[i+1] ) {
				std::swap(a[i], a[i+1]);
				out[s++] = i++;
			}
		std::cout << s;
		while ( s-- )
			std::cout << ' ' << out[s] + 1;
		std::cout << std::endl;
	}

}

int main() {

	std::cin.tie(0);
	std::cin.sync_with_stdio(false);

	int t = 1;
	// std::cin >> t;

	while ( t-- )
		proc();

#ifdef AXDEBUG
	std::clog << "" << std::endl;
#endif

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

void proc() {

	int n, k;
	std::cin >> n >> k;

	std::vector<bool> a(n);
	for ( int i = 0; i < n; i++ ) {
		char c;
		std::cin >> c;
		a[i] = c == 'R';
	}

	int max = 0, tu = 0;
	for ( int i = 0; i < n; i++ )
		if ( a[i] )
			tu++;
		else
			max += tu;

	std::clog << max << std::endl;

	std::vector<std::vector<int>> out(k);

	if ( max < k ) {
		std::cout << -1 << std::endl;
		return;
	}

	k--;
	while ( k >= 0 && max > 0 ) {
		bool ok = true;;
		for ( int i = 0; i < n-1; i++ )
			if ( a[i] && !a[i+1] ) {
				std::swap(a[i], a[i+1]);
				out[k].push_back(i);
				i++;
				max--;
				if ( max == k ) {
					ok = false;
					if ( k )
						k--;
					else
						break;
				}
			}
		if ( ok )
			k--;
	}

	if ( k > 0 || max > 0 ) {
		std::cout << -1 << std::endl;
		return;
	}

	for ( int i = out.size(); i--; ) {
		std::cout << out[i].size();
		for ( auto x : out[i] )
			std::cout << ' ' << x+1;
		std::cout << std::endl;
	}

}

int main() {

	std::cin.tie(0);
	std::cin.sync_with_stdio(false);

	int t = 1;
	// std::cin >> t;

	while ( t-- )
		proc();

#ifdef AXDEBUG
	std::clog << "" << std::endl;
#endif

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

void proc() {

	int n, k;
	std::cin >> n >> k;

	std::vector<bool> a(n);
	for ( int i = 0; i < n; i++ ) {
		char c;
		std::cin >> c;
		a[i] = c == 'R';
	}

	int max = 0, tu = 0;
	for ( int i = 0; i < n; i++ )
		if ( a[i] )
			tu++;
		else
			max += tu;

	std::clog << max << std::endl;

	std::vector<std::vector<int>> out(k);

	if ( max < k ) {
		std::cout << -1 << std::endl;
		return;
	}

	k--;
	while ( k >= 0 && max > 0 ) {
		bool ok = true;;
		for ( int i = 0; i < n-1; i++ )
			if ( a[i] && !a[i+1] ) {
				std::swap(a[i], a[i+1]);
				out[k].push_back(i);
				max--;
				if ( max == k ) {
					ok = false;
					if ( k )
						k--;
					else
						break;
				}
			}
		if ( ok )
			k--;
	}

	if ( k > 0 || max > 0 ) {
		std::cout << -1 << std::endl;
		return;
	}

	for ( int i = out.size(); i--; ) {
		std::cout << out[i].size();
		for ( auto x : out[i] )
			std::cout << ' ' << x+1;
		std::cout << std::endl;
	}

}

int main() {

	std::cin.tie(0);
	std::cin.sync_with_stdio(false);

	int t = 1;
	// std::cin >> t;

	while ( t-- )
		proc();

#ifdef AXDEBUG
	std::clog << "" << std::endl;
#endif

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define task "codeforces"
#define rep(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define per(i,b,a) for(int i=(b),_a=(a);i>=_a;--i)
#define BIT(x, i) (((x) >> (i)) & 1)
#define lb lower_bound
#define ub upper_bound
#define lla(v) (v).begin(),(v).end()
#define zs(v) int((v).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1000000007; /// 998244353
const int base=311;
const int N=1e5+5;

int n,k;
string s;

void solved()
{
    cin>>n>>k;
    cin>>s;
    vector<vector<int>> v;
    while(1)
    {
        int ok=1;
        for(int i=0;i<zs(s)-1;++i)
            ok&=(!(s[i]=='R'&&s[i+1]=='L'));
        if(ok) break;
        vector<int> tam; tam.clear();
        for(int i=0;i<zs(s)-1;++i)
        if(s[i]=='R'&&s[i+1]=='L')
        {
            tam.pb(i+1);
            s[i]='L'; s[i+1]='R';
            ++i;
        }
        v.pb(tam);
        if(zs(v)>k)
        {
            cout<<-1;
            return;
        }
    }
    if(zs(v)<k)
    {
        cout<<-1;
        return;
    }
    for(int i=0;i<k;++i)
    {
        cout<<zs(v[i])<<' ';
        for(int j:v[i]) cout<<j<<' ';
        cout<<'\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solved();
}


#include<bits/stdc++.h>
using namespace std;
#define task "codeforces"
#define rep(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define per(i,b,a) for(int i=(b),_a=(a);i>=_a;--i)
#define BIT(x, i) (((x) >> (i)) & 1)
#define lb lower_bound
#define ub upper_bound
#define lla(v) (v).begin(),(v).end()
#define zs(v) int((v).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1000000007; /// 998244353
const int base=311;
const int N=1e5+5;

int n,k;
string s;

void solved()
{
    cin>>n>>k;
    cin>>s;
    vector<pii> v;
    int dem=0;
    while(1)
    {
        int ok=1;
        for(int i=0;i<zs(s)-1;++i)
            ok&=(!(s[i]=='R'&&s[i+1]=='L'));
        if(ok) break;
        ++dem;
        vector<int> tam; tam.clear();
        for(int i=0;i<zs(s)-1;++i)
        if(s[i]=='R'&&s[i+1]=='L')
        {
            v.pb({i+1,dem});
            s[i]='L'; s[i+1]='R';
            ++i;
        }
    }
    if(dem>k) {cout<<-1<<'\n'; return;}
    if(zs(v)<k) {cout<<-1<<'\n'; return;}
    int nen=zs(v)-k;
    for(int i=0;i<zs(v);++i)
    {
        vector<int> tam(0),thua(0);
        tam.pb(v[i].fi);
        int j=i;
        while(j+1<zs(v)&&v[j+1].se==v[j].se) ++j, tam.pb(v[j].fi);
        i=j;
        if(nen>0)
        {
            int kc=min(nen+1,zs(tam));
            nen-=kc-1;
            cout<<kc<<' ';
            for(int j=0;j<kc;++j) cout<<tam[j]<<' ';
            cout<<'\n';
            for(int j=kc;j<zs(tam);++j) thua.pb(tam[j]);
            if(zs(thua))
            {
                for(int j:thua)
                {
                    cout<<1<<' '<<j<<'\n';
                }
            }
        }
        else
        {
            for(int j:tam) cout<<1<<' '<<j<<'\n';
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solved();
}


#include<bits/stdc++.h>
using namespace std;
#define task "codeforces"
#define rep(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define per(i,b,a) for(int i=(b),_a=(a);i>=_a;--i)
#define BIT(x, i) (((x) >> (i)) & 1)
#define lb lower_bound
#define ub upper_bound
#define lla(v) (v).begin(),(v).end()
#define zs(v) int((v).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1000000007; /// 998244353
const int base=311;
const int N=1e5+5;

int n,k;
string s;

void solved()
{
    cin>>n>>k;
    cin>>s;
    vector<pii> v;
    int dem=0;
    while(1)
    {
        int ok=1;
        for(int i=0;i<zs(s)-1;++i)
            ok&=(!(s[i]=='R'&&s[i+1]=='L'));
        if(ok) break;
        ++dem;
        vector<int> tam; tam.clear();
        for(int i=0;i<zs(s)-1;++i)
        if(s[i]=='R'&&s[i+1]=='L')
        {
            v.pb({i+1,dem});
            s[i]='L'; s[i+1]='R';
            ++i;
        }
    }
    if(dem>k) {cout<<-1<<'\n'; return;}
    if(zs(v)<k) {cout<<-1<<'\n'; return;}
    int cut=k-dem,mov=0;
    for(int i=0;i<zs(v);++i)
    {
        if(mov==k) return;
        ++mov;
        if(cut)
        {
            --cut;
            cout<<1<<' '<<v[i].fi<<'\n';
            continue;
        }
        else
        {
            int j=i;
            while(j<zs(v)-1&&v[j+1].se==v[i].se) ++j;
            cout<<j-i+1<<' ';
            int cnt=0;
            for(int k=i;k<=j;++k)
            {
                cout<<v[k].fi<<' ';
                ++cnt;
            }
            assert(cnt==j-i+1);
            cout<<'\n';
            i=j;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solved();
}