#612
Silver II
Leaders
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Farmer John has NN cows (2N1052 \leq N \leq 10^5). Each cow has a breed that is either Guernsey or Holstein. As is often the case, the cows are standing in a line, numbered 1N1 \ldots N in this order.

Over the course of the day, each cow writes down a list of cows. Specifically, cow ii's list contains the range of cows starting with herself (cow ii) up to and including cow EiE_i (iEiNi \leq E_i \leq N).

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 NN.

The second line contains a string of length NN, with the iith character denoting the breed of the iith 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 E1ENE_1 \dots E_N.

출력

Output the number of possible pairs of leaders.

예제 입력 1

4
GHHG
2 4 3 4

예제 출력 1

1

예제 입력 2

3
GGH
2 3 3

예제 출력 2

2

점수

Inputs 3-5: N100N \leq 100Inputs 6-10: N3000N \leq 3000Inputs 11-17: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver II1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.