n = int(input())
l = list(map(int, input().split()))


l += [l[0], l[1], l[2]]
flag = True
for i in range(n):
    if l[i] != l[i + 3]:
        flag = False
        break

if flag:
    print('Yes')
else:
    print('No')