Description
Andrewid The Android is a galaxy-famous detective. In the He free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation:we choose any of the adjacentpositions in the string, and if one them contains 0, and T He other contains 1, then we is allowed to remove these and digits from the string, obtaining a string of length N -2 as a result.
Now Andreid thinks on what's the minimum length of the string that can remain after applying the described Operation s Everal Times (possibly, zero)? Help him to calculate this number.
Input
First line of the input contains a single integer n (1≤ n ≤2 105), the length of the Strin G that Andreid have.
The second line contains the string of length n consisting only from zeros and ones.
Output
Output the minimum length of the string that is remain after applying the described operations several times.
Sample Input
Input
4
1100
Output
0
Input
5
01010
Output
1
Input
8
11101111
Output
6
Hint
In the first sample test it's possible to change the string like the following:.
In the second sample test it's possible to change the string like the following:.
In the third sample test it's possible to change the string like the following:.
Test instructions
0 and 1 met to cancel each other out.
And let you find the minimum length of the sequence
With n 0 M 1;
Ans=str.length ()-(Max (n,m)-min (n,m));
1#include <iostream>2 using namespacestd;3 intMain () {4 intN;5 while(cin>>n&&N) {6Cin.Get();7 ints=0;8 ints1=0;9 for(intI=0; i<n;i++){Ten if(CIN.)Get()=='0') s++; One } ACin.Get(); -s1=n-s; -cout<<n-2* (S1>S?S:S1) <<Endl; the } - return 0; -}
View Code
0 and 1