#include<cstdio>
#include<stack>
#include<iostream>
using namespace std;
int arr[1003];
stack<int>st;
int main()
{
int n,tag,i,a;
while(scanf("%d",&n)&&n)
{
while(scanf("%d",&arr[1])==1)
{
if(arr[1]==0)
{
break;
}
for(i=2; i<=n; i++)
{
scanf("%d",&arr[i]);
}
i=1;
tag=0;
bool toggle=0;
a=arr[1];
st.push(++tag);
for(;;)
{
if(st.empty())
{
st.push(++tag);
if(tag==n)
{
break;
}
}
else if(st.top()==a)
{
st.pop();
a=arr[++i];
toggle=1;
}
else if(st.top()!=a)
{
st.push(++tag);
if(tag==n)
{
break;
}
}
}
if(toggle==0)
{
i=1;
}
for(;;)
{
if(st.empty()) break;
if(st.top()==arr[i++])
{
st.pop();
}
else
{
break;
}
}
if(st.empty())
{
puts("Yes");
}
else
{
puts("No");
}
while(!st.empty())
{
st.pop();
}
}
puts("");
}
return 0;
}