#include<stdio.h>
#include<algorithm>
using namespace std;
int power[21],A[100001],M[100001][21],M1[100001][21];
int MinTime(int i, int j)
{
int k = log2(j-i+1);
return (A[M[i][k]] <= A[M[j-power[k]+1][k]]) ? A[M[i][k]] : A[M[j-power[k]+1][k]];
}
int MaxTime(int i, int j)
{
int k = log2(j-i+1);
return (A[M1[i][k]] >= A[M1[j-power[k]+1][k]]) ? A[M1[i][k]] : A[M1[j-power[k]+1][k]];
}
void RMQ_MIN(int n)
{
int i, j;
for (i = 0; i < n; i++) M[i][0] = i;
for (j = 1; power[j] <= n; j++)
{
for (i = 0; i + power[j] - 1 < n; i++)
{
M[i][j] = (A[M[i][j - 1]] < A[M[i + power[j-1]][j - 1]]) ? M[i][j - 1] : M[i + power[j-1]][j - 1];
}
}
}
void RMQ_MAX(int n)
{
int i,j;
for(i = 0; i < n; i++) M1[i][0] = i;
for(j = 1; power[j] <= n; j++)
{
for (i = 0; i + power[j] - 1 < n; i++)
{
M1[i][j] = (A[M1[i][j - 1]] > A[M1[i + power[j-1]][j - 1]]) ? M1[i][j - 1] : M1[i + power[j-1]][j - 1];
}
}
}
int main()
{
double Ans,FastTime;
int i,N,Q,L,R,Min1,Max1,Max2,Max3,Max4;
power[0] = 1;
for(i=1; i<=20; i++) power[i] = 2*power[i-1];
scanf("%d",&N);
for(i=0; i<N; i++) scanf("%d",&A[i]);
RMQ_MIN(N);
RMQ_MAX(N);
scanf("%d",&Q);
while(Q--)
{
scanf("%d%d",&L,&R);
Min1 = MinTime(L,R);
//printf("%d ",Min1);
Max1 = MaxTime(L,R);
//printf("%d ",Max1);
FastTime = (Max1-Min1)/2.0;
//printf("%d ",FastTime);
Max2 = (L > 0) ? MaxTime (0,L-1) : 0;
Max3 = (R < N-1) ? MaxTime(R+1, N-1) : 0;
Max4 = max(Max2 + 0.0, Max3 + 0.0);
Ans = Min1 + max( FastTime , Max4 + 0.0 );
printf("%.1lf\n",Ans);
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBwb3dlclsyMV0sQVsxMDAwMDFdLE1bMTAwMDAxXVsyMV0sTTFbMTAwMDAxXVsyMV07CiAKaW50IE1pblRpbWUoaW50IGksIGludCBqKQp7CiAgICAgICAgaW50IGsgPSBsb2cyKGotaSsxKTsKICAgICAgICByZXR1cm4gKEFbTVtpXVtrXV0gPD0gQVtNW2otcG93ZXJba10rMV1ba11dKSA/IEFbTVtpXVtrXV0gOiBBW01bai1wb3dlcltrXSsxXVtrXV07Cn0KIAppbnQgTWF4VGltZShpbnQgaSwgaW50IGopCnsKICAgICAgICBpbnQgayA9IGxvZzIoai1pKzEpOwogICAgICAgIHJldHVybiAoQVtNMVtpXVtrXV0gPj0gQVtNMVtqLXBvd2VyW2tdKzFdW2tdXSkgPyBBW00xW2ldW2tdXSA6IEFbTTFbai1wb3dlcltrXSsxXVtrXV07Cn0KIAp2b2lkIFJNUV9NSU4oaW50IG4pCnsKICAgIGludCBpLCBqOwogICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykgTVtpXVswXSA9IGk7CiAgICAKICAgIGZvciAoaiA9IDE7IHBvd2VyW2pdIDw9IG47IGorKykKICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpICsgcG93ZXJbal0gLSAxIDwgbjsgaSsrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBNW2ldW2pdID0gKEFbTVtpXVtqIC0gMV1dIDwgQVtNW2kgKyBwb3dlcltqLTFdXVtqIC0gMV1dKSA/IE1baV1baiAtIDFdIDogTVtpICsgcG93ZXJbai0xXV1baiAtIDFdOwogICAgICAgICAgICAgICAgfQogICAgICAgIH0KfQogCnZvaWQgUk1RX01BWChpbnQgbikKewogICAgICAgIGludCBpLGo7CiAgICAgICAgZm9yKGkgPSAwOyBpIDwgbjsgaSsrKSBNMVtpXVswXSA9IGk7CiAgICAKICAgICAgICBmb3IoaiA9IDE7IHBvd2VyW2pdIDw9IG47IGorKykKICAgICAgICB7CiAgICAgICAgICAgICAgICBmb3IgKGkgPSAwOyBpICsgcG93ZXJbal0gLSAxIDwgbjsgaSsrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIE0xW2ldW2pdID0gKEFbTTFbaV1baiAtIDFdXSA+IEFbTTFbaSArIHBvd2VyW2otMV1dW2ogLSAxXV0pID8gTTFbaV1baiAtIDFdIDogTTFbaSArIHBvd2VyW2otMV1dW2ogLSAxXTsKICAgICAgICAgICAgICAgIH0KICAgICAgICB9Cn0KIAppbnQgbWFpbigpCnsKICAgIGRvdWJsZSBBbnMsRmFzdFRpbWU7CiAgICBpbnQgaSxOLFEsTCxSLE1pbjEsTWF4MSxNYXgyLE1heDMsTWF4NDsKICAgIAogICAgcG93ZXJbMF0gPSAxOwogICAgZm9yKGk9MTsgaTw9MjA7IGkrKykgcG93ZXJbaV0gPSAyKnBvd2VyW2ktMV07CiAgICAKICAgIHNjYW5mKCIlZCIsJk4pOwogICAgZm9yKGk9MDsgaTxOOyBpKyspIHNjYW5mKCIlZCIsJkFbaV0pOwogCiAgICBSTVFfTUlOKE4pOwogICAgUk1RX01BWChOKTsKICAgIAogICAgc2NhbmYoIiVkIiwmUSk7CiAgICB3aGlsZShRLS0pCiAgICB7CiAgICAgICAgc2NhbmYoIiVkJWQiLCZMLCZSKTsKICAgICAgICBNaW4xID0gTWluVGltZShMLFIpOwogICAgICAgIC8vcHJpbnRmKCIlZCAiLE1pbjEpOwogICAgICAgIE1heDEgPSBNYXhUaW1lKEwsUik7CiAgICAgICAgLy9wcmludGYoIiVkICIsTWF4MSk7CiAgICAgICAgRmFzdFRpbWUgPSAoTWF4MS1NaW4xKS8yLjA7CiAgICAgICAgLy9wcmludGYoIiVkICIsRmFzdFRpbWUpOwogICAgICAgIE1heDIgPSAoTCA+IDApID8gTWF4VGltZSAoMCxMLTEpIDogMDsKICAgICAgICBNYXgzID0gKFIgPCBOLTEpID8gTWF4VGltZShSKzEsIE4tMSkgOiAwOwogICAgICAgIE1heDQgPSBtYXgoTWF4MiArIDAuMCwgTWF4MyArIDAuMCk7CiAgICAgICAgQW5zICA9IE1pbjEgKyBtYXgoIEZhc3RUaW1lICwgIE1heDQgKyAwLjAgKTsKICAgICAgICBwcmludGYoIiUuMWxmXG4iLEFucyk7CiAgICB9CiAgcmV0dXJuIDA7Cn0=