#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 using P = pair; P op(P a,P b){ pair r; r.first = max({a.first,b.first}); r.second = r.first; if(a.first==r.second){ r.second = max(a.second,b.first); } else{ r.second = max(a.first,b.second); } return r; } P e(){ return make_pair(0,0); } int main(){ int n; cin>>n; vector pos(n+2,0); fenwick_tree F(n); set S; rep(i,n){ int pp; cin>>pp; //cin>>PP[i].first; S.insert(i+1); //PP[i].second = 0; pos[pp] = i; //F.add(i,1); } S.insert(n+1); vector a,b; rep(i,n){ auto it= S.begin(); int r0 = *it; it++; int r1 = *it; int p0 = pos[r0]; int p1= pos[r1]; if(p0>p1){ swap(p0,p1); swap(r0,r1); } int v0 = F.sum(0,p0); int v1 = F.sum(0,p1); //cout<