http://codeforces.com/contest/1092/problem/D1

Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.

The current state of the wall can be respresented by a sequence aa of nn integers, with aiai being the height of the ii-th part of the wall.

Vova can only use 2×12×1 bricks to put in the wall (he has infinite supply of them, however).

Vova can put bricks horizontally on the neighboring parts of the wall of equal height. It means that if for some ii the current height of part iiis the same as for part i+1i+1, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part 11 of the wall or to the right of part nn of it).

The next paragraph is specific to the version 1 of the problem.

Vova can also put bricks vertically. That means increasing height of any part of the wall by 2.

Vova is a perfectionist, so he considers the wall completed when:

  • all parts of the wall has the same height;
  • the wall has no empty spaces inside it.

Can Vova complete the wall using any amount of bricks (possibly zero)?

Input

The first line contains a single integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of parts in the wall.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the initial heights of the parts of the wall.

Output

Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero).

Print "NO" otherwise.

Examples
input

Copy
5
2 1 1 2 5
output

Copy
YES
input

Copy
3
4 5 3
output

Copy
YES
input

Copy
2
10 10
output

Copy
YES
input

Copy
3
1 2 3
output

Copy
NO
Note

In the first example Vova can put a brick on parts 2 and 3 to make the wall [2,2,2,2,5][2,2,2,2,5] and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it [5,5,5,5,5][5,5,5,5,5].

In the second example Vova can put a brick vertically on part 3 to make the wall [4,5,5][4,5,5], then horizontally on parts 2 and 3 to make it [4,6,6][4,6,6] and then vertically on part 1 to make it [6,6,6][6,6,6].

In the third example the wall is already complete.

代码:

#include <bits/stdc++.h>
using namespace std; int N;
stack<int> s; int main() {
scanf("%d", &N);
for(int i = 0; i < N; i ++) {
int x;
scanf("%d", &x);
if(s.empty())
s.push(x);
else {
if(abs(s.top() - x) % 2)
s.push(x);
else s.pop();
}
} if(s.size() > 1) printf("NO\n");
else printf("YES\n");
return 0;
}

  相邻的两个墙的高度差是 2 的倍数就可以了

CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)的更多相关文章

  1. CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)

    http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...

  2. Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...

  3. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  4. CodeForces Round #527 (Div3) C. Prefixes and Suffixes

    http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...

  5. CodeForces Round #527 (Div3) A. Uniform String

    http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...

  6. D1. Great Vova Wall (Version 1)

    链接 [https://codeforces.com/contest/1092/problem/D1] 题意 给你n个位置墙的高度,现在你有2×1 砖块,你可以竖直或者水平放置 问你是否可以使得所有位 ...

  7. Codeforces Round #602 Div2 D1. Optimal Subsequences (Easy Version)

    题意:给你一个数组a,询问m次,每次返回长度为k的和最大的子序列(要求字典序最小)的pos位置上的数字. 题解:和最大的子序列很简单,排个序就行,但是题目要求字典序最小,那我们在刚开始的时候先记录每个 ...

  8. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  9. Codeforces Round #527 (Div. 3)

    一场div3... 由于不计rating,所以打的比较浪,zhy直接开了个小号来掉分,于是他AK做出来了许多神仙题,但是在每一个程序里都是这么写的: 但是..sbzhy每题交了两次,第一遍都是对的,结 ...

随机推荐

  1. Leecode刷题之旅-C语言/python-231 2的幂

    /* * @lc app=leetcode.cn id=231 lang=c * * [231] 2的幂 * * https://leetcode-cn.com/problems/power-of-t ...

  2. C语言——第一章,1.4程序开发过程

    1.4程序开发过程 一,开发过程 1,分析问题,设计一种解决问题的途径(方案)★ 2,写出源代码 (*.c) 3,编译→(连接)   *.obj→(*.exe) 4,运行*.exe (可执行程序) 二 ...

  3. SSM-CRUD入门项目——查询

    查询 1.基础查询 分析:访问项目主页 index.jsp 时应该跳转到列表页 我们可以在index.jsp发出查询员工列表请求,来到 list.jsp 使用插件 pageHelper 完成分页功能— ...

  4. 版本控制工具(下)——Git的远程仓库、分支管理与其它操作

    预备知识: SSH协议参考资料:http://blog.csdn.net/vevenlcf/article/details/43273405 图解公钥和私钥:http://blog.csdn.net/ ...

  5. SSM-CRUD入门项目——删除

    删除 分析 可以进行单个删除,直接点击每条记录后的删除按钮 批量删除,通过勾选checkbox框进行选择删除 单个删除: 通过发送DELETE请求的URL:/emp/{id} 这次我们先从contro ...

  6. 20155231 信息安全技术概论实验二 Windows口令破解

    20155231 信息安全技术概论实验二 Windows口令破解 实验目的 了解Windows口令破解原理 对信息安全有直观感性认识 能够运用工具实现口令破解 实验人数 每组一人 系统环境 windo ...

  7. HTML 5 +CSS3 + 原生js 做(雪花全屏飘落 + 3d旋转图)

    原文:HTML 5 +CSS3 + 原生js 做(雪花全屏飘落 + 3d旋转图) 3d旋转图:主要用css3中transform属性中的rotate,translate;以及用来做舞台效果的 pers ...

  8. installshield 判断mdmcpq.inf和usbser.sys 是否 存在

    1.产品上位机程序,需要驱动支持,在安装  exe程序的时候,连同NET框架4.0和 .inf驱动文件,一起安装, 安装驱动的时候,会发现, 如果系统 C:\Windows\Inf 缺少mdmcpq. ...

  9. 使用github高级搜索

    想瞅瞅github上面有哪些中国开发者最活跃,followers最多.可以按照下面的步骤: 打开github的搜索页面 输入 location:china .点search 然后选择不同的排序方式. ...

  10. Linux 的字符串截取

    假设有变量 var=http://www.aaa.com/123.htm 1. # 号截取,删除左边字符,保留右边字符. echo ${var#*//} 其中 var 是变量名,# 号是运算符,*// ...