#P4667. Case of the Zeros and Ones
Case of the Zeros and Ones
Case of the Zeros and Ones
题面翻译
题目描述
安德鲁德是一位银河著名的侦探。 在空闲时间,他喜欢思考包含零和字符串的字符串。
有一次,他想到了一串由零和一组成的长度为n的字符串。 考虑以下操作:我们在字符串中选择任意两个相邻的位置,如果其中一个包含0,另一个包含1,则允许从字符串中移除这两个数字,从而获得长度为n - 2的字符串,作为 结果。
现在,安德鲁德考虑了多次应用所描述的操作(可能是零)后可以保留的字符串的最小长度是多少? 帮助他计算这个数字。
输入
输入的第一行包含一个整数n(1≤n≤2.105),即Andreid所具有的字符串的长度。
第二行包含长度为n的字符串,仅由0和1组成。
输出
输出多次应用描述的操作后可能保留的字符串的最小长度。
感谢@HNYLMS_MuQiuFeng 提供的翻译
题目描述
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
输入格式
First line of the input contains a single integer ( ), the length of the string that Andreid has.
The second line contains the string of length consisting only from zeros and ones.
输出格式
Output the minimum length of the string that may remain after applying the described operations several times.
样例 #1
样例输入 #1
4
1100
样例输出 #1
0
样例 #2
样例输入 #2
5
01010
样例输出 #2
1
样例 #3
样例输入 #3
8
11101111
样例输出 #3
6
提示
In the first sample test it is possible to change the string like the following: .
In the second sample test it is possible to change the string like the following: .
In the third sample test it is possible to change the string like the following: .