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

#DSU0000045. Petya khám phá hầm mộ (Petya and Catacombs)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Petya khám phá hầm mộ (Petya and Catacombs)

Petya and Catacombs

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Petya explores a system of rooms connected by bidirectional passages. A passage is allowed to lead from a room back to itself. At time 00, Petya is standing in a room but does not record anything.

Every minute, Petya traverses exactly one passage and arrives in a room at the next time. Upon arriving at minute ii (i≥1i\ge1), Petya records an integer tit_i. If this room has never been visited before, he may choose any number in [0,i−1][0,i-1]. If the room has been visited, he must record the most recent earlier minute when he was in that same room. The journal records only the numbers tit_i, not room names.

Given the journal t1,t2,…,tnt_1,t_2,\ldots,t_n, find the minimum possible number of rooms in a system for which a journey and a journal satisfying all these rules can exist.

Input

The first line contains nn. The second line contains nn integers t1,t2,…,tnt_1,t_2,\ldots,t_n.

Output

Print the minimum number of rooms.

Subtasks

  • Subtask 1 (20 points): 1≤n≤401\le n\le40; 0≤ti<i0\le t_i<i for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤50001\le n\le5000; 0≤ti<i0\le t_i<i for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; 0≤ti<i0\le t_i<i for every 1≤i≤n1\le i\le n.

Examples

Input

5
0 1 0 1 3

Output

3

Explanation

One possible walk at minutes 0,1,2,3,4,50,1,2,3,4,5 is A→B→C→A→B→AA\to B\to C\to A\to B\to A. It produces notes 0,1,0,1,30,1,0,1,3 and needs at least three rooms.