#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void induce(Int l,Int r,Int a,Int b,vector &dp,F dist){ if(l==r) return; Int m=(l+r)>>1; Int &idx=(dp[m]=a); T res=dist(idx,m); for(Int i=a;i(l,m,a,idx+1,dp,dist); induce(m+1,r,idx,b,dp,dist); } template vector args(Int n,F dist){ vector dp(n,-1); induce(0,n,0,n,dp,dist); return dp; } } template struct SegmentTree{ using H = function; Int n,height; H h; E ei; vector laz; SegmentTree(H h,E ei):h(h),ei(ei){} void init(Int n_){ n=1;height=0; while(n>i); } void update(Int a,Int b,E x){ thrust(a+=n); thrust(b+=n-1); for(Int l=a,r=b+1;l>=1,r>>=1){ if(l&1) laz[l]=h(laz[l],x),l++; if(r&1) --r,laz[r]=h(laz[r],x); } } E get_val(Int a){ thrust(a+=n); return laz[a]; } void set_val(Int a,E x){ thrust(a+=n); laz[a]=x; } }; struct FastIO{ FastIO(){ cin.tie(0); ios::sync_with_stdio(0); } }fastio_beet; //INSERT ABOVE HERE signed main(){ Int n; cin>>n; vector as(n); for(Int i=0;i>as[i]; const Int INF = 1e18; auto g=[&](Int a,Int b){return min(a,b);}; SegmentTree seg(g,INF); seg.init(n); for(Int uku=0;uku<2;uku++){ vector sm(n+1,0); for(Int i=0;iInt{ if(i(n,dist); auto latte=[&](Int k){return uku?n-k:k;}; for(Int i=0;i sm(n+1,0); for(Int i=0;iInt{ if(i