#C9548. Optimal Card Arrangement Difference
Optimal Card Arrangement Difference
Optimal Card Arrangement Difference
You are given two types of cards: Type A and Type B. You have a cards of Type A and b cards of Type B. Your task is to arrange these cards in a row in such a way that the absolute difference between the number of neighboring pairs of the same type and the number of neighboring pairs of different types is minimized.
Formally, if we denote the number of neighboring pairs with the same card type by S and those with different types by D, then you need to minimize:
\( |S - D| \)
An optimal strategy always achieves a difference of \(0\) when the counts are equal (i.e. \(a = b\)) and a difference of \(1\) when they are not. Thus, the answer equals \(0\) when \(a = b\) and \(1\) otherwise.
Note: You should output the computed answer as an integer.
inputFormat
The input consists of a single line containing two space-separated integers a
and b
(\(0 \leq a,b \leq 10^9\)), representing the number of Type A cards and Type B cards respectively.
outputFormat
Output a single integer, which is the smallest possible absolute difference between the counts of neighboring same-type and different-type pairs.
## sample4 3
1
</p>