Олимпиадный тренинг

Задача 44571. Minimum OR amount


Задача

Темы: Битовые операции

Gromozeka wrote down n numbers on a piece of paper ai. It then performs the following operation on the array

  • selects two distinct integers i, j (1 <= i < j <= n) and  ;replaces ai to x and aj to y. In order not to break the array, Gromozeka should make sure ai|aj=x|y, where |< /code> denotes bitwise OR. Note that x and y are non-negative integers.

Gromoseka wants to determine the minimum sum of array elements that he can get after performing the above operation any number of times. Since Gromozeka needs to go on his next space journey as soon as possible, he asks for your help!


Input

The  first line of the  input contains an integer n (2 <= n <= 100) -  nbsp;nbsp;nbsp;nbsp; leaf. The second line of the input contains n integers a1,a2,…,an (0<=ai<= 230).


Output

Print the minimum possible sum of the array.



Examples
# Input Output
1
3
1 3 2
3
2
5
1 2 4 8 16
31
3
2
6 6
6
4
3
3 5 6
7