#P6365. [传智杯 #2 初赛] 众数出现的次数

[传智杯 #2 初赛] 众数出现的次数

Description

In the class of ChuanZhi training students, to liven up the atmosphere and reinforce knowledge of bitwise operations, the students play a game.

There are n(n106)n(n\le10^6) students in the class. Each student receives two cards, a red card and a black card. Each card has a non-negative integer not exceeding 10910^9. For student ii, the number on the red card is aia_i, and the number on the black card is bib_i.

Now each student needs to play a number. Each student may either play the number on their red card directly, or play the result of applying bitwise XOR to their red-card number and their black-card number. In the end, the teacher collects all numbers played by the students.

Among these numbers, the one that appears the most times is the mode. Under the optimal cooperative strategy of all students, we want the number of occurrences of the mode to be as large as possible. What is the number that appears the most times?

Input Format

The first line contains a positive integer nn.

The next nn lines follow. On line ii, two non-negative integers ai,bia_i,b_i represent the numbers on the red card and the black card of student ii.

Output Format

Output one integer, representing the answer. If there are multiple solutions, output the smallest one.

4
21 9
28 9
28 3
17 4
21

Hint

Explanation of the sample:

The maximum number of occurrences of a mode is 33. There are two ways:

  • Student 11 plays the red card directly, student 22 plays the XOR of red and black, student 33 plays either one, and student 44 plays the XOR of red and black. Then students 1,2,41,2,4 can all play 2121.
  • Student 11 plays the XOR of red and black, student 22 plays the red card directly, student 33 plays the red card directly, and student 44 plays either one. Then students 1,2,31,2,3 can all play 2828.

So both 2121 and 2828 are modes with the maximum number of occurrences, because at most it can occur 33 times, and there is no plan that makes it occur 44 times. But since the problem requires that if there are multiple solutions we output the smaller one, we should output 2121.

Translated by ChatGPT 5