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

Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le 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 $c_i$ changes to $c_i' = c_{i + 1} + c_{i - 1} - c_i$.

Andrew, Grigory's friend, also has $n$ stones with charges $t_i$. 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 $c_i$ into $t_i$ for all $i$?


-----Input-----

The first line contains one integer $n$ ($2 \le n \le 10^5$) — the number of magic stones.

The second line contains integers $c_1, c_2, \ldots, c_n$ ($0 \le c_i \le 2 \cdot 10^9$) — the charges of Grigory's stones.

The second line contains integers $t_1, t_2, \ldots, t_n$ ($0 \le t_i \le 2 \cdot 10^9$) — 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 ($1$-indexed):  First, synchronize the third stone $[7, 2, \mathbf{4}, 12] \rightarrow [7, 2, \mathbf{10}, 12]$.  Then synchronize the second stone: $[7, \mathbf{2}, 10, 12] \rightarrow [7, \mathbf{15}, 10, 12]$. 

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

Difficulty: HARD
Tags: Sorting

Mathematics

Constructive algorithms
Skill types: Sorting

Starter code:

Solutions:
cnt_num = int(input())
a_str = input()
b_str = input()
a_arr = [int(x) for x in a_str.split(' ')]
b_arr = [int(x) for x in b_str.split(' ')]
if a_arr[0] != b_arr[0] or a_arr[cnt_num - 1] != b_arr[cnt_num - 1]:
	print('No')
	exit(0)
(a_tmp_arr, b_tmp_arr) = ([], [])
for i in range(cnt_num - 1):
	a_tmp_arr.append(a_arr[i + 1] - a_arr[i])
	b_tmp_arr.append(b_arr[i + 1] - b_arr[i])
a_tmp_arr = sorted(a_tmp_arr)
b_tmp_arr = sorted(b_tmp_arr)
for i in range(cnt_num - 1):
	if a_tmp_arr[i] != b_tmp_arr[i]:
		print('No')
		exit(0)
print('Yes')
exit(0)


n = int(input())
c = list(map(int, input().split(' ')))
t = list(map(int, input().split(' ')))
check = c[0] == t[0]
c_diff = [c[i] - c[i - 1] for i in range(1, n)]
t_diff = [t[i] - t[i - 1] for i in range(1, n)]
c_diff.sort()
t_diff.sort()
if check and c_diff == t_diff:
	print('Yes')
else:
	print('No')


n = int(input())
t1 = list(map(int, input().split()))
t2 = list(map(int, input().split()))
if t1[0] != t2[0] or t2[n - 1] != t1[n - 1]:
	print('No')
	exit()
l1 = list()
l2 = list()
for i in range(0, n):
	if i == 0:
		l1.append(t1[i])
	else:
		l1.append(t1[i] - t1[i - 1])
	if i == n - 1:
		l1.append(t1[i])
for i in range(0, n):
	if i == 0:
		l2.append(t2[i])
	else:
		l2.append(t2[i] - t2[i - 1])
	if i == n - 1:
		l2.append(t2[i])
l1.sort()
l2.sort()
if l1 == l2:
	print('Yes')
else:
	print('No')


n = int(input(''))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
dpx = []
dpy = []
flag = 0
if x[0] != y[0] or x[n - 1] != y[n - 1]:
	flag = 1
for i in range(1, n):
	dpx.append(x[i] - x[i - 1])
	dpy.append(y[i] - y[i - 1])
dpx.sort()
dpy.sort()
if dpx != dpy:
	flag = 1
if flag:
	print('No')
else:
	print('Yes')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
f = a[0] == b[0]
a = sorted([a[i + 1] - a[i] for i in range(n - 1)])
b = sorted([b[i + 1] - b[i] for i in range(n - 1)])
print('YES' if f and a == b else 'NO')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
for i in range(n - 1):
	x.append(a[i + 1] - a[i])
for i in range(n - 1):
	y.append(b[i + 1] - b[i])
x.sort()
y.sort()
if x == y and a[0] == b[0] and (a[n - 1] == b[n - 1]):
	print('Yes')
else:
	print('No')


def mp():
	return map(int, input().split())
n = int(input())
c = list(mp())
t = list(mp())
a = [abs(c[i] - c[i + 1]) for i in range(n - 1)]
b = [abs(t[i] - t[i + 1]) for i in range(n - 1)]
if sorted(a) == sorted(b) and c[0] == t[0]:
	print('Yes')
else:
	print('No')


