Similarly , fill row matrix
for ( int i = 0 ; i < n ; i ++ ) { bool isEndless = true ; for ( int j = n - 1 ; j >= 0 ; j -- ) { if ( input [ i , j ] == false ) isEndless = false ; row [ i , j ] = isEndless ; } }