Print lexographically smallest order
while ( row [ ri ] == 1 ) { ri ++ ; } while ( col [ ci ] == 1 ) { ci ++ ; } System . out . println ( ( ri + 1 ) + " ▁ " + ( ci + 1 ) + " ▁ " ) ; ri ++ ; ci ++ ; } }