N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
S = [A[i] - A[i - 1] for i in range(1, N)]
T = [B[i] - B[i - 1] for i in range(1, N)]
S.sort()
T.sort()
if A[0] == B[0] and A[N - 1] == B[N - 1] and (S == T):
	print('Yes')
else:
	print('No')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] != b[0]:
	print('NO')
else:
	c = sorted((a[i + 1] - a[i] for i in range(n - 1)))
	d = sorted((b[i + 1] - b[i] for i in range(n - 1)))
	if c == d:
		print('YES')
	else:
		print('NO')


number = int(input())
gregory = list(map(int, input().split()))
andrew = list(map(int, input().split()))
(glen, alen) = (len(gregory), len(andrew))

def canSync(g, a):
	(gdiffs, adiffs) = ([], [])
	for i in range(1, len(g)):
		gdiffs.append(g[i] - g[i - 1])
		adiffs.append(a[i] - a[i - 1])
	gdiffs.sort()
	adiffs.sort()
	gdiffs.append(g[0])
	adiffs.append(a[0])
	return 'Yes' if gdiffs == adiffs else 'No'
print(canSync(gregory, andrew))


import sys
from atexit import register
from io import FileIO, StringIO
sys.stdin = StringIO(FileIO(0).read().decode())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : FileIO(1, 'w').write(sys.stdout.getvalue().encode()))

def main():
	n = int(input())
	c = list(map(int, input().split()))
	t = list(map(int, input().split()))
	if c[0] != t[0] or c[-1] != t[-1]:
		print('No')
		return
	(diff_c, diff_t) = ([0] * n, [0] * n)
	for i in range(n - 1):
		(diff_c[i], diff_t[i]) = (c[i + 1] - c[i], t[i + 1] - t[i])
	diff_c.sort()
	diff_t.sort()
	if diff_c == diff_t:
		print('Yes')
	else:
		print('No')
main()


from collections import defaultdict as dd
import math

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return list(map(int, input().split()))

def lm():
	return list(map(int, input().split()))
n = nn()
Gs = lm()
As = lm()
diffsG = [Gs[i] - Gs[i - 1] for i in range(1, n)]
diffsA = [As[i] - As[i - 1] for i in range(1, n)]
diffsG.sort()
diffsA.sort()
if Gs[0] == As[0] and diffsG == diffsA:
	print('Yes')
else:
	print('No')


n = int(input())
c = input().split()
t = input().split()
for i in range(n):
	c[i] = int(c[i])
	t[i] = int(t[i])
d = [0 for i in range(n - 1)]
s = [0 for i in range(n - 1)]
for i in range(n - 1):
	d[i] = c[i + 1] - c[i]
	s[i] = t[i + 1] - t[i]
d.sort()
s.sort()
index = 0
same = True
while same and index < n - 1:
	if d[index] == s[index]:
		index += 1
	else:
		same = False
if not c[0] == t[0]:
	same = False
if not c[n - 1] == t[n - 1]:
	same = False
if same:
	print('Yes')
else:
	print('No')


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def deltas(a):
	r = [0] * (len(a) - 1)
	for i in range(0, len(a) - 1):
		r[i] = a[i + 1] - a[i]
	r.sort()
	return r
n = mint()
a = list(mints())
b = list(mints())
print('Yes') if deltas(a) == deltas(b) and a[0] == b[0] else print('No')


n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))
c_diffs = [c[i] - c[i - 1] for i in range(1, n)]
t_diffs = [t[i] - t[i - 1] for i in range(1, n)]
print('Yes' if c[0] == t[0] and c[-1] == t[-1] and (sorted(c_diffs) == sorted(t_diffs)) else 'No')


n = int(input())
C = [int(a) for a in input().split()]
T = [int(a) for a in input().split()]
CC = [C[i + 1] - C[i] for i in range(n - 1)]
TT = [T[i + 1] - T[i] for i in range(n - 1)]
if C[0] == T[0] and C[-1] == T[-1] and (sorted(CC) == sorted(TT)):
	print('Yes')
else:
	print('No')


n = int(input())
y = lambda l: sorted(list((l[i + 1] - l[i] for i in range(len(l) - 1))))
z = lambda : list(map(int, input().split()))
c = z()
t = z()
print(['No', 'Yes'][c[0] == t[0] and y(c) == y(t)])


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = [a[i + 1] - a[i] for i in range(n - 1)]
b1 = [b[i + 1] - b[i] for i in range(n - 1)]
a1.sort()
b1.sort()
if a[0] != b[0] or a[-1] != b[-1]:
	print('No')
elif a1 == b1:
	print('Yes')
else:
	print('No')


