Function to fill the grid in a possible way
void fill ( char a [ ] [ 1001 ] , int n , int m , char odd , char even ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( ( i + j ) & 1 ) { a [ i ] [ j ] = odd ; } else { a [ i ] [ j ] = even ; } } } }