#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	int a[100];
	bool dp[105][105] = {};
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++){
		dp[i][i] = true;
	}
	for(int i = 2;i <= n;i++){
		for(int j = 0;j < n - i + 1;j++){
			for(int k = j + 1;k <= j + i - 1;k++){
				if(dp[j][k] && dp[k][j + i]) dp[j][j + i] = true;
			}
			if(a[j] != a[j + i - 1]) continue;
			int num = a[j];
			int l = j,r = j + i - 1;
			while(l < r && a[l] == num) l++;
			while(l < r && a[r] == num) r--;
			if(l == r && a[l] == num) dp[j][j + i] = true;
			if(dp[l][r + 1]) dp[j][j + i] = true;
			for(int k = j + 1;k <= j + i - 2;k++){
				if(a[k] == num && dp[j + 1][k] && dp[k + 1][j + i - 1]) dp[j][j + i] = true;
			}
		}
	}
	/*for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++) cout << dp[i][j] << " ";
		cout << endl;
	}*/
	if(dp[0][n]) cout << "yes" << endl;
	else cout << "no" << endl;
	return 0;
}