#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::(); let mut v = read_vec::(); if v[0] > v[v.len() - 1] { println!("No"); return; } println!("Yes"); let mut prev_pointer = 1; let mut next_pointer = 2; let mut answers = vec![]; while next_pointer < n - 1 { if prev_pointer >= next_pointer { next_pointer += 1; continue; } if v[prev_pointer] == 0 { prev_pointer += 1; } if v[next_pointer] == 0 { next_pointer += 1; } if v[prev_pointer] < v[next_pointer] { answers.push(v[next_pointer]); v[next_pointer] = 0; next_pointer += 1; } else { prev_pointer += 1; } } debug!(v); let mut pointer = 1; while pointer < n - 1 { if v[pointer] == 0 { pointer += 1; continue; } if v[pointer] < v[0] { break; } answers.push(v[pointer]); v[pointer] = 0; pointer += 1; } let mut pointer = n - 2; while pointer > 0 { if v[pointer] == 0 { pointer -= 1; continue; } if v[pointer] > v[n - 1] { break; } answers.push(v[pointer]); v[pointer] = 0; pointer -= 1; } debug!(v); answers.push(v[0]); print_array(&answers); } fn print_array(array: &Vec) { println!( "{}", array .iter() .map(|ref x| x.to_string()) .collect::>() .join(" ") ); } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }