#![allow(non_snake_case)] use std::collections::{ HashMap }; #[allow(unused_macros)] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut tokens = $s.split_whitespace(); input_inner! { tokens, $($r)* } }; ($($r:tt)*) => { let s = { use std::io::Read; let mut res = String::new(); ::std::io::stdin().read_to_string(&mut res).unwrap(); res }; let mut tokens = s.split_whitespace(); input_inner! { tokens, $($r)* } }; } #[allow(unused_macros)] macro_rules! input_inner { ($tokens:expr) => {}; ($tokens:expr,) => {}; ($tokens:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($tokens, $t); input_inner! { $tokens $($r)* } }; } #[allow(unused_macros)] macro_rules! read_value { ($tokens:expr, ( $($t:tt),* )) => { $(read_value!($tokens, $t)),* }; ($tokens:expr, [ $t:tt; $len:expr ]) => { (0..$len).map(|_| read_value!($tokens, $t)).collect::>() }; ($tokens:expr, chars) => { read_value!($tokens, String).chars().collect::>() }; ($tokens:expr, usize1) => { read_value!($tokens, usize) - 1 }; ($tokens:expr, $t:ty) => { $tokens.next().unwrap().parse::<$t>().expect("parse error") }; } fn main() { const N_SEAT: usize = 20; type Wish = HashMap; use std::io::prelude::*; let stdin = ::std::io::stdin(); let mut stdin = stdin.lock(); let mut line = String::new(); stdin.read_line(&mut line).unwrap(); input! { source=line, N_DATA: usize } let mut seats = vec![Wish::new(); N_SEAT]; for _ in 0..N_DATA { let mut line = String::new(); stdin.read_line(&mut line).unwrap(); let s1 = line[..1].to_owned(); let s2 = line[2..].to_owned(); input! { source=s1, TYPE: i32 } match TYPE { 0 => { input! { source=s2, N: usize1, M: usize, A: [String; M], } let wish = &mut seats[N]; for a in A { *wish.entry(a).or_insert(0) += 1; } }, 1 => { input! { source=s2, B: String, } let mut ans = -1i64; for i in 0..N_SEAT { let wish = &mut seats[i]; let count = wish.entry(B.clone()).or_insert(0); if *count > 0 { *count -= 1; ans = i as i64 + 1; break; } } println!("{}", ans); }, 2 => { input! { source=s2, C: usize1 } seats[C] = Wish::new(); }, _ => { panic!(); } } } }