class MyException < Exception; end

class Player
  def initialize(name)
    @name
    @win = 0
  end

  def -(other)
    if @win == 0
      raise MyException if other.win == 0
      other.win -= 1
      return other
    end
    if other.win == 0
      @win -= 1
      return self
    end
    raise MyException
  end

  attr_accessor :win
end

(?a..?z).each do |c|
  eval "#{c.upcase} = Player.new(?#{c})"
end

s = gets.chomp.tr('a-z[]', 'A-Z()')
while gets
  c, k = $_.chomp.split
  eval "#{c.upcase}.win = #{k}"
end

begin
  winner = eval s
  puts winner.win == 0 ? 'Yes' : 'No'
rescue MyException
  puts 'No'
end
