#![allow(unused_imports)] #![allow(non_snake_case)] use std::collections::HashMap; use std::collections::HashSet; use std::collections::VecDeque; #[allow(unused_macros)] macro_rules! read { ([$t:ty] ; $n:expr) => ((0..$n).map(|_| read!([$t])).collect::>()); ($($t:ty),+ ; $n:expr) => ((0..$n).map(|_| read!($($t),+)).collect::>()); ([$t:ty]) => (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::>()); ($t:ty) => (rl().parse::<$t>().unwrap()); ($($t:ty),*) => {{ let buf = rl(); let mut w = buf.split_whitespace(); ($(w.next().unwrap().parse::<$t>().unwrap()),*) }}; } #[allow(dead_code)] fn rl() -> String { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().to_owned() } fn main() { let _ = read!(usize); let mut s = read!([String]); s.sort_by_key(|e| { let mut key = 0; let mut chars = e.chars(); match chars.next() { Some('D') => { key += 14; } Some('C') => { key += 28; } Some('H') => { key += 42; } Some('S') => { key += 56; } _ => unreachable!(), } match chars.next() { Some('A') => { key += 1; } Some('2') => { key += 2; } Some('3') => { key += 3; } Some('4') => { key += 4; } Some('5') => { key += 5; } Some('6') => { key += 6; } Some('7') => { key += 7; } Some('8') => { key += 8; } Some('9') => { key += 9; } Some('T') => { key += 10; } Some('J') => { key += 11; } Some('Q') => { key += 12; } Some('K') => { key += 13; } _ => unreachable!(), } key }); let ans = s.into_iter().fold(String::new(), |mut acc, e| { acc.push_str(&format!("{} ", e)); acc }); println!("{}", ans.trim_end()); }