Bit Counting Sequence
시간 제한2초메모리 제한1024 MB
팝카운트 값의 수열이 주어질 때, 어떤 음이 아닌 정수 x부터 시작하는 연속한 정수들의 팝카운트와 같은지 판별하고 가장 작은 x를 구한다.
문제
For a non-negative integer , let be the number of ones in the binary representation of . For example, because .
You are given a sequence of integers . Your task is to determine whether there exists a non-negative integer such that is equal to . Furthermore, if it exists, compute the smallest satisfying the condition.
입력
The first line of input contains one integer () representing the number of test cases. After that, test cases follow. Each of them is presented as follows.
The first line contains one integer (). The second line contains integers ( for all ).
The sum of across all test cases in one input file does not exceed .
출력
For each test case, output the smallest non-negative integer satisfying the condition above. If there is no such , output -1 instead.