Double Up
면접 대비시간 제한3초메모리 제한1024 MB
2의 거듭제곱으로 이루어진 수열에서 원소를 지우거나 같은 인접 원소를 합쳐 하나만 남길 때 얻을 수 있는 가장 큰 값을 구한다.
문제
A Double Up game consists of a sequence of numbers , where each is a power of two. In one move one can either remove one of the numbers, or merge two identical adjacent numbers into a single number of twice the value. For example, for sequence , we can merge the s and obtain , then merge the s and obtain , then remove the , and, finally, merge the s, obtaining a single final number, . We play the game until a single number remains. What is the largest number we can obtain?
입력
The input consists of two lines. The first line contains (). The second line contains numbers , where for each .
출력
The ouput consists of a single line containing the largest number that can be obtained from the input sequence .