Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is equal to cici.

Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index ii, where 2≤i≤n−12≤i≤n−1), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge cici changes to c′i=ci+1+ci−1−cici′=ci+1+ci−1−ci.

Andrew, Grigory's friend, also has nn stones with charges titi. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory's stones into charges of corresponding Andrew's stones, that is, changes cici into titi for all ii?

Input

The first line contains one integer nn (2≤n≤1052≤n≤105) — the number of magic stones.

The second line contains integers c1,c2,…,cnc1,c2,…,cn (0≤ci≤2⋅1090≤ci≤2⋅109) — the charges of Grigory's stones.

The second line contains integers t1,t2,…,tnt1,t2,…,tn (0≤ti≤2⋅1090≤ti≤2⋅109) — the charges of Andrew's stones.

Output

If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print "Yes".

Otherwise, print "No".

Examples

Input

4
7 2 4 12
7 15 10 12

Output

Yes

Input

3
4 4 4
1 2 3

Output

No

Note

In the first example, we can perform the following synchronizations (11-indexed):

  • First, synchronize the third stone [7,2,4,12]→[7,2,10,12][7,2,4,12]→[7,2,10,12].
  • Then synchronize the second stone: [7,2,10,12]→[7,15,10,12][7,2,10,12]→[7,15,10,12].

In the second example, any operation with the second stone will not change its charge.

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>using namespace std;int a[100005],b[100005],c[100005],d[100005];
int main()
{int n;cin>>n;int flag=0;for(int t=1;t<=n;t++){scanf("%d",&a[t]);}for(int t=1;t<=n;t++){scanf("%d",&b[t]);}for(int t=1;t<=n-1;t++){c[t]=a[t+1]-a[t];}for(int t=1;t<=n-1;t++){d[t]=b[t+1]-b[t];}if(a[1]!=a[1]||a[n]!=b[n]){flag=1;}sort(c+1,c+n);sort(d+1,d+n);for(int t=1;t<=n;t++){if(c[t]!=d[t]){flag=1;}}if(!flag){puts("Yes");}else{puts("No");}return 0;
}

转载于:https://www.cnblogs.com/Staceyacm/p/10781806.html

CodeForces - 1110E-Magic Stones(差分+思维)相关推荐

  1. Codeforces.1110E.Magic Stones(思路 差分)

    题目链接 听dalao说很nb,做做看(然而不小心知道题解了). \(Description\) 给定长为\(n\)的序列\(A_i\)和\(B_i\).你可以进行任意多次操作,每次操作任选一个\(i ...

  2. Codeforces Contest 1110 problem E Magic Stones —— 更改算式

    Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal ...

  3. CF1110E Magic Stones

    CF1110E Magic Stones 题目链接:(http://codeforces.com/problemset/problem/1110/E?csrf_token=c50ced6ad87d78 ...

  4. 【CF1110E】Magic Stones

    题目 题意翻译 题意: 一次操作选择1<i<n1<i<n,使c_ic i ​ 变为c_i'c i ′ ​ ,c_i'=c_{i+1}+c_{i-1}-c_ic i ′ ​ =c ...

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

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

  6. Codeforces Round #590 (Div. 3) E. Special Permutations 差分 + 思维

    传送门 文章目录 题意: 思路: 题意: 思路: 直接考虑比较难想,这种公式题基本都是将部分答案看成一个整体,考虑xi,xi+1x_i,x_{i+1}xi​,xi+1​的贡献的. 假设当前的xi=x, ...

  7. 【codeforces 731D】【差分+线段扫描 思维题】80-th Level Archeology【给你n个word,现在要使得word按字典序排列,随便操作多少次,每次可以使每个word+1】

    传送门:http://codeforces.com/contest/731/problem/D 题意:给你n个word,每个word都有若干个字母,现在要使得从上到下的word都必须小于或等于下一个w ...

  8. CodeForces - 1343D Constant Palindrome Sum(思维+差分数组)

    题目链接:点击查看 题目大意:给出 n 个数,保证 n 是偶数,且每个数的范围都在 [ 1 , k ] 之间,现在问我们至少需要给多少个数重新赋值,使得可以满足条件: 所有的数的值域都在 [ 1 , ...

  9. CodeForces - 1000C Covered Points Count(差分+思维)

    题目链接:点击查看 题目大意:给出n个区间,现在要求输出覆盖次数为1,2,3....n-1,n的点分别有多少个 题目分析:一开始看到区间问题想用线段树去做,但想了想又可以直接用差分去做,不过因为数比较 ...

最新文章

  1. 梯度下降原理及Python实现
  2. mysql删除redo_删除redo log group or member
  3. python在财务上的应用-致工作党:Python这项技能你一定要会
  4. Primality Test 素数,打表
  5. iPad导入Mac:非常快!一气呵成,直接去photo里面选择,之后左上角倒出就好,颠覆之前windows上面的认知!
  6. 协同过滤——基于模型的算法
  7. 宁波镇海区无犯罪记录办理流程
  8. 同一个PC只能运行一个应用实例(考虑多个用户会话情况)
  9. VLAN aggregation(vlan聚合)配置
  10. 使用ReactiveCocoa实现iOS平台响应式编程
  11. 【2021考研数学汤家凤高数辅导讲义】第三章 中值定理与一元微分学的应用
  12. 解析腾讯企业邮箱到自己域名,设置mail的cname
  13. cacti 文件服务器,免费的服务器和网络监控工具-CactiEZ
  14. Informatic 体系结构
  15. 计算机电源24针,ATX电源20针和24针接口定义
  16. 斜体加粗昵称生成源码
  17. LabVIEW操作者框架(Actor Framework)范例集锦之二:视频范例
  18. 工程院院士李德毅:汽车正在被软件所改变
  19. MySQL 索引基本原则
  20. JAVA创建一个Box类(长方体),在Box类中定义三个变量,分别表示长方体的长(length)、宽(width)和高(heigth)

热门文章

  1. 使用ffmpeg打印音视频的详细信息
  2. 拔掉 MacBookPro,用 8GB 树莓派4 工作一天,体验原来是这样的
  3. 构建linux根文件系统
  4. 不恰当使用read会造成服务器阻塞
  5. python 怎么在一行获取多个数字
  6. Tensorflow2.0与Tensorflow1.0的理解
  7. Java Arrays.asList()方法详解
  8. Java基本数据类型及String类
  9. Bit-Z生态联盟正式上线 开启全球加密货币市场新征程
  10. GRPC golang版源码分析之客户端(二)