#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; int T[101010]; vector A[101010]; int K[101010]; int ok(int v) { vector P,Q; int i; Q.push_back(-1); FOR(i,N) { int X=0,Y=0; FORR(a,A[i]) { if(a R; R.insert(1<<30); FOR(i,Q.size()-1) R.insert(K[N-1-i]); sort(ALL(P)); sort(ALL(Q)); if(P.empty()||Q.back()>=*R.begin()) return 1; for(i=P.size()-1;i>=0;i--) { if(P[i]>=min(*R.begin(),K[i])) return 1; if(P[i]<=min(*R.begin(),K[i])-2) return 0; if(P[i]==*R.begin()-1&&Q.back()>=K[i]) return 1; if(P[i]<=*R.begin()-2) continue; R.erase(R.begin()); R.insert(K[i]); } return 0; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) cin>>K[i]; FOR(i,N) { cin>>T[i]; A[i].resize(T[i]); FORR(t,A[i]) cin>>t; } int ma=0; for(i=29;i>=0;i--) if(ok(ma+(1<