time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Given an array a=[a1,a2,…,an]a=[a1,a2,…,an] of nn positive integers, you can do operations of two types on it:

  1. Add 11 to every element with an odd index. In other words change the array as follows: a1:=a1+1,a3:=a3+1,a5:=a5+1,…a1:=a1+1,a3:=a3+1,a5:=a5+1,….
  2. Add 11 to every element with an even index. In other words change the array as follows: a2:=a2+1,a4:=a4+1,a6:=a6+1,…a2:=a2+1,a4:=a4+1,a6:=a6+1,….

Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.

Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.

Input

The first line contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases.

The first line of each test case contains an integer nn (2≤n≤502≤n≤50) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1031≤ai≤103) — the elements of the array.

Note that after the performed operations the elements in the array can become greater than 103103.

Output

Output tt lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and "NO" otherwise.

You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

Example

input

Copy

4
3
1 2 1
4
2 2 2 3
4
2 2 2 2
5
1000 1 1000 1 1000

output

Copy

YES
NO
YES
YES

Note

For the first test case, we can increment the elements with an even index, obtaining the array [1,3,1][1,3,1], which contains only odd numbers, so the answer is "YES".

For the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so the answer is "NO".

For the third test case, all elements already have the same parity so the answer is "YES".

For the fourth test case, we can perform one operation and increase all elements at odd positions by 11, thus obtaining the array [1001,1,1001,1,1001][1001,1,1001,1,1001], and all elements become odd so the answer is "YES".

解题说明:此题找规律能发现必须要保证数列奇数位置奇偶状态一致,偶数位置也是同样的道理,只需要判断前两个,后面遍历即可。

#include<stdio.h>
int main()
{int t, n, a[52], b1, b2, i, flag;scanf("%d", &t);while (t--) {flag = 0;scanf("%d", &n);scanf("%d", &a[1]);scanf("%d", &a[2]);b1 = a[1] % 2;b2 = a[2] % 2;if (n>2) {for (i = 3; i <= n; i++){scanf("%d", &a[i]);if (i % 2 == 1) {if (a[i] % 2 != b1){flag = 1;}}else {if (a[i] % 2 != b2){flag = 1;}}}}if (flag == 0){printf("YES\n");}else{printf("NO\n");}}return 0;
}

C. Odd/Even Increments相关推荐

  1. 【cf】Codeforces Round #784(Div 4)

    由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...

  2. Codeforces Round #784 (Div. 4)

    A. Division? Codeforces separates its users into 4 divisions by their rating: For Division 1: 1900≤r ...

  3. 【Codeforces Round #784 (Div. 4)】【AK题解】

    2022年4月30日19:43:21 文章目录 2022年4月30日19:43:21 A. Division? 题目描述 测试样例 题解 B. Triple 题目描述 测试样例 题解 C. Odd/E ...

  4. Codeforces Round #784 (Div. 4)(A~F)

    更好的阅读体验 \color{red}{更好的阅读体验} 更好的阅读体验 文章目录 A. Division? B. Triple C. Odd/Even Increments D. Colorful ...

  5. 关于SIGBUS 信号

    最近遇到一个程序因为收到 SIGBUS死机的问题.刚开始不清楚是哪个模块导致的,用 address sanitizer 也查不出来. 后来想了一下,可以用gdb来执行程序,当收到了 BUS 消息的时候 ...

  6. Even-Odd Increments

    Even-Odd Increments You are given nn of integers a_1, a_2, \ldots, a_na1​,a2​,-,an​. Process qq quer ...

  7. P2955 [USACO09OCT]奇数偶数Even? Odd?

    题目描述 Bessie's cruel second grade teacher has assigned a list of N (1 <= N <= 100) positive int ...

  8. 【Codeforces1327A】: Sum of Odd Intergers C/C++题解

    Sum of Odd Intergers 题解 Codeforces[1327A]: Sum of Odd Intergers题解 一.题目描述 二.解题思路 三.注意事项 四.完整代码 五.另一种不 ...

  9. C++Odd Even Sort奇偶排序的实现算法(附完整源码)

    C++Odd Even Sort奇偶排序的实现算法 C++Odd Even Sort奇偶排序的实现算法完整源码(定义,实现,main函数测试) C++Odd Even Sort奇偶排序的实现算法完整源 ...

最新文章

  1. POJ 2391 Ombrophobic Bovines ★(Floyd+二分+拆点+最大流)
  2. android 8.0的imei简书,Android 8.0通知栏渠道,渠道组的适配和使用
  3. idea中package和directory的区别
  4. “触达率图”新功能上线,量化网页浏览深度
  5. PagedList.Mvc只有一行时不显示分页
  6. 程序员硬核宝典(面试题集、在线免费工具箱)
  7. 学习 WCF (4)--学会使用配置文件
  8. sql server 修改IDENTITY 字段 的统计当前值
  9. HttpClientFactory的套路,你知多少?
  10. C#笔记14 LINQ
  11. nodejs小问题:express不是内部或外部命令
  12. 全行业产业链图示(摘自企查查)
  13. 调用腾讯云短信API接口
  14. 卡尔曼滤波原理及公式推导
  15. PCB表面贴片元件的手工焊接技巧
  16. 无线流媒体网关改变视频会议室
  17. matlab julia分形图,Three.js 朱丽亚集(Julia set)分形图案
  18. c语言x的n次方怎么写_C语言入门教程(三)进制与操作符
  19. 基于C++实现平台类对战游戏
  20. IDEA推出新字体,极度舒适

热门文章

  1. 图说全球浏览器市场份额变迁史
  2. 计算机组成与体系结构(软件设计师考试)
  3. 四层负载均衡 动静分离和资源分离 Rewrite rewrite伪静态实例
  4. Arcmap矢量数据的基础编辑
  5. 王炸-GPT4.0的新能力与商业价值
  6. Context-free grammar 与 BNF,ASN.1
  7. 专访网秦创始人林宇:我曾每天戴20公斤手铐 生不如死
  8. 吕著三国史话(观后感一)
  9. 在线EXCEL编辑器-Luckysheet
  10. 有一种选择叫女程(2)