409023: GYM103416 C Mura and love

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Mura and lovetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Mura is a tree-lover. Unfortunately, recently, he has lost his favorite rooted tree $$$t$$$ of size $$$n$$$, each node $$$v$$$ of which was assigned a value ($$$v.val$$$).

$$$t$$$ satisfies the following:

  1. The next pseudocode function returns a given array $$$a$$$ of size $$$n$$$ as a result, if $$$t$$$ is passed as an argument:

    Array to_array(Tree t):
    Array res = [t.root.val]

    for each child v of t.root:
    res = res + to_array(v.subtree)

    return res

  2. Among all trees that satisfy the first condition, $$$t$$$ has the maximum sum of $$$f(v)$$$ over all nodes $$$v$$$ of the tree. Here, $$$f(v) = xor(v) \curlywedge size(v)$$$, where:
    • $$$xor(v)$$$ — the result of bitwise XOR operation over the values of all nodes in the subtree of $$$v$$$.
    • $$$size(v)$$$ — the number of nodes in the subtree of $$$v$$$.
    • $$$\curlywedge$$$ — bitwise AND operation.

Mura knows, that he will never see his favorite tree again. But, at least, he wants to find the value of the sum of $$$f(v)$$$ over all nodes $$$v$$$ of $$$t$$$. Can you help him?

Input

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the size of the tree $$$t$$$ and the array $$$a$$$.

The second line contains $$$n$$$ integers $$$a_1, a_2,...a_{n - 1}, a_{n}$$$ ($$$0 \leq a_i \leq 10^6$$$) — the array $$$a$$$.

Output

Output the sum of $$$f(v)$$$ over all nodes $$$v$$$ of $$$t$$$.

ExampleInput
3
4 5 2
Output
5

加入题单

算法标签: