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 nn integer 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 aiai is the state of light in the ii -th flat.

Output

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

Examples

Input

Copy

10
1 1 0 1 1 0 1 0 1 0

Output

Copy

2

Input

Copy

5
1 1 0 0 0

Output

Copy

0

Input

Copy

4
1 1 1 1

Output

Copy

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.

思路:倒序直接根据条件判断即可,满足就ans++,将左边的1变成0

AC代码:

#include<cstdio>
using namespace std;
int a[108];
int main()
{int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}int ans=0;for(int i=n-1;i>1;i--){if(a[i-1]==a[i+1]&&a[i-1]==1&&a[i]==0){a[i-1]=0;ans++;}}printf("%d\n",ans);return 0;
}

Codeforces Round #521 (Div. 3) B. Disturbed People相关推荐

  1. 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 ...

  2. Codeforces Round #521 (Div. 3) B - Disturbed People (贪心)

    题目链接:http://codeforces.com/contest/1077/problem/B 题意:给你一长度为n的01序列.0表示当前位置的房子灯是灭的,1表示当前房子的位置灯是亮的.判断某个 ...

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

    题解 题目大意 n个灯0关灯1开灯 101则中间的睡不着 问最少关掉多少个灯可以全都能睡着 遇见101则将后面的1的灯泡关掉 这样解决10101的问题 计数输出即可 AC代码 #include < ...

  4. 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 ...

  5. Codeforces Round #521 (Div. 3)

    题目链接:http://codeforces.com/contest/1077 A.Frog Jumping 解题思路:作差再判断最后是否还要向右跳一次即可. AC代码: 1 #include< ...

  6. Codeforces Round #521 (Div.3)题解

    A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...

  7. Codeforces Round #521 (Div. 3): F. Pictures with Kittens(DP+单调队列)

    题意: 你有n幅画,第i幅画的好看程度为ai,再给你两个数字k,x,表示你要从中选出刚好x幅画,并且相邻两幅画的距离不能≥k,好看程度之和最大能多少,选不出来输出-1,F1数据范围<200,F2 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. php arrayaccess 二维,php的ArrayAccess(数组式访问接口)
  2. Python基础——细琐知识点
  3. powershell新建python文件_powershell如何打开Python
  4. Apache Hadoop HDFS数据节点Apache Mesos框架
  5. 人工智能的概念和知识构架_概念验证:玩! 构架
  6. IDEA15 下运行Scala遇到问题以及解决办法
  7. Tomcat配置和使用——详解
  8. 小米路由 php 服务器,小米路由器在后台不停访问小米服务器发送设备信息,继续分析发现不止如此,还......
  9. apereo cas mysql_史上最详细的 Apereo CAS 5.3开发教程:二、Apereo CAS 5.3 Server环境搭建,登录名,密码从数据库中获取...
  10. 设计模式之构造函数模式
  11. 简单电脑***《菜鸟级》
  12. 冒泡排序时间复杂度计算和优化
  13. Spyder5 启动报错 spyder-kernels
  14. bch verilog代码_BCH源码学习笔记 | 第一步:搭建BCH的源码学习环境
  15. 使用Rosetta批量生成fasta
  16. (Tekla Structures二次开发)使用VS创建Tekla Structures插件的模板
  17. html页面实现打印
  18. 使用python turtle库13行代码实现奥运五环
  19. Kali下卸载程序和安装程序的方法
  20. 经典WinCC如何移植到TIA博途WinCC Professional?

热门文章

  1. gif动态图太大如何发微信?手机如何快速压缩动图?
  2. blender用视频做背景渲染动画节点设置
  3. 使用Proxmox 和 Deskpool 搭建桌面云系统
  4. php手册3.1,thinkphp3.1手册下载|thinkphp3.1手册(thinkphp3.1开发手册chm版下载)_星星软件园...
  5. win10安装—手记
  6. 白帽子挖洞第II篇作业--xray+fofa主动扫描
  7. 用css实现骰子的六个面(flex布局的学习)
  8. 重磅推出:2019中国开源年度报告
  9. 一步步教你轻松学关联规则Apriori算法
  10. mac笔记本怎么外接显示屏_Mac电脑外接显示器全攻略