You are given a string S of length N, consisting of the characters 'I' and 'D'. The variable x is initially set to 0. You will perform a series of operations based on the characters in the string. Specifically:
For each character in the string:
If the character is 'I', increment x by 1.
If the character is 'D', decrement x by 1.
Your task is to find the maximum value of x during the operations, including the starting value (before the first operation) and the final value (after the last operation).
Input Format
A single string S (1 ≤ |S| ≤ 100,000) consisting of characters 'I' and 'D'.
Output Format
Output a single integer, which is the maximum value of x during the operations.
Examples
Example 1:
Input:
text
IDIDI
Output:
text
2
Explanation:
Initial value: x = 0
After operations:
1st: I -> x = 1
2nd: D -> x = 0
3rd: I -> x = 1
4th: D -> x = 0
5th: I -> x = 1
Maximum value of x during operations is 1.
Example 2:
Input:
text
IIIDDDI
Output:
text
3
Explanation:
Initial value: x = 0
After operations:
1st: I -> x = 1
2nd: I -> x = 2
3rd: I -> x = 3
4th: D -> x = 2
5th: D -> x = 1
6th: D -> x = 0
7th: I -> x = 1
Maximum value of x during operations is 3.
Implementation
Please place your solution in the file located at /app/.