The water problem of the competition five times

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, a nd the 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 T He string 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 was possible to the "the string like the following: ." 1100 to 10 and then empty.

In the second sample test it's possible to change the string like the following: . 01010 through 010 to 0

In the third sample test it's possible to change the string like the following: . 11101111 to 111111

Test instructions: Give a string (note is a string), if the next two are 0 and 1, then take them, always so the length of the last output string, and it is worth noting that this is only required to output and input a set of data ....

Problem-solving ideas: start to see the topic, understand the meaning of play, almost be fooled by it. The first thought is the tag recursion what, and then carefully think, in fact, not so troublesome. As long as there are 0 and 1 in the string, it is bound to pop out. This allows the problem to be converted to see how many 1 and 0 of this string, minus less with more, and the rest is the string length ....

(Note that in this case, I see that the first response to the number is to use an array, and then there is no output.) Obviously know to do but stuck in the array for half an hour more, this acid cool ....

Finally, the string is used, because the title means to use a string, and the array can not be entered consecutively, for example, input 1100, the program will interpret 1100 as a number ....

I hope someone and I have made the same stupid mistake can be changed when ..... (I was really stupid to cry ....) ))

The code is as follows:

1#include <stdio.h>2#include <string>3 Chara[200010];4 intMain ()5 {6     intN;7scanf"%d",&n);8     intm1=0, m2=0;9scanf"%s",&a);Ten      for(intj=0; j<n; J + +) One     { A         if(a[j]=='0') -m1=m1+1; -         if(a[j]=='1') them2=m2+1; -     } -     if(m1>=m2) -printf"%d\n", m1-m2); +     Else -printf"%d\n", m2-M1); +  A     return 0; at}

The water problem of the competition five times

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.