/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.3.2"
    lflags "-stack_size" "100000000"
+/

import std.stdio, std.conv, std.algorithm, std.range;
import std.math;
import std.container.util : make;
import std.container.rbtree;

// import dcomp.scanner;
// import dcomp.container.deque;

struct CHT(T) {
    //max only
    //y = ax + b, this a is increase
    //query x, this x is decrease
    alias L = T[2]; //[a, b]
    Deque!L data;
    bool isNeed(L x, L l, L r) {
        assert(l[0] <= x[0] && x[0] <= r[0], "a must be increase");
        return (r[0]-x[0])*(l[1]-x[1]) <= (x[0]-l[0])*(x[1]-r[1]);
    }
    void insertBack(L x) {
        while (data.length >= 2) {
            if (isNeed(data[$-1], data[$-2], x)) break;
            data.removeBack;
        }
        data.insertBack(x);
    }
    T value(L l, T x) { return l[0]*x + l[1]; }
    T backX = T.max;
    long get(T x) {
        assert(x <= backX, "query must be decrease");
        assert(data.length);
        while (data.length >= 2) {
            if (value(data[$-2], x) < value(data[$-1], x)) break;
            data.removeBack;
        }
        backX = x;
        return value(data.back, x);
    }
}

int main(string[] argv) {
    auto sc = new Scanner();
    long n;
    sc.read(n); n += 2;
    long[] t = new long[n];
    foreach (i; 1..n-1) {
        sc.read(t[i]);
    }
    t[] *= 2;
    long[] tsm = new long[n+1];
    foreach (i; 0..n) {
        tsm[i+1] = tsm[i] + t[i];
    }

    long[] ldp = new long[n], rdp = new long[n];
    {
        auto cht = CHT!long();
        cht.insertBack([0, 0+tsm[1]+0*(0+1)]);
        foreach (long i; 1..n) {
            auto v = cht.get(-2L*i);
            ldp[i] = v-tsm[i]+i*(i-1);
            cht.insertBack([i, ldp[i]+tsm[i+1]+i*(i+1)]);
        }
    }
    {
        auto cht = CHT!long();
        cht.insertBack([-(n-1), 0-tsm[n-1]+(n-1)*(n-2)]);
        foreach_reverse (long i; 0..n-1) {
            auto v = cht.get(2L*i);
            rdp[i] = v+tsm[i+1]+i*(i+1);
            cht.insertBack([-i, rdp[i]-tsm[i]+i*(i-1)]);
        }
    }    

    long mx = ldp[n-1];

    long[] ans = new long[](n);
    long[] buf = new long[](n);
    ans[] = -(10L^^18);
    void dfs(long l, long r) {
        if (r-l == 2) {
            ans[l+1] = max(ans[l+1], ldp[l]+rdp[r]+2-t[l+1]);
            return;
        }
        long md = (l+r)/2;
        //[l, md], [md+1, r]
        {
            auto cht = CHT!long();
            foreach (long i; l..md) {
                cht.insertBack([i, ldp[i]+tsm[i+1]+i*(i+1)]);                
            }
            foreach (long i; md+2..r+1) {
                auto v = cht.get(-2L*i);
                buf[i-1] = v-tsm[i]+i*(i-1) + rdp[i];
            }
            long ma = -(10L^^18);
            foreach_reverse (long i; md+1..r) {
                ma = max(ma, buf[i]);
                ans[i] = max(ans[i], ma);
            }
        }
        {
            auto cht = CHT!long();
            foreach_reverse (long i; md+2..r+1) {
                cht.insertBack([-i, rdp[i]-tsm[i]+i*(i-1)]);
            }            
            foreach_reverse (long i; l..md) {
                auto v = cht.get(2L*i);
                buf[i+1] = v+tsm[i+1]+i*(i+1) + ldp[i];
            }
            long ma = -(10L^^18);
            foreach (long i; l+1..md+1) {
                ma = max(ma, buf[i]);
                ans[i] = max(ans[i], ma);
            }            
        }
        dfs(l, md+1);
        dfs(md, r);
    }
    dfs(0, n-1);

    int q;
    sc.read(q);
    foreach (i; 0..q) {
        long p, m;
        sc.read(p, m); m *= 2;
        long res = ldp[p]+rdp[p];
        res = max(res, ans[p]+t[p]-m);
        writeln(res/2);
    }
    return 0;
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/container/deque.d */
// module dcomp.container.deque;

struct Deque(T) {
    import std.traits : isImplicitlyConvertible;
    import std.range : ElementType, isInputRange;
    import core.exception : RangeError;

    struct Payload {
        T[] d;
        size_t st, length;
        @property bool empty() const { return length == 0; }
        alias opDollar = length;
        ref inout(T) opIndex(size_t i) inout {
            version(assert) if (length <= i) throw new RangeError();
            return d[(st+i >= d.length) ? (st+i-d.length) : st+i];
        }
        private void expand() {
            import std.algorithm : max;
            assert(length == d.length);
            T[] nd = new T[](max(4L, 2*d.length));
            foreach (i; 0..d.length) {
                nd[i] = this[i];
            }
            d = nd; st = 0;
        }
        void insertFront(T v) {
            if (length == d.length) expand();
            if (st == 0) st += d.length;
            st--; length++;
            this[0] = v; 
        }
        void insertBack(T v) {
            if (length == d.length) expand();
            length++;
            this[length-1] = v; 
        }
        void removeFront() {
            assert(!empty, "Deque.removeFront: Deque is empty");        
            st++; length--;
            if (st == d.length) st = 0;
        }
        void removeBack() {
            assert(!empty, "Deque.removeBack: Deque is empty");        
            length--;
        }        
    }
    struct RangeT(A) {
        alias T = typeof(*(A.p));
        alias E = typeof(A.p.d[0]);
        T *p;
        size_t a, b;
        @property bool empty() const { return b <= a; }
        @property size_t length() const { return b-a; }
        @property RangeT save() { return RangeT(p, a, b); }
        @property RangeT!(const A) save() const {
            return typeof(return)(p, a, b);
        }
        alias opDollar = length;
        @property ref inout(E) front() inout { return (*p)[a]; }
        @property ref inout(E) back() inout { return (*p)[b-1]; }
        void popFront() {
            version(assert) if (empty) throw new RangeError();
            a++;
        }
        void popBack() {
            version(assert) if (empty) throw new RangeError();
            b--;
        }
        ref inout(E) opIndex(size_t i) inout { return (*p)[i]; }
        RangeT opSlice() { return this.save; }
        RangeT opSlice(size_t i, size_t j) {
            version(assert) if (i > j || a + j > b) throw new RangeError();
            return typeof(return)(p, a+i, a+j);
        }
        RangeT!(const A) opSlice() const { return this.save; }
        RangeT!(const A) opSlice(size_t i, size_t j) const {
            version(assert) if (i > j || a + j > b) throw new RangeError();
            return typeof(return)(p, a+i, a+j);
        }
    }
    
    alias Range = RangeT!Deque;
    alias ConstRange = RangeT!(const Deque);
    alias ImmutableRange = RangeT!(immutable Deque);

    Payload *p;
    private void I() { if(!p) p = new Payload(); }
    private void C() const { assert(p, "this deque is not init"); }
    //some value
    this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {I;
        p = new Payload();
        foreach (v; values) {
            insertBack(v);
        }
    }
    //range
    this(Range)(Range r)
    if (isInputRange!Range &&
    isImplicitlyConvertible!(ElementType!Range, T) &&
    !is(Range == T[])) {I;
        p = new Payload();
        foreach (v; r) {
            insertBack(v);
        }
    }
    
    @property bool empty() const { return (!p || p.empty); }
    @property size_t length() const { return (p ? p.length : 0); }
    alias opDollar = length;
    ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }
    ref inout(T) front() inout {C; return (*p)[0]; }
    ref inout(T) back() inout {C; return (*p)[$-1]; }
    void insertFront(T v) {I; p.insertFront(v); }
    void insertBack(T v) {I; p.insertBack(v); }
    void removeFront() {C; p.removeFront(); }
    void removeBack() {C; p.removeBack(); }
    Range opSlice() {I; return Range(p, 0, length); }
}

