class Problem0216: def solve(this): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) res = {} for (idx, v) in enumerate(b): res[v] = res.get(v, 0) + a[idx] k1 = res.get(0, 0) k2 = sorted(list(res.values()), reverse=True) if k1 == k2[0]: print("YES") else: print("NO") if __name__ == "__main__": problem = Problem0216() problem.solve()