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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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 .
Given the final string , determine the minimum possible length of the original string.
Input
- The first line contains an integer , the length of the final string.
- The second line contains a binary string of exactly characters, each either
0or1.
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): ; ; every character of is either
0or1. - Subtask 2 (30 points): ; ; every character of is either
0or1. - Subtask 3 (50 points): ; ; every character of is either
0or1.
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.