Codeforces Round 832 (Div. 2)
E
List Generation
Codeforces
2900
原题
← D→
翻译中…

For given integers $n$ and $m$, let's call a pair of arrays $a$ and $b$ of integers good, if they satisfy the following conditions:

翻译中…
  • $a$ and $b$ have the same length, let their length be $k$.
  • $k \ge 2$ and $a_1 = 0, a_k = n, b_1 = 0, b_k = m$.
  • For each $1 \lt i \le k$ the following holds: $a_i \geq a_{i - 1}$, $b_i \geq b_{i - 1}$, and $a_i + b_i \neq a_{i - 1} + b_{i - 1}$.
翻译中…

Find the sum of $|a|$ over all good pairs of arrays $(a,b)$. Since the answer can be very large, output it modulo $10^9 + 7$.

翻译中…

Input

翻译中…

The input consists of multiple test cases. The first line contains a single integer $t (1 \leq t \leq 10^4)$  — the number of test cases. The description of the test cases follows.

翻译中…

The only line of each test case contains two integers $n$ and $m$ $(1 \leq n, m \leq 5 \cdot 10^6)$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^6$ and the sum of $m$ over all test cases does not exceed $5 \cdot 10^6$.

翻译中…

Output

翻译中…

For each test case, output a single integer  — the sum of $|a|$ over all good pairs of arrays $(a,b)$ modulo $10^9 + 7$.

翻译中…

Note

翻译中…

In the first testcase, the good pairs of arrays are

翻译中…
  • $([0, 1], [0, 1])$, length = $2$.
  • $([0, 1, 1], [0, 0, 1])$, length = $3$.
  • $([0, 0, 1], [0, 1, 1])$, length = $3$.
翻译中…

Hence the sum of the lengths would be ${2 + 3 + 3} = 8$.

翻译中…

样例

Input #1
4
1 1
1 2
2 2
100 100
Output #1
8
26
101
886336572
InputCopy OutputCopy
题目信息
题号
1747E
时间限制
1 s
内存限制
256 MB
标签
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。