|
Four friends are playing a card game with two teams of two players each. Team \(A\) consists of players \(A1\) and \(A2\) while team \(B\) consists of players \(B1\) and \(B2\). |
|
|
|
There is a deck of \(N\) cards (where \(N\) is always a multiple of \(4\)), numbered from \(1\) to \(N\), with all cards visible to all players at all times. First, the cards are dealt out evenly to each player: |
|
- Player \(A1\) has cards \(A1_1\), ..., \(A1_{N/4}\). |
|
- Player \(B1\) has cards \(B1_1\), ..., \(B1_{N/4}\). |
|
- Player \(A2\) has cards \(A2_1\), ..., \(A2_{N/4}\). |
|
- Player \(B2\) has cards \(B2_1\), ..., \(B2_{N/4}\). |
|
|
|
The game proceeds for \(N/4\) rounds. In each round, each player plays a card. Player \(A1\) plays first, then player \(B1\), then player \(A2\), then player \(B2\). A player may choose to play any of their cards when it’s their turn. After all four players have played a card, the team who played the highest card will score \(1\) point. Once a round is complete, the four played cards are removed from the game, and then the next round starts. This continues until all cards have been played. |
|
|
|
For example, the first round of the second sample case might be played as follows, with player \(B2\) winning a point for team \(B\): |
|
|
|
{{PHOTO_ID:1558229151280116|WIDTH:600}} |
|
|
|
Assuming each team plays to maximize its score, how many points will team \(A\) score? |
|
|
|
|
|
# Constraints |
|
|
|
\(1 \le T \le 500\) |
|
\(4 \le N \le 4{,}000{,}000\) |
|
\(N\) is a multiple of \(4\). |
|
Each card from \(1\) to \(N\) is guaranteed to exist in exactly one player’s hand. |
|
|
|
The sum of \(N\) across all test cases is at most \(5{,}000{,}000\). |
|
|
|
|
|
# Input Format |
|
|
|
Input begins with a single integer \(T\), the number of test cases. For each test case, there is first a line containing a single integer \(N\). Then there are \(4\) lines containing the players' cards: |
|
- Line 1: \(N/4\) space-separated integers, \(A1_1, ..., A1_{N/4}\). |
|
- Line 2: \(N/4\) space-separated integers, \(B1_1, ..., B1_{N/4}\). |
|
- Line 3: \(N/4\) space-separated integers, \(A2_1, ..., A2_{N/4}\). |
|
- Line 4: \(N/4\) space-separated integers, \(B2_1, ..., B2_{N/4}\). |
|
|
|
|
|
# Output Format |
|
|
|
For the \(i\)th test case, output a line containing `"Case #i: "` followed by a single integer, the number of points that team \(A\) will score. |
|
|
|
|
|
# Sample Explanation |
|
|
|
In the first case, one possible way the cards can be played optimally is: |
|
- Round 1: \([2, 7, \textbf{8}, 5]\) |
|
- Round 2: \([1, 3, \textbf{6}, 4]\) |
|
|
|
Team \(A\) will score \(2\) points, and team \(B\) can do no better by playing differently. |
|
|
|
In the second case, one possible way the cards can be played optimally is: |
|
|
|
- Round 1: \([1, 6, 2, \textbf{9}]\) |
|
- Round 2: \([\textbf{13}, 5, 3, 8]\) |
|
- Round 3: \([12, 15, \textbf{16}, 10]\) |
|
- Round 4: \([\textbf{14}, 7, 4, 11]\) |
|
|
|
Team \(A\) will score \(3\) points. |
|
|
|
In the third case, one possible way the cards can be played optimally is: |
|
|
|
- Round 1: \([11, \textbf{12}, 9, 4]\) |
|
- Round 2: \([13, 2, 8, \textbf{14}]\) |
|
- Round 3: \([6, 1, 5, \textbf{10}]\) |
|
- Round 4: \([15, \textbf{16}, 7, 3]\) |
|
|
|
Team \(B\) can always prevent team \(A\) from scoring any points. |
|
|