Function to create the possible grids
def createGrid ( grid , is1 , N , M ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT if ( is1 ) : NEW_LINE INDENT grid [ i ] [ j ] = '0' NEW_LINE is1 = False NEW_LINE DEDENT else : NEW_LINE INDENT grid [ i ] [ j ] = '1' NEW_LINE is1 = True NEW_LINE DEDENT DEDENT if ( M % 2 == 0 ) : NEW_LINE INDENT is1 = True if is1 == False else False NEW_LINE DEDENT DEDENT DEDENT