#P5031. Ponzi Scheme Pairing

    ID: 18269 Type: Default 1000ms 256MiB

Ponzi Scheme Pairing

Ponzi Scheme Pairing

Charles Ponzi once orchestrated a fraudulent financial scheme in 1919. He collected investments from two groups of investors: from K1 investors he collected \(1\times10^4\) dollars each and from K2 investors he collected \(2\times10^4\) dollars each. In order to avoid attracting attention from the IRS, every day he would spend exactly \(10^4\) dollars from two distinct sources. Note that even if a source provided \(2\times10^4\) dollars, it must be used in two different days (one \(10^4\) dollar consumption per day) and the same pair of sources cannot be used on more than one day. The daily pairs have no order (i.e. the pair \((A, B)\) is the same as \((B, A)\)). When all the money is spent, how many distinct sets of pairing schemes are there? Since the answer can be large, output it modulo \(10^9+7\).

Note: If the total number of \(10^4\) dollar portions, i.e. \(K_1 + 2K_2\), is odd then it is impossible to form pairs and the answer is 0.

Mathematical formulation:

You are given two non‐negative integers \(K_1\) and \(K_2\). Define \(S = K_1 + 2K_2\). If \(S\) is odd, output 0. Otherwise, let \(m = S/2\). Consider a set of sources where \(K_1\) sources appear once and \(K_2\) sources appear twice. We wish to count the number of perfect matchings of these \(S\) occurrences into \(m\) pairs such that the two occurrences in a pair come from distinct sources. This number can be computed via inclusion‐exclusion as follows: \[ \text{Answer} = \sum_{j=0}^{K_2} (-1)^j \binom{K_2}{j} \frac{(2(m-j))!}{2^{(m-j)} (m-j)!} \pmod{10^9+7}. \]

inputFormat

The input consists of a single line containing two integers \(K_1\) and \(K_2\) separated by a space.

outputFormat

Output a single integer representing the number of different valid pairing schemes modulo \(10^9+7\).

sample

2 1
2