n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) s = [0 for _ in range(n)] for i in range(n): s[b[i]] += a[i] if max(s) == s[0]: print('YES') else: print('NO')