N = gets.to_i S = gets.chomp() ans = if N >= 4 or (N == 3 and not ["101", "010"].include?(S)) or ["00", "11"].include?(S) "YES" else "NO" end puts ans