#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 struct SparseTable{ using F = function; vector > dat; vector ht; const F f; SparseTable(){} SparseTable(int n,F f):f(f){init(n);} void init(int n){ int h=1; while((1<(n)); ht.assign(n+1,0); for(int j=2;j<=n;j++) ht[j]=ht[j>>1]+1; } void build(int n,vector &v){ int h=1; while((1<>n>>m; vector > r(m,vector(n)); for(int i=0;i>r[j][i]; auto f=[](int a,int b){return max(a,b);}; vector > ss; for(int j=0;j dp(n+1,0); for(int i=0;ir[j][i]) continue; int L=i,R=n; while(L+1>1; if(ss[j].query(0,M+1)>r[j][i]) R=M; else L=M; } chmax(s,R); } //cout<