#include using namespace std; random_device rnd; mt19937 mt(rnd()); int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; { if(N == 2){ cout << 1 << endl; cout << "1 2 1" << endl; cout << "1 1" << endl; return 0; } if(N == 3){ cout << 3 << endl; cout << "1 2 1" << endl; cout << "1 3 4" << endl; cout << "2 3 9" << endl; cout << "1 1" << endl; cout << "1 2" << endl; cout << "1 3" << endl; return 0; } if(N == 4){ cout << 5 << endl; cout << "1 2 1" << endl; cout << "2 3 3" << endl; cout << "3 4 5" << endl; cout << "2 3 4" << endl; cout << "3 4 9" << endl; cout << "1 1" << endl; cout << "2 1 2" << endl; cout << "3 1 2 3" << endl; cout << "1 4" << endl; cout << "2 4 3" << endl; cout << "1 5" << endl; return 0; } if(N == 5){ cout << 7 << endl; cout << "1 2 1" << endl; cout << "2 3 3" << endl; cout << "3 4 5" << endl; cout << "4 5 7" << endl; cout << "2 3 4" << endl; cout << "3 4 9" << endl; cout << "4 5 16" << endl; cout << "1 1" << endl; cout << "2 1 2" << endl; cout << "3 1 2 3" << endl; cout << "4 1 2 3 4" << endl; cout << "1 5" << endl; cout << "2 5 3" << endl; cout << "3 5 3 4" << endl; cout << "1 6" << endl; cout << "2 6 4" << endl; cout << "3 7" << endl; return 0; } } vector Sq(40000); for(int i=1; i<200; i++) Sq.at(i*i) = true; if(N <= 8){ while(true){ vector A(N),B(N); vector already(201); for(int p=0; p B.at(i)) swap(A.at(i),B.at(i)); bool ok = true; vector>> S(N,vector>(N)); for(int i=0; i Bs(200,-1); Bs.at(0) = 0; int sum = 0; for(int p=i; p!=k; p++){ sum += A.at(p); if(A.at(p) == B.at(p)) continue; int d = B.at(p)-A.at(p); for(int v=199; v>=d; v--) if(Bs.at(v-d) != -1) Bs.at(v) = Bs.at(v-d)+(1<=d; v--) if(Bs.at(v-d) != -1) Bs.at(v) = Bs.at(v-d)+(1< P; if(inc){ for(int p=i; p!=k; p++){ if(s&(1< A(N),B(N); vector already(201); for(int p=0; p B.at(i)) swap(A.at(i),B.at(i)); bool ok = true; vector>> S(N,vector>(N)); for(int i=0; i Bs(200,-1); Bs.at(0) = 0; int sum = 0; for(int p=i; p!=k; p++){ sum += A.at(p); if(A.at(p) == B.at(p)) continue; int d = B.at(p)-A.at(p); for(int v=199; v>=d; v--) if(Bs.at(v-d) != -1) Bs.at(v) = Bs.at(v-d)+(1<=d; v--) if(Bs.at(v-d) != -1) Bs.at(v) = Bs.at(v-d)+(1< P; if(inc){ for(int p=i; p!=k; p++){ if(s&(1< A(N),B(N); vector already(201); for(int i=0; i<6; i++){ for(int v=1; ; v++) if(!already.at(v) && !already.at(v+(1< B.at(i)) swap(A.at(i),B.at(i)); bool ok = true; vector>> S(N,vector>(N)); int time = 0; vector T(N,-1); for(int i=0; i Bs(200,-1); Bs.at(0) = 0; int sum = 0; for(int p=i; p!=k; p++){ sum += A.at(p); if(A.at(p) == B.at(p)) continue; int d = B.at(p)-A.at(p); for(int v=199; v>=d; v--) if(Bs.at(v-d) != -1 && Bs.at(v) == -1) Bs.at(v) = p; } bool end = true; for(int v=0; v<200; v++) if(Bs.at(v) != -1 && Sq.at(sum+v)){ end = false; while(v){ int p = Bs.at(v); T.at(p) = time; v -= B.at(p)-A.at(p); } vector now; for(int p=i; p!=k; p++){ if(T.at(p) == time) now.push_back(N+p); else now.push_back(p); } S.at(i).at(k) = now; break; } if(!end) continue; Bs.assign(200,-1); sum = 0,Bs.at(0) = 0; for(int p=(i-1+N)%N; ; p=(p-1+N)%N){ sum += A.at(p); if(A.at(p) != B.at(p)){ int d = B.at(p)-A.at(p); for(int v=199; v>=d; v--) if(Bs.at(v-d) != -1 && Bs.at(v) == -1) Bs.at(v) = p; } if(p == k) break; } for(int v=0; v<200; v++) if(Bs.at(v) != -1 && Sq.at(sum+v)){ end = false; while(v){ int p = Bs.at(v); T.at(p) = time; v -= B.at(p)-A.at(p); } vector now; for(int p=(i-1+N)%N; ; p=(p-1+N)%N){ if(T.at(p) == time) now.push_back(N+p); else now.push_back(p); if(p == k) break; } S.at(i).at(k) = now; break; } if(end){ok = false; break;} } } if(!ok) continue; cout << 2*N-3 << "\n"; for(int i=0; i