Problem:
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:

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>


int main()
{
  int cnt;
  int R, B;
  int M = 0; 
  int i,j,m;
  int K = 0;

  cnt = scanf("%d %d", &R, &B);

  M = R;
  if(M < B) M=B;

  for (m=1; m<M; m++) {
    for (i=0; i<m; i++) {
      for (j=0; j<m; j++) {
        if ((i != (m-1)) && (j != (m-1))) continue;
        if ((R >= i) && (B >= j)) {
          K++;
          R -= i;
          B -= j;
        } else if (B < j) {
          break;
        }
      }
    }
  }

  printf("%d", (K - 1));

  return 0;
}