There are $$$k$$$ arrays of integers $$$a_1, a_2, \ldots, a_k$$$, where the array with index $$$i$$$ contains $$$l_i$$$ elements. Let $$$n = l_1 + l_2 + \ldots + l_k$$$.
You need to find $$$k$$$ integers $$$d_1, d_2, \ldots, d_k$$$ such that the numbers $$$(a_{i,j} + d_i)$$$ are pairwise distinct and satisfy $$$1 \leq a_{i,j} + d_i \leq n$$$.
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^4$$$, $$$1 \le k \le 5$$$) – the total number of elements in the arrays and the number of arrays, respectively.
The next $$$k$$$ lines contain the arrays. The $$$i$$$-th line contains an integer $$$l_i$$$ ($$$1\le l_i\le n$$$) and $$$l_i$$$ integers $$$a_{i,1},a_{i,2},\ldots,a_{i,l_i}$$$ ($$$1 \le a_{i,j} \le n$$$) – the length and elements of the $$$i$$$-th array, respectively.
It is guaranteed that $$$n = l_1 + l_2 + \ldots + l_k$$$.
If the required values of $$$d$$$ do not exist, output a single line "No".
Otherwise, output "Yes" on the first line.
On the second line, output $$$k$$$ integers $$$d_1,d_2,\ldots,d_k$$$ – the values that need to be added to the elements of the arrays to form a total of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$.
If there are multiple correct answers, any one of them may be output.
5 5 1 1 1 2 1 3 1 4 1 5
Yes 0 0 0 0 0
6 4 2 2 3 1 6 1 4 2 1 5
Yes 1 -5 1 1
7 2 4 1 4 5 6 3 1 2 6
Yes 0 1
4 2 2 2 3 2 2 4
No
In the first example, $$$d = [0,0,0,0,0]$$$ satisfies the condition, since after adding the corresponding values, the arrays $$$[1]$$$, $$$[2]$$$, $$$[3]$$$, $$$[4]$$$, $$$[5]$$$ are formed.
In the second example, $$$d = [1,-5,1,1]$$$ satisfies the condition, since after adding the corresponding values, the arrays $$$[3,4]$$$, $$$[1]$$$, $$$[5]$$$, $$$[2,6]$$$ are formed.
In the third example, $$$d = [0,1]$$$ satisfies the condition, since after adding the corresponding values, the arrays $$$[1,4,5,6]$$$ and $$$[2,3,7]$$$ are formed.
Given an array of integers $$$a$$$ of length $$$n$$$.
You can modify the array using the addition operation. To apply the addition operation, you need to perform three sequential actions:
Find the minimum number of addition operations required to make all elements of the array $$$a$$$ pairwise distinct.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array.
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array.
Output a single integer — the minimum number of addition operations required to make all elements of the array $$$a$$$ pairwise distinct.
3 1 2 3
0
5 2 3 2 3 2
2
9 2 3 1 1 3 2 1 3 3
2
In the first example, all elements of the array $$$a$$$ are pairwise distinct.
In the second example, after applying two addition operations with parameters $$$x=-3$$$, $$$l=1$$$, $$$r=2$$$ and $$$x=-1$$$, $$$l=1$$$, $$$r=3$$$, the array $$$a$$$ becomes equal to $$$[-2,-1,1,3,2]$$$.
In the third example, after applying two addition operations with parameters $$$x=-3$$$, $$$l=4$$$, $$$r=8$$$ and $$$x=-10$$$, $$$l=7$$$, $$$r=9$$$, the array $$$a$$$ becomes equal to $$$[2,3,1,-2,0,-1,-12,-10,-7]$$$.
Let's call the median of an array of length $$$(2 \cdot k + 1)$$$ the number that appears in position $$$(k + 1)$$$ after sorting its elements in non-decreasing order. For example, the medians of the arrays $$$[1]$$$, $$$[4,2,5]$$$, and $$$[6,5,1,2,3]$$$ are $$$1$$$, $$$4$$$, and $$$3$$$, respectively.
You are given an array of integers $$$a$$$ of even length $$$n$$$.
Determine whether it is possible to split $$$a$$$ into several subarrays of odd length such that all the medians of these subarrays are pairwise equal.
Formally, you need to determine whether there exists a sequence of integers $$$i_1, i_2, \ldots, i_k$$$ such that the following conditions are satisfied:
The first line contains a single even integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the array.
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\le a_i\le 10^9)$$$ — the elements of the array.
It is guaranteed that $$$n$$$ is even.
Output "Yes" if it is possible to divide $$$a$$$ into several subarrays of odd length in such a way that all medians of these subarrays are pairwise equal, and "No" otherwise.
4 1 1 1 1
Yes
6 1 2 3 3 2 1
Yes
6 1 2 1 3 2 3
No
In the first example, the array $$$[1,1,1,1]$$$ can be divided into the arrays $$$[1]$$$ and $$$[1,1,1]$$$ with medians equal to $$$1$$$.
In the second example, the array $$$[1,2,3,3,2,1]$$$ can be divided into the arrays $$$[1,2,3]$$$ and $$$[3,2,1]$$$ with medians equal to $$$2$$$.
In the third example, the array $$$[1,2,1,3,2,3]$$$ cannot be divided into several arrays of odd length with the same median values.
This is an interactive problem.
A string is considered a palindrome if it reads the same from both sides. Formally, a string $$$s$$$ of length $$$n$$$ is considered a palindrome if $$$s_i = s_{n-i+1}$$$ for $$$1 \le i \le n$$$. For example, the strings "gg", "ara", "abacaba", and "rotator" are palindromes, while the strings "array", "palindrome", and "uoi" are not.
We call a string a nearly palindrome if its characters can be rearranged to form a palindrome. For example, the strings "n", "ara", "arr", and "array" are nearly palindromes, while the strings "palindrome", "uoi", and "random" are not.
A substring of a string is a string that can be obtained by deleting some (possibly zero) elements from its beginning and end.
Let $$$f(s)$$$ be the maximum length among the lengths of substrings of $$$s$$$ that are not nearly palindromes, or $$$0$$$ if there are no such substrings.
You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters. You are also given $$$q$$$ queries of the form $$$l_i$$$, $$$r_i$$$. For each query, find the value of $$$f(s[l_i..r_i])$$$, where $$$s[l_i..r_i]$$$ denotes the substring consisting of characters $$$s_{l_i}, s_{l_{i} + 1}, \ldots, s_{r_i}$$$.
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2\cdot 10^5$$$) — the length of the string.
The second line contains a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.
The third line contains one integer $$$q$$$ ($$$1\le q \le 2\cdot 10^5$$$) — the number of queries.
The fourth line contains two integers $$$l_1, r_1$$$ ($$$1 \leq l_1 \leq r_1 \leq n$$$) — the parameters of the first query.
You will receive the parameters of the next queries from the jury program (see section "Interaction Protocol").
For each $$$i$$$-th query, output one integer — the value of $$$f(s[l_i..r_i])$$$, in a separate line.
The jury program will output two integers $$$l_i$$$, $$$r_i$$$ ($$$1\le l_i\le r_i\le n$$$) on separate lines for each query, starting from the second one.
The jury program will not output the parameters for the next query until it reads the response of your program to the previous query.
Make sure to call the flush method after outputting each line. You can use:
8 aabaaaba 3 3 7 1 8 4 4
4 6 0
In the first example, you need to find the answers to three queries:
Let's call the weight of an array of integers $$$b$$$ of length $$$m$$$ the absolute value of the sum of its elements, i.e., $$$|b_1+b_2+...+b_m|$$$.
We define the beauty of a partition of array $$$c$$$ into several subarrays as the minimum weight among the weights of the subarrays. Formally, the beauty of a partition of array $$$c$$$ into $$$k$$$ subarrays $$$[c_1,\ldots,c_{p_1}],[c_{p_1+1},\ldots,c_{p_2}],\ldots,[c_{p_{k-1}+1},\ldots,c_{p_k}]$$$, where $$$1 \leq p_1 \lt p_2 \lt \ldots \lt p_{k-1} \lt p_k = n$$$, is the value $$$\min(|c_1+\ldots+c_{p_1}|,|c_{p_1+1}+\ldots+c_{p_2}|,\ldots,|c_{p_{k-1}+1}+\ldots+c_{p_k}|)$$$. For example, the partition of the array $$$[3,-6,4,5,-8]$$$ into subarrays $$$[3,-6],[4],[5,-8]$$$ has a beauty of $$$\min(|3+(-6)|,|4|,|5+(-8)|)=\min(3,4,3)=3$$$.
We define the beauty of an array $$$c$$$ as the maximum beauty among all possible partitions into subarrays.
An array of integers $$$a$$$ of length $$$n$$$ is given.
You need to perform $$$q$$$ queries. The queries can be of two types:
The first line contains two integers $$$n$$$, $$$q$$$ ($$$1\le n, q\le 10^6$$$) — the length of array $$$a$$$ and the number of queries, respectively.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9\le a_i\le 10^9)$$$ — the elements of array $$$a$$$.
The next $$$q$$$ lines contain three integers each. The first of the numbers, $$$type_i$$$ ($$$1 \le type_i \le 2$$$), denotes the type of the query. Queries of the first type are given in the format "1 l r" ($$$1\le l\le r\le n$$$), and queries of the second type are given in the format "2 x v" ($$$1\le x\le n,$$$ $$$-10^9\le v\le 10^9$$$).
For each query of the first type, output a single integer — the beauty of the corresponding subarray.
6 41 -3 4 2 -5 61 1 61 2 31 2 51 1 1
5 3 3 1
5 61 -2 3 -4 51 1 41 2 32 3 -61 2 42 4 21 1 5
2 2 12 7
In the first example, for the third query, the maximum beauty of the partition of the array $$$[-3,4,2,-5]$$$ is achieved when partitioned into subarrays $$$[-3],[4,2],[-5]$$$.
In the second example, for the first query, the maximum beauty of the partition of the array $$$[1,-2,3,-4]$$$ is achieved when partitioned into subarrays $$$[1,-2,3],[-4]$$$.
You are given a table $$$a$$$ of size $$$n \times m$$$, consisting of symbols "R", "G", "B".
Also, given are integers $$$c$$$ ($$$2 \leq c \leq 3$$$) and $$$q$$$, where $$$c$$$ is the number of different symbols that can appear in the table. If $$$c$$$ equals $$$2$$$, only the symbols "R" and "G" are available; if $$$c$$$ equals $$$3$$$, the symbols "R", "G", "B" are available.
You need to change the values of at most $$$q$$$ elements of the table so that there are no pairs of neighboring cells with the same value. Note that if $$$c=2$$$, using the symbol "B" when changing the values of the table cells is prohibited.
It is guaranteed that under the given constraints, there is a way to change the values of at most $$$q$$$ elements of the table so that there are no pairs of neighboring cells with the same value.
Note that there are no additional constraints in the problem.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 100$$$) — the number of rows and columns of the table $$$a$$$ respectively.
The second line contains two integers $$$c$$$ ($$$2 \leq c \leq 3$$$) and $$$q$$$, representing the number of available symbols and the number of allowed changes in the table, respectively.
The next $$$n$$$ lines contain $$$m$$$ symbols each — the elements of the table $$$a$$$. If $$$c=2$$$, then $$$a_{ij} \in $$$ {"R", "G"}. If $$$c=3$$$, then $$$a_{ij} \in $$$ {"R", "G", "B"}.
Output $$$n$$$ lines of $$$m$$$ symbols each, describing the table after the changes.
If there are multiple correct answers, any of them is allowed.
3 33 4RRRRRRRRR
RGR GRG RGR
3 22 3RGGGGR
RG GR RG
There are $$$n$$$ heroes and $$$n$$$ monsters. The heroes and monsters are numbered with integers from $$$1$$$ to $$$n$$$. The strength of the $$$i$$$-th hero is equal to $$$a_i$$$, and the strength of the $$$i$$$-th monster is equal to $$$b_i$$$. It is guaranteed that all values $$$a_1, a_2, \ldots, a_n, b_1, b_2, \ldots, b_n$$$ are pairwise distinct.
There will be a total of $$$n$$$ battles. In each battle, exactly one hero and exactly one monster will participate, with each hero and each monster participating in exactly one battle. Let the battle involve the hero with number $$$i$$$ and the monster with number $$$j$$$. If $$$a_i \gt b_j$$$, then the hero with number $$$i$$$ will be happy, otherwise, he will be sad.
Let $$$ans_k$$$ be the number of different sets of heroes $$$S$$$ of size $$$k$$$, such that there is a distribution of battles where all heroes in $$$S$$$ will be happy and all other heroes will be sad.
Given $$$q$$$ queries of the form $$$l$$$, $$$r$$$. For each query, find $$$(\sum\limits_{i=l}^{r} ans_i) \mod 998244353$$$.
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^3$$$) — the number of battles that will take place.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the strengths of the heroes.
The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ $$$(1 \leq b_i \leq 2 \cdot n)$$$ — the strengths of the monsters.
It is guaranteed that all values $$$a_1, a_2, \ldots, a_n, b_1, b_2, \ldots, b_n$$$ are pairwise distinct.
The fourth line contains a single integer $$$q$$$ $$$(1 \leq q \leq n+1)$$$ — the number of queries.
The next $$$q$$$ lines contain two integers each, $$$l$$$ and $$$r$$$ $$$(0 \leq l \leq r \leq n)$$$ — the parameters of the corresponding query.
It is guaranteed that all values $$$a_1, a_2, \ldots, a_n, b_1, b_2, \ldots, b_n$$$ are pairwise distinct.
For each query, output a single integer — the required value $$$(\sum\limits_{i=l}^{r} ans_i) \mod 998244353$$$.
33 4 61 2 531 22 33 3
2 3 1
The image below shows the heroes and monsters of the first example. The heroes are at the top, and the monsters are at the bottom. The number inside the square represents the strength of the corresponding hero or monster.
In the example, there are three possible sets of happy heroes: $$$\{1,2,3\}$$$, $$$\{2,3\}$$$, and $$$\{1,3\}$$$. Below are three possible distributions of battles in which the corresponding sets of heroes will be happy. Note that there may be multiple distributions of battles where the same set of heroes will be happy.
There are $$$n$$$ types of boys and $$$2 \cdot n$$$ girls. The types of boys are numbered with integers from $$$1$$$ to $$$n$$$, while the girls are numbered with integers from $$$1$$$ to $$$2 \cdot n$$$.
There are $$$c_i$$$ boys of the $$$i$$$-th type, and each of them likes girls numbered $$$a_i$$$ and $$$b_i$$$.
Find the size of the largest set of boys such that for every pair of boys in this set, there is at least one girl that both of them like.
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 $$$T$$$ $$$(1 \le T \le 500)$$$ — 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 $$$n$$$ $$$(1 \le n \le 7 \cdot 10^5)$$$.
In the next $$$n$$$ lines, there are three integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$ $$$(1 \le a_i \lt b_i \le 2 \cdot n, 1 \le c_i \le 10^9)$$$ — the parameters for the corresponding type of boys.
It is guaranteed that $$$a_i \ne a_j$$$ or $$$b_i \ne b_j$$$ for any $$$1 \le i \lt j \le n$$$.
It is guaranteed that the sum of $$$n$$$ across all input data sets of a single test does not exceed $$$7 \cdot 10^5$$$.
For each set of input data, output one integer on a separate line — the size of the largest set of boys such that for every pair of boys in this set, there is at least one girl that both of them like.
Let $$$S$$$ be the sum of $$$n$$$ over all test case input sets of one test, and $$$K$$$ be the sum of all $$$c_i$$$ over all test case input sets of one test.
321 2 33 4 551 2 11 3 44 5 23 4 21 4 341 2 32 3 43 5 41 3 2
5 9 10
There are $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ arranged in a circle. The neighboring numbers in the circular order are $$$a_1$$$ and $$$a_2$$$, $$$a_2$$$ and $$$a_3$$$, $$$\ldots$$$, $$$a_{n-1}$$$ and $$$a_n$$$, $$$a_n$$$ and $$$a_1$$$.
Partition these numbers into three non-empty groups such that each number belongs to exactly one group, the numbers in each group are consecutively arranged in a circle, and the difference between the maximum and minimum sums of the numbers in the groups is minimized.
The first line contains one integer $$$n$$$ $$$(3 \le n \le 10^6)$$$ — the number of arranged numbers.
The second line contains $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ $$$(0 \le a_i \le 10^9)$$$ — the numbers arranged in a circle.
In the first line, output one integer — the difference between the maximum and minimum sums of the numbers in the groups in the optimal partition.
In the second line, output three integers $$$x$$$, $$$y$$$, $$$z$$$ $$$(1 \le x \lt y \lt z \le n)$$$ — such indices that the optimal partition of the numbers into three groups is of the form $$$[a_{x}, a_{x+1}, \ldots, a_{y-1}]$$$, $$$[a_{y}, a_{y+1}, \ldots, a_{z-1}]$$$, $$$[a_{z}, a_{z+1}, \ldots, a_{n-1}, a_{n}, a_{1}, a_{2}, \ldots, a_{x-1}]$$$.
If there are multiple correct answers, any of them is allowed to be output.
41 2 3 4
1 1 3 4
71 6 1 0 5 3 2
0 2 3 6
83 1 4 1 5 9 2 6
1 3 6 8
In the third example, the optimal partition looks as follows:
In this case, the sums in the groups are $$$10$$$, $$$11$$$, and $$$10$$$.
You are given an array of integers $$$a$$$ of length $$$n$$$.
Determine whether there exists a permutation of its elements $$$b$$$ such that for every $$$2\leq i \leq n-1$$$, the condition $$$b_{i-1} + b_{i+1} \ge 2\cdot b_i$$$ holds.
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 a single integer $$$T$$$ $$$(1\le T\le 10^5)$$$ — 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 a single integer $$$n$$$ $$$(3\le n\le 3\cdot 10^5)$$$ — the length of the array $$$a$$$.
In the second line of each input data set, there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(0\le a_i\le 10^9)$$$ — the elements of the array $$$a$$$.
It is guaranteed that the sum of $$$n$$$ across all input data sets of a single test does not exceed $$$3\cdot 10^5$$$.
For each set of input data, output on a separate line "YES", if the desired permutation exists, and "NO" otherwise.
Let $$$S$$$ be the sum $$$n$$$ over all input data sets of one test.
1040 3 4 645 4 1 481 4 4 8 6 10 10 472 1 5 1 9 4 667 1 6 10 2 376 6 10 2 5 3 849 9 1 548 4 3 471 2 1 6 4 2 973 9 7 5 9 10 10
YES NO NO YES YES NO YES YES YES NO
In the first set of input data from the first example, the permutations of the array $$$[0, 3, 4, 6]$$$ that satisfy the described condition are $$$[4, 0, 3, 6]$$$ and $$$[6, 3, 0, 4]$$$.
We call an array of integers $$$d_1, d_2, \ldots, d_m$$$ good if its length is equal to $$$0$$$, or for any $$$1\le i\le m$$$, both values $$$\sum\limits_{j=1}^{i} d_j$$$ and $$$\sum\limits_{j=i}^{m} d_j$$$ are non-negative. Here, $$$\sum\limits_{j=l}^{r} d_j$$$ denotes $$$d_l+d_{l+1}+\ldots+d_{r}$$$.
We define the beauty of the array as the length of its longest good subsequence$$$^1$$$.
You are given an array $$$a$$$ of length $$$n$$$, which consists of numbers $$$-1$$$ and $$$1$$$.
You need to perform $$$q$$$ queries. The queries are of two types:
In the first line, two integers $$$n$$$, $$$q$$$ are given $$$(1\le n, q\le 5 \cdot 10^5)$$$ — the length of the array $$$a$$$ and the number of queries, respectively.
In the second line, $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(a_i \in \{-1, 1\})$$$ are given — the elements of the array $$$a$$$.
In the next $$$q$$$ lines, the description of the queries is given. The first of the numbers $$$type_i$$$ $$$(1 \le type_i \le 2)$$$ denotes the type of the query. Queries of the first type are given in the format "1 p" $$$(1 \le p \le n)$$$, and queries of the second type are given in the format "2 l r" $$$(1 \le l \le r \le n)$$$.
For each query of the second type, output one integer in a separate line — the beauty of the corresponding array.
5 41 1 1 -1 12 1 51 32 1 42 2 5
5 2 3
4 41 1 1 -12 1 22 2 42 3 32 3 4
2 2 1 1
$$$^1$$$ An array $$$c$$$ is called a subsequence of an array $$$b$$$ if it is possible to remove a certain number of elements from the array $$$b$$$ (possibly zero) so that the array $$$c$$$ is formed. The empty array is a subsequence of any array.
For a pair of points on the Cartesian plane $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$, we define the Manhattan distance between them as $$$|x_1-x_2|+|y_1-y_2|$$$. For example, for the pair of points $$$(4, 1)$$$ and $$$(2, 7)$$$, the Manhattan distance between them is $$$|4-2|+|1-7| = 2+6 = 8$$$.
You are given $$$2 \cdot n$$$ points on the Cartesian plane, whose coordinates are integers. All $$$y$$$-coordinates of the given points are either $$$0$$$ or $$$1$$$.
Split the given points into $$$n$$$ pairs such that each of these points belongs to exactly one pair, and the maximum Manhattan distance between the points of one pair is minimized.
The first line contains a single integer $$$n$$$ $$$(1 \le n \le 10^5)$$$.
In the following $$$2 \cdot n$$$ lines, each line contains two integers $$$x_i$$$ and $$$y_i$$$ $$$(0 \le x_i \le 10^9, 0 \le y_i \le 1)$$$ — the coordinates of the corresponding point.
Output a single integer — the maximum Manhattan distance between the points of one pair in the optimal partition.
13 11 0
3
318 03 01 010 08 014 0
4
43 00 15 02 16 03 05 12 1
2
In the second example, the pairing $$$[(18, 0), (14, 0)]$$$, $$$[(3, 0), (1, 0)]$$$, and $$$[(8, 0), (10, 0)]$$$ is the only optimal partition. The Manhattan distances between the points of one pair in this partition are $$$4$$$, $$$2$$$, and $$$2$$$, respectively.
In the third example, the pairing $$$[(0, 1), (2, 1)]$$$, $$$[(2, 1), (3, 0)]$$$, $$$[(3, 0), (5, 0)]$$$, and $$$[(5, 1), (6, 0)]$$$ is an optimal partition. All Manhattan distances between the points of one pair in this partition are equal to $$$2$$$.
Given a string $$$s$$$ consisting of characters $$$\texttt{A}$$$, $$$\texttt{B}$$$, and $$$\texttt{C}$$$.
In one operation, you are allowed to choose two adjacent elements of the string $$$s_is_{i+1}$$$ that are in the following order: $$$\texttt{AB}$$$, $$$\texttt{BC}$$$, or $$$\texttt{CA}$$$, and swap them.
Find the maximum number of consecutive operations that can be performed on the string $$$s$$$.
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 $$$T$$$ $$$(1\le T\le 10^5)$$$ — 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 $$$n$$$ $$$(1 \le n \le 10^6)$$$ — the length of the string $$$s$$$.
In the second line of each input data set, there is a string $$$s$$$ of length $$$n$$$, consisting of characters $$$\texttt{A}$$$, $$$\texttt{B}$$$, and $$$\texttt{C}$$$.
It is guaranteed that the sum of $$$n$$$ across all input data sets of a single test does not exceed $$$10^6$$$.
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 $$$s$$$.
Let $$$K$$$ be the sum of $$$n$$$ over all input data sets of one test.
25ABCCA19CCAABBBABBAAABBCCAA
3 28
In the first set of input data from the first example, no more than $$$3$$$ consecutive operations can be performed on the string ABCCA. One example of how $$$3$$$ consecutive operations can be performed is [ABCCA $$$\rightarrow$$$ BACCA, BACCA $$$\rightarrow$$$ BACAC, BACAC $$$\rightarrow$$$ BAACC].