#ARC104B. [ARC104B] DNA Sequence
[ARC104B] DNA Sequence
Score : points
Problem Statement
We have a string of length consisting of A, T, C, and G.
Strings and of the same length are said to be complementary when, for every (), the -th character of and the -th character of 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 of that satisfies the following condition:
- There exists a string that is a permutation of and is complementary to .
Here, we distinguish strings that originate from different positions in , even if the contents are the same.
Constraints
- consists of
A,T,C, andG.
Input
Input is given from Standard Input in the following format:
Output
Print the number of non-empty contiguous substrings of that satisfies the condition.
4 AGCT
2
The following two substrings satisfy the condition:
GC(the -nd through -rd characters) is complementary toCG, which is a permutation ofGC.AGCT(the -st through -th characters) is complementary toTCGA, which is a permutation ofAGCT.
4 ATAT
4
The following four substrings satisfy the condition:
AT(the -st through -nd characters) is complementary toTA, which is a permutation ofAT.TA(the -st through -rd characters) is complementary toAT, which is a permutation ofTA.AT(the -rd through -th characters) is complementary toTA, which is a permutation ofAT.ATAT(the -st through -th characters) is complementary toTATA, which is a permutation ofATAT.
10 AAATACCGCG
6