CF BUDDY
← Problems·

1926D · Vlad and Division

1300 · bitmasks, greedy

Problem: Vladislav has nn non-negative integers, and he wants to divide all of them into several groups so that in any group, any pair of numbers does not have matching bit values among bits from 11-st to 3131-st bit (i.e., considering the 3131 least significant bits of the binary representation).

For an integer kk, let k2(i)k_2(i) denote the ii-th bit in its binary representation (from right to left, indexing from 1). For example, if k=43k=43, since 43=101011243=101011_2, then 432(1)=143_2(1)=1, 432(2)=143_2(2)=1, 432(3)=043_2(3)=0, 432(4)=143_2(4)=1, 432(5)=043_2(5)=0, 432(6)=143_2(6)=1, 432(7)=043_2(7)=0, 432(8)=0,,432(31)=043_2(8)=0, \dots, 43_2(31)=0.

Formally, for any two numbers xx and yy in the same group, the condition x2(i)y2(i)x_2(i) \neq y_2(i) must hold for all 1i<321 \leq i < 32.

What is the minimum number of groups Vlad needs to achieve his goal? Each number must fall into exactly one group.

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

The first line of each test case contains a single integer nn (1n21051 \leq n \leq 2 \cdot 10^5) — the total number of integers.

The second line of each test case contains nn given integers a1,,ana_1, \ldots, a_n (0aj<2310 \leq a_j < 2^{31}).

The sum of nn over all test cases in a test does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output a single integer  — the minimum number of groups required to satisfy the condition.

Note: In the first test case, any two numbers have the same last 3131 bits, so we need to place each number in its own group.

In the second test case, a1=00000000000000000000000000000002a_1=0000000000000000000000000000000_2, a2=11111111111111111111111111111112a_2=1111111111111111111111111111111_2 so they can be placed in the same group because a1(i)a2(i)a_1(i) \ne a_2(i) for each ii between 11 and 3131, inclusive.

Sample Cases

Case 1

Input

9
4
1 4 3 4
2
0 2147483647
5
476319172 261956880 2136179468 1671164475 1885526767
3
1335890506 811593141 1128223362
4
688873446 627404104 1520079543 1458610201
4
61545621 2085938026 1269342732 1430258575
4
0 0 2147483647 2147483647
3
0 0 2147483647
8
1858058912 289424735 1858058912 2024818580 1858058912 289424735 122665067 289424735

Output

4
1
3
2
2
3
2
2
4

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