D - Distinct Boxes Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 2000 points

Problem Statement

Snuke has R red balls and B blue balls. He distributes them into K boxes, so that no box is empty and no two boxes are identical. Compute the maximum possible value of K.

Formally speaking, let's number the boxes 1 through K. If Box i contains r_i red balls and b_i blue balls, the following conditions must be satisfied:

  • For each i (1 \leq i \leq K), r_i > 0 or b_i > 0.
  • For each i, j (1 \leq i < j \leq K), r_i \neq r_j or b_i \neq b_j.
  • \sum r_i = R and \sum b_i = B (no balls can be left outside the boxes).

Constraints

  • 1 \leq R, B \leq 10^{9}

Input

Input is given from Standard Input in the following format:

R B

Output

Print the maximum possible value of K.


Sample Input 1

8 3

Sample Output 1

5

The following picture shows one possible way to achieve K = 5:

配点 : 2000

問題文

すぬけ君は R 個の赤いボールと B 個の青いボールを持っています。 彼は、これらのボールを K 個の箱に分けて入れます。このとき、どの箱も空でなく、またどのふたつの箱も中身が一致しないようにします。 K のとりうる最大値を求めてください。

より形式的には、箱に 1 から K までの番号を振り、箱 ir_i 個の赤いボールと b_i 個の青いボールを含むとすると、次の条件が満たされなければなりません。

  • i (1 \leq i \leq K) に対し、r_i > 0 または b_i > 0 である。
  • i, j (1 \leq i < j \leq K) に対し、r_i \neq r_j または b_i \neq b_j である。
  • \sum r_i = R かつ \sum b_i = B である (箱の外にボールが取り残されてはならない)。

制約

  • 1 \leq R, B \leq 10^{9}

入力

入力は以下の形式で標準入力から与えられる。

R B

出力

K のとりうる最大値を出力せよ。


入力例 1

8 3

出力例 1

5

K = 5 を達成する方法として考えられるものをひとつ、以下の画像に示します。