Always Know Where Your Towel Is

시간 제한4초메모리 제한1024 MB

요약
합이 2^N-2 이하인 서로 다른 N개의 양의 정수가 주어질 때, 서로 다른 두 부분집합의 합으로 표현되는 S를 찾는다.
난이도

보통10점 중 7점

유형
조합론, 수학, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Arthur wants to go swimming. Another chance to use his favourite towel! He is concerned that if he leaves it out at the pool then someone might take it. So he keeps it in a locker.

Accessing the lockers is done in a peculiar way. One has to use an app on their phone to unlock the lockers. The app displays NN distinct positive integers whose sum is at most 2N−22^N-2. The lockers are also numbered from 11 to 2N−22^N-2. To open locker SS, one simply pushes a subset of buttons on the app (a "combination") whose sum is exactly SS. Pushing a button multiple times has the same effect as pushing it once, so there is no point to pushing a button more than once.

Arthur makes some observations. Oddly, it might be impossible to open some lockers. Also, since there are 2N−12^N-1 nonempty subsets of buttons and each such subset has its values summing to an integer from 11 to 2N−22^N-2, then there must be at least one locker that can be opened with more than one combination.

Arthur does not want to forget where he puts his towel when he goes swimming. He believes it will be easier to remember which locker he uses if it has more than one combination that can open it. Help Arthur find such a locker!

입력

The first line of input contains a single integer NN (3≤N≤423 \leq N \leq 42). Then next and final line contains NN positive integers a_1,…,a_Na\_1, \ldots, a\_N. These integers are distinct and satisfy ∑_i=1Na_i≤2N−2\sum\_{i=1}^N a\_i \leq 2^N-2.

출력

Output a single integer SS (1≤S≤2N−21 \leq S \leq 2^N-2) such that locker SS can be opened by more than one combination. If there are multiple possible solutions, any will suffice.

예제3

  1. 예제 1

    입력
    5
    2 5 8 4 7
    
    예상 출력
    9
    
  2. 예제 2

    입력
    3
    1 2 3
    
    예상 출력
    3
    
  3. 예제 3

    입력
    7
    19 24 11 23 9 21 18
    
    예상 출력
    41