#C3300. Balanced String Deletions
Balanced String Deletions
Balanced String Deletions
You are given a string S consisting solely of the characters 'X' and 'Y'. A string is considered balanced if it contains an equal number of 'X' and 'Y'. Your task is to compute the minimum number of deletions required to make S balanced. In other words, if we denote the number of occurrences of 'X' by \(n_X\) and of 'Y' by \(n_Y\), you need to output \(|n_X - n_Y|\).
Example: For S = "XXXY", there are 3 occurrences of 'X' and 1 occurrence of 'Y'. The absolute difference is \(|3-1| = 2\), so the answer is 2.
inputFormat
The input is a single line read from standard input containing the string S. The string is guaranteed to contain only the characters 'X' and 'Y'.
outputFormat
Output a single integer representing the minimum number of deletions required to balance the string, printed to standard output.
## sampleXYXY
0