#K60012. Maximum Books Stack

    ID: 30992 Type: Default 1000ms 256MiB

Maximum Books Stack

Maximum Books Stack

You are given two integers (f) and (nf) which represent the number of fiction books and non-fiction books respectively. A valid stack of books is one in which no two fiction books are placed adjacently. Formally, an arrangement is considered valid if (f \le nf + 1). If the condition is satisfied, the maximum number of books in the stack is (f + nf); otherwise, no valid arrangement exists and the answer is 0.

For example:

  • If (f = 3) and (nf = 5), then the output is 8 because the condition holds.
  • If (f = 4) and (nf = 2), then the condition is violated, so the output is 0.

Your task is to read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The input consists of a single line containing two space-separated integers (f) and (nf), where (f) is the number of fiction books and (nf) is the number of non-fiction books.

outputFormat

Output a single integer: the maximum number of books in the stack that satisfies the condition of no two fiction books being adjacent. If no valid stack can be formed, output 0.## sample

3 5
8