Bobo has a string of length 2(n + m) which consists of characters `A` and `B`. The string also has a fascinating property: it can be decomposed into (n + m) subsequences of length 2, and among the (n + m) subsequences n of them are `AB` while other m of them are `BA`.

Given n and m, find the number of possible strings modulo (1e9+7)

输入描述:

The input consists of several test cases and is terminated by end-of-file.
Each test case contains two integers n and m.
* 0n,m1030≤n,m≤103 * There are at most 2019 test cases, and at most 20 of them has max{n,m}>50max{n,m}>50.

输出描述:

For each test case, print an integer which denotes the result.

根据题意一共有n个AB和m个BA,即n+m个A和n+m个B的组合,
首先在2*(n+m)个空位里填上A,其余填B,一共有C(2*(n+m),n+m)种选法,然后去除不合理项。
什么情况下不合理呢,根据贪心思想,前n个A属于n,设当前A的数量为y,B的数量为x,y要保证小于等于x+n。同理,可以得到x要保证小于等于y+m。

x轴代表B的数量,y轴代表A的数量,可行解范围如图,
题意即可转化为从0走到n+m不穿过y=x+n和x=y+m两条线的走法。
下面讲一下怎么求,
假设我们是在求从0到(n,m)不穿过对角线的走法,我们可以把对角线向下平移一格,得到线l2,即到达线l2就一定穿过了对角线;
节奏我们取(0,0)关于l2的对称点(1,-1),如果从这个点走到(n,m)就一定经过l2,然后让路径关于线l2作对称,
可以发现从(1,-1)到(n,m)的路径与(0,0)到达l2的路径数相同,详情可以参考下图:
即路径数为C(n+m,n)-C(n+m,m-1)。
由此方法可以推出E题结论为C(2*(n+m),n+m)-C(2*(n+m),n-1)-C(2*(n+m),m-1)。
代码如下:
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3fffffff
#define maxn 100005
typedef long long ll;
ll n,m,k,t;
const ll mod = 1e9+7;
ll fac[maxn];
ll inv[maxn];
ll qpow(ll a, ll b)
{
    ll r = 1, t = a;
    while (b) {
        if (b & 1)r = (r*t) % mod;
        b >>= 1;t = (t*t) % mod;
    }
    return r;
}
void init()
{
    fac[0] = 1;
    for (int i = 1;i <= mmax;i++) fac[i] = fac[i - 1] * 1ll * i%mod;
    inv[mmax] = qpow(fac[mmax], mod - 2);
    for (int i = mmax - 1;~i;i--) inv[i] = inv[i + 1] * 1ll * (i + 1) % mod;
}
ll C(ll n, ll m)
{
    if (m>n) return 0;
    if (m == n || m == 0) return 1;
    return fac[n] * 1ll * inv[n - m] % mod*inv[m] % mod;
}
int main(){
    init();
    while(~scanf("%lld%lld",&n,&m))
        printf("%lld\n",(C(2*m+2*n,n+m)+mod-(C(2*m+2*n,n-1)+C(2*m+2*n,m-1))%mod)%mod);
}