N = gets.to_i customers = 20.times.map{[]} $<.map{|s| # p customers sa = s.split case sa.shift when ?0 n, m, *a = sa customers[n.to_i-1] = a when ?1 neta = sa.shift p (customers.index{|wish_list| idx = wish_list.index(neta) idx && wish_list.delete_at(idx) } || -2) + 1 else n = sa.shift.to_i customers[n - 1] = Array.new end }