#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[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 balls = vec![]; for i in 0..n { let v = read_vec::(); let y: usize = v[2].parse().unwrap(); let (c, x, y) = ( v[0].chars().next().unwrap(), v[1].chars().next().unwrap(), y, ); balls.push((c, x, y, i)); } let mut red_cond = vec![]; let mut blue_cond = vec![]; for (c, x, y, i) in balls { let same; if c == x { same = 1; } else { same = 0; } if x == 'R' { red_cond.push((y, same, i)); } else { blue_cond.push((y, same, i)); } } red_cond.sort(); blue_cond.sort(); let mut red_cond = red_cond.into_iter().collect::>(); let mut blue_cond = blue_cond.into_iter().collect::>(); let mut r_count = 0; let mut b_count = 0; let mut answers = vec![]; while !red_cond.is_empty() || !blue_cond.is_empty() { let mut changed = false; let mut used = true; if let Some(&(_, same, _)) = red_cond.iter().next() { if let Some(&(y1, _, _)) = blue_cond.iter().next() { if y1 == b_count && same == 0 { used = false; } } } if used { if let Some(&(y, same, idx)) = red_cond.iter().next() { if y == r_count { red_cond.pop_front(); if same == 1 { r_count += 1; } else { b_count += 1; } answers.push(idx); changed = true; } } } let mut used = true; if let Some(&(_, same, _)) = blue_cond.iter().next() { if let Some(&(y1, _, _)) = red_cond.iter().next() { if y1 == r_count && same == 0 { used = false; } } } if used { if let Some(&(y, same, idx)) = blue_cond.iter().next() { if y == b_count { blue_cond.pop_front(); if same == 1 { b_count += 1; } else { r_count += 1; } answers.push(idx); changed = true; } } } if !changed { // debug!((answers, r_count, b_count)); println!("No"); return; } } debug!(answers); println!("Yes"); for num in answers.iter().take(n - 1) { print!("{} ", num + 1); } println!("{}", answers[n - 1] + 1); } 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() }