Suspicious Event
Time limit1sMemory limit1024 MB
Count the logout events whose user has not logged in earlier in a sequence of login and logout records.
- Level
Easy2 of 10
- Topics
- Simulation, Hash map
- Solved
- No attempts yet
Problem
Before you graduate from your beloved university, you managed to secure an internship at a security company. Your first task is to analyze a login/logout sequence.
You are given a sequence of integers that records the login and logout events of users in chronological order. Each user is represented by a unique integer. A positive integer is a login event by user , and a negative integer is a logout event by user . No two events in are the same.
Sometimes the record shows a user who logs out without having logged in before. This can be caused by a bug in the system or by a hacking attempt. Either way, such an event is suspicious.
For example, let . There are 8 events from 5 distinct users (users 1, 3, 6, 7, and 8).
- : user 8 logs in.
- : user 3 logs in.
- : user 8 logs out.
- : user 6 logs out. This is a suspicious event, because user 6 has not logged in.
- : user 7 logs in.
- : user 3 logs out.
- : user 1 logs out. This is a suspicious event, because user 1 has not logged in.
- : user 6 logs in.
There are 2 suspicious logout events, and . User 6 logs in at , but that is after the logout at , so is still suspicious.
Your task is to count the suspicious logout events in the record.
Input
The first line contains an integer (), the number of events. The second line contains integers (, ), the events in chronological order. All integers in are distinct.
Output
Print one integer on a line: the number of suspicious logout events.