Time
limit:1000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u
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 Stri ng 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:.
Puzzle: Look at the number of 0 and 1 in the string, subtract
#include <cstdio>#include<cstring>intn,p,q;Chara[200000];intMain () {scanf ("%d",&N); scanf ("%s",&a); Q=0, p=0; for(intI=0; i<n; i++) { if(a[i]=='1') P++; if(a[i]=='0') Q++; } if(p>=q) printf ("%d", P-q); Elseprintf ("%d", Q-p); return 0;}
Codeforces 556A case of the Zeros and Ones (elimination 01)