String of CCPC

TimeLimit:1000MS  MemoryLimit:128MB
64-bit integer IO format:%lld
未提交 | 登录后收藏
Problem Description

BaoBao has just found a string  of length  consisting of 'C' and 'P' in his pocket. As a big fan of the China Collegiate Programming Contest, BaoBao thinks a substring  of  is "good", if and only if  'C', and  'P', where  denotes the -th character in string . The value of  is the number of different "good" substrings in . Two "good" substrings  and are different, if and only if .

To make this string more valuable, BaoBao decides to buy some characters from a character store. Each time he can buy one 'C' or one 'P' from the store, and insert the character into any position in . But everything comes with a cost. If it's the -th time for BaoBao to buy a character, he will have to spend  units of value.

The final value BaoBao obtains is the final value of  minus the total cost of all the characters bought from the store. Please help BaoBao maximize the final value.


Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer  (), indicating the length of string .

The second line contains the string  () consisting of 'C' and 'P'.

It's guaranteed that the sum of  over all test cases will not exceed .


Output

For each test case output one line containing one integer, indicating the maximum final value BaoBao can obtain.

SampleInput
3
3
CCC
5
CCCCP
4
CPCP
SampleOutput
1
1
1
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数0
总提交量0
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签
出处

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: