Palindrome

시간 제한1초메모리 제한512 MB

요약
0과 1로 이루어진 문자열에서 문자 하나를 문자열 끝으로 옮기는 연산을 반복해 팰린드롬으로 만들 때 필요한 최소 이동 횟수를 구하고, 불가능하면 -1을 출력한다.
난이도

보통10점 중 5점

유형
문자열, 그리디, 완전 탐색
정답자
아직 제출이 없습니다

문제

Zenyk bought a string of length n, which contains only 0 and 1 characters. He wants to present it to Marichka, however he knows that she likes only palindromes (strings which read the same backward as forward) and she will be satisfied with just such a gift.

In one hour, Zenyk can change the string by moving any one of its characters to the end of the string. What is the minimum number of hours needed for Zenyk to prepare a gift for Marichka?

입력

The first line contains one integer n (1 ≤ n ≤ 300). The second line contains a string of length n containing only 0 and 1 characters.

출력

If Zenyk succeeds in preparing a gift then print one integer — the minimum number of hours.

If he can’t do that print “-1” (without quotes).

예제3

  1. 예제 1

    입력
    7
    1101001
    
    예상 출력
    1
    
  2. 예제 2

    입력
    4
    1001
    
    예상 출력
    0
    
  3. 예제 3

    입력
    12
    110100010011
    
    예상 출력
    3