#K85947. Maximum XOR Subsequence

    ID: 36754 Type: Default 1000ms 256MiB

Maximum XOR Subsequence

Maximum XOR Subsequence

You are given a sequence of non-negative integers. The task is to determine the maximum XOR value that can be obtained by selecting any subsequence of the given sequence.

The key insight is that the maximum XOR obtainable is equivalent to taking the bitwise OR of all the numbers in the sequence. In mathematical terms, given a sequence \(a_1, a_2, \dots, a_n\), the answer is:

\[ a_1 \;|\; a_2 \;|\; \dots \;|\; a_n \]

This works because for any bit position, if at least one number in the sequence has a 1, you can always select a subset that sets that bit in the XOR result.

Note: The subsequence may be non-contiguous and can even consist of a single element.

inputFormat

The input is read from stdin:

  • The first line contains a single integer \(n\), representing the number of elements in the sequence.
  • The second line contains \(n\) space-separated non-negative integers.

outputFormat

Output to stdout a single integer representing the maximum XOR value obtainable by selecting a subsequence from the input sequence.

## sample
4
1 2 3 4
7