All problems

Problem 480

Sum of All Subset XOR Totals

Easy · 10 pts · Array, Math, Bit Manipulation, Combinatorics

Problem

The XOR total of a set of numbers is the bitwise XOR of all its elements (the empty set has XOR total 0). Compute the sum of the XOR totals of all 2^N subsets of the array. Enumerating subsets works for small N, but there is a shortcut: every bit that is set in at least one element is set in exactly half of the subsets' XOR totals, so the answer is (OR of all elements) · 2^(N-1). Use 64-bit integers.

Input

First line: N. Second line: N integers.

Output

Print the sum of all subset XOR totals.

Constraints

1 <= N <= 30; 1 <= A[i] <= 1000000000

Example input

2
1 3

Example output

6

Explanation

For 1 3 the subsets are {} (0), {1} (1), {3} (3) and {1, 3} (1 XOR 3 = 2). Their XOR totals add up to 0 + 1 + 3 + 2 = 6.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Single Number III Next: Maximum XOR of Two Numbers