AtCoder Regular Contest 104
B
DNA Sequence
AtCoder
⌀ 487
原题
← AC →
翻译中…

Problem Statement

翻译中…

We have a string $S$ of length $N$ consisting of A, T, C, and G.

翻译中…

Strings $T_1$ and $T_2$ of the same length are said to be complementary when, for every $i$ ($1 \leq i \leq l$), the $i$-th character of $T_1$ and the $i$-th character of $T_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 $T$ of $S$ that satisfies the following condition:

翻译中…
  • There exists a string that is a permutation of $T$ and is complementary to $T$.
翻译中…

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

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 5000$
  • $S$ consists of A, T, C, and G.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N S

翻译中…

Output

翻译中…

Print the number of non-empty contiguous substrings $T$ of $S$ that satisfies the condition.

翻译中…

样例

Input #1
4 AGCT
Output #1
2
The following two substrings satisfy the condition: - `GC` (the $2$-nd through $3$-rd characters) is complementary to `CG`, which is a permutation of `GC`. - `AGCT` (the $1$-st through $4$-th characters) is complementary to `TCGA`, which is a permutation of `AGCT`.
Input #2
4 ATAT
Output #2
4
The following four substrings satisfy the condition: - `AT` (the $1$-st through $2$-nd characters) is complementary to `TA`, which is a permutation of `AT`. - `TA` (the $2$-st through $3$-rd characters) is complementary to `AT`, which is a permutation of `TA`. - `AT` (the $3$-rd through $4$-th characters) is complementary to `TA`, which is a permutation of `AT`. - `ATAT` (the $1$-st through $4$-th characters) is complementary to `TATA`, which is a permutation of `ATAT`.
Input #3
10 AAATACCGCG
Output #3
6
题目信息
题号
arc104_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。