#3953. [USACO23JAN] Leaders B
[USACO23JAN] Leaders B
题面描述
FJ 有 头奶牛,每一头奶牛的品种是根西岛 G
或荷斯坦 H
中的一种。
每一头奶牛都有一个名单,第 头奶牛的名单上记录了从第 头奶牛到第 头奶牛的所有奶牛。
每一种奶牛都有且仅有一位“领导者”,对于某一头牛 ,如果它能成为“领导者”仅当它满足以下条件的至少一个:
- 其记录的名单上包含它的品种的所有奶牛。
- 其记录的名单上记录了另一品种奶牛的“领导者”。
请求出有多少对奶牛可能成为两种奶牛的领导者,保证存在至少一种。
数据范围
对于 的数据:。
输入格式
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
样例输入 #1
4
GHHG
2 4 3 4
样例输出 #1
1
样例 #2
样例输入 #2
3
GGH
2 3 3
样例输出 #2
2