inputs = STDIN.readlines.map(&:chomp) N = inputs[0].to_i TRIES = inputs[1..-1].map { |line| t = line.split(/\s+/) [t[0..3].map(&:to_i), t[4] == 'YES'] } cands = (0..9).to_a TRIES.each do |digits, result| if result cands &= digits else cands -= digits end end puts cands.first