AT_abc485_d [ABC485D] ABC|ABC|ABC
Description
You are given a string $ S $ of length $ N $ consisting of `A`, `B`, and `C`.
We split $ S $ at two positions to divide it into three non-empty substrings. Formally, let $ S_k $ denote the $ k $ -th character of $ S $ ; we choose a pair of integers $ (i, j) $ such that $ 1 \leq i < j < N $ , and divide $ S $ into three substrings $ S_1S_2 \ldots S_i $ , $ S_{i + 1}S_{i + 2} \ldots S_j $ , and $ S_{j + 1}S_{j + 2} \ldots S_N $ .
Find the number of ways to split $ S $ such that each of the three substrings contains all of `A`, `B`, and `C`.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ S $
Output Format
Print the answer.
Explanation/Hint
### Sample Explanation 1
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`.
### Constraints
- $ 3 \leq N \leq 3 \times 10^5 $
- $ N $ is an integer.
- $ S $ is a string of length $ N $ consisting of `A`, `B`, and `C`.