[ABC485D] 三分三全字符段 (ABC|ABC|ABC)
Score : points
Problem Statement
You are given a string of length consisting of A, B, and C.
We split at two positions to divide it into three non-empty substrings. Formally, let denote the -th character of ; we choose a pair of integers such that , and divide into three substrings , , and .
Find the number of ways to split such that each of the three substrings contains all of A, B, and C.
Constraints
-
-
is an integer.
-
is a string of length consisting of
A,B, andC.
Input
The input is given from Standard Input in the following format:
$N$
$S$
Output
Print the answer.
Sample Input 1
12
AABCCABCCBCA
Sample Output 1
5
Using | to denote the positions where the string is split, there are five ways to split it: AABC|CAB|CCBCA, AABC|CABC|CBCA, AABC|CABCC|BCA, AABCC|ABC|CBCA, and AABCC|ABCC|BCA.
Sample Input 2
3
ABC
Sample Output 2
0
Sample Input 3
20
BCACABCACACABCAACBCA
Sample Output 3
65