#arc104b. [arc104_b]DNA Sequence

[arc104_b]DNA Sequence

Problem Statement

We have a string SS of length NN consisting of A, T, C, and G.

Strings T1T_1 and T2T_2 of the same length are said to be complementary when, for every ii (1leqileql1 \\leq i \\leq l), the ii-th character of T1T_1 and the ii-th character of T2T_2 are complementary. Here, A and T are complementary to each other, and so are C and G.

Find the number of non-empty contiguous substrings TT of SS that satisfies the following condition:

  • There exists a string that is a permutation of TT and is complementary to TT.

Here, we distinguish strings that originate from different positions in SS, even if the contents are the same.

Constraints

  • 1leqNleq50001 \\leq N \\leq 5000
  • SS consists of A, T, C, and G.

Input

Input is given from Standard Input in the following format:

NN SS

Output

Print the number of non-empty contiguous substrings TT of SS that satisfies the condition.


Sample Input 1

4 AGCT

Sample Output 1

2

The following two substrings satisfy the condition:

  • GC (the 22-nd through 33-rd characters) is complementary to CG, which is a permutation of GC.
  • AGCT (the 11-st through 44-th characters) is complementary to TCGA, which is a permutation of AGCT.

Sample Input 2

4 ATAT

Sample Output 2

4

The following four substrings satisfy the condition:

  • AT (the 11-st through 22-nd characters) is complementary to TA, which is a permutation of AT.
  • TA (the 22-st through 33-rd characters) is complementary to AT, which is a permutation of TA.
  • AT (the 33-rd through 44-th characters) is complementary to TA, which is a permutation of AT.
  • ATAT (the 11-st through 44-th characters) is complementary to TATA, which is a permutation of ATAT.

Sample Input 3

10 AAATACCGCG

Sample Output 3

6