/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.8.0"
+/
 
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.datastructure.convexhull;
 
int main(string[] argv) {
    auto sc = new Scanner(stdin);
    alias C = ConvexHull!(long, CHQueryType.decr);
    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 = C();
        cht.insertLine([0, 0+tsm[1]+0*(0+1)]);
        foreach (long i; 1..n) {
            auto v = cht.maxY(-2L*i);
            ldp[i] = v-tsm[i]+i*(i-1);
            cht.insertLine([i, ldp[i]+tsm[i+1]+i*(i+1)]);
        }
    }
    {
        auto cht = C();
        cht.insertLine([-(n-1), 0-tsm[n-1]+(n-1)*(n-2)]);
        foreach_reverse (long i; 0..n-1) {
            auto v = cht.maxY(2L*i);
            rdp[i] = v+tsm[i+1]+i*(i+1);
            cht.insertLine([-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 = C();
            foreach (long i; l..md) {
                cht.insertLine([i, ldp[i]+tsm[i+1]+i*(i+1)]);                
            }
            foreach (long i; md+2..r+1) {
                auto v = cht.maxY(-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 = C();
            foreach (long i; md+2..r+1) {
                cht.insertLine([-i, rdp[i]-tsm[i]+i*(i-1)]);
            }            
            foreach_reverse (long i; l..md) {
                auto v = cht.maxY(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 /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

// import dcomp.container.stackpayload;

 
class Scanner {
    import std.stdio : File;
    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) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                 
                 
                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        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);
        }
    }
}


 
 

 
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/deque.d */
// module dcomp.container.deque;

struct DequePayload(T) {
    import core.exception : RangeError;

    private T* _data;
    private uint start, len, cap;

    @property bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        if (start + i < cap) return _data[start + i];
        else return _data[start + i - cap];
    }
    ref inout(T) front() inout { return this[0]; }
    ref inout(T) back() inout { return this[$-1]; }

    void reserve(size_t newCap) {
        import core.memory : GC;
        import std.algorithm : max;
        import std.conv : to;
        if (newCap <= cap) return;
        T* newData = cast(T*)GC.malloc(newCap * T.sizeof);
        foreach (i; 0..length) {
            newData[i] = this[i];
        }
        _data = newData; start = 0; cap = newCap.to!uint;
    }
    void clear() {
        start = len = 0;
    }
    import std.algorithm : max;
    void insertFront(T item) {
        if (len == cap) reserve(max(cap * 2, 4));
        if (start == 0) start += cap;
        start--; len++;
        this[0] = item;
    }
    void insertBack(T item) {
        if (len == cap) reserve(max(cap * 2, 4));
        len++;
        this[len-1] = item;
    }
    void removeFront() {
        assert(!empty, "Deque.removeFront: Deque is empty");
        start++; len--;
        if (start == cap) start = 0;
    }
    void removeBack() {
        assert(!empty, "Deque.removeBack: Deque is empty");        
        len--;
    }
}

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

    alias Payload = DequePayload!T;
    Payload* _p;
    
    static if (!mayNull) @disable this();

     
    this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {
        _p = new Payload();
        foreach (v; values) {
            insertBack(v);
        }
    }
     
    this(Range)(Range r)
    if (isInputRange!Range &&
    isImplicitlyConvertible!(ElementType!Range, T) &&
    !is(Range == T[])) {
        _p = new Payload();
        foreach (v; r) {
            insertBack(v);
        }
    }
    private this(Payload* p) { _p = p; }
    static Deque make() { return Deque(new Payload()); }
    
    private bool havePayload() const { return (!mayNull || _p); }    
    @property bool empty() const { return (!havePayload || _p.empty); }  
    @property size_t length() const { return (havePayload ? _p.length : 0); }  
    alias opDollar = length;  

    ref inout(T) opIndex(size_t i) inout {
        assert(!empty, "Deque.opIndex: Deque is empty");
        return (*_p)[i];
    }  
    ref inout(T) front() inout { return this[0]; }  
    ref inout(T) back() inout { return this[$-1]; }  

    void clear() { if (_p) _p.clear(); }  

     
    void insertFront(T item) {
        if (mayNull && !_p) _p = new Payload();
        _p.insertFront(item);
    }
    void insertBack(T item) {
        if (mayNull && !_p) _p = new Payload();
        _p.insertBack(item);
    }  
    alias opOpAssign(string op : "~") = insertBack;  
    alias stableInsertBack = insertBack;  

     
    void removeFront() {
        assert(!mayNull || _p, "Deque.removeFront: Deque is empty");
        _p.removeFront();
    }
    void removeBack() {
        assert(!mayNull || _p, "Deque.removeBack: Deque is empty");
        _p.removeBack();
    }  
    alias stableRemoveBack = removeBack;  

     
    alias Range = RangeT!(DequePayload!T);
    alias ConstRange = RangeT!(const DequePayload!T);  
    alias ImmutableRange = RangeT!(immutable DequePayload!T);  

    size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {
        assert(start <= end && end <= length);
        return [start, end];
    }  
    Range opIndex(size_t[2] rng) { return Range(_p, rng[0], rng[1]); }  
    ConstRange opIndex(size_t[2] rng) const { return ConstRange(_p, rng[0], rng[1]); }  
    ImmutableRange opIndex(size_t[2] rng) immutable { return ImmutableRange(_p, rng[0], rng[1]); }  
    auto opIndex() inout { return this[0..$]; }  

    static struct RangeT(QualifiedPayload) {
        alias A = QualifiedPayload;
        import std.traits : CopyTypeQualifiers;
        alias E = CopyTypeQualifiers!(A, T);
        A *p;
        size_t l, r;

        @property bool empty() const { return r <= l; }
        @property size_t length() const { return r - l; }
        alias opDollar = length;

        @property auto save() { return this; }
        
        ref inout(E) opIndex(size_t i) inout {
            version(assert) if (empty) throw new RangeError();
            return (*p)[l+i];
        }
        @property ref inout(E) front() inout { return this[0]; }
        @property ref inout(E) back() inout { return this[$-1]; }

        void popFront() {
            version(assert) if (empty) throw new RangeError();
            l++;
        }
        void popBack() {
            version(assert) if (empty) throw new RangeError();
            r--;
        }
        
        size_t[2] opSlice(size_t dim : 0)(size_t start, size_t end) const {
            assert(start <= end && end <= length);
            return [start, end];
        }
        auto opIndex(size_t[2] rng) { return RangeT(p, l+rng[0], l+rng[1]); }
        auto opIndex(size_t[2] rng) const { return RangeT!(const A)(p, l+rng[0], l+rng[1]); }
        auto opIndex(size_t[2] rng) immutable { return RangeT!(immutable A)(p, l+rng[0], l+rng[1]); }
        auto opIndex() inout { return this[0..$]; }
    } 
}

 
 

 

 

 

 

 

 
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/datastructure/convexhull.d */
// module dcomp.datastructure.convexhull;

// import dcomp.container.deque;


 
enum CHQueryType {
    incr,  
    decr,  
}

 
struct ConvexHull(T, CHQueryType queryType) {
    import std.algorithm : max;
    alias L = T[2];  
    private static T value(L l, T x) { return l[0]*x + l[1]; }
    
    Deque!L lines;
     
    private static bool isNeed(L mid, L left, L right) {
        assert(left[0] <= mid[0] && mid[0] <= right[0]);
        return (right[0]-mid[0])*(left[1]-mid[1]) < (mid[0]-left[0])*(mid[1]-right[1]);
    }
    private void insertFront(L l) {
        if (lines.empty) {
            lines.insertFront(l);
            return;
        }
        assert(l[0] <= lines[0][0]);
        if (l[0] == lines[0][0]) {
            if (l[1] <= lines[0][1]) return;
            lines.removeFront;
        }
        while (lines.length >= 2 && !isNeed(lines.front, l, lines[1])) {
            lines.removeFront;
        }
        lines.insertFront(l);
    }
    private void insertBack(L l) {
        if (lines.empty) {
            lines.insertBack(l);
            return;
        }
        assert(lines[$-1][0] <= l[0]);
        if (lines[$-1][0] == l[0]) {
            if (l[1] <= lines[$-1][1]) return;
            lines.removeBack;
        }
        while (lines.length >= 2 && !isNeed(lines.back, lines[$-2], l)) {
            lines.removeBack;
        }
        lines.insertBack(l);
    }
     
    void insertLine(L line) {
        if (lines.empty) {
            lines.insertBack(line);
            return;
        }
        if (line[0] <= lines[0][0]) insertFront(line);
        else if (lines[$-1][0] <= line[0]) insertBack(line);
        else {
            assert(false, "line's degree must be minimum or maximum");
        }
    }
     
    long maxY(T x) {
        assert(lines.length);
        static if (queryType == CHQueryType.incr) {
            while (lines.length >= 2 &&
                value(lines[0], x) <= value(lines[1], x)) {
                lines.removeFront;
            }
            return value(lines.front, x);
        } else {
            while (lines.length >= 2 &&
                value(lines[$-2], x) >= value(lines[$-1], x)) {
                lines.removeBack;
            }
            return value(lines.back, x);
        }
    }
}

 
 

 
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/stackpayload.d */
// module dcomp.container.stackpayload;

 
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

    @property bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

     
    inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
    
    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }  
    ref inout(T) front() inout { return this[0]; }  
    ref inout(T) back() inout { return this[$-1]; }  

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }  
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }  
     
    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }  
    alias opOpAssign(string op : "~") = insertBack;  
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }  
}

 

/*
This source code generated by dcomp and include dcomp's source code.
dcomp's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dcomp)
dcomp's License: MIT License(https://github.com/yosupo06/dcomp/blob/master/LICENSE.txt)
*/


Measured memory_bytes: 22084