Printing lexographically smallest configuration
while ( ri < k && row [ ri ] == 1 ) { ri ++ ; } while ( ci < k && col [ ci ] == 1 ) { ci ++ ; } document . write ( ( ri + 1 ) + " " + ( ci + 1 ) + " " ) ; ri ++ ; ci ++ ; } }