You are given an integer n and a string s of length 2n consisting only of characters 0, 2, and 6.
You want to partition the positions {1,2,…,2n} into exactly n pairs.
That is, you must choose n pairs of indices (i,j) such that:
- 1≤i<j≤2n
- every index from 1 to 2n appears in exactly one pair
For each chosen pair (i,j), the two-character string sisj must be a substring of 2026, meaning it must be equal to one of:
Determine whether it is possible.
Constraints
- 1≤t≤104
- 1≤n≤105
- ∣s∣=2n
- s consists only of
0, 2, 6
- The sum of n over all test cases does not exceed 105.