#include using namespace std; typedef vector V; #define TABLE_SIZE 1000*20 typedef int TABLE_TYPE; TABLE_TYPE ___a[2][TABLE_SIZE]; template class max_sparse_table{ private: T *Ltable,*Rtable;int _size; void build(){ for(long long k = _size,b=1 ;b*2<=_size; k+=_size,b<<=1){ for(int i = 0; i < _size; i++){ if(i+b*2<=_size)Rtable[k+i]=max(Rtable[k-_size+i],Rtable[k-_size+i+b]); if(i+b*2>=-1)Ltable[k+i]=max(Ltable[k-_size+i],Ltable[k-_size+i-b]); } } } public:/*methods*/ int size(){return _size;} max_sparse_table(vector &v){_size=v.size();Ltable=___a[0],Rtable=___a[1];for(int i = 0; i < _size; i++)Ltable[i]=Rtable[i]=v[i];build();} max_sparse_table(T* v,int n){_size=n;Ltable=___a[0],Rtable=___a[1];for(int i = 0; i < _size; i++)Ltable[i]=Rtable[i]=v[i];build();} T get(int l,int r){int k=(31-__builtin_clz(r-l+1))*_size;return max(Ltable[k+l],Rtable[k+r]);} }; TABLE_TYPE ___b[2][TABLE_SIZE]; template class min_sparse_table{ private: T *Ltable,*Rtable;int _size; void build(){ for(long long k = _size,b=1 ;b*2<=_size; k+=_size,b<<=1){ for(int i = 0; i < _size; i++){ if(i+b*2<=_size)Rtable[k+i]=min(Rtable[k-_size+i],Rtable[k-_size+i+b]); if(i+b*2>=-1)Ltable[k+i]=min(Ltable[k-_size+i],Ltable[k-_size+i-b]); } } } public:/*methods*/ int size(){return _size;} T get(int l,int r){int k=(31-__builtin_clz(r-l+1))*_size;return min(Ltable[k+l],Rtable[k+r]);} min_sparse_table(vector &v){_size=v.size();Ltable=___b[0],Rtable=___b[1];for(int i = 0; i < _size; i++)Ltable[i]=Rtable[i]=v[i];build();} min_sparse_table(T* v,int n){_size=n;Ltable=___b[0],Rtable=___b[1];for(int i = 0; i < _size; i++)Ltable[i]=Rtable[i]=v[i];build();} }; int solve(V& v){ int n=v.size(); int res=0; max_sparse_table s(v); min_sparse_table t(v); for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ int top=0; if(i>0){ if(v[i]>v[j]){int g=t.get(0,i-1);if(gv[i])top=max(top,max(g,v[j]));} } if(j-i>1){ {int g=s.get(i+1,j-1);if(g>max(v[i],v[j]))top=max(g,top);} {int g=t.get(i+1,j-1);if(gv[j])top=max(top,max(g,v[i]));} } // cout<>N>>M; int id=0; int top=0; V v(N); for(int i = 0; i < M; i++){ for(auto& it : v)cin>>it; int t=solve(v); if(t>top){ top=t; id=i; } } cout<