Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/saralash-xirsh-indeksi

h-index

Medium 1000 ms 128 MB 51%
Share

A scientist has $n$ papers, the $i$-th paper has been cited $c_{i}$ times. The scientist's h-index (Hirsch index) is the largest number $h$ such that at least $h$ of the papers have each been cited at least $h$ times. Find the h-index.

Paper columns in decreasing order of citations; the place where a column's height is not less than its position is highlighted

Input

The first line contains a positive integer $n$. The second line contains $n$ integers $c_{i}$.

Output

One integer — $h$.

Note

$1 \le n \le 2 \cdot 10^{5}$
$0 \le c_{i} \le 10^{9}$

Examples

Input #1
5
3 0 6 1 5
Output #1
3
Input #2
1
0
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.