atcoder#WTF19D. Distinct Boxes

Distinct Boxes

Score : 20002000 points

Problem Statement

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

Formally speaking, let's number the boxes 11 through KK. If Box ii contains rir_i red balls and bib_i blue balls, the following conditions must be satisfied:

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

Constraints

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

Input

Input is given from Standard Input in the following format:

RR BB

Output

Print the maximum possible value of KK.

8 3
5

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