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

#PS0000120. Điểm lớn nhất khi chia xâu (Maximum Score After Splitting a String)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Điểm lớn nhất khi chia xâu (Maximum Score After Splitting a String)

Maximum Score After Splitting a String

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

A binary string ss of length nn is given. Cut it between two adjacent characters, forming two nonempty contiguous parts. The score is the count of zeros in the left part plus the count of ones in the right part. Determine the greatest achievable score.

Input

The only line contains the string ss. Let nn be its length.

Output

Print the maximum score as an integer.

Subtasks

  • Subtask 1 (20 points): 2≤n≤202\le n\le 20; si∈{0,1}s_i\in\{0,1\} for 0≤i<n0\le i<n.
  • Subtask 2 (30 points): 2≤n≤5002\le n\le 500; si=1s_i=1 for 0≤i<n0\le i<n.
  • Subtask 3 (50 points): 2≤n≤5002\le n\le 500; si∈{0,1}s_i\in\{0,1\} for 0≤i<n0\le i<n.

Example 1

Input

011101

Output

5

Explanation

Cuts after 1, 2, 3, 4, 5 characters score 5, 4, 3, 2, 3. The split 0 and 11101 yields 1 + 4 = 5, the maximum.

Example 2

Input

00111

Output

5

Explanation

The parts 00 and 111 score 2 + 3 = 5. No score exceeds the length 5.

Example 3

Input

1111

Output

3

Explanation

There are no zeros. Cutting after the first character leaves three ones on the right.