n = int(input()) list1 = list(map(int, input().split(' '))) list2 = list(map(int, input().split(' '))) if abs(list1.index(list2[0]) - list1.index(list2[1])) == 1: print('Yes') else: print('No')