Codeforces 556A case of the Zeros and Ones (elimination 01)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.