#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int i = 0; i < n; i++ ){ cout << x[i] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second
     
using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

struct ConvexHullTrick{
  vi st;
  vl a, b;
  int s, t, it;
  void init( int n ){
    st = vi( n );
    a.clear(); b.clear();
    s = t = 0;
  }
  bool check( int i , int j , int k ){
    return ( a[i] - a[k] ) * ( b[j] - b[i] ) <= ( a[i] - a[j] ) * ( b[k] - b[i] );
  }
  void add( ll ca , ll cb ){
    a.pb( ca ); b.pb( cb );
    while( s <= t-2 && check( st[t-2] , st[t-1] , SZ(a)-1 ) ) t--;
    st[t++] = SZ(a)-1;
  }
  ll f( int i , ll x ){
    return a[i] * x + b[i];
  }
  ll query( ll x ){
    while( s <= t-2 && f(st[t-1],x) <= f(st[t-2],x) ) t--;
    return f(st[t-1],x);
  }
};

ConvexHullTrick cft;

vl t[2];
vl d[2];
vl sum[2];

vl yuyu( int q , int l , int r , int p = INF ){
  int n = r-l;
  vl dp( n+1 , 0 );
  cft.init( n+1 );
  cft.add( -l , d[q][l] + sum[q][l] + l * ( l - 1 ) / 2 );
  dp[0] = d[q][l];
  FOR( i , l , r ){
    dp[i+1-l] = cft.query( i+1 ) + ( i + 1 ) * ( i + 2 ) / 2 - sum[q][i+1];
    if( i+1 <= p ){
      if( p == INF ){
	chmax( dp[i+1-l] , dp[i-l] );
      } else {
	dp[i+1-l] = d[q][i+1];
      }
      cft.add( -(i+1) , dp[i+1-l] + sum[q][i+1] + i * ( i + 1 ) / 2 );
    }
  }
  return dp;
}

int n, q;

ll u[300010], nu[300010];

void rec( int l , int r ){
  if( l == r ){
    return;
  }
  int m = ( l + r ) / 2;
  vl f = yuyu( 0 , l , r , m );
  vl dp( r-l , -INFLL );
  for( int i = r-1; i >= m; i-- ){
    dp[i-l] = f[i+1-l] + d[1][n-1-i];
    if( i < r-1 ){
      chmax( dp[i-l] , dp[i-l+1] );
    }
    chmax( u[i] , dp[i-l] );
  }
  vl b = yuyu( 1 , n-r , n-l , n-1-m );
  dp = vl( r-l , -INFLL );
  FOR( i , l , m+1 ){
    dp[i-l] = d[0][i] + b[r-i];
    if( i > l ){
      chmax( dp[i-l] , dp[i-l-1] );
    }
    chmax( u[i] , dp[i-l] );
  }
  rec( l , m );
  rec( m+1 , r );
}

int main(){

  n = in();
  REP( i , n ){
    t[0].pb( in() );
  }
  t[1] = t[0];
  REVERSE( t[1] );

  d[0] = d[1] = sum[0] = sum[1] = vl( n+1 , 0 );
  REP( i , n ){
    REP( j , 2 ){
      sum[j][i+1] = sum[j][i] + t[j][i];
    }
  }

  d[1] = yuyu( 1 , 0 , n );
  d[0] = yuyu( 0 , 0 , n );

  assert( d[0][n] == d[1][n] );
  
  REP( i , n ){
    nu[i] = d[0][i] + d[1][n-1-i];
  }

  REP( i , n ){
    u[i] = -INFLL;
  }
  
  rec( 0 , n );
  
  q = in();
  REP( qc , q ){
    ll p = in() - 1;
    ll x = in();
    ll ans = max( nu[p] , u[p] + t[0][p] - x );
    printf( "%lld\n" , ans );
  }
  
  return 0;
}


Measured memory_bytes: 38084