#C9668. Shortest String Reduction

    ID: 53786 Type: Default 1000ms 256MiB

Shortest String Reduction

Shortest String Reduction

You are given a string (s) of length (n) consisting only of lowercase English letters. You can perform an operation any number of times where you remove two consecutive identical characters from the string. Your task is to determine the length of the shortest string that can be obtained after applying such operations.

For example, given (n = 8) and (s = \texttt{abccbaab}), the answer is 2.

inputFormat

The input is provided via standard input (stdin) and consists of two lines:

  1. The first line contains an integer (n), the length of the string.
  2. The second line contains the string (s) consisting of lowercase letters.

outputFormat

Output a single integer which is the length of the shortest string achievable after removing any adjacent pairs of identical characters. The result should be printed to standard output (stdout).## sample

8
abccbaab
2