#L9010. [USACO23JAN] Leaders B
[USACO23JAN] Leaders B
P9010 [USACO23JAN] Leaders B
题目描述
Farmer John has cows . Each cow has a breed that is either Guernsey or Holstein. As is often the case, the cows are standing in a line, numbered in this order.
Over the course of the day, each cow writes down a list of cows. Specifically, cow 's list contains the range of cows starting with herself (cow ) up to and including cow .
FJ has recently discovered that each breed of cow has exactly one distinct leader. FJ does not know who the leaders are, but he knows that each leader must have a list that includes all the cows of their breed, or the other breed's leader (or both).
Help FJ count the number of pairs of cows that could be leaders. It is guaranteed that there is at least one possible pair.
输入格式
The first line contains .
The second line contains a string of length , with the ith character denoting the breed of the -th cow (G meaning Guernsey and H meaning Holstein). It is guaranteed that there is at least one Guernsey and one Holstein.
The third line contains .
输出格式
Output the number of possible pairs of leaders.
输入输出样例 1
4
GHHG
2 4 3 4
1
输入输出样例 2
3
GGH
2 3 3
2
说明/提示
Explanation for Sample 1
The only valid leader pair is . Cow 's list contains the other breed's leader (cow ). Cow 's list contains all cows of her breed (Holstein).
No other pairs are valid. For example, is invalid since cow 's list does not contain the other breed's leader, and it also does not contain all cows of her breed.
Explanation for Sample 2
There are two valid leader pairs, and .
Scoring
- Inputs :
- Inputs :
- Inputs : No additional constraints.