N = int(input()) D = list(map(int, input().split(' '))) W = list(map(int, input().split(' '))) def unite(n, pairs, graphs): if n == len(pairs): return pair = pairs[n] indeces = [] for i,graph in enumerate(graphs): if pair[0] in graph or pair[1] in graph: indeces.append(i) graph = {} for i in indeces: graph.update(graphs[i]) graphs.remove(graphs[i]) graph.update({pair[0]:1, pair[1]:1}) # flag to indicate that the same coin is flipped if pair[0] == pair[1]: graph[N] = 1 graphs.append(graph) unite(n+1, pairs, graphs) normalized = [] for d in D: normalized.append(d % N) pairs = [] for i,n in enumerate(normalized): pairs.append( ((i + n + N) % N, (i - n + N) % N) ) graphs = [] unite(0, pairs, graphs) for graph in graphs: zeros = 0 for key in graph: if key < N and W[key] == 0: zeros = zeros + 1 if zeros % 2 != 0 and N not in graph: print('No') exit(0) print('YES')