from sys import setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect
setrecursionlimit(10 ** 7)

def read():
	return int(input())

def reads():
	return [int(x) for x in input().split()]
n = read()
c = reads()
t = reads()
if c[0] != t[0] or c[-1] != t[-1]:
	print('No')
	return
dc = [c[k + 1] - c[k] for k in range(n - 1)]
dt = [t[k + 1] - t[k] for k in range(n - 1)]
if sorted(dc) == sorted(dt):
	print('Yes')
else:
	print('No')


n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))

def comp(l):
	out = 0
	for v in l:
		out += v * v
	for i in range(n - 1):
		out -= l[i] * l[i + 1]
	return out
if c[0] == t[0] and t[-1] == c[-1] and (comp(c) == comp(t)):
	print('Yes')
else:
	print('No')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([a[i + 1] - a[i] for i in range(n - 1)])
d = sorted([b[i + 1] - b[i] for i in range(n - 1)])
print('YNEOS'[a[0] != b[0] or c != d::2])


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Diff1 = [A[i] - A[i - 1] for i in range(1, n)]
Diff2 = [B[i] - B[i - 1] for i in range(1, n)]
Diff1.sort()
Diff2.sort()
if A[0] == B[0] and B[-1] == A[-1] and (Diff1 == Diff2):
	print('Yes')
else:
	print('No')


def E():
	n = int(input())
	c = [int(x) for x in input().split()]
	t = [int(x) for x in input().split()]
	c_p = sorted([c[i + 1] - c[i] for i in range(n - 1)])
	t_p = sorted([t[i + 1] - t[i] for i in range(n - 1)])
	if c_p != t_p:
		print('No')
		return
	print('Yes') if c[0] == t[0] else print('No')
E()


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def dif(x):
	c = []
	for i in range(n - 1):
		c.append(x[i + 1] - x[i])
	return c
if list(sorted(dif(a))) == list(sorted(dif(b))) and a[0] == b[0] and (a[n - 1] == b[n - 1]):
	print('Yes')
else:
	print('No')


n = int(input())
L = [int(x) for x in input().split()]
S = [int(x) for x in input().split()]
D1 = [0]
D2 = [0]
for i in range(n - 1):
	D1.append(L[i + 1] - L[i])
	D2.append(S[i + 1] - S[i])
D1.sort()
D2.sort()
if D1 == D2 and L[0] == S[0]:
	print('Yes')
else:
	print('No')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == b[0] and a[-1] == b[-1]:
	q = []
	w = []
	for i in range(n - 1):
		q.append(abs(a[i + 1] - a[i]))
		w.append(abs(b[i + 1] - b[i]))
	q.sort()
	w.sort()
	if q == w:
		print('Yes')
	else:
		print('No')
else:
	print('No')


n = int(input().strip())
x = [int(tmp) for tmp in input().strip().split(' ')]
y = [int(tmp) for tmp in input().strip().split(' ')]

def solve(x, y):
	if x[0] != y[0] or x[-1] != y[-1]:
		return False
	cha_dict = {}
	for i in range(n - 1):
		cha = x[i + 1] - x[i]
		if cha not in cha_dict:
			cha_dict[cha] = []
		cha_dict[cha].append(i)
	fu_set = set()
	zheng_set = set([0])
	for i in range(n - 1):
		cha = y[i + 1] - y[i]
		is_ok = False
		if cha not in cha_dict:
			return False
		for j in cha_dict[cha]:
			if j in fu_set or j + 1 in zheng_set:
				continue
			is_ok = True
			if j in zheng_set:
				zheng_set.remove(j)
			else:
				fu_set.add(j)
			if j + 1 in fu_set:
				fu_set.remove(j + 1)
			else:
				zheng_set.add(j + 1)
			break
		if not is_ok:
			return False
	return True
if solve(x, y):
	print('Yes')
else:
	print('No')


n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))
v = []
v1 = []
if c[0] != t[0] and c[n - 1] != t[n - 1]:
	print('No')
else:
	for _ in range(n - 1):
		v.append(c[_ + 1] - c[_])
		v1.append(t[_ + 1] - t[_])
	v.sort()
	v1.sort()
	if v != v1:
		print('No')
	else:
		print('Yes')


n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))
arr_1 = [c[i] - c[i - 1] for i in range(1, n)]
arr_2 = [t[i] - t[i - 1] for i in range(1, n)]
arr_1.sort()
arr_2.sort()
if c[0] == t[0] and c[-1] == t[-1] and (arr_1 == arr_2):
	print('Yes')
