Orig Description
Score : 600 points
Problem StatementWe have 3N cards arranged in a row from left to right, where each card has an integer between 1 and N (inclusive) written on it. The integer written on the i-th card from the left is A_i.
You will do the following operation N-1 times:
Rearrange the five leftmost cards in any order you like, then remove the three leftmost cards. If the integers written on those three cards are all equal, you gain 1 point.
After these N-1 operations, if the integers written on the remaining three cards are all equal, you will gain 1 additional point.
Find the maximum number of points you can gain.
Constraints
1 \leq N \leq 2000
1 \leq A_i \leq N
InputInput is given from Standard Input in the following format:
N
A_1 A_2 \cdots A_{3N}
OutputPrint the maximum number of points you can gain.
Sample Input 12
1 2 1 2 2 1
Sample Output 12
Let us rearrange the five leftmost cards so that the integers written on the six cards will be 2\ 2\ 2\ 1\ 1\ 1 from left to right.
Then, remove the three leftmost cards, all of which have the same integer 2, gaining 1 point.
Now, the integers written on the remaining cards are 1\ 1\ 1.
Since these three cards have the same integer 1, we gain 1 more point.
In this way, we can gain 2 points - which is the maximum possible.
Sample Input 23
1 1 2 2 3 3 3 2 1
Sample Output 21
Sample Input 33
1 1 2 2 2 3 3 3 1
Sample Output 33
Extracted Specification
An integer N (1 ≤ N ≤ 2000).
A list of 3N integers, each between 1 and N.
### Example Input:
```
2
1 2 1 2 2 1
```
### Function Signature:
Write a function f(N, A) that takes in the input.
def f(N: int, A: List[int]):
'''
N: an integer
A: a list of integers
'''
Test Case Generator
To generate test cases for the given problem statement, we need to ensure that the generated test cases adhere to the constraints and structure specified. Here's a test case generator for the problem:
```python
import random
def tcgen():
N = random.randint(1, 2000)
A = [random.randint(1, N) for _ in range(3 * N)]
return N, A
# Example usage:
N, A = tcgen()
print(N)
print(" ".join(map(str, A)))
```
This script will generate random test cases that can be used for the problem statement. Here's a breakdown of the generator function:
1. **N Generation**: Randomly select \(N\) such that \(1 \leq N \leq 2000\).
2. **A Generation**: Create a list \(A\) with \(3N\) integers, where each integer is between 1 and \(N\) inclusive.
Each time the function `tcgen` is called, it produces a new test case that satisfies the constraints of the problem. The example usage shows how to call the function and print the generated values in the format expected by the problem's input.
Extract Arguments
def extract_arguments(fh):
N = int(fh.readline().strip())
A = list(map(int, fh.readline().strip().split()))
return N, A