Disturbed People_CodeForces1077B

题目

There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of nninteger numbers a1,a2,…,ana1,a2,…,an, where ai=1ai=1 if in the ii-th flat the light is on and ai=0ai=0 otherwise.

Vova thinks that people in the ii-th flats are disturbed and cannot sleep if and only if 1<i<n1<i<n and ai−1=ai+1=1ai−1=ai+1=1 and ai=0ai=0.

Vova is concerned by the following question: what is the minimum number kk such that if people from exactly kk pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number kk.

Input

The first line of the input contains one integer nn (3≤n≤1003≤n≤100) — the number of flats in the house.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (ai∈{0,1}ai∈{0,1}), where aiaiis the state of light in the ii-th flat.

Output

Print only one integer — the minimum number kk such that if people from exactly kkpairwise distinct flats will turn off the light then nobody will be disturbed.

Examples

Input

10
1 1 0 1 1 0 1 0 1 0

Output

2

Input

5
1 1 0 0 0

Output

0

Input

4
1 1 1 1

Output

0

Note

In the first example people from flats 22 and 77 or 44 and 77 can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.

There are no disturbed people in second and third examples.

 题目大意

有一条街道,街道上有n间房子,如果某一间房子关着灯,而他左边、右边的房子都开着灯,那么他就会被打扰。

输入一个n

然后输入n个数字:0或者是1  0代表关灯,1代表开灯

要求求出最少关闭几间房子的灯就能使所有人都不被打扰

算法:模拟 

思路分析 

 一开始想到这么几种情况:101101关两个  10101关一个

但后来想只要时他关灯,左右都不关就会被打扰,然后我想她不被打扰,那我就去关掉左右中的一个灯就好了,那我每次都关掉右边的灯就好了(后边会讲到为什么关右边)

先找到第一个被打扰的房子,关掉它右边的灯,再去找第二个,关掉它右边的灯......遍历到最后一个被打扰的房子

10101这种情况 关掉第一个0后边的那个灯之后,第二个零就不被打扰了

101101这种情况 关掉第一个0后边的那个灯之后,第二个零还会被打扰,继续找第二个被打扰的房子

(至于为什么每次都关掉右边的灯:因为我是从第一个被打扰的房子开始判断的,我关掉左边的话,确实是第一个不会被打扰了,但这样就没法达到一次解决两个房子的问题,还是10101这个 我关掉第一个0左边的那个灯之后,第二个零还是会被被打扰了,那就还需要关一个灯,这个关右边的灯就是解决这个问题的关键

猜你喜欢

转载自blog.csdn.net/baidu_41907100/article/details/85130946