#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>>K; vector A(K); for(int i=0;i>A[i]; A[i]--; } vector cnt(6,-INF); for(int i=K-1;i>=0;i--){ for(int x=0;x<6;x++){ int y=(x+6-(A[i]%6))%6; if(cnt[x]>=A[i]+y){ if(y==1){ chmax(cnt[A[i]%6],A[i]); chmax(cnt[(A[i]+y)%6],A[i]+y); chmax(cnt[(A[i]+3)%6],A[i]-3); chmax(cnt[(A[i]+4)%6],A[i]-8); } if(y==3){ chmax(cnt[A[i]%6],A[i]); chmax(cnt[(A[i]+y)%6],A[i]+y); chmax(cnt[(A[i]+4)%6],A[i]-2); chmax(cnt[(A[i]+1)%6],A[i]-5); } if(y==5){ chmax(cnt[A[i]%6],A[i]); chmax(cnt[(A[i]+y)%6],A[i]+y); chmax(cnt[(A[i]+2)%6],A[i]-4); chmax(cnt[(A[i]+3)%6],A[i]-9); } } } for(int j=i+1;j