Santa Chunbae's Gift Distribution
InterviewTime limit1sMemory limit1024 MB
Given N gifts priced from 0 to 3, pair them into N/2 pairs so that the sum of the XOR values of the pairs is as large as possible.
- Level
Medium5 of 10
- Topics
- Greedy, Implementation
- Solved
- No attempts yet
Problem

Santa Chunbae is sorting gifts for baby cats. There are gifts in total, and Chunbae gives two gifts each to baby cats. is even.
Each gift has a price, and every price is an integer from to . The satisfaction a baby cat gets from its two gifts is the XOR of their prices. For example, gifts priced and give satisfaction XOR , and gifts priced and give satisfaction XOR .
Chunbae wants to hand out the gifts so that the total satisfaction is as large as possible. Write a program that computes this maximum total satisfaction.
Input
The first line contains , the number of gifts Chunbae has. is even
The second line contains the prices of the gifts, separated by spaces. Every price is an integer from to .
Output
Print the maximum total satisfaction that Chunbae can get by giving out the gifts to the baby cats.
Hint
You can check the definition of XOR here.