Under construction

Still being built. Things may change

Palindromic Length

Time limit0.5sMemory limit2048 MB

Summary
Given a lowercase string of up to 100,000 letters, find the fewest palindromic substrings it can be split into with no overlaps.
Level

Medium7 of 10

Topics
Dynamic programming, String, String matching
Solved
No attempts yet

Problem

A string is called a palindrome if it reads the same forward and backward. Palindromes are useful for measuring the complexity of strings, such as their asymmetry.

The asymmetry of a string SS of length nn can be measured by its palindromic length, PL(S)PL(S). This is the minimum number of palindromic substrings into which SS can be partitioned. More precisely, PL(S)PL(S) is the minimum tt (1≤t≤n1 \le t \le n) such that there exist palindromic substrings S1,S2,…,StS_1, S_2, \dots, S_t whose concatenation S1S2⋯StS_1 S_2 \cdots S_t equals SS. A partition of SS into S1,S2,…,StS_1, S_2, \dots, S_t is written as S1S_1 | S2S_2 | ⋯\cdots | StS_t.

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

Input

The first line contains a positive integer nn (1≤n≤100 0001 \le n \le 100\,000), the number of letters in the string. The next line contains a string of nn English lowercase letters. The letters are not separated by spaces.

Output

Print exactly one line containing the palindromic length PL(S)PL(S) of the input string SS. The value is a positive integer.

Examples4

  1. Example 1

    Input
    6
    abaaca
    
    Expected output
    2
    
  2. Example 2

    Input
    5
    acaba
    
    Expected output
    3
    
  3. Example 3

    Input
    5
    abcde
    
    Expected output
    5
    
  4. Example 4

    Input
    5
    radar
    
    Expected output
    1