#include <iostream>
using namespace std;
int n, c[109]; bool dp[109][109], dp2[109];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> c[i], dp[i][i] = true;
	for (int i = 2; i <= n; i++) {
		for (int l = 0; l <= n - i; l++) {
			int r = l + i;
			for (int j = l + 1; j < r; j++) {
				if (dp[l][j] && dp[j][r]) dp[l][r] = true;
			}
			if (c[l] != c[r - 1]) continue;
			fill(dp2, dp2 + n + 1, false); dp2[l] = true;
			for (int j = l + 1; j <= r; j++) {
				if (c[j - 1] == c[l] && dp2[j - 1]) dp2[j] = true;
				for (int k = l; k < j; k++) {
					if (dp[k][j] && dp2[k]) dp2[j] = true;
				}
			}
			if (dp2[r]) dp[l][r] = true;
		}
	}
	cout << (dp[0][n] ? "yes" : "no") << endl;
	return 0;
}