One and Two
Time limit1sMemory limit1024 MB
Given a sequence of 1s and 2s, find the smallest split point k where the product of the prefix equals the product of the suffix, or report -1.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
You are given a sequence . Each element of is or .
Find out if an integer exists so that the following conditions are met.
- , and
- .
If there exist multiple that satisfy the given condition, print the smallest.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains one integer ().
The second line of each test case contains integers ().
Output
For each test case, print the smallest that satisfies the conditions. If there is no such , print .