A. Case of the Zeros and Ones

来源:互联网 发布:linux hexdump源码 编辑:程序博客网 时间:2024/05/16 00:29

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 n 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 n - 2 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.

Input

First line of the input contains a single integer n (1 ≤ n ≤ 2·105), the length of the string that Andreid has.

The second line contains the string of length n consisting only from zeros and ones.

Output

Output the minimum length of the string that may remain after applying the described operations several times.

Sample test(s)
input
41100
output
0
input
501010
output
1
input
811101111
output
6
Note

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: .


解题说明:此题其实就是统计0和1的个数,然后进行删除即可,由于0和1总有相邻的情况出现,所以不需要判断0和1出现的位置。


#include<stdio.h>int main(){int i,sum=0,j=0,k=0,n;char a[200001];scanf("%d",&n);scanf("%s",a);for(i=0;i<n;i++){if(a[i]=='0'){j++;}else{k++;}}if(j>k){j=k;}sum=n-(2*j);printf("%d\n",sum);return 0;}


0 0