#include #include #include #include using namespace std; queue > q; map visited; int N,A[11]; int get(){ int ret=0,x=1,pos[11],st=0; while(A[st]!=1) st++; st=(st+1)%N; while(A[st]!=1) pos[A[st]]=x++,st=(st+1)%N; for(int j=2;j<=N;j++) ret=ret*10+pos[j]; return ret; } void construct(int seq){ int st=N; while(seq){ A[(seq%10)]=st; st--; seq/=10; } A[0]=1; } bool isFinal(int seq){ int st=N-1; while(seq){ if(seq%10!=st) return false; seq/=10; st--; } return true; } int main(){ scanf("%d",&N); for(int i=0;i next=q.front(); q.pop(); if(isFinal(next.first)){ ans=next.second; break; } construct(next.first); for(int i=0;i