#P1620. 漂亮字串

漂亮字串

Description

Caima thinks that O\tt O and X\tt X are the two most beautiful letters, and a string made of O,X\tt O, X is a most beautiful string. Among these most beautiful strings, if every substring that contains only X\tt X has length at most maxX\max_{\tt X}, every substring that contains only O\tt O has length at most maxO\max_{\tt O}, and the whole string has at most countO\rm count_{\tt O} letters O\tt O and countX\rm count_{\tt X} letters X\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.

10 10 0 0
3 5 1 1

0
7

Hint

Sample 2 Explanation

  • XOXOXOX\tt XOXOXOX.

Constraints and Conventions

At most 10001000 groups of testdata.

For 30%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 2020.

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