Under construction

Still being built. Things may change

111111111111111

Time limit2.5sMemory limit1024 MB

Summary
For each prefix of N given integers, find the maximum popcount of the XOR of some subset of those integers, and print one such XOR value per day.
Level

Medium7 of 10

Topics
Bit manipulation, Math, Brute force
Solved
No attempts yet

Problem

Runos who work at AI Network use binary numbers, and they like numbers whose binary representation has many 11s.

AIN manages the runos. To motivate them, AIN wants to give the "Runo of the Day" award each day for the next NN days to the runo who worked hardest that day. The prize is a number whose binary representation has many 11s, the kind of number runos are likely to like.

AIN found that choosing a number by hand is hard, so AIN subscribed to a service that delivers one integer per day for the next NN days. Let ViV_i be the number delivered on day ii.

Each day, AIN looks at the numbers collected so far and makes the prize as follows.

  1. If today is day ii of the subscription, pick any subset of V1,V2,⋯ ,ViV_1, V_2, \cdots, V_i. AIN may pick none of them or all of them.
  2. Compute the bitwise XOR of all picked numbers. If no number is picked, the result is 00. If exactly one number is picked, the result is that number.

AIN chooses, as the prize, the number with the most 11s in its binary representation among all numbers that can be made this way.

For each of the next NN days, find one number that AIN can choose as the prize that day.

Input

The first line contains NN, the number of days for the award and the number of days the delivery service is subscribed.

Each of the next NN lines contains one integer delivered by the service. The integer on the ii-th line is ViV_i.

Output

Print NN lines. On the ii-th line, print one number that AIN can choose as the prize on day ii.

Constraints

  • 1≤N≤1111 \leq N \leq 111
  • 0≤Vi≤111 111 111 111 1110 \leq V_i \leq 111\,111\,111\,111\,111

Examples3

  1. Example 1

    Input
    2
    3
    5
    
    Expected output
    3
    6
    
  2. Example 2

    Input
    3
    6
    14
    9
    
    Expected output
    6
    14
    15
    
  3. Example 3

    Input
    3
    1010000000
    110
    1
    
    Expected output
    1010000000
    1010000110
    1010000111