PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000092. Tháp đỏ xanh (Red-Green Towers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tháp đỏ xanh (Red-Green Towers)

Red-Green Towers

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You have rr red blocks and gg green blocks. A tower of height hh has exactly hh blocks on its bottom level, h−1h-1 blocks on the next, and so on, down to a top level with one block. Every level is monochromatic: all its blocks must be red or all must be green.

A tower of height hh uses exactly

Sh=1+2+⋯+h=h(h+1)2S_h=1+2+\cdots+h=\frac{h(h+1)}2

blocks. Some blocks may remain unused. Let HH be the maximum possible height using the available blocks.

Count how many different towers of height exactly HH can be built. Two towers differ if at least one level has a different color, even when the total number of red or green blocks is equal. Output the count modulo 109+710^9+7.

For r=g=1r=g=1, the only level may be red or green, yielding two towers. For r=4,g=6r=4,g=6, the maximum height is four because S4=10S_4=10, and two different colorings are possible.

Input

A single line contains integers r,gr,g, the available red and green block counts.

Output

Print the number of maximum-height towers modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 0≤r,g≤300\le r,g\le30, r+g≥1r+g\ge1.

  • Subtask 2 (30 points): 0≤r,g≤30000\le r,g\le3000, r+g≥1r+g\ge1.

  • Subtask 3 (50 points): 0≤r,g≤2⋅1050\le r,g\le2\cdot10^5, r+g≥1r+g\ge1.

Examples

Example 1

Input

4 6

Output

2

Explanation: The ten available blocks give H=4H=4. To use exactly four red blocks, color the level of size four red, or color the levels of sizes one and three red. Hence there are two towers.

Example 2

Input

1 1

Output

2

Explanation: The maximum height is one. Its single level may be either red or green, yielding two towers.

Example 3

Input

0 3

Output

1

Explanation: A height-two tower is possible with three green blocks, and only one coloring exists because there are no red blocks.