N = int(input()) l = list(map(int, input().split())) l1 = list(map(int, input().split())) d = {} for i in range(N): if l1[i] in d: d[l1[i]] += l[i] else: d[l1[i]] = l[i] ck = 0 flg = 0 for i in d.values(): if i > ck: ck = i for k, v in d.items(): if v == ck and k == 0: print("YES") flg = 1 break if flg == 0: print("NO")