unittest {
    import std.algorithm : equal;
    import std.range.primitives : isRandomAccessRange;
    import std.container.util : make;
    auto q = make!(Deque!int);
//    Deque!int q;
    assert(isRandomAccessRange!(typeof(q[])));

    //insert,remove
    assert(equal(q[], new int[](0)));
    q.insertBack(1);
    assert(equal(q[], [1]));
    q.insertBack(2);
    assert(equal(q[], [1, 2]));
    q.insertFront(3);
    assert(equal(q[], [3, 1, 2]) && q.front == 3);
    q.removeFront;
    assert(equal(q[], [1, 2]) && q.length == 2);
    q.insertBack(4);
    assert(equal(q[], [1, 2, 4]) && q.front == 1 && q.back == 4 && q[$-1] == 4);
    q.insertFront(5);
    assert(equal(q[], [5, 1, 2, 4]));

    //range
    assert(equal(q[][1..3], [1, 2]));
    assert(equal(q[][][][], q[]));
    //const range
    const auto rng = q[];
    assert(rng.front == 5 && rng.back == 4);
    
    //reference type
    auto q2 = q;
    q2.insertBack(6);
    q2.insertFront(7);
    assert(equal(q[], q2[]) && q.length == q2.length);

    //construct with make
    auto a = make!(Deque!int)(1, 2, 3);
    auto b = make!(Deque!int)([1, 2, 3]);
    assert(equal(a[], b[]));
}

unittest {
    Deque!int a;
    Deque!int b;
    a.insertFront(2);
    assert(b.length == 0);
}
/* IMPORT /Users/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f = stdin) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}


Measured memory_bytes: 24324