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. PrimeNG01 angular集成PrimeNG

    1 开发环境 本博文基于angular5 2 步骤 2.1 创建angular5项目 详情参见百度 2.2 下载PrimeNG依赖 npm install primeng --save npm ins ...

  2. Angular24 树形菜单 ???

    待更新... 2018年5月21日15:17:47 参考博文01 参考博文02

  3. 当this指针成为指向之类的基类指针时,也能形成多态

    this指针: 1)对象中没有函数,只有成员变量 2)对象调用函数,通过this指针告诉函数是哪个对象自己谁. #include<iostream> using namespace std ...

  4. C# 控制win7任务栏、开始菜单的显示与隐藏

    因为是做显示程序,故需要控制任务栏与开始菜单的显示与隐藏,这样就美观些.不啰嗦.直接上代码: using System; using System.Collections.Generic; using ...

  5. C# socket请求的名称有效 但是找不到请求的类型的数据

    程序以前在xp下运行一直良好,但将安装在win7下面却出现"请求的名称有效 但是找不到请求的类型的数据"错误,程序底层通信是基于socket,时间久了就会出现系统黑屏死机,但并不知 ...

  6. MVC ASP.NET MVC各个版本的区别

    ASP.NET MVC各个版本的区别 Net Framework4.5是不支持安装在window server 2003上,如非装请用net framework4.0; MVC1.0 publsh t ...

  7. ubuntu14.04,安装Git(源代码管理工具)

    在shell中执行:sudo apt-get install git-core

  8. 入门训练 Fibonacci数列 (水题)

    入门训练 Fibonacci数列   时间限制:1.0s   内存限制:256.0MB        问题描述 Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. 当n ...

  9. php代码审计9审计反序列化漏洞

    序列化与反序列化:序列化:把对象转换为字节序列的过程称为对象的序列化反序列化:把字节序列恢复为对象的过程称为对象的反序列化 漏洞成因:反序列化对象中存在魔术方法,而且魔术方法中的代码可以被控制,漏洞根 ...

  10. [Swift]八大排序算法(五):插入排序

    排序分为内部排序和外部排序. 内部排序:是指待排序列完全存放在内存中所进行的排序过程,适合不太大的元素序列. 外部排序:指的是大文件的排序,即待排序的记录存储在外存储器上,待排序的文件无法一次装入内存 ...