#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using P = pair; constexpr ld EPS = 1e-12; constexpr int INF = numeric_limits::max() / 2; constexpr int MOD = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; string s; cin >> n >> s; if (n == 1) { cout << "NO" << endl; } else if (n == 2) { if (s[0] == s[1]) cout << "YES" << endl; else cout << "NO" << endl; } else if (n == 3) { if (s == "010" || s == "101") cout << "NO" << endl; else cout << "YES" << endl; } else cout << "YES" << endl; }