407442: GYM102791 H String Deletion

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. String Deletiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have a string $$$s$$$ consisting of $$$n$$$ characters. Each character is either 0 or 1.

You can perform operations on the string. Each operation consists of two steps:

  1. select an integer $$$i$$$ from $$$1$$$ to the length of the string $$$s$$$, then delete the character $$$s_i$$$ (the string length gets reduced by $$$1$$$, the indices of characters to the right of the deleted one also get reduced by $$$1$$$);
  2. if the string $$$s$$$ is not empty, delete the maximum length prefix consisting of the same characters (the indices of the remaining characters and the string length get reduced by the length of the deleted prefix).

Note that both steps are mandatory in each operation, and their order cannot be changed.

For example, if you have a string $$$s =$$$ 111010, the first operation can be one of the following:

  1. select $$$i = 1$$$: we'll get 111010 $$$\rightarrow$$$ 11010 $$$\rightarrow$$$ 010;
  2. select $$$i = 2$$$: we'll get 111010 $$$\rightarrow$$$ 11010 $$$\rightarrow$$$ 010;
  3. select $$$i = 3$$$: we'll get 111010 $$$\rightarrow$$$ 11010 $$$\rightarrow$$$ 010;
  4. select $$$i = 4$$$: we'll get 111010 $$$\rightarrow$$$ 11110 $$$\rightarrow$$$ 0;
  5. select $$$i = 5$$$: we'll get 111010 $$$\rightarrow$$$ 11100 $$$\rightarrow$$$ 00;
  6. select $$$i = 6$$$: we'll get 111010 $$$\rightarrow$$$ 11101 $$$\rightarrow$$$ 01.

You finish performing operations when the string $$$s$$$ becomes empty. What is the maximum number of operations you can perform?

Input

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$.

The second line contains string $$$s$$$ of $$$n$$$ characters. Each character is either 0 or 1.

Output

Print a single integer — the maximum number of operations you can perform.

ExamplesInput
6
111010
Output
3
Input
1
0
Output
1
Input
1
1
Output
1
Input
2
11
Output
1
Input
6
101010
Output
3

加入题单

算法标签: