P2773 Beautiful String
Description
Caima believes that O and X are the two most beautiful letters, and a string composed of O and X is the most beautiful string. Among these strings, if any substring that consists only of X has length at most maxX, any substring that consists only of O has length at most maxO, and the entire string contains at most countO letters O and at most countX letters X, then it is a "super beautiful unbeatable" string. Now Caima wants to know the length of the longest such string. Please tell him.
Input Format
The input contains multiple lines, until EOF.
Each line has four numbers, in order: countO, countX, maxO, maxX.
All of countO, countX, maxO, maxX are integers in the range [0, 1000000].
Output Format
For each dataset, output one line with a single number, which is the length of the longest "super beautiful unbeatable" string.
Explanation/Hint
Translated by ChatGPT 5