#P5514. [MtOI2019] 永夜的报应

[MtOI2019] 永夜的报应

Description

Houraisan Kaguya (Kaguya) has a bunch of numbers.

Kaguya has nn non-negative integers a1,a2ana_1,a_2\cdots a_n. Since Kaguya went to play a Gal Game, she hopes that you, who are wise, can help.

  • You need to divide these numbers into several groups, such that each of the nn numbers is assigned to exactly one group, and each group contains at least one number.

Define the weight of a group as the xor sum of all numbers in that group. Please find a grouping plan that minimizes the sum of the weights of all groups, and output this minimum value.

Input Format

The first line contains a positive integer nn, representing the number of given non-negative integers.

The next line contains nn non-negative integers a1,a2ana_1,a_2\cdots a_n.

Output Format

Output one line with one integer representing the answer.

3
1 2 5
6
6
9 18 36 25 9 32

15

Hint

Explanation for Sample 11:

One optimal grouping plan is:

  • Put the 11st number and the 33rd number into one group, whose weight is 15=41\oplus 5 = 4.
  • Put the 22nd number into one group, whose weight is 22.

The sum of the weights of all groups is 4+2=64 + 2 = 6. It can be proven that there is no grouping plan with a smaller total weight sum.

Explanation for Sample 22:

One optimal grouping plan is:

  • Put the 11st number and the 55th number into one group, whose weight is 99=09\oplus 9 = 0.
  • Put the 22nd number and the 44th number into one group, whose weight is 1825=1118\oplus 25 = 11.
  • Put the 33rd number and the 66th number into one group, whose weight is 3632=436\oplus 32 = 4.

The sum of the weights of all groups is 0+11+4=150 + 11 + 4 = 15. It can be proven that there is no grouping plan with a smaller total weight sum.

Subtasks

  • For 80%80\% of the testdata, n15n\leq 15.
  • For 100%100\% of the testdata, n106,ai109n\leq 10^6,a_i \leq 10^9.

Source

Lost Home 2019 League (MtOI2019) T1

Problem setter: disangan233

Translated by ChatGPT 5