ANA is a palindrome
InterviewTime limit1sMemory limit1024 MB
Count the substrings of S that start and end with A, contain exactly one N, and have no other A.
- Level
Easy2 of 10
- Topics
- String, Brute force
- Solved
- No attempts yet
Problem
Minyong is a devoted fan of ANA, so he studies all day in the club room even during vacation. He likes ANA because the string ANA is a palindrome, meaning it reads the same forward and backward. Minyong loves ANA so much that he defined a similar ANA string as follows.
- A similar ANA string is a string of uppercase English letters with length 3 or more.
- A similar ANA string starts and ends with the uppercase letter
A, andAdoes not appear at any other position in the string. - A similar ANA string contains exactly one uppercase letter
N.
For example, ARENA and AGENDA are similar ANA strings. However, ANACONDA is not, because it contains three As and two Ns.
Minyong was sad that a string might not be a similar ANA string. So he tries to find the similar ANA strings among the substrings of . Given a string , count how many substrings of are similar ANA strings.
Input
The first line contains the length of the string ().
The second line contains the string of length . consists of uppercase English letters.
Output
Print the number of substrings of that are similar ANA strings.
Hint
A substring is a contiguous part of a string.