logo AlgoBeat OnlineJudge
登录 注册

#215828. [JAG 2025 Summer Camp #2] 00 → 1

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

For any binary string , define as follows.

You may apply the following three operations on any number of times (possibly zero), in any order:

  • Operation 1: Swap two adjacent characters.
  • Operation 2: Choose a contiguous substring "00" and replace it with "1".
  • Operation 3: Choose a contiguous substring "11" and replace it with "0".

Let be the minimum number of operations required to make the string equal to either "0", "1", or "01". If it is impossible to transform into any of these strings, we define .

You are given a binary string .

Compute .

输入格式

The input consists of a single test case of the following format.

The first line contains an integer (), the length of the string. The second line contains a binary string . Each character () is either '0' or '1'.

输出格式

Print the answer.

样例

样例输入 1

4
0100

样例输出 1

10

样例输入 2

10
1110001100

样例输出 2

152