Double Palindrome

시간 제한2초메모리 제한1024 MB

요약
길이가 짝수인 부분 문자열 가운데 왼쪽 절반과 오른쪽 절반이 각각 회문인 것의 개수를 센다.
난이도

어려움10점 중 8점

유형
문자열, 해시맵, 분할 정복
정답자
아직 제출이 없습니다

문제

Vanya works at the factory producing palindromes. The factory has a workpiece --- a string ss line of length nn, consisting of lowercase English letters, from which Vanya can cut out any substring for sale. We remind you that palindrome --- is a string that reads in the same way from left to right and from right to left.

A lot of people are fed up with a usual palindromes, so Vanya decided to produce double palindromes instead. Double palindrome is a string formed by a concatenation of two palindromes of equal length. For example, the strings "aabb", "aaaa" are double palindromes, while strings "abba" and "aaaabb" are not.

Vanya wonders how many ways are there to cut out double palindrome from ss. In other words, how many there are pairs (l,r)(l, r), such that substring s_ls_l+1…s_rs\_l s\_{l+1} \ldots s\_r is a double palindrome. Please help Vanya to find an answer to this question.

입력

The first line contains an integer nn (1≤n≤500,0001 \leq n \leq 500\\,000) --- the length of the string ss. The second contains a string ss, consisting of lowercase English letters.

출력

Print a single integer --- the number of double palindrome substrings.

힌트

In the first example, there are 5 double palindromes of length 2 ("ab", "ba", "ac", "ca" and "ac"), and the whole string is a double palindrome as well ("abacac").

예제2

  1. 예제 1

    입력
    6
    abacac
    
    예상 출력
    6
    
  2. 예제 2

    입력
    5
    aaaaa
    
    예상 출력
    6