N=int(input())
A=list(map(int, input().split()))
last=A[-1]
fir=A[0]
A=[last]+A+[fir]
ok=True
for i in range(1,N+1):
    if (A[i-1]^A[i+1])&A[i]!=1:
        ok=False
if ok:
    print("Yes")
else:
    print("No")