n total size
k subsequence size
number of combinations? n choose k
number of times a particular number is seen in all combinations? (n-1) choose (k-1)
So for the same simple example
[ [1,2,3], [1,2,4], [1,3,4], [2,3,4] ]
total combinations: 4 choose 3 --> 4 combinations in total.
"1" is seen: 3 choose 2 --> 3 times
"4" is also seen 3 times.
However you can't just product everything with power occurrences and divide by min/max to that power, because:
1**3 * 2**3 * 3**3 * 4**3 / 1**3 / 4**3 --> result is 216.
In the first subset, "3" is the maximum and should be discarded.
In the last subset, "2" is the minimum and should also be discarded.
So that's why the real answer is 36, or 6 times less.
Btw, the big prime thing can help you keep the running product low. As you calculate the product, you can take its modulus if it's greater than that prime.
x = 1000000007
# Some loop that increases prod...
prod = prod%x if prod>x |
Easier on scripting languages that automagically upscale to bigger ints; on C++ might just need to have everything as long.