Ratio
Practice
4.5 (28 votes)
Adhoc
Basic programming
Basics of implementation
Implementation
Medium
Problem
66% Success 5802 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There are 2 types of chocolates in Chocoland denoted by A and B.

The cholates are lined up in a queue.You want to satisfy your friends by distributing some number of non-empty contiguous chocolates such that the ratio of number of type A chocolates to number of type B chocolates is same for all the friends.You have to distribute all the chocolates and satisfy maximum number of friends.
Therefore you have to find the maximum number of friends that can be satisfied.

Input Format

The first line of input contains the number of test cases T .
Each test case starts with one line containing an integer N which is the length of the description of a queue.

Each of the following lines consists of an integer and one of the characters A or B, meaning that characters of the given type (A or B) follow next in the queue.

Output Format

For each test case, output a single line containing the maximum number of friends that can be satisfied.

Constraints

\(1 \le T \le 50\)

\(1 \le N \le 10^5\)

\(1 \le K \le 10^9\)

Length of queue \(\le 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
AlgorithmsBasic ProgrammingBasics of ImplementationImplementationMedium
Points:30
54 votes
Tags:
ApprovedImplementationMediumOpen
Points:30
8 votes
Tags:
Basic ProgrammingBasics of ImplementationData StructuresHash MapsHash TablesImplementationMedium