
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val a = readLine.trim.toList
  val b = readLine.trim.toList
  val aTree = parseAll(a).get
  val bTree = parseAll(b).get
  println(
    aTree.merge(bTree)
  )
  sealed trait BinaryTree {
    def merge(that: BinaryTree): BinaryTree
  }
  case class Node(value: Int, left: BinaryTree, right: BinaryTree) extends BinaryTree {
    override def toString: String = s"($left)[$value]($right)"

    override def merge(that: BinaryTree): BinaryTree = {
      that match {
        case Leaf ⇒ Leaf
        case Node(v, l, r) ⇒ Node(value + v, left.merge(l), right.merge(r))
      }
    }
  }
  case object Leaf extends BinaryTree {
    override def toString: String = ""

    override def merge(that: BinaryTree): BinaryTree = Leaf
  }
  def parseAll(arg: List[Char]): Option[BinaryTree] = {
    parse(arg) match {
      case (n, Nil) ⇒ Some(n)
      case _ ⇒ None
    }
  }
  def parse(arg: List[Char]): (BinaryTree, List[Char]) = {
    def readValue(arg: List[Char], res: Int = 0): (Int, List[Char]) = {
      arg match {
        case h::t if h.isDigit ⇒ readValue(t, res * 10 + h.asDigit)
        case _ ⇒ (res, arg)
      }
    }
    arg match {
      case '('::t ⇒ parse(t) match {
        case (left, ')'::'['::t) ⇒ readValue(t) match {
          case (value, ']'::'('::t) ⇒ parse(t) match {
            case (right, ')'::t) ⇒ (Node(value, left, right), t)
            case _ ⇒ ???
          }
          case _ ⇒ ???
        }
        case (left, ')'::Nil) ⇒ (left, Nil)
        case _ ⇒ ???
      }
      case _ ⇒ (Leaf, arg)
    }
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
/*
 */
