from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a_ = {int(x) for x in stdin.readline().rstrip().split()}
    count = 0


    for i in range(N):
        
        if i == N-1:
            if not a[i-1] ^ a[0] in a_:
                count += 1
        else:
            if not a[i-1] ^ a[i+1] in a_:
                count += 1

    if count == 0:
        print("Yes")
    else:
        print("No")    


if __name__ == "__main__":
    main()