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

#BS0000082. Chỉ số H trên dãy đã sắp xếp (H-Index II)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chỉ số H trên dãy đã sắp xếp (H-Index II)

H-Index II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A researcher has nn papers with non-decreasing citation counts c0,…,cn−1c_0,\ldots,c_{n-1}. Find the greatest nonnegative integer hh such that at least hh papers have at least hh citations each.

Input

The first line contains nn, and the next line contains the non-decreasing citation counts.

Output

Print the greatest valid hh.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤ci≤10000\le c_i\le1000; citation counts are non-decreasing.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 0≤ci≤10000\le c_i\le1000; citation counts are non-decreasing.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 0≤ci≤10000\le c_i\le1000; citation counts are non-decreasing.

Examples

Input

5
0 1 3 5 6

Output

3

Explanation

Three papers have citation counts 3,5,63,5,6, hence h=3h=3 works. Only two papers have at least four citations, so h=4h=4 is impossible. Output 3.