n=int(input()) a=[int(i) for i in input().split()] b=[int(i) for i in input().split()] count=[0 for i in range(100)] count_k=0 for i in range(n): if b[i]==0: count_k+=a[i] else: count[b[i]-1]+=a[i] jud=0 for i in range(n): if count_k