n = input()
a = list(map(int, input().split()))
res = []
for n in range(len(a)):
  if(n == (len(a) - 1)):
    res.append(a[n - 1]^a[0])
  else:
    res.append(a[n - 1]^a[n + 1])
ling = []
for i, num in enumerate(res):
  if(num == 1):
    ling.extend(res[i:])
    ling.extend(res[0:i])
    break
mes = "Yes"
if(len(ling) == 0):  
  mes = "No"
for i, j in enumerate(ling):
  if(i+1 != j):
    mes = ("No")
    break
print(mes)