import java.io.*; import java.util.*; import java.math.*; class Main { public static void out (Object o) { System.out.println(o); } public static boolean solve (String s , int n) { if (n == 1) return false; if (n == 2) return !s.equals("01") && !s.equals("10"); if (n == 3) return !s.equals("010") && !s.equals("101"); return true; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String s = br.readLine(); out(solve(s , n) ? "YES" : "NO"); } }