Under construction

Still being built. Things may change

Palindrome Check 2

Time limit1sMemory limit1024 MB

Summary
Given a string with some unknown positions, find the fewest adaptive queries asking whether position i holds letter c that are needed to decide if the string is a palindrome.
Level

Medium5 of 10

Topics
String, Math, Game theory
Solved
No attempts yet

문제

Ian has a string SS of length NN, where each character is one of the lowercase English letters (a, b, ⋯\cdots, z). If reading the characters of SS from back to front gives exactly SS, then SS is a palindrome. For example, abccba is a palindrome, but abccbba is not. Eunseong knows some of the characters of SS and wants to decide whether SS is a palindrome. Knowing only some characters may not be enough, so Eunseong can ask Ian the following kind of query.

  • Eunseong asks Ian for a pair (i,c)(i, c), where ii is an integer with 1≤i≤N1 \le i \le N and cc is a lowercase letter.
  • Ian answers 1 if the ii-th character of SS from the left is cc, and 0 otherwise.

Eunseong does not want to bother Ian, so Eunseong wants to decide whether SS is a palindrome with as few queries as possible. Ian answers each query right away, so the next query can depend on earlier answers. Find the smallest KK such that Eunseong can decide whether SS is a palindrome with at most KK queries, no matter what SS is.

입력

The first line contains the integer NN.

The second line contains a string TT of length NN. For each 1≤i≤N1 \le i \le N, if the ii-th character of TT is a lowercase letter, Eunseong knows that the ii-th character of SS equals the ii-th character of TT. If the ii-th character of TT is ?, Eunseong does not know the ii-th character of SS.

출력

Print on the first line the minimum number of queries that guarantees Eunseong can decide whether SS is a palindrome.

제한

  • 1≤N≤200 0001 \le N \le 200\ 000
  • Each character of SS is a lowercase English letter or ?.

Examples3

  1. Example 1

    Input
    5
    a???b
    
    Expected output
    0
    
  2. Example 2

    Input
    6
    abccb?
    
    Expected output
    1
    
  3. Example 3

    Input
    9
    abc?????a
    
    Expected output
    28