#P9517. drink

drink

Background

Problem Description

There are nn bottles in front of you, numbered from left to right as 1n1 \sim n. Each bottle may be empty or may contain water.

You can choose a pair l,r(lr)l, r (l \le r), and then drink up all the water in bottles lrl \sim r. You want to drink all the remaining water on the table in one go. What is the minimum number of bottles you need to pick up?

It is possible that you do not need to pick up any bottle.

Input Format

The first line contains an integer nn.

The second line contains nn integers. The ii-th integer is 11 if the ii-th bottle contains water, and 00 if the ii-th bottle is empty.

Output Format

Output one integer kk, representing the minimum number of bottles to pick up.

5
0 0 0 1 0
1
6
0 0 1 1 0 1
4

Hint

Sample Explanation

In Sample 11, picking up bottle 44 is enough. In total, 11 bottle is picked up.

In Sample 22, picking up bottles 363 \sim 6 allows you to drink all the water. In total, 44 bottles are picked up.

Constraints

For 30%30\% of the testdata, it is guaranteed that n100n \le 100.

For 60%60\% of the testdata, it is guaranteed that n2000n \le 2000.

For 100%100\% of the testdata, it is guaranteed that 1n1051 \le n \le 10^5, and 0ai10 \le a_i \le 1.

Translated by ChatGPT 5