#K42992. Balanced Log Checker

    ID: 27210 Type: Default 1000ms 256MiB

Balanced Log Checker

Balanced Log Checker

You are given a sequence of log events and your task is to determine if the log is balanced. A log is considered balanced if every event 'START' has a corresponding event 'END' and no 'END' appears before its matching 'START'. In other words, if you add +1 for a 'START' and -1 for an 'END', the running sum should never drop below zero and must equal zero at the end.

Input is provided via standard input and output should be printed on standard output.

inputFormat

The first line contains an integer N, representing the number of events in the log. The next N lines each contain a string which is either 'START' or 'END'.

outputFormat

Output a single line: 'True' if the log is balanced, otherwise 'False'.## sample

4
START
START
END
END
True