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 adjacent positions in the string, and if one them contains 0, and The 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
#include<iostream>#include<cstdio>#include<cstring>Constint MAXN=200000;Char s[MAXN];UsingNamespace Std;IntMain(){int nC, flag, Kase;While(scanf("%d", &n)==1&&n){C=0; flag=0, Kase=0;scanf('%s ', S); c=Strlen(s);For(int I=0; I<c; I++){If(s[I]-' 0 '==1)++flag;If(s[I]-' 0 '==0)++kase; }if(flag>=kase)printf("%d\ n", flag-kase); elseprintf("%d\ n", Kase-flag);} return 0;}
Problem A Codeforces 556A