else:
	print('No')


import os
import sys
from collections import deque
import pdb
import heapq
from heapq import *
from pprint import pprint
from bisect import *
if os.getcwd() == 'C:\\Users\\User\\Desktop\\python\\Prog':
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def rI():
	return [int(i) for i in input().split()]
n = rI()[0]
c = rI()
t = rI()

def rec(c):
	for i in range(1, len(c)):
		print(c[i] - c[i - 1], end=' ')
	print()
rt = []
rc = []
for i in range(1, len(c)):
	rc.append(c[i] - c[i - 1])
	rt.append(t[i] - t[i - 1])
rt.sort()
rc.sort()
if rt == rc and c[0] == t[0]:
	print('Yes')
else:
	print('No')


from collections import Counter, defaultdict, deque, namedtuple
from math import gcd
import sys

def read_ints():
	return [int(token) for token in input().split()]

def read_tokens():
	return input().split()

def differences(a):
	return (a[0], a[-1], sorted((x - y for (x, y) in zip(a, a[1:]))))

def main():
	N = read_ints()[0]
	c = differences(read_ints())
	t = differences(read_ints())
	result = 'Yes' if c == t else 'No'
	print(result)
main()


n = int(input())
c = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
new1 = []
new2 = []
for i in range(n - 1):
	new1.append(c[i + 1] - c[i])
	new2.append(t[i + 1] - t[i])
if c[0] == t[0] and c[-1] == t[-1] and (sorted(new1) == sorted(new2)):
	print('Yes')
else:
	print('No')


import sys, math

def read_int():
	return int(input().strip())

def read_int_list():
	return list(map(int, input().strip().split()))

def read_string():
	return input().strip()

def read_string_list(delim=' '):
	return input().strip().split(delim)
n = read_int()
gr = read_int_list()
an = read_int_list()
if gr[0] != an[0] or gr[-1] != an[-1]:
	print('No')
	sys.exit()
(d1, d2) = ([], [])
for i in range(n - 1):
	d1.append(gr[i + 1] - gr[i])
	d2.append(an[i + 1] - an[i])
d1.sort()
d2.sort()
if d1 == d2:
	print('Yes')
else:
	print('No')


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_elements = int(input())
first = [int(x) for x in input().split()]
secon = [int(x) for x in input().split()]
if first[-1] != secon[-1] or first[0] != secon[0]:
	print('No')
else:
	first_1 = [y - x for (x, y) in zip(first, first[1:])]
	secon_1 = [y - x for (x, y) in zip(secon, secon[1:])]
	print(['No', 'Yes'][sorted(first_1) == sorted(secon_1)])


n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))
d = lambda x: sorted((x[i + 1] - x[i] for i in range(n - 1)))
print('Yes' if c[0] == t[0] and d(c) == d(t) else 'No')


import sys
n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))
if c[0] != t[0] or c[n - 1] != t[n - 1]:
	print('No')
	sys.exit()
if n == 2:
	print('Yes')
	sys.exit()
g1 = [c[i + 1] - c[i] for i in range(n - 1)]
g2 = [t[i + 1] - t[i] for i in range(n - 1)]
if sorted(g1) == sorted(g2):
	print('Yes')
else:
	print('No')


n = int(input())
a = list(map(int, str(input()).split(' ')))
b = list(map(int, str(input()).split(' ')))
c = [0] * (n - 1)
d = [0] * (n - 1)
for i in range(n - 1):
	c[i] = a[i + 1] - a[i]
	d[i] = b[i + 1] - b[i]
c.sort()
d.sort()
if c == d and a[0] == b[0] and (a[-1] == b[-1]):
	print('Yes')
else:
	print('No')


M = int(input())
tree1 = []
tree2 = []
numbers1 = input().split()
numbers2 = input().split()
for x in range(M - 1):
	tree1 += [int(numbers1[x + 1]) - int(numbers1[x])]
tree1 = sorted(tree1)
for x in range(M - 1):
	tree2 += [int(numbers2[x + 1]) - int(numbers2[x])]
tree2 = sorted(tree2)
if tree1 == tree2 and numbers1[0] == numbers2[0]:
	print('YES')
else:
	print('NO')


def get(l):
	res = []
	for i in range(1, n):
		res.append(l[i] - l[i - 1])
	res.sort()
	return res
