#P1799. 数列

数列

Description

Although msh has grown up, she still likes to play little games to amuse herself. One day, she wrote a sequence of numbers on paper: 1,1,2,5,41, 1, 2, 5, 4. Then she erased one 11, and found that the remaining 1,2,41, 2, 4 were all in their own positions, namely 11 at position 11, 22 at position 22, and 44 at position 44. She wants, after erasing some numbers, to make as many numbers as possible be in their own positions in the remaining sequence. She found this game very fun and kept playing it again and again, but she cannot determine the maximum possible count, so she asks you to compute it.

Input Format

The first line contains an integer nn, the length of the sequence.

The next line contains nn positive integers separated by spaces; the ii-th number is AiA_i.

Output Format

Output a single integer, the maximum possible number of elements that can be in their own positions in the remaining sequence after erasing some numbers, that is, after reindexing the remaining sequence from 11, the maximum count of positions where the value equals its index.

5
1 1 2 5 4

3

Hint

Constraints

  • For 20%20\% of the testdata, n20n \leq 20.
  • For 60%60\% of the testdata, n100n \leq 100.
  • For 100%100\% of the testdata, n103n \leq 10^3.

Translated by ChatGPT 5