Given the number of men (M) and women (W) available, your task is to calculate the total number of unique ways a valid 3-member committee can be formed.
A committee is considered invalid if it consists of all men or all women.
The first and only line of input contains two space-separated integers, M (number of men) and W (number of women).
Print a single integer representing the total number of valid, diverse committees that can be formed.
The number of combinations can be large, so be sure to use a 64-bit integer type (like long in Java or long long in C++) for your calculations.
3 3
18
There are 3 men and 3 women.
Ways to choose 1 man and 2 women: C(3,1) * C(3,2) = 3 * 3 = 9.
Ways to choose 2 men and 1 woman: C(3,2) * C(3,1) = 3 * 3 = 9.
Total valid committees = 9 + 9 = 18.
2 4
16
There are 2 men and 4 women.
Ways to choose 1 man and 2 women: C(2,1) * C(4,2) = 2 * 6 = 12.
Ways to choose 2 men and 1 woman: C(2,2) * C(4,1) = 1 * 4 = 4.
Total valid committees = 12 + 4 = 16.
The expected time complexity is O(1).
0 <= M, W <= 1000
Time limit: 1 sec