(n, a, b) = (int(input()), [int(_) for _ in input().split()], [int(_) for _ in input().split()])
(ma, mb) = (get(a), get(b))
print('Yes' if ma == mb and a[0] == b[0] and (a[-1] == b[-1]) else 'No')


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
array1 = [a[i] - a[i - 1] for i in range(1, n)]
array2 = [b[i] - b[i - 1] for i in range(1, n)]
array2.sort()
array1.sort()
if a[0] == b[0] and array1 == array2:
	print('Yes')
else:
	print('No')


input()
c = list(map(int, input().split()))
t = list(map(int, input().split()))
cd = []
td = []
for i in range(len(c) - 1):
	cd.append(c[i + 1] - c[i])
for i in range(len(t) - 1):
	td.append(t[i + 1] - t[i])
cd.sort()
td.sort()
if c[0] == t[0] and c[-1] == t[-1] and (cd == td):
	print('Yes')
else:
	print('No')


n = int(input())
l = input().split()
li = [int(i) for i in l]
hashi = dict()
l = input().split()
li2 = [int(i) for i in l]
if li[0] != li2[0]:
	print('No')
	quit()
diff1 = [li[i + 1] - li[i] for i in range(n - 1)]
diff2 = [li2[i + 1] - li2[i] for i in range(n - 1)]
for i in diff1:
	if i in hashi:
		hashi[i] += 1
	else:
		hashi[i] = 1
poss = 1
for i in diff2:
	if i not in hashi:
		poss = 0
		break
	if hashi[i] == 0:
		poss = 0
		break
	hashi[i] -= 1
if poss:
	print('Yes')
else:
	print('No')


n = int(input())
GR = list(map(int, input().split()))
ANDR = list(map(int, input().split()))
h = {}
k = {}
for y in range(1, n):
	if GR[y] - GR[y - 1] not in h:
		h[GR[y] - GR[y - 1]] = 0
	h[GR[y] - GR[y - 1]] += 1
for y in range(1, n):
	if ANDR[y] - ANDR[y - 1] not in k:
		k[ANDR[y] - ANDR[y - 1]] = 0
	k[ANDR[y] - ANDR[y - 1]] += 1
if h == k and ANDR[0] == GR[0] and (ANDR[-1] == GR[-1]):
	print('yes')
else:
	print('no')


from random import randrange
n = int(input())
c = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
dc = [c[i] - c[i - 1] for i in range(1, n)]
dt = [t[i] - t[i - 1] for i in range(1, n)]
dc.sort()
dt.sort()
print('Yes' if dc == dt and c[0] == t[0] else 'No')


import math
try:
	while True:
		n = int(input())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		f = a[0] == b[0]
		a = sorted([a[i + 1] - a[i] for i in range(n - 1)])
		b = sorted([b[i + 1] - b[i] for i in range(n - 1)])
		print('YES' if f and a == b else 'NO')
except:
	pass


def main():
	n = int(input())
	c = list(map(int, input().split()))
	t = list(map(int, input().split()))
	cd = [c[i + 1] - c[i] for i in range(n - 1)]
	td = [t[i + 1] - t[i] for i in range(n - 1)]
	cd.sort()
	td.sort()
	if c[0] != t[0] or c[-1] != t[-1]:
		print('No')
	elif cd == td:
		print('Yes')
	else:
		print('No')
main()


n = int(input())
c = list(map(int, input().split()))
t = list(map(int, input().split()))
cdiffs = [c[i + 1] - c[i] for i in range(n - 1)]
tdiffs = [t[i + 1] - t[i] for i in range(n - 1)]
if sorted(cdiffs) == sorted(tdiffs) and t[0] == c[0]:
	print('Yes')
else:
	print('No')


(lambda N, c, t: print('Yes' if c[0] == t[0] and c[-1] == t[-1] and (sorted((c[i] - c[i + 1] for i in range(N - 1))) == sorted((t[i] - t[i + 1] for i in range(N - 1)))) else 'No'))(int(input()), list(map(int, input().split())), list(map(int, input().split())))


n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if a[0] == b[0] and a[-1] == b[-1]:
	c = []
	d = []
	for i in range(1, n):
		c.append(a[i] - a[i - 1])
		d.append(b[i] - b[i - 1])
	c.sort()
	d.sort()
	if c == d:
		print('Yes')
	else:
		print('No')
else:
	print('No')


from sys import stdin
n = int(input())
a = list(map(int, stdin.readline().strip().split()))
b = list(map(int, stdin.readline().strip().split()))
c = [a[i + 1] - a[i] for i in range(n - 1)]
d = [b[i + 1] - b[i] for i in range(n - 1)]
if a[0] == b[0] and a[-1] == b[-1] and (sorted(c) == sorted(d)):
	print('Yes')
else:
	print('No')