cho.sh
Notes
Loading...

Shomtring

Time limit

2s

Memory limit

128 MB

Problem

A string made only of the characters A and B is called a Shomtring if it satisfies all of the following conditions.

  • It uses at most countA characters A.
  • It uses at most countB characters B.
  • Every contiguous block made only of A has length at most maxA.
  • Every contiguous block made only of B has length at most maxB.

Given countA, countB, maxA, and maxB, find the maximum possible length of a Shomtring.

Input

The first line contains four integers countA, countB, maxA, and maxB. Each value is between 0 and 1,000,000, inclusive.

Output

Print the maximum possible length of a Shomtring.