欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2072B.Having Been a Treasurer in the Past, I Help Goblins Deceive
Having Been a Treasurer in the Past, I Help Goblins Deceive
After completing the first quest, Akito left the starting cave. After a while, he stumbled upon a goblin village.
Since Akito had nowhere to live, he wanted to find out the price of housing. It is well known that goblins write numbers as a string of characters '-' and '_', and the value represented by the string is the number of distinct subsequences of the string that are equal to the string "-\_-" (this is very similar to goblin faces).
For example, the string "-\_--\_-" represents the number , as it has subsequences "-\_-":
Initially, the goblins wrote a random string-number in response to Akito's question, but then they realized that they wanted to take as much gold as possible from the traveler. To do this, they ask you to rearrange the characters in the string so that the value of the number represented by the string is maximized.
A subsequence of a string is a string that can be obtained by deleting several (possibly ) characters from . Subsequences are considered different if they are obtained by deleting different sets of indices.
Input
The first line contains the number () — the number of test cases.
In the first line of each test case, there is one number () — the length of the string written by the goblins.
In the second line of each test case, there is a string of length , consisting only of characters '-' and '_' — the string written by the goblins.
It is guaranteed that the sum of across all test cases does not exceed .
Output
For each test case, you need to output one number — the maximum number of subsequences equal to the string "-_-", if the characters in the string are optimally rearranged.
Note
In the first test case, it is beneficial to rearrange the characters to form the string "-_-". This is the only string of three characters that has at least one subsequence "-_-".
In the second test case, there is only one character "-", and at least two are needed for the subsequence "-_-". This means that for any rearrangement of characters, the answer will be .
In the seventh and eighth test cases, the length of the string , which means that subsequences of length do not exist.
Samples
8
3
--_
5
__-__
9
--__-_---
4
_--_
10
_-_-_-_-_-
7
_------
1
-
2
_-
1
0
27
2
30
9
0
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |