#K4536. Check Operations Consistency

    ID: 27736 Type: Default 1000ms 256MiB

Check Operations Consistency

Check Operations Consistency

You are given a sequence of operations which represent entering and leaving sections. Each operation is given as a string: the symbol '+' indicates a section entry while '-' indicates a section exit, followed by a section identifier.

The operations are considered consistent if and only if:

  • No section is entered more than once before it is exited.
  • A section is never exited if it has not been entered.

Formally, let \( S \) be the set of sections currently entered. For an operation \( op \):
if \( op = +x \), then \( x \not\in S \) and \( S \leftarrow S \cup \{x\}\);
if \( op = -x \), then \( x \in S \) and \( S \leftarrow S \setminus \{x\}\).

Your task is to determine whether the given sequence of operations is CONSISTENT or INCONSISTENT. Output the result accordingly.

inputFormat

The first line of input contains an integer \( n \) representing the number of operations. The following \( n \) lines each contain a non-empty string representing an operation. Each operation is formatted as either +x or -x where x is the section identifier.

outputFormat

Output a single line: CONSISTENT if the sequence of operations is valid, or INCONSISTENT otherwise.

## sample
3
+1
+2
-1
CONSISTENT