ROCK - Sweet and Sour Rock


A manufacturer of sweets has started production of a new type of sweet called rock. Rock comes in sticks composed of one-centimetre-long segments, some of which are sweet, and the rest are sour. Before sale, the rock is broken up into smaller pieces by splitting it at the connections of some segments.

Today's children are very particular about what they eat, and they will only buy a piece of rock if it contains more sweet segments than sour ones. Try to determine the total length of rock which can be sold after breaking up the rock in the best possible way.

Input

The input begins with the integer t, the number of test cases. Then t test cases follow.

For each test case, the first line of input contains one integer N - the length of the stick in centimetres (1<=N<=200). The next line is a sequence of N characters '0' or '1', describing the segments of the stick from the left end to the right end ('0' denotes a sour segment, '1' - a sweet one).

Output

For each test case output a line with a single integer: the total length of rock that can be sold after breaking up the rock in the best possible way.

Example

Sample input:
2
15
100110001010001
16
0010111101100000

Sample output:
9
13

hide comments
sitesh_sonu123: 2015-05-17 07:14:08

sir i want d code of this programme any one could sent it on my gmail.. plzzz

Shubham: 2015-05-16 09:44:43

phew finally AC...:)

GAURAV CHANDEL: 2015-04-12 20:21:04

Good dp problem
needs practice to think dynamically...

Ayur Jain: 2015-04-06 21:34:05

Nice problem :)

Shubham Bansal: 2015-03-28 19:25:25

yes..! best submission feeling ever felt..! :-)

SHASHI BHUSHAN KUMAR: 2015-03-26 19:01:09

very easy... :P

kp: 2015-03-23 16:53:12

after 1 whole day :) first dp

CoNtRaDiCtIoN: 2015-01-29 13:23:16

good problem

Daniel Polaczanski: 2015-01-07 22:47:34

Do I good understand that for 0101001 the answer is 4?

Rishav Jain: 2014-12-23 08:55:43

any1 can plz explain how the answer of 1 st case is 9,?


Added by:adrian
Date:2004-08-03
Time limit:7s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:based on a problem from the VII Polish Collegiate Team Programming Contest (AMPPZ), 2002