A. Case of the Zeros and Ones

Description

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 Input

 

Input
4 1100
Output
0
Input
5 01010
Output
1
Input
8 11101111
Output
6

Sample Output

 

Hint

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<cstdio>
#include<iostream>
using namespace std; const int maxn=; int main()
{
int n,i;
scanf("%d",&n);
char a[maxn];
scanf("%s",a);
int m0=,m1=;
for( i=;i<=n;i++)
{
if(a[i]=='')
m0++;
if(a[i]=='')
m1++;
}
int b=m1-m0;
int c=m0-m1;
if(m0<=m1)
printf("%d\n",b);
else
printf("%d\n",c);
return ;
}

由于我输入的是字符型,判断0,1时要带引号,这要注意。

最新文章

  1. PJAX的实现与应用
  2. 站点图标favicon.ico
  3. C# 6.0的字典(Dictionary)的语法
  4. 【CodeForces 266C】Below the Diagonal(模拟)
  5. C#知识点有必要知会
  6. Checked 和 UnChecked 异常 的使用场合
  7. 6.24 AppCan移动开发者大会,我爱我家即将闪亮登场!
  8. Android基础问题汇总
  9. HDU 5791 Two
  10. 关于UITableview刷新笔记
  11. python 模块BeautifulSoup使用
  12. Entity Framework 调用返回标量值的存储过程
  13. Python3基础教程2——Python的标准数据类型
  14. Python/ MySQL练习题(一)
  15. Dynamics CRM项目实例之七:站点地图修改,联系人-订单-积分管理
  16. VMware Workstation:安装windows xp系统
  17. python下载安装BeautifulSoup库
  18. python的类和对象——类的静态字段番外篇
  19. HTML使用button的一个小坑
  20. 使用FreeSWITCH做电话自动回访设置

热门文章

  1. [NOIP2013提高组] CODEVS 3287 火车运输(MST+LCA)
  2. 网络编程——TCP连接
  3. C#代码模拟http发送get和post请求
  4. 两台linux机器文件传输之scp
  5. Linux必学的60个命令【转载】
  6. Qt多线程编程总结(一)(所有GUI对象都是线程不安全的)
  7. QT4/QT5设置界面风格(QT4支持更多的Windows界面风格)
  8. AlertDialog弹出时背景明暗程度调整
  9. UVA 10312 - Expression Bracketing(数论+Catalan数)
  10. C# inherit