#C7656. Minimum Stacks for Unique Rem Values
Minimum Stacks for Unique Rem Values
Minimum Stacks for Unique Rem Values
You are given a sequence of strings, called rem values. You have an infinite number of stacks available. However, you must assign each rem value to a stack under the following condition:
- All values in a single stack must be identical.
- No two adjacent stacks (i.e. immediate neighbors in the left-to-right ordering) may contain the same value.
The process works as follows: Traverse the given sequence in order. For each rem value, if it has not been encountered before, create a new stack and place the value in that stack. If the value has been seen before, you must place it in the same stack that was created for that value. This guarantees that every stack is homogeneous and that adjacent stacks have different values.
Your task is to determine the minimum number of stacks required after processing the entire sequence.
Note: If the sequence is empty, the answer is 0.
In mathematical terms, if the sequence has N elements and U is the set of unique rem values encountered in order, then the answer is |U|.
inputFormat
The input is given via standard input (stdin) and has the following format:
N s1 s2 ... sN
Here, N
is a non-negative integer representing the number of rem values, and s1, s2, ..., sN
are the rem values (non-empty strings).
outputFormat
Output a single integer on a single line to standard output (stdout), representing the minimum number of stacks needed.
## sample0
0
</p>