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

#BS0000172. Chỉ số H (H-Index)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chỉ số H (H-Index)

H-Index

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A researcher has nn published papers. Paper ii has been cited cic_i times, where cic_i is a non-negative integer. The H-index is the greatest integer hh for which at least hh papers have each received at least hh citations. Determine this value; the H-index may be 00.

Input

The first line contains the integer nn, the number of papers. The second line contains nn integers c1,c2,…,cnc_1,c_2,\ldots,c_n, the citation counts for the papers in order.

Output

Print exactly one integer: the maximum H-index.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le30; 0≤ci≤1000\le c_i\le100 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤50001\le n\le5000; 0≤ci≤1060\le c_i\le10^6 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 0≤ci≤1090\le c_i\le10^9 for every 1≤i≤n1\le i\le n.

Examples

Input

5
3 0 6 1 5

Output

3

Explanation

The five citation counts are 3,0,6,1,53,0,6,1,5. For h=3h=3, three papers have at least three citations: 66, 55, and 33. For h=4h=4, only the papers with 66 and 55 citations qualify, so there are fewer than four. Thus the largest feasible value is 33.

Input

3
0 0 0

Output

0

Explanation

All papers have zero citations. No h≥1h\ge1 satisfies the definition, so the H-index is 00.