open String

let rec make_string_list s n =
  if n == 0 then
    []
  else
    String.sub s (2 * (n - 1)) 1 :: make_string_list s (n - 1)

let n_ref = ref 0

let f s =
  let n = int_of_string s in
  let () = n_ref := !n_ref + 1 in
  let n_sub = !n_ref in
  if n = n_sub then
    0
  else
    1


let answer n str =
  let lst = make_string_list str n |> List.rev in
  let n =
    List.map f lst |> List.fold_left (+) 0
  in
    if n = 2 || n = 0 then
      "YES"
    else
      "NO"


let () = Scanf.scanf "%d" (fun a ->
    let s = read_line () in
      print_endline (answer a s)
  )
