Problem1012--Doing the calculation

1012: Doing the calculation

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Given a list of N integers ( N = 2 x is positive integer  x <= 20) ki, please do the following:
1) add the two integers in odd position and even position (that is  k+ k2, k3+k4 and so on...), if the sum S is even number, then place the sum S with S/2, if the sum S is odd number, then place it with 3*S + 1
2) After 1) is done, there is a new sequence formed by those S, that is S1, S2 , S3, .... and so on; then repeat the steps in one for the S sequence
3) Repeat 1) and 2) until only one integer is left.
Please output the last integer 

Input

the first line is N
the second line has N integers which are ki

Output

One integer which is the last integer

Sample Input Copy

8
1 5 9 2 3 7 8 1

Sample Output Copy

106

HINT

The first list is 1 5 9 2 3 7 8 1
The second list is: 3 34 5 28
The thirst list is : 112 100
The fourth list is : 106

Source/Category