#P10077. Minimum Days to Read the Book

    ID: 12059 Type: Default 1000ms 256MiB

Minimum Days to Read the Book

Minimum Days to Read the Book

Zayin is an avid reader who recently received a book with n chapters. Each chapter i has a restriction: she must have read at least \(a_i\) other chapters before she can understand chapter i.

Every day, Zayin starts from the first chapter and goes sequentially to the last chapter. During a day, she will read a chapter if and only if:

  • The chapter has not yet been read.
  • The condition \(a_i \leq R\) holds, where \(R\) is the total number of chapters she has already read (including those read earlier in the same day).

If a chapter does not meet the condition or has already been read, she skips it. At the end of the day, the process repeats until all n chapters are read. Your task is to determine the minimum number of days needed for Zayin to finish reading the book.

inputFormat

The first line contains a single integer n (1 ≤ n ≤ 105), the number of chapters in the book.

The second line contains n non-negative integers \(a_1, a_2, \ldots, a_n\) where \(0 \leq a_i < n\), each representing the minimum number of chapters that must be read before chapter i can be read.

outputFormat

Output a single integer, the minimum number of days required for Zayin to finish reading all chapters.

sample

3
0 1 1
1