import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  @tailrec
  def gcd(a: Long, b: Long): Long = {
    b match {
      case 0 ⇒ a
      case _ ⇒ gcd(b, a % b)
    }
  }
  def lcm(a: Long, b: Long): Long = {
    a * b / gcd(a, b)
  }
  solve
  def solve: Unit = {
    val line = readLine.trim
    if (line == ".") return
    line.toList match {
      case l MoleculeSequence '-'::'>'::(r MoleculeSequence '.'::Nil) ⇒
        val atoms = (l.flatMap(_.keys) ++ r.flatMap(_.keys)).distinct
        //Array(atom)(moleculeIndex)
        val moleculeLength = l.length + r.length
        val leftLength = l.length - 1
        val coefficient = Array.tabulate(atoms.length){_ ⇒ Array.tabulate(moleculeLength - 1){_ ⇒ 0L}}
        for ((name, i) ← atoms.zipWithIndex){
          for ((map, li) ← l.tail.zipWithIndex) {
            coefficient(i)(li) = map(name)
          }
          for ((map, ri) ← r.zipWithIndex){
            coefficient(i)(ri + leftLength) = -map(name)
          }
        }
        val result = atoms.map{name ⇒ -l.head(name).toLong}.toArray
        val res = solveSimultaneousEquations(coefficient, result)
        val first = res.foldLeft(1L){(l, c) ⇒ lcm(l, c.denominator)}
        println((first +: res.map(f ⇒ math.abs(f.numerator) * first / f.denominator)).mkString(" "))
      case _ ⇒ ???
    }
    solve
  }
  object MoleculeSequence{
    def unapply(arg: List[Char]): Option[(List[mutable.Map[String, Int]], List[Char])] = {
      arg match {
        case m Molecule r ⇒ r match {
          case '+'::(m2 MoleculeSequence t) ⇒ Some(m.countUpMolecule::m2, t)
          case _ ⇒ Some(List(m.countUpMolecule), r)
        }
        case _ ⇒ None
      }
    }
  }
  object Molecule{
    def unapply(arg: List[Char]): Option[(MoleculeType, List[Char])] = {
      arg match {
        case g Group r ⇒ r match {
          case g2 Molecule t ⇒ Some(ChemicalSequence(g, g2), t)
          case _ ⇒ Some(g, r)
        }
        case _ ⇒ None
      }
    }
  }
  object Group {
    def unapply(arg: List[Char]): Option[(MoleculeType, List[Char])] = {
      arg match {
        case u UnitGroup r ⇒ r match {
          case n Number t ⇒ Some(RepeatChemical(u, n), t)
          case _ ⇒ Some(u, r)
        }
        case _ ⇒ None
      }
    }
  }

  object UnitGroup {
    def unapply(arg: List[Char]): Option[(MoleculeType, List[Char])] = {
      arg match {
        case name ChemicalElement t ⇒ Some(Chemical(name), t)
        case '('::(m Molecule ')'::t) ⇒ Some(m, t)
        case _ ⇒ None
      }
    }
  }
  object ChemicalElement {
    def unapply(arg: List[Char]): Option[(String, List[Char])] = {
      arg match {
        case u::l::t if u.isUpper && l.isLower ⇒ Some(s"$u$l", t)
        case h::t if h.isUpper ⇒ Some(h.toString, t)
        case _ ⇒ None
      }
    }
  }
  object Number {
    def unapply(arg: List[Char]): Option[(Int, List[Char])] = {
      arg.span(_.isDigit) match {
        case (Nil, _) ⇒ None
        case (n, t) ⇒ Some(n.mkString.toInt, t)
      }
    }
  }
  sealed trait MoleculeType {
    def countUpMolecule: mutable.Map[String, Int] = {
      val map = mutable.Map[String, Int]().withDefault(_ ⇒ 0)
      countUp(map)
      map
    }
    def countUp(map: mutable.Map[String, Int], times: Int = 1): Unit
  }
  case class Chemical(name: String) extends MoleculeType {
    override def countUp(map: mutable.Map[String, Int], times: Int = 1)= {
      if (map.isDefinedAt(name)) map(name) += times
      else map(name) = times
    }
  }

  case class RepeatChemical(molecule: MoleculeType, repeat: Int) extends MoleculeType {
    override def countUp(map: mutable.Map[String, Int], times: Int = 1): Unit = {
      molecule.countUp(map, times * repeat)
    }
  }
  case class ChemicalSequence(left: MoleculeType, right: MoleculeType) extends MoleculeType {
    override def countUp(map: mutable.Map[String, Int], times: Int = 1): Unit = {
      left.countUp(map, times)
      right.countUp(map, times)
    }
  }
  def solveSimultaneousEquations(coefficient: Array[Array[Long]], result: Array[Long]): Array[Rational] = {

    val co = coefficient.indices.map{i ⇒ coefficient(i) :+ result(i)}.toArray
    for (i ← co.indices){
      co(i).indices.find(k ⇒ co(i)(k) != 0) match {
        case None ⇒
        case Some(k) ⇒
          for (j ← co.indices if i != j && co(j)(k) != 0) {
            val cm = lcm(co(i)(k), co(j)(k))
            for (l ← co(j).indices if l != k){
              co(j)(l) = co(j)(l) * cm / co(j)(k) - co(i)(l) * cm / co(i)(k)
            }
            co(j)(k) = 0
          }
      }
    }
    Array.tabulate(coefficient.head.length){i ⇒ co.find(_(i) != 0) match {
      case Some(a) ⇒ Rational(a.last, a(i))
      case None ⇒ ??? //複数解
    }}
  }
  import scala.math._

  object Rational{
    def apply(numerator: Long, denominator: Long): Rational = {
      val g = gcd(math.abs(numerator), math.abs(denominator))
      val signum = numerator.signum * denominator.signum
      new Rational(signum * math.abs(numerator / g), math.abs(denominator / g))
    }
    private def gcd(a: Long, b: Long): Long = {
      b match {
        case 0l ⇒ a
        case _ ⇒ gcd(b, a % b)
      }
    }
  }
  implicit class ToRational(val value: Int){
    def +(that: Rational): Rational = Rational(value, 1) + that
    def -(that: Rational): Rational = Rational(value, 1) - that
    def *(that: Rational): Rational = Rational(value, 1) * that
    def /(that: Rational): Rational = Rational(value, 1) / that
  }

  class Rational private (val numerator: Long, val denominator: Long) extends Ordered[Rational] {
    def +(that: Rational): Rational = Rational(numerator * that.denominator + denominator * that.numerator, denominator * that.denominator)
    def -(that: Rational): Rational = Rational(numerator * that.denominator - denominator * that.numerator, denominator * that.denominator)
    def *(that: Rational): Rational = Rational(numerator * that.numerator, denominator * that.denominator)
    def /(that: Rational): Rational = Rational(numerator * that.denominator, denominator * that.numerator)
    def +(that: Int): Rational = this + Rational(that, 1)
    def -(that: Int): Rational = this - Rational(that, 1)
    def *(that: Int): Rational = this * Rational(that, 1)
    def /(that: Int): Rational = this / Rational(that, 1)
    def unary_-(): Rational = Rational(-numerator, denominator)
    override def compare(that: Rational): Int = (this - that).numerator.compare(0)
    override def equals(obj: Any): Boolean = {
      obj match {
        case r: Rational ⇒ this.compare(r) == 0
        case _ ⇒ super.equals(obj)
      }
    }
    override def toString: String = s"$numerator / $denominator"
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}


Measured memory_bytes: 46876