PivotOJ

Palindromic Length

시간 제한: 500ms메모리 제한: 2048MB출처: ICPC Asia Seoul Regional 2024BOJ 32835

문제

A string is called a palindrome if it is read the same forward and backward. Palindromes are useful factors for measuring the complexity of strings like the asymmetry of the strings. The asymmetry of a string SS of length nn can be measured by its palindromic length, PL(S)PL(S), which is the minimum number of palindrome substrings into which SS can be partitioned. More precisely, PL(S)PL(S) is the minimum number tt (1 ≤ t ≤ n) such that there exist palindrome substrings S1,S2,,StS_1, S_2, \dots , S_t whose concatenation S1S2StS_1S_2 \cdots S_t becomes SS. To make it easier to distinguish, we denote a partition of SS into S1,S2,,StS_1, S_2, \dots , S_t as S1S_1 | S2S_2 | \cdots | StS_t.

For example, a string S=S = abaaca can be partitioned into two palindrome substrings as aba | aca, that is the minimum, so PL(PL(abaaca)=2) = 2. A string acaba cannot be partitioned into two palindrome substrings, but it can be partitioned into three palindrome substrings, S=S = aca | b | a or S=S = a | c | aba, so PL(PL(acaba)=3) = 3. For S=S = radar, PL(S)=1PL(S) = 1 because SS is a palindrome. PL(S)=5PL(S) = 5 for S=S = abcde.

Given a non-empty string SS of English lowercase letters, write a program to output PL(S)PL(S).

입력

Your program is to read from standard input. The input starts with a line containing a positive integer nn (1 ≤ n ≤ 100\,000), where nn is the number of letters of a string. The next line contains a string of nn English lowercase letters. Note that the string contains no space between the letters.

출력

Your program is to write to standard output. Print exactly one line. The line should contain a positive integer which is the palindromic length PL(S)PL(S) of the input string SS.

예제

예제 1

입력
6
abaaca
출력
2

예제 2

입력
5
acaba
출력
3

예제 3

입력
5
abcde
출력
5

예제 4

입력
5
radar
출력
1
코드를 제출하려면 로그인하세요.