PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000138. Maria mời bạn ra sân (Maria Breaks the Self-isolation)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Maria mời bạn ra sân (Maria Breaks the Self-isolation)

Maria Breaks the Self-isolation

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Initially only Maria is in the courtyard. There are nn friends; friend ii agrees to appear if at least aia_i other people are present at the same time, including Maria and friends appearing simultaneously. Maria may invite any number of uninvited friends together, provided every invited friend sees enough other people. Maximize the total attendance including Maria.

Input

The first line contains nn. The next line contains nn values aia_i.

Output

Print the maximum number of attendees, including Maria.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤ai≤2⋅1051\le a_i\le2\cdot10^5.
  • Subtask 2 (30 points): 1≤n≤12001\le n\le 1200; 1≤ai≤2⋅1051\le a_i\le2\cdot10^5.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤ai≤2⋅1051\le a_i\le2\cdot10^5.

Examples

Input

6
1 5 4 5 1 9

Output

6

Explanation

Invite the two friends requiring one other person; attendance becomes three. Then invite simultaneously the friends requiring 4,5,54,5,5 others: each sees five other attendees. The friend requiring nine cannot join. Answer 66.