PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000008. Thêm vào hai đầu (Prepend and Append)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Thêm vào hai đầu (Prepend and Append)

Prepend and Append

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Timur starts with a binary string, which may be empty. In each operation he appends 0 to one end and 1 to the other. He may choose which character goes on the left and which goes on the right. After any number of operations, including zero, he obtains the final string ss.

Given the final string ss, determine the minimum possible length of the original string.

Input

  • The first line contains an integer nn, the length of the final string.
  • The second line contains a binary string ss of exactly nn characters, each either 0 or 1.

Output

Print one non-negative integer: the minimum possible initial length. Print 0 if the original string may have been empty.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; ∣s∣=n|s|=n; every character of ss is either 0 or 1.
  • Subtask 2 (30 points): 1≤n≤2001\le n\le 200; ∣s∣=n|s|=n; every character of ss is either 0 or 1.
  • Subtask 3 (50 points): 1≤n≤20001\le n\le 2000; ∣s∣=n|s|=n; every character of ss is either 0 or 1.

Examples

Input

4
0111

Output

2

Explanation

In 0111, the outermost 0 and 1 can be removed together. The remaining string is 11. Both ends now match, so the minimum initial length is 2.