time limit per test1 second

memory limit per test256 megabytes

inputstandard input

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

Examples

input

4

1100

output

0

input

5

01010

output

1

input

8

11101111

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

【题目链接】:http://codeforces.com/contest/556/problem/A

【题解】



让你消除相邻的01子串;

因为看到挺多人过的,就用函数写了个暴力;

然后就过了。

不过…998ms…….

用数组模拟链表应该更快.

不过挺麻烦的吧.



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
#define pri(x) printf("%d",x)
#define prl(x) printf("%I64d",x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int MAXN = 2e5+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); string s;
int n; int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin>>n;
cin >> s;
s=' '+s;
int len = s.size();
len--;
int i = 1;
while (i <= len-1)
{
if (s[i]!=s[i+1])
{
s.erase(i,2);
i--;
if (i==0) i=1;
}
else
i++;
len = s.size()-1;
}
cout << len;
return 0;
}

【52.49%】【codeforces 556A】Case of the Zeros and Ones的更多相关文章

  1. Codeforces 556A:Case of the Zeros and Ones

    A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...

  2. JAVA 基础编程练习题49 【程序 49 子串出现的个数】

    49 [程序 49 子串出现的个数] 题目:计算字符串中子串出现的次数 package cskaoyan; public class cskaoyan49 { public static void m ...

  3. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  4. Codeforces 556 A Case of the Zeros and Ones

    A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...

  5. 【30.49%】【codeforces 569A】Music

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【59.49%】【codeforces 554B】Ohana Cleans Up

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 776E】The Holmes Children

    [题目链接]:http://codeforces.com/contest/776/problem/E [题意] f(n)是小于n的不同整数对(x,y)这里x+y==n且gcd(x,y)==1的个数; ...

  8. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  9. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

随机推荐

  1. ActiveMQ学习总结(2)——ActiveMQ入门实例教程

    1.下载ActiveMQ 去官方网站下载:http://activemq.apache.org/ 2.运行ActiveMQ 解压缩apache-activemq-5.5.1-bin.zip,然后双击a ...

  2. JavaScript学习总结(8)——JS实用技巧总结

    后退 前进 <!--<input type="button" value="后退" onClick="history.go(-1)&quo ...

  3. [Redux-Observable && Unit testing] Testing the output of epics

    Epics can be unit-tested just like any other function in your application - they have a very specifi ...

  4. Android-Volley网络通信框架(二次封装数据请求和图片请求(包含处理请求队列和图片缓存))

    1.回想 上篇 使用 Volley 的 JsonObjectRequest 和 ImageLoader 写了 电影列表的样例 2.重点 (1)封装Volley 内部 请求 类(请求队列,数据请求,图片 ...

  5. 中间件 —— 消息中间件(MOM)

    维基百科对消息中间件的定义为:Message-oriented middleware (MOM) is software or hardware infrastructure supporting s ...

  6. 建堆是 O(n) 的时间复杂度证明。

    建堆的复杂度先考虑满二叉树,和计算完全二叉树的建堆复杂度一样. 对满二叉树而言,第 \(i\) 层(根为第 \(0\) 层)有 \(2^i\) 个节点. 由于建堆过程自底向上,以交换作为主要操作,因此 ...

  7. gdbserver 使用方法

    1.分别编译出在宿主机运行的交叉调试器arm-linux-gdb和在目标板上运行的gdbserver: 2.在目标板开启gdbserver#gdbserver  宿主机ip:任意指定端口号 ./待调试 ...

  8. Django快速搭建博客

    准备工作: 1.Python 2.Django 3.Git 安装Python: 官网下载 安装Django: #安装最新版本的Django $ pip install django #或者指定安装版本 ...

  9. CListCtrl 隔行变色

    响应消息 ON_NOTIFY(NM_CUSTOMDRAW, ListCtrl的ID, OnNMCustomdrawList) 实现函数OnNMCustomdrawList void CFinishWe ...

  10. 洛谷 P3654 First Step (ファーストステップ)

    洛谷 P3654 First Step (ファーストステップ) https://www.luogu.org/problemnew/show/P3654 题目描述 可是……这个篮球场,好像很久没有使用过 ...