Shortest String
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Marichka really loves strings of the form A..AB..BA..A.
There must be at least one, but no more than \(a\) letters A on the left;
there must be at least one, but no more than \(b\) letters B in the middle;
there must be at least one, but no more than \(c\) letters A at the end.
Zenyk wants to gift Marichka a single string that contains each favorite string as a contiguous substring. Note that the substrings can overlap.
Your task is to find the length of the shortest string that Zenyk can gift.
Input
The single line contains three integers separated by a space: \(a\), \(b\), and \(c\).
Output
In the single line, print a single integer — the answer to the problem.
Constraints
\(1 \le a, b, c \le 1000\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 1 1 1 | 3 |
| Input (stdin) | Output (stdout) |
|---|---|
| 2 1 1 | 4 |
| Input (stdin) | Output (stdout) |
|---|---|
| 2 4 2 | 20 |
Notes
In the first test, there is only one favorite string
ABA, so the answer is 3.
In the second test, the shortest string is AABA, it
contains both favorite strings ABA and
AABA.
In the third test, there are 16 different favorite strings, and the
shortest string containing all of them has length 20. One such string is
AABBBAABAABBAABBBBAA.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|