#K43162. Valid Book Arrangement
Valid Book Arrangement
Valid Book Arrangement
You are given two non-negative integers (n) and (m) which represent the number of books from two distinct genres. Your task is to determine the number of valid arrangements of these books in a single row such that no two books of the same genre are placed next to each other.
If (|n - m| > 1), then it is impossible to arrange the books without having two books of the same genre adjacent; in this case, you should output ERROR
. Otherwise, the number of valid arrangements is given by the binomial coefficient:
[
C(n+m, n) = \frac{(n+m)!}{n!, m!}
]
Note: It is assumed that within each genre, the books are identical.
inputFormat
The input consists of two non-negative integers (n) and (m), separated by space. (n) and (m) represent the counts of books of two different genres.
outputFormat
Output a single line. If a valid arrangement is possible, output the number of valid arrangements as an integer. Otherwise, output ERROR
(without quotes).## sample
3 3
20