#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int _n=(n),i=0; i<_n; ++i) #define FOR(i,a,b) for(int _b=(b),i=(a); i<=_b; ++i) #define FORD(i,a,b) for(int _b=(b),i=(a); i>=_b; --i) #define FORE(i,a) for(VAR(i,a.begin()); i!=a.end(); ++i) #define PB push_back #define BEG begin() #define END end() #define SZ size() #define MP make_pair #define F first #define S second #define D double #define LL long long #define LD long double #define VI vector vector > > cycles; vector input; vector output; int n; LL K; LL gcd(LL a,LL b){ if (a vis; vector v; vis=vector(n,0); REP(i,n) if (!vis[i]){ int p=i,s=0; v.clear(); while(!vis[p]){ v.PB(p); vis[p]=1; s++; p=input[p]; } cycles[s].PB(v); } } inline void do_reconstruction(int t, int q, int r){ LL T=t*r; assert(t==(T/gcd(T,K))); assert(K%r==0); LL Kp=(K/r)%t; assert(gcd(Kp,t)==1); LL a=RevMod(Kp,t); REP(i,r) REP(j,t) { assert(output[cycles[t][q+i][j]]==-1); if (i > >(n+1,vector >()); REP(i,n){ int a; scanf("%d",&a); a--; input.PB(a); } create_cycles(); /* printf("%d %lld\n",n,K); FOR(t,1,n){ printf("%d: ",t); REP(j,cycles[t].size()){ printf("("); REP(i,cycles[t][j].size()) printf(" %d",cycles[t][j][i]); printf(" ) "); } printf("\n"); } printf("TUTAJ\n");*/ output=vector(n,-1); // printf("TUTAJ\n"); // fflush(stdout); FOR(t,1,n){ if (reconstruct_cycles(t)) goto hell; } // sanity_check(); REP(i,n){ if (i) printf(" "); printf("%d",output[i]+1); } printf("\n"); return 0; hell: printf("Impossible\n"); return 0; }