if flag is not reset inbetween .
if ( flag == 0 ) { Console . Write ( " YES STRNEWLINE " ) ; arr [ qi [ k ] ] = qj [ k ] ; arr [ qj [ k ] ] = qi [ k ] ; } else Console . Write ( " NO STRNEWLINE " ) ; } }