eval'N,*A='+$<.read.split*?, (1..2*N-4).map{|i|(0..i).map{|j|a,b=[j,i-j].sort;b>N-1&&break;A[a]>(c=A[b])&&(A[b]=A[a];A[a]=c)}} $><