### 题解

#include<bits/stdc++.h>
#define fo(i, a, b) for (Re int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (Re int i = (a); i >= (b); --i)
#define Re register
#define N 100005
#define mod 1004535809
#define ll long long
int n, m, a[N], sq, bl[N], u[N], tot;
ll ans[N];
struct node{
int l, r, id;
friend bool operator < (node x, node y)
{
return bl[x.l] == bl[y.l] ? x.r < y.r : x.l < y.l;
}
}q[N];
ll tmp[N];
inline ll calc (int l, int r)
{
ll ret = 0;
fo (i, l, r) tmp[a[i]] = 0;
fo (i, l, r) {++tmp[a[i]]; ret = std::max(ret, tmp[a[i]] * u[a[i]]);}
return ret;
}
ll now, cur, cnt[N];
{
++cnt[x];
now = std::max(now, cnt[x] * u[x]);
}
inline void del (int x)
{
--cnt[x];
}
inline void modui ()
{
cur = 0, now = 0;
int L = sq, R = L - 1, pl = L;
fo (i, 1, m)
{
if (bl[q[i - 1].l] < bl[q[i].l])
{
L = (bl[q[i].l] + 1) * sq; R = L - 1;
memset(cnt, 0, sizeof cnt);
pl = L;
cur = now = 0;
}
if (bl[q[i].l] == bl[q[i].r]) {ans[q[i].id] = calc(q[i].l, q[i].r); continue;}
cur = now;
ans[q[i].id] = now;
while (L < pl) del(a[L++]);
now = cur;
}
}
int main()
{
scanf("%d %d", &n, &m);
sq = (int) sqrt(n);
fo (i, 1, n) {scanf("%d", &a[i]); bl[i] = i / sq; u[i] = a[i];}
std::sort(u + 1, u + n + 1);
tot = std::unique(u + 1, u + n + 1) - u - 1;
fo (i, 1, n) a[i] = std::lower_bound(u + 1, u + tot + 1, a[i]) - u;
fo (i, 1, m)
{
scanf("%d %d", &q[i].l, &q[i].r);
q[i].id = i;
}
std::sort(q + 1, q + m + 1);
modui();
fo (i, 1, m)
printf("%lld\n", ans[i]);
return 0;
}