0 and 1

Source: Internet
Author: User

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

Test instructions

0 and 1 met to cancel each other out.

And let you find the minimum length of the sequence

With n 0 M 1;

Ans=str.length ()-(Max (n,m)-min (n,m));

1#include <iostream>2 using namespacestd;3 intMain () {4     intN;5      while(cin>>n&&N) {6Cin.Get();7         ints=0;8         ints1=0;9          for(intI=0; i<n;i++){Ten             if(CIN.)Get()=='0') s++; One         } ACin.Get(); -s1=n-s; -cout<<n-2* (S1&GT;S?S:S1) <<Endl; the     } - return 0; -}
View Code

0 and 1

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.