시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 809 163 109 20.000%

문제

홍준이는 프로그래밍 대회를 개최했다. 이 대회는 사람들이 팀을 이루어서 참가해야 하며, 팀원의 수는 홍준이가 정해준다. 팀원이 홍준이가 정한 값보다 부족하다면, 그 팀은 대회에 참여할 수 없다. 모든 팀은 같은 수의 팀원으로 이루어져 있다.

대회에 참여 의사를 밝힌 학교는 총 N개이다. 각 학교는 모든 학생이 참여할 수 있는 경우에만 대회에 참가한다. 즉, 남는 사람 없이 모든 학생이 팀에 들어갈 수 있어야 한다.

대회는 예선과 본선으로 구성되어 있다. 모든 팀은 같은 학교 소속으로 이루어져 있어야 한다. 예선에서 각 학교 1등팀만 본선에 진출한다. 

홍준이의 대회는 올해가 첫 해이기 때문에, 많은 관심이 필요하다. 따라서, 본선에 참가하는 사람의 수를 최대가 되도록 팀원의 수를 정하려고 한다. 또, 본선이 지루해지는 것을 막기 위해 적어도 두 팀이 본선에 참가할 수 있어야 한다.

홍준이가 팀원을 몇 명으로 정해야 본선에 참가하는 사람의 수가 최대가 되는지 구하는 프로그램을 작성하시오.

입력

첫째 줄에 홍준이의 대회에 참여 의사를 밝힌 학교의 수 N (2 ≤ N ≤ 200,000)이 주어진다.

둘째 줄에는 각 학교 학생의 수가 주어진다. 학생의 수는 구간 [1, 2,000,000]에 포함된다.

출력

첫째 줄에 홍준이의 대회 본선에 참가하는 사람의 수의 최대값을 출력한다.

예제 입력 1

3
1 2 4

예제 출력 1

4

예제 입력 2

2
1 5

예제 출력 2

2

예제 입력 3

5
4 6 3 8 9

예제 출력 3

9

힌트

홍준이가 한 팀당 두 명으로 결정하면, 2번과 3번 학교가 참가할 수 있다.

W3sicHJvYmxlbV9pZCI6IjEyMjIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQ2NGRcdWM5MDAgXHVkNTA0XHViODVjXHVhZGY4XHViNzk4XHViYzBkIFx1YjMwMFx1ZDY4YyIsImRlc2Ny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