
object Main extends App {
  import scala.io.StdIn._
  import scala.math
  val str = readLine.trim.toList
  val winCounts = Array.tabulate(26){_ ⇒ 0}
  for (_ ← 0 until str.count{_.isLetter}) {
    val Array(p, c) = readLine.trim.split(' ')
    winCounts(p(0) - 'a') = c.toInt
  }
  Person.winCounts = winCounts
  println(
    str match{
      case winner Winner Nil if winner.isValid && winner.winCount == 0 ⇒ "Yes"
      case _ ⇒ "No"
    }
  )

  sealed trait Winner {
    def isValid: Boolean
    def winCount: Int
  }
  object Winner{
    def unapply(arg: List[Char]): Option[(Winner, List[Char])] = {
      arg match{
        case Person(p)::t ⇒ Some((new Person(p), t))
        case (a, b) Match t ⇒ Some((new Match(a, b), t))
        case _ ⇒ None
      }
    }
  }
  object Person{
    var winCounts: Array[Int] = Array()
    def unapply(str: Char): Option[Int] = {
      str match {
        case c if c.isLetter ⇒ Some(winCounts(c - 'a'))
        case _ ⇒ None
      }
    }
  }
  object Match{
    def unapply(arg: List[Char]): Option[((Winner, Winner), List[Char])] = {
      arg match {
        case '['::(a Winner ('-':: (b Winner ']'::t))) ⇒ Some(((a, b), t))
        case _ ⇒ None
      }
    }
  }
  class Person(override val winCount: Int) extends Winner {
    override def isValid: Boolean = true
  }
  class Match(val left: Winner, val right: Winner) extends Winner {
    override val isValid: Boolean = left.isValid && right.isValid && ((left.winCount > 0 && right.winCount == 0) || (left.winCount == 0 && right.winCount > 0))
    override val winCount: Int = if (left.winCount == 0) right.winCount - 1 else left.winCount - 1
  }
  implicit class ScopeFunc[T](private val value: T) {
    def let[A](func:T ⇒ A): A = func(value)
    def also(func:T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


