#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b>N; vector> S(17,vector(3)); S[0][0]=INF; S[0][1]=INF; S[0][2]=INF; for(int i=0;i>S[i+1][j]; } } for(int bit=0;bit<(1<<17);bit++){ for(int i=0;i<17;i++){ for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ dp[bit][i][j][k]=-INF; dp[1][0][j][k]=0; } } } } for(int bit=0;bit<(1<<17);bit++){ for(int i=0;i<17;i++){ if(!(bit&(1<b) swap(a,b); int d=S[to][toj],e=S[to][tok],f=S[to][3-toj-tok]; if(d>e) swap(d,e); if(a>=d&&b>=e){ chmax(dp[bit|(1<