#C8543. Minimum Study Groups

    ID: 52537 Type: Default 1000ms 256MiB

Minimum Study Groups

Minimum Study Groups

You are given several test cases. In each test case, there are n students and each student is either capable of performing a special spell or not. The students are represented by either 0 or 1. Your task is to determine the minimum number of study groups required so that each group contains at least one student who can perform the special spell.

If there is no student in a test case who can perform the spell, output -1 for that test case. Otherwise, the answer is simply the count of students who can perform the spell.

Note: The input is provided via standard input (stdin) and the output should be printed to standard output (stdout). All formulas are given in LaTeX format. In this problem, the minimal number of groups is defined as:

$$\text{groups} = \begin{cases}\text{count of }1, & \text{if at least one }1 \text{ exists}\\ -1, & \text{otherwise}\end{cases} $$

inputFormat

The first line of input contains an integer t representing the number of test cases. For each test case, the first line contains an integer n — the number of students. The second line contains n integers (each either 0 or 1) separated by spaces, where 1 indicates that the student can perform the special spell and 0 indicates otherwise.

outputFormat

For each test case, print a single line containing the minimum number of study groups needed. If no student in the test case can perform the special spell, print -1.

## sample
2
5
0 1 0 0 1
4
0 0 0 0
2

-1

</p>