local n=io.read("n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end
a[0]=a[n]
a[n+1]=a[1]

local flag=true
for i=1,n do
    if a[i-1]~a[i+1]~=a[i] then
        flag=false
        break
    end
end
print(flag and "Yes" or "No")