P1620 Beautiful String

Description

Caima thinks that $\tt O$ and $\tt X$ are the two most beautiful letters, and a string made of $\tt O, X$ is a most beautiful string. Among these most beautiful strings, if every substring that contains only $\tt X$ has length at most $\max_{\tt X}$, every substring that contains only $\tt O$ has length at most $\max_{\tt O}$, and the whole string has at most $\rm count_{\tt O}$ letters $\tt O$ and $\rm count_{\tt X}$ letters $\tt X$, then it is a super beautiful unbeatable string. Now Caima wants to know how long the longest super beautiful unbeatable string can be. Please tell him.

Input Format

The input contains multiple lines, until the end of file. Each line has four numbers, in order: $\rm count_{\tt O}, \rm count_{\tt X}, \rm max_{\tt O}, \rm max_{\tt X}$.

Output Format

For each set of testdata, output one line with a single number, the length of the longest super beautiful unbeatable string.

Explanation/Hint

### Sample 2 Explanation - $\tt XOXOXOX$. ### Constraints and Conventions At most $1000$ groups of testdata. For $30\%$ of the testdata, $0 \le \rm count_{\tt O}, \rm count_{\tt X}, \rm max_{\tt O}, \rm max_{\tt X} \le 20$, and the number of groups of testdata does not exceed $20$. For all testdata, $0 \le \rm count_{\tt O}, \rm count_{\tt X}, \rm max_{\tt O}, \rm max_{\tt X} \le 10^6$. Translated by ChatGPT 5