P16235 [Lanqiao Cup 2026 NOI Qualifier B] Lanqiao Esports
Description
Xiao Lan, as the team manager of the esports club "Lanqiao Esports", is facing a huge management crisis. The club has currently signed $N$ different roles of professional players, and for the $i$-th role there are $A_i$ players.
To participate in the upcoming "Rift 5v5", Xiao Lan must assign all players in the club into teams. No one is allowed to sit on the bench.
According to the strict rules of the organizing committee, a valid team must satisfy the following conditions:
1. A group of $5$: Each team consists of exactly $5$ players.
2. Role exclusivity: The $5$ players in the same team must come from $5$ completely different roles.
Now, please help Xiao Lan determine whether, with the current number of players, there exists a grouping plan that can distribute all players exactly, and every team satisfies the competition rules.
Input Format
The first line contains an integer $T$, which denotes the number of test cases.
Then follow $T$ test cases, each in the following format:
- The first line contains an integer $N$, which denotes the number of role types.
- The second line contains $N$ integers $A_1, A_2, \dots, A_N$, where $A_i$ denotes the number of players of the $i$-th role.
Output Format
For each test case, if there exists a grouping plan that meets the conditions, output T; otherwise output F.
Explanation/Hint
### Sample Explanation.
In the first test case, there are $5$ players, each in a different role, so they can form exactly $1$ team.
In the second test case, there are $10$ players, which can be divided into $2$ teams. One valid assignment is: Team 1 consists of roles $1, 2, 3, 4, 5$; Team 2 consists of roles $1, 2, 3, 4, 6$.
In the third and fourth test cases, no grouping plan satisfies the conditions.
### Constraints.
For $30\%$ of the testdata: $1 \le T \le 5$, $1 \le N \le 20$, $0 \le A_i \le 100$.
For $100\%$ of the testdata: $1 \le T \le 10^3$, $1 \le N \le 10^5$, $0 \le A_i \le 10^9$, and it is guaranteed that the sum of $N$ over all test cases does not exceed $2 \times 10^5$.
Translated by ChatGPT 5