Logland

시간 제한1초메모리 제한512 MB

요약
2의 거듭제곱 단위로 주어진 동전 개수에서 남은 돈을 둘로 정확히 나눌 수 있도록 버려야 하는 최소 가치를 구해 10^9+7로 나눈 나머지를 출력한다.
난이도

보통10점 중 6점

유형
그리디, 수학, 비트 연산, 구현
정답자
아직 제출이 없습니다

문제

Two thieves (who strongly "recommended" us not to reveal their names) has broken into the central bank of Logland, where the country's cash reserve is stored. In Logland, the currency has the kk denominations 1,2,4,8,…,2k−11, 2, 4, 8, \ldots, 2^{k - 1}, and the bank currently stores x_ix\_i coins of denominations 2i2^i.

Thieves live by a very strict honor code, which stipulates that any loot grabbed must be divided evenly between the theives. Unfortunately (for the thieves), this may mean that some loot must be left behind. For example, if the bank contained a single coin of denomination 88, and two coins of denomination 22, there is no way they could bring the 88 coin. Instead, they would have to take one coin of value 22 each, leaving more than half of the possible loot!

Since neither leaving loot nor solving NP-hard problems are things thieves like to do, they have asked you to compute the minimum value of the loot they must leave behind, in order to be able to split the remaining loot evenly.

입력

The first line of input contains the integer 1≤k≤1061 \le k \le 10^6 -- the number of denominations in Logland. The next line contains the kk integers 0≤x_0,x_1,…,x_k−1≤2300 \le x\_0, x\_1, \dots, x\_{k-1} \le 2^{30}, the number of coins of the denominations 20,21,…,2k−12^0, 2^1, \dots, 2^{k - 1}.

출력

Output a single line, the minimum amount of money the thieves must leave behind. Since this number may be very large, output it modulo the prime number 109+710^9 + 7.

예제3

  1. 예제 1

    입력
    4
    0 2 0 1
    
    예상 출력
    8
    
  2. 예제 2

    입력
    5
    1000000 1 1 1 1
    
    예상 출력
    0
    
  3. 예제 3

    입력
    5
    3 3 3 3 3
    
    예상 출력
    1