#[allow(unused_macros)] macro_rules! invec { ( $t:ty ) => {{ let mut s = String::new(); match std::io::stdin().read_line(&mut s) { Ok(0) => Vec::<$t>::new(), Ok(_) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::>(), Err(_) => Vec::<$t>::new(), } }} } #[allow(unused_macros)] macro_rules! input { ( $($t:ty),* ) => {{ let mut s = String::new(); std::io::stdin().read_line(&mut s); let mut splits = s.trim().split_whitespace(); ($( { splits.next().unwrap().parse::<$t>().unwrap() }, )*) }} } type Mat33 = [[i64; 3]; 3]; const ROTATION: Mat33 = [[0, 1, 0], [-1, 0, 0], [0, 0, 1]]; fn input_command() -> Mat33 { let commands = invec!(i64); if commands.len() > 1 { let command = commands[0]; let pos = commands[1]; match command { 1 => [[1, 0, pos], [0, 1, 0], [0, 0, 1]], 2 => [[1, 0, 0], [0, 1, pos], [0, 0, 1]], _ => panic!(""), } } else { ROTATION } } fn multiple_mat33(a: Mat33, b: Mat33) -> Mat33 { let mut c = [[0; 3]; 3]; for i in 0..3 { for j in 0..3 { for k in 0..3 { c[i][j] += a[i][k] * b[k][j]; } } } c } fn multiple_mat33_vec(m: Mat33, v: [i64; 3]) -> [i64; 3] { let mut a = [0; 3]; for i in 0..3 { for j in 0..3 { a[i] += m[i][j] * v[j]; } } a } #[allow(unused_must_use)] #[allow(unused_variables)] fn solve() { let (n, px, py) = input!(usize, i64, i64); let mut commands = Vec::::with_capacity(n); for i in 0..n { commands.push(input_command()); } let mut multi_mats = Vec::::with_capacity(n); let mut current_mat = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]; for command in commands.iter().rev() { let mat = multiple_mat33(current_mat, *command); multi_mats.push(mat); current_mat = mat; } multi_mats.reverse(); for mat in multi_mats { let v = multiple_mat33_vec(mat, [px, py, 1]); println!("{} {}", v[0], v[1]); } } fn main() { solve(); }