Under construction

Still being built. Things may change

Suspicious Event

Time limit1sMemory limit1024 MB

Summary
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 AA that records the login and logout events of users in chronological order. Each user is represented by a unique integer. A positive integer xx is a login event by user xx, and a negative integer −x-x is a logout event by user ∣x∣|x|. No two events in AA 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 A1..8=(8,3,−8,−6,7,−3,−1,6)A_{1..8} = (8, 3, -8, -6, 7, -3, -1, 6). There are 8 events from 5 distinct users (users 1, 3, 6, 7, and 8).

  • A1=8A_1 = 8: user 8 logs in.
  • A2=3A_2 = 3: user 3 logs in.
  • A3=−8A_3 = -8: user 8 logs out.
  • A4=−6A_4 = -6: user 6 logs out. This is a suspicious event, because user 6 has not logged in.
  • A5=7A_5 = 7: user 7 logs in.
  • A6=−3A_6 = -3: user 3 logs out.
  • A7=−1A_7 = -1: user 1 logs out. This is a suspicious event, because user 1 has not logged in.
  • A8=6A_8 = 6: user 6 logs in.

There are 2 suspicious logout events, A4=−6A_4 = -6 and A7=−1A_7 = -1. User 6 logs in at A8A_8, but that is after the logout at A4A_4, so A4A_4 is still suspicious.

Your task is to count the suspicious logout events in the record.

Input

The first line contains an integer NN (1≤N≤10001 \le N \le 1000), the number of events. The second line contains NN integers AiA_i (−1000≤Ai≤1000-1000 \le A_i \le 1000, Ai≠0A_i \ne 0), the events in chronological order. All integers in AA are distinct.

Output

Print one integer on a line: the number of suspicious logout events.

Examples5

  1. Example 1

    Input
    8
    8 3 -8 -6 7 -3 -1 6
    
    Expected output
    2
    
  2. Example 2

    Input
    4
    17 -17 12 -12
    
    Expected output
    0
    
  3. Example 3

    Input
    4
    -317 -1 -20 -300
    
    Expected output
    4
    
  4. Example 4

    Input
    4
    27 108 36 9
    
    Expected output
    0
    
  5. Example 5

    Input
    4
    -100 -200 200 100
    
    Expected output
    2