#P7212. Black Magic
Black Magic
Problem Description
HoshiYo is learning Black Magic with $n$ blocks. The left and right sides of each block are painted black or white. HoshiYo arranges the blocks in a row in a certain order without rotating them and then releases the Black Magic. Here's what happens next:
- For any two adjacent blocks, if the right side of the left block and the left side of the right block are both painted black, then the two sides will be pasted together making the two blocks into one.
Input
The first line contains an integer $T$ ($1 \le T \le 4\times 10^3$), indicating the number of test cases.
Each test case contains four integers $E,L,R,B$ ($0 \le E,L,R,B \le 10^5, E+L+R+B\ge 1$), indicating the number of blocks.
- $E$: the number of blocks whose both sides are painted white.
- $L$: the number of blocks whose left side is painted black and right side is painted white.
- $R$: the number of blocks whose right side is painted black and left side is painted white.
- $B$: the number of blocks whose both sides are painted black.
Output
For each test case, output two integers in a single line, indicating the minimum and maximum blocks HoshiYo can get.
3
1 1 1 1
1 2 3 4
3 4 5 6
2 4
4 8
8 16
Hint
Let's denote a block by $(x,y)$, where $x$ indicates the color on the left side, and $y$ indicates the color on the right side. We use $0$ to represent white and $1$ to represent black.
For the first test case in the sample, here is a possible solution to get the minimum number of blocks:
$$(0,0) \quad (0,1) \quad (1,1) \quad (1,0)$$
As shown above, the last three blocks will be pasted into one.
And here is a possible solution to get the maximum number of blocks:
$$(0,0) \quad (1,0) \quad (1,1) \quad (0,1)$$
As shown above, any two blocks will not be pasted together.