#DSU0000045. Petya khám phá hầm mộ (Petya and Catacombs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 , 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 (), Petya records an integer . If this room has never been visited before, he may choose any number in . 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 , not room names.
Given the journal , 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 . The second line contains integers .
Output
Print the minimum number of rooms.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
5
0 1 0 1 3
Output
3
Explanation
One possible walk at minutes is . It produces notes and needs at least three rooms.