日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2025/3/15 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces - 1110E-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

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(差分+思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。