Hide

Problem N
No Stragglers

/problems/nostragglers/file/statement/en/img-0001.jpg
Photo retrieved from the Mines Dining website.

Mines Market, the premier on-campus dining hall option, has had some security issues over the past few weeks; some troublemakers have been hiding overnight to score free breakfast and steal ice cream from the fridges! Thus, the Mines Market staff and Mines PD have installed a new, state-of-the-art security and CCTV system which can detect people coming and going from Mines Market. This new security system is remarkable, it can even tell the difference between students, faculty, and visitors!

As the technician for this new security solution, you’ve been tasked to determine whether, at the end of the day, there are stragglers present in Mines Market or not. Assume there are no students, faculty, or visitors present in Mines Market at the beginning of the day.

Input

The first line of input is an integer, $1 \leq N \leq 1\, 000\, 000$, representing the number of entry or exit events logged by the new security system. Each of the subsequent $N$ lines of input represent a single entry or exit event. These $N$ lines will be formatted as three space-separated values:

  • The type of person entering or exiting Mines Market; will be one of STU, FAC, or VIS denoting students, faculty, and visitors, respectively.

  • The direction the person is going; will be either IN or OUT representing a person entering or exiting, respectively.

  • The integer number of people entering or exiting Mines Market of the specified type; this integer will be in the range $[0, 16\, 383]$.

Assume that there will be no more than $32\, 767$ of any type of person (students, faculty, or visitors) present in Mines Market at any given time. Also assume that it is impossible for there to be a negative quantity of any type of person (students, faculty, or visitors) present in Mines Market at any given time.

Output

Output “NO STRAGGLERS” (without the quotes) if there are no stragglers present in Mines Market at the end of the day. Otherwise, output the total number of stragglers (of any person type) present at the end of the day.

Sample Input Explanation

The first sample input has $3$ entry or exit events logged by the security system, with $10$ students entering, $38$ visitors entering, then $4$ students leaving. That means there are $44$ people ($6$ students, and $38$ visitors) still in Mines Market at the end of the day. Thus, the output is $44$.

Sample Input 1 Sample Output 1
3
STU IN 10
VIS IN 38
STU OUT 4
44
Sample Input 2 Sample Output 2
5
STU IN 10
VIS IN 38
STU OUT 4
VIS OUT 38
STU OUT 6
NO STRAGGLERS

Please log in to submit a solution to this problem

Log in