logo AlgoBeat OnlineJudge
登录 注册

#212608. [UOI 2025] Reversal ABC

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Given a string consisting of characters , , and .

In one operation, you are allowed to choose two adjacent elements of the string that are in the following order: , , or , and swap them.

Find the maximum number of consecutive operations that can be performed on the string .

In this problem, each test contains several sets of input data. You need to solve the problem independently for each such set.

输入格式

The first line contains one integer --- the number of sets of input data. The description of the input data sets follows.

In the first line of each input data set, there is one integer --- the length of the string .

In the second line of each input data set, there is a string of length , consisting of characters , , and .

It is guaranteed that the sum of across all input data sets of a single test does not exceed .

输出格式

For each set of input data, output on a separate line one integer --- the maximum number of consecutive operations that can be performed on the string .

样例

样例输入 1

2
5
ABCCA
19
CCAABBBABBAAABBCCAA

样例输出 1

3
28

数据范围与提示

In the first set of input data from the first example, no more than consecutive operations can be performed on the string . One example of how consecutive operations can be performed is .

Scoring

Let be the sum of over all input data sets of one test.

  • ( points): the answer is equal to or ;
  • ( points): ;
  • ( points): for ;
  • ( points): has the form (that is, for certain positive , , );
  • ( points): for ;
  • ( points): , ;
  • ( points): ;
  • ( points): ;
  • ( points): without additional constraints.