Total ways of choosing X men and Y women from a total of M men and W women | Function to return the value of ncr effectively ; Initialize the answer ; Divide simultaneously by i to avoid overflow ; Function to return the count of required ways ;
def ncr ( n , r ) : NEW_LINE INDENT ans = 1 NEW_LINE for i in range ( 1 , r + 1 ) : NEW_LINE INDENT ans *= ( n - r + i ) NEW_LINE ans //= i NEW_LINE DEDENT return ans NEW_LINE DEDENT def totalWays ( X , Y , M , W ) : NEW_LINE INDENT return ( ncr ( M , X ) * ncr ( W , Y ) ) NEW_LINE DEDENT / * Driver code * / NEW_LINE X = 4 NEW_LINE Y = 3 NEW_LINE M = 6 NEW_LINE W = 5 NEW_LINE print ( totalWays ( X , Y , M , W ) ) NEW_LINE