#include <cstdio>
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(n) rep(i,n)
typedef long long ll;
using namespace std;


signed main()
{
	int N;
	string S;
	
	cin >> N >> S;
	int l = S.length();
	if (l == 1)
	{
		cout << "NO" << endl;
	} else if (l == 2) {
		if (S == "00" || S == "11") cout << "YES" << endl;
		else cout << "NO" << endl;
	} else if (l == 3) {
		if (S == "101" || S == "010") cout << "NO" << endl;
		else cout << "YES" << endl;
	} else {
		cout << "YES" << endl;
	}
	
	return 0;
}