题目

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左边的那个灯之后,第二个零还是会被被打扰了,那就还需要关一个灯,这个关右边的灯就是解决这个问题的关键

Disturbed People_CodeForces1077B相关推荐

  1. Disturbed People(思维)

    There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house ...

  2. 【Disturbed People】【CodeForces - 1077B】(思维水题)

    题目: There is a house with nn flats situated on the main street of Berlatov. Vova is watching this ho ...

  3. 【Paper】2022_Fixed-Time Cooperative Tracking for Delayed Disturbed Multi-Agent Systems Under Dynamic

    2022_Fixed-Time Cooperative Tracking for Delayed Disturbed Multi-Agent Systems Under Dynamic Event-T ...

  4. Codeforces Round #521 (Div. 3) B. Disturbed People

    There is a house with nn flats situated on the main street of Berlatov. Vova is watching this house ...

  5. Codeforces 1077b Disturbed People

    题目链接 : http://codeforces.com/problemset/problem/1077/B   B. Disturbed People There is a house with n ...

  6. Codeforces 1077B Disturbed People(思维题)

    Codeforces 1077B Disturbed People(思维题) There is a house with nn flats situated on the main street of ...

  7. CodeForces Round #521 (Div.3) B. Disturbed People

    http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...

  8. Disturbed People CodeForces - 1077B

    贪心题,先关掉那些管一个灯造福两个寝室的,然后一边关灯一边统计一边继续向后判断.最后加上那些依然还受影响的寝室数(只要受影响我一定要关一盏灯),不废话,看代码: #include <iostre ...

  9. B. Disturbed People(模拟) Codeforces Round #521 (Div. 3)

    原题链接: https://codeforces.com/contest/1077/problem/B 样例: Examples Input 10 1 1 0 1 1 0 1 0 1 0 Output ...

最新文章

  1. Python2.x爬虫入门之URLError异常处理
  2. Node 即学即用 笔记 思维导图
  3. UVA - 10934 Dropping water balloons(装满水的气球)(dp)
  4. 实际工作中,一个完整的可视化大屏项目有哪些步骤?
  5. Transformer 是万能的吗?
  6. 用Maven创建第一个web项目Struts2项目
  7. PHP Mysql or条件排序问题
  8. 北京圣思园java视频教程全套_北京圣思园Java8新特性及实战视频教程完整版
  9. 格力空调售后服务管理系统
  10. linux addr2line 用法,addr2line的用法
  11. elipse配色方案
  12. 经典SFM步骤——Lowe2005
  13. 深入Scala系列之一组件重用
  14. 正心,修身,方能齐家,治国,平天下
  15. OPENSSL FIPS
  16. 08.音频系统:第002节_Android音频系统框架简述
  17. (JAVA)获取支付宝二维码 带参数
  18. 一文带你全面了解MVC、MVP、MVVM模式(实例讲解)
  19. mysql通过卡号识别银行_Java 根据银行卡号获取银行名称以及图标
  20. 逆向windows“恶搞锁机”程序

热门文章

  1. Google Chrome 更新失败(错误:3)检查更新时出错
  2. 程序员专属手机壁纸来了。。。
  3. 捣鼓nsq - 安装和运行
  4. 分词并去停用词自定义函数:seg_word(sentence)
  5. JS-移除class
  6. Nide.js安装配置
  7. 5G商用牌照正式发放!万亿级市场大门开启
  8. Windows XP 打印机端口LPT1 响应挂死 解决
  9. COPU副主席刘澎:中国开源在局部领域已接近或达到世界先进水平
  10. 基于javaweb的在线点餐+外卖配送系统