#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
namespace Slongod{
using ll = long long;
constexpr int N = 5e5+7 , B = 750;
int n , m , a[N] , bl[N];
struct frac{
ll a , b;
void yuefen(){ll g = __gcd(a , b); a /= g; b /= g;}
frac(){a = 0; b = 1;} frac(ll x , ll y){a = x; b = y;}
bool operator < (const frac&x) const{return a * x.b < x.a * b;}
}ans[N] , now[N] , tag[N];
vector <pair<int,int>> p[N];
inline frac max(const frac&a , const frac&b){return a < b ? b : a;}
void main()
{
cin >> n; for (int i = 1; i <= n; i++){cin >> a[i]; bl[i] = (i - 1) / B + 1;}
cin >> m; for (int i = 1 , l , r; i <= m; i++){cin >> l >> r; p[r].push_back({l , i});}
for (int i = 1; i <= n; i++) {
for (int j = i , sum = a[i]; j >= 1 and j >= i - 1900; j-- , sum += a[j]) {
now[j] = max(now[j] , frac(1ll * abs(sum) * abs(sum) , i - j + 1));
tag[bl[j]] = max(tag[bl[j]] , now[j]);
}
for (auto o : p[i]) {
if (bl[i] == bl[o.first]) {
for (int j = o.first; j <= i; j++) {
ans[o.second] = max(ans[o.second] , now[j]);
}
} else {
for (int j = o.first; bl[j] == bl[o.first]; j++) {
ans[o.second] = max(ans[o.second] , now[j]);
}
for (int j = bl[o.first] + 1; j < bl[i]; j++) {
ans[o.second] = max(ans[o.second] , tag[j]);
}
for (int j = i; bl[j] == bl[i]; j--) {
ans[o.second] = max(ans[o.second] , now[j]);
}
}
}
}
for (int i = 1; i <= m; i++) {
ans[i].yuefen();
cout << ans[i].a << ' ' << ans[i].b << '\n';
}
}
}int main()
{
ios :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
return Slongod :: main(),0;
}