eval"N,*A="+`dd`.split*?,
c,d=[0,N].map{|i|y=A[i+N-1];A[i,N].map{|i|y^y=i}}
d+=m=[k=-1]
f=->l,t{l=m[l]until l<0||d[l]==t;l+1}
d.map{|x|m<<k=f[k,x]}
(2*N-1).times{|i|$.=f[$.,c[i%N]];p i+=1-N,A[N]^A[i]if$.==N}