#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

using CHT_TYPE = ll;
struct CHT { //get min, if you want to get max, flip signs of a and b
	struct Line {
		CHT_TYPE a, b;
		mutable function<const Line*()> getSuc;

		bool operator<(const Line& rhs) const {
			if(rhs.b == IS_QUERY) {
				const Line* suc = getSuc();
				if(suc == nullptr) return false;
				const CHT_TYPE& x = rhs.a;
				return (suc->a - a) * x + suc->b - b > 0;
			}
			if(b == IS_QUERY) {
				const Line* suc = rhs.getSuc();
				if(suc == nullptr) return true;
				const CHT_TYPE& x = a;
				return (suc->a - rhs.a) * x + suc->b - rhs.b < 0;
			}
			return a < rhs.a;
		}
	};

	struct LinesSet: public multiset<Line> {
		inline bool isBad(iterator l) {
			const auto&& nel = next(l);
			if(l == begin()) {
				if(nel == end()) return false;
				return l->a == nel->a && l->b <= nel->b;
			}
			else {
				const auto&& prl = prev(l);
				if(nel == end()) return l->a == prl->a && l->b <= prl->b;
				return (prl->b - l->b) * (nel->a - l->a) 
					>= (nel->b - l->b) * (prl->a - l->a);
			}
		}

		inline void add(CHT_TYPE a, CHT_TYPE b) {
			auto&& it = insert({-a, -b});
			it->getSuc = [=] {
				return (next(it) == end() ? nullptr : &*next(it)); };
			if(isBad(it)) { erase(it); return; }
			while(next(it) != end() && isBad(next(it))) erase(next(it));
			while(it != begin() && isBad(prev(it))) erase(prev(it));
		}

		inline CHT_TYPE get(CHT_TYPE x) {
			auto&& l = *lower_bound(Line{x, IS_QUERY});
			return -l.a * x - l.b;
		}
	};

	static const CHT_TYPE IS_QUERY = numeric_limits<CHT_TYPE>::lowest();
	LinesSet linesSet;

	inline void add(CHT_TYPE a, CHT_TYPE b) { linesSet.add(a, b); }
	inline CHT_TYPE get(CHT_TYPE x) { return linesSet.get(x); }
	inline bool empty() { return linesSet.empty(); }
};

int N, M;
ll T[MAX_N], P[MAX_N], X[MAX_N];
ll ans1[MAX_N], ans2[MAX_N];
ll B[MAX_N], RB[MAX_N];
ll S[MAX_N];

void loop(int l, int r) {
	if(r - l == 1) {
		MAX(ans2[l], B[l] + 1 + RB[r] - T[l]);
		return;
	}
	int m = (l + r) / 2;
	CHT cht;
	rep(i, l, m + 1) {
		cht.add((-1) * (-i), (-1) * (B[i] + (1ll * i * i - i) / 2 + S[i]));
	}
	ll v = -linf;
	rer(i, r + 1, m + 1) {
		ll tv = cht.get(i) * -1;
		MAX(v, tv + (1ll * i * i + i) / 2 - S[i] + RB[i]);
		MAX(ans2[i - 1], v);
	}
	cht = CHT();
	rep(j, m, r + 1) {
		int i = N - j;
		cht.add((-i) * (-1), (-1) * (RB[j] + (1ll * i * i - i) / 2 - S[j]));
	}
	v = -linf;
	rep(j, l, m) {
		int i = N - j;
		ll tv = cht.get(i) * -1;
		MAX(v, tv + (1ll * i * i + i) / 2 + S[j] + B[j]);
		// debug(l, r, i, v, tv);
		MAX(ans2[j], v);
	}
	loop(l, m);
	loop(m, r);
}

void solve() {
	cin >> N;
	rep(i, 0, N) {
		cin >> T[i];
		S[i + 1] = S[i] + T[i];
	}
	cin >> M;
	rep(i, 0, M) {
		cin >> P[i] >> X[i];
		P[i]--;
	}

	CHT cht;
	cht.add(0, 0);
	rep(i, 1, N + 1) {
		ll v = cht.get(i) * -1;
		// debug(i, v);
		MAX(B[i], v + (1ll * i * i + i) / 2 - S[i]);
		MAX(B[i], B[i - 1]);
		cht.add((-i) * -1, -1 * (B[i] + (1ll * i * i - i) / 2 + S[i]));
	}
	cht = CHT();
	cht.add(0, -1 * (-S[N]));
	rer(j, N, 0) {
		int i = N - j;
		ll v = cht.get(i) * -1;
		MAX(RB[j], v + (1ll * i * i + i) / 2 + S[j]);
		MAX(RB[j], RB[j + 1]);
		cht.add((-i) * -1, -1 * (RB[j] + (1ll * i * i - i) / 2 - S[j]));
	}
	// debug(vl(B, B + N + 1));
	// debug(vl(RB, RB + N + 1));
	rep(i, 0, N) {
		ans1[i] = B[i] + RB[i + 1];
		ans2[i] = -linf;
	}
	loop(0, N);
	// debug(vl(ans2, ans2 + N));
	rep(i, 0, M) {
		// debug(P[i], X[i], T[P[i]], ans1[P[i]], ans2[P[i]]);
		cout << max(ans1[P[i]], ans2[P[i]] + T[P[i]] - X[i]) << "\n";
	}
	
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 21376