CF BUDDY
← Problems·

1720D1 · Xor-Subsequence (easy version)

1800 · bitmasks, brute force, dp

Problem: It is the easy version of the problem. The only difference is that in this version ai200a_i \le 200.

You are given an array of nn integers a0,a1,a2,an1a_0, a_1, a_2, \ldots a_{n - 1}. Bryap wants to find the longest beautiful subsequence in the array.

An array b=[b0,b1,,bm1]b = [b_0, b_1, \ldots, b_{m-1}], where 0b0<b1<<bm1<n0 \le b_0 < b_1 < \ldots < b_{m - 1} < n, is a subsequence of length mm of the array aa.

Subsequence b=[b0,b1,,bm1]b = [b_0, b_1, \ldots, b_{m-1}] of length mm is called beautiful, if the following condition holds:

  • For any pp (0p<m10 \le p < m - 1) holds: abpbp+1<abp+1bpa_{b_p} \oplus b_{p+1} < a_{b_{p+1}} \oplus b_p.

Here aba \oplus b denotes the bitwise XOR of aa and bb. For example, 24=62 \oplus 4 = 6 and 31=23 \oplus 1=2.

Bryap is a simple person so he only wants to know the length of the longest such subsequence. Help Bryap and find the answer to his question.

Input Format: The first line contains a single integer tt (1t1051 \leq t \leq 10^5)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (2n31052 \leq n \leq 3 \cdot 10^5) — the length of the array.

The second line of each test case contains nn integers a0,a1,...,an1a_0,a_1,...,a_{n-1} (0ai2000 \leq a_i \leq 200) — the elements of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 31053 \cdot 10^5.

Output Format: For each test case print a single integer — the length of the longest beautiful subsequence.

Note: In the first test case, we can pick the whole array as a beautiful subsequence because 11<201 \oplus 1 < 2 \oplus 0.

In the second test case, we can pick elements with indexes 11, 22 and 44 (in 00-indexation). For this elements holds: 22<412 \oplus 2 < 4 \oplus 1 and 44<124 \oplus 4 < 1 \oplus 2.

Sample Cases

Case 1

Input

3
2
1 2
5
5 2 4 3 1
10
3 8 8 2 9 1 6 2 8 3

Output

2
3
6

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback