Codeforces Global Round 1 E. Magic Stones

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

Copy

4
7 2 4 12
7 15 10 12

output

Copy

Yes

input

Copy

3
4 4 4
1 2 3

output

Copy

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<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long

using namespace std;
const int maxn=1e5+100;
int a[maxn],b[maxn];
int c1[maxn],c2[maxn];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
    }
    if(a[1]!=b[1])
    {
        printf("NO\n");
        return 0;
    }
    c1[n]=a[n];
    for(int i=1;i<n;i++)
    {
        c1[i]=a[i+1]-a[i];
    }
    c2[n]=a[n];
    for(int i=1;i<n;i++)
    {
        c2[i]=b[i+1]-b[i];
    }
    sort(c1+1,c1+n+1);
    sort(c2+1,c2+1+n);
    for(int i=1;i<=n;i++)
    {
        if(c1[i]!=c2[i])
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值