{"raw_statement":[{"iden":"statement","content":"Farmer John has $N$ cows $(2 \\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 $1 \\cdots N$ in this order.\n\nOver the course of the day, each cow writes down a list of cows. Specifically, cow $i$\n's list contains the range of cows starting with herself (cow $i$) up to and including cow $E_i(i \\le E_i \\le N)$.\n\nFJ 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).\n\nHelp FJ count the number of pairs of cows that could be leaders. It is guaranteed that there is at least one possible pair. "},{"iden":"input","content":"The first line contains $N$.\n\nThe second line contains a string of length $N$\n, with the ith character denoting the breed of the $i$-th cow (G meaning Guernsey and H meaning Holstein). It is guaranteed that there is at least one Guernsey and one Holstein.\n\nThe third line contains $E_1 \\cdots E_N$. "},{"iden":"output","content":"Output the number of possible pairs of leaders. "},{"iden":"note","content":"### Explanation for Sample 1\n\nThe only valid leader pair is $(1,2)$. Cow $1$'s list contains the other breed's leader (cow $2$). Cow $2$'s list contains all cows of her breed (Holstein).\n\nNo other pairs are valid. For example, $(2,4)$\nis invalid since cow $4$'s list does not contain the other breed's leader, and it also does not contain all cows of her breed.\n\n### Explanation for Sample 2\n\nThere are two valid leader pairs, $(1,3)$ and $(2,3)$.\n\n### Scoring\n\n - Inputs $3-5$: $N \\le 100$  \n - Inputs $6-10$: $N \\le 3000$\n - Inputs $11-17$: No additional constraints."}],"translated_statement":null,"sample_group":[["4\nGHHG\n2 4 3 4","1"],["3\nGGH\n2 3 3","2"]],"show_order":[],"formal_statement":null,"simple_statement":null,"has_page_source":false}