Problem A CodeForces 556A

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

41100

Output

0

Input

501010

Output

1

Input

811101111

Output

6
#include <iostream>
#include <cstdio>
#include <cstring>
const int maxn=200000;
char s[maxn];
using namespace std;
int main()
{
	int n,c,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);
		else
			printf("%d\n",kase-flag);
	}
	return 0;
}
 
时间: 2024-08-07 17:00:52

Problem A CodeForces 556A的相关文章

Problem E CodeForces 237C

Description You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers a, a + 1, ..., b (a ≤ b).

Problem F CodeForces 16E

Description n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability 

Problem B Codeforces 295B 最短路(floyd)

Description Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists

Problem - D - Codeforces Fix a Tree

Problem - D - Codeforces  Fix a Tree 看完第一名的代码,顿然醒悟... 我可以把所有单独的点全部当成线,那么只有线和环. 如果全是线的话,直接线的条数-1,便是操作数. 如果有环和线,环被打开的同时,接入到线上.那就是线和环的总数-1. 如果只有环的话,把所有的环打开,互相接入,共需n次操作. #include <cstdio> #include <algorithm> using namespace std; const int maxn =

Codeforces Round #425 (Div. 2) Problem C (Codeforces 832C) Strange Radiation - 二分答案 - 数论

n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is a

Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

Digital collectible card games have become very popular recently. So Vova decided to try one of these. Vova has n cards in his collection. Each of these cards is characterised by its power pi, magic number ci and level li. Vova wants to build a deck

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案

There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo

Problem - 9D - Codeforces

https://codeforces.com/problemset/problem/9/D 一开始居然还想直接找公式的,想了想还是放弃了.原来这种结构是要动态规划. 状态是知道怎么设了,tnh表示节点数为n个,树高为h的BST的个数. 为什么要这么设状态呢?是考虑到题目关心BST的高度,而且BST具有递归性. 但是这个关键就是要加上n个节点的标记,因为不同节点数量明显可以构造出的高为h的树不同,而且也会影响BST另一侧的构造. 所以说设对状态就做对了一半. 思路就是按高为h的BST是怎么由高为h