O,R=print,range I=lambda:int(input()) N=I() n=R(N) Q=[0]*N u=set(i+1for i in n) def S(Q,k): v=set(u) for i in n: Q[i],k=sorted(v)[k//F[N-i-1]],k%F[N-i-1] v.remove(Q[i]) F=[1] for i in n:F+=[F[-1]*(i+1)] l,r=0,F[N] while l