Stable Mex

 Chef gives you a sequence 

of length .
Let denote the of the sequence . Chef is interested in the count of positive values , such that, if every element of is replaced by , the of the sequence still remains

.

Find the count of such values. If there are infinite such values, print

instead.

As a friendly reminder, the

of a sequence is the smallest non-negative integer that does not belong to the sequence. For instance:

  • The
of is because
  • does not belong to the sequence.
  • The
  • of is because and belong to the sequence, but
    • does not.

    Input Format

    • The first line of the input contains a single integer
    denoting the number of test cases. The description of
  • test cases follows.
  • The first line of each test case contains a single integer
  • - the length of the sequence
  • .
  • The second line of each test case contains
  • space-separated integers
    • .

    Output Format

    For each test case print a single integer — the count of positive values

    satisfying the given condition. If there are infinite such values, print

    instead.

    Constraints

  • Sum of
  • over all test cases does not exceed
    • .

    Sample Input 1

    3
    4
    1 2 3 5
    1
    0
    7
    5 10 2 4 0 6 1
    

    Sample Output 1

    0
    -1
    1
    

    Explanation

    • Test case
    : There doesn't exist any value of
  • satisfying the given condition.
  • Test case
  • : There are infinite values of
  • satisfying the given condition.
  • Test case
  • : There is only value of satisfying the given condition: . The of the given sequence is . When every element of the given sequence is replaced by , the sequence becomes , which also has .
    Previous
    Next Post »