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;
}

CodeForces - 1110E-Magic Stones(差分+思维)的更多相关文章

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

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

  2. E. Magic Stones CF 思维题

    E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. 【CF1110E】 Magic Stones - 差分

    题面 Grigory has n n magic stones, conveniently numbered from \(1\) to \(n\). The charge of the \(i\)- ...

  4. CF1110E Magic Stones 差分

    传送门 将原数组差分一下,设\(d_i = c_{i+1} - c_i\) 考虑在\(i\)位置的一次操作会如何影响差分数组 \(d_{i+1}' = c_{i+1} - (c_{i+1} + c_{ ...

  5. Magic Stones CodeForces - 1110E (思维+差分)

    E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. CF 1110 E. Magic Stones

    E. Magic Stones 链接 题意: 给定两个数组,每次可以对一个数组选一个位置i($2 \leq i \leq n - 1$),让a[i]=a[i-1]+a[i+1]-a[i],或者b[i] ...

  7. 【Codeforces 1110E】Magic Stones

    Codeforces 1110 E 题意:给定两个数组,从第一个数组开始,每次可以挑选一个数,把它变化成左右两数之和减去原来的数,问是否可以将第一个数组转化成第二个. 思路: 结论:两个数组可以互相转 ...

  8. Codeforces 1108E2 Array and Segments (Hard version)(差分+思维)

    题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利 ...

  9. Codeforces 1110E (差分)

    题面 传送门 分析 一开始考虑贪心和DP,发现不行 考虑差分: 设d[i]=c[i+1]-c[i] (i<n) 那么一次操作会如何影响差分数组呢? \(c[i]'=c[i+1]+c[i-1]-c ...

随机推荐

  1. c++ 多态问题(在虚函数里调用虚函数)

    最近在看cocos2d-x的源码,非常感激cocos2d作者的开源精神.在看代码的过程中感觉两个方向让我受益,1.把之前从书中看到的c++知识,明白了怎么运用.2.学习作者驾驭代码的巧妙方法. 看co ...

  2. 661. Image Smoother色阶中和器

    [抄题]: Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoo ...

  3. 766. Toeplitz Matrix斜对角矩阵

    [抄题]: A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now ...

  4. Linux设置串口波特率等参数

    转自 http://blog.csdn.net/zoomdy/article/details/50921336 mingdu.zheng at gmail dot com stty查看串口参数 stt ...

  5. Oracle——创建和管理表

    一.常见的数据库对象 对象 描述 表 基本的数据存储集合,由行和列组成 视图 从表中抽出的逻辑上相关的数据集合 序列 提供有规律的数值 索引 提高查询的效率 同以词 给对象起别名 二.Oracle 数 ...

  6. Python开发 第一篇 python的前世今生

    Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC ...

  7. JAVA WEB第0课

            在这学期内要掌握JAVA WAB高级网站开发的所有知识,并可以实际运用到.每周将花费20小时左右的时间来学习此门课程,每一天,在当天其他课程任务完成后将开始学习该课程,具体时间要看当天 ...

  8. 记.gitignore的一次惊心动魄

    git rm -r --cached .  #清除缓存 git add . #重新trace file git commit -m "update .gitignore" #提交和 ...

  9. HackTwo

    使用延迟加载以及避免代码重复 ​一.概要:     <include />标签是整理布局的有效工具,提供了合理组织XML布局文件的有效方法.     ViewStub是实现延迟加载视图的优 ...

  10. GCC 显示所有的warning option

    此事需求的来源是有要求调查,gcc中的那些warning是有问题的,代码必须要修改,那些事需要确认的,就要显示所有的warning选项是什么 查了下,方法如下 显示所有的warning和warning ...