#P1328. Leaders

Leaders

Description

Farmer John has NN cows (2N1052 \le N \le 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 \cdots 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 \le E_i \le 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.

Format

Input

The first line contains NN. The second line contains a string of length 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 \cdots E_n.

Output

Output the number of possible pairs of leaders.

Samples

4
GHHG
2 4 3 4
1
3
GGH
2 3 3
2

Tips

For the second simple,there are two valid leader pairs, (1,3)(1,3) and (2,3)(2,3).

Scoring

  • Inputs 353 \sim 5: N100N \le 100
  • Inputs 6106 \sim 10: N3000N \le 3000
  • Inputs 111711 \sim 17: No additional constraints.