Under construction

Still being built. Things may change

Xor of Subset Sums

Time limit1sMemory limit512 MB

Summary
Given n integers, find the XOR of the sums of all 2^n subsets.
Level

Medium7 of 10

Topics
Bit manipulation, Combinatorics, Math
Solved
No attempts yet

Problem

You are given nn integers A1,A2,…,AnA_1, A_2, \dots, A_n. Let N={1,2,…,n}N = \{1, 2, \dots, n\}.

For a subset II of NN, define SIS_I as follows.

SI=∑k∈IAkS_I = \sum_{k \in I} A_k

That is, SIS_I adds up AkA_k over every index kk that belongs to II. The empty subset has sum 0, and NN itself counts as a subset, so there are 2n2^n values SIS_I in total.

Let XX be the bitwise exclusive or of all 2n2^n values.

X=⨁I⊆NSIX = \bigoplus_{I \subseteq N} S_I

Compute XX.

Input

The first line contains nn (1≤n≤301 \le n \le 30).

The second line contains nn integers A1,A2,…,AnA_1, A_2, \dots, A_n separated by spaces (0≤Ai<2300 \le A_i < 2^{30}).

Output

Print XX on the first line.

Examples2

  1. Example 1

    Input
    4
    1 2 3 4
    
    Expected output
    8
    
  2. Example 2

    Input
    6
    10 59 21 7 52 44
    
    Expected output
    160