### subroutines

# <chemical_equation> ::= <molecule_sequence> "->" <molecule_sequence>
# <molecule_sequence> ::= <molecule> | <molecule> "+" <molecule_sequence>
#          <molecule> ::= <group> | <group> <molecule>
#             <group> ::= <unit_group> | <unit_group> <number>
#        <unit_group> ::= <chemical_element> | "(" <molecule> ")"
#  <chemical_element> ::= <uppercase_letter>
#                       | <uppercase_letter> <lowercase_letter>
#  <uppercase_letter> ::= "A"-"Z"
#  <lowercase_letter> ::= "a"-"z"
#            <number> ::= <non_zero_digit>
#                       | <non_zero_digit> <digit>
#    <non_zero_digit> ::= "1"-"9"
#             <digit> ::= "0" | <non_zero_digit>

def celmid(celm)
  if $celmhash[celm].nil?
    $celmhash[celm] = $n
    $n += 1
  end
  $celmhash[celm]
end

def cequation(str)
  ms0 = molseq(str)
  $pos += 2
  ms1 = molseq(str)

  for ml in (ms0 + ms1)
    for i in (0...$n)
      ml[i] = 0 if ml[i].nil?
    end
  end

  [ms0, ms1]
end

def molseq(str)
  ms = []
  ms << mol(str)

  while str[$pos] == '+'
    $pos += 1
    ms << mol(str)
  end

  ms
end

def mol(str)
  ml = []

  while str[$pos] =~ /^[A-Z\(]/
    gr = group(str)
    for i in (0...gr.length)
      if ml[i].nil?
        ml[i] = gr[i]
      else
        ml[i] += gr[i]
      end
    end
  end

  ml
end

def group(str)
  gr = unitgroup(str)
  if str[$pos] =~ /^[0-9]/
    n = num(str)
    (0...gr.length).each{|i| gr[i] *= n}
  end
  gr
end

def unitgroup(str)
  if str[$pos] == '('
    $pos += 1
    ml = mol(str)
    $pos += 1
    return ml
  end

  celm = str[$pos]
  $pos += 1
  if str[$pos] =~ /^[a-z]/
    celm += str[$pos]
    $pos += 1
  end

  id = celmid(celm)
  ug = $n.times.map{0}
  ug[id] = 1
  ug
end

def num(str)
  n = 0
  while str[$pos] =~ /^[0-9]/
    n = n * 10 + str[$pos].to_i
    $pos += 1
  end
  n
end

def solve(mtx, v)
  m = mtx[0].length

  for i in (0...m)
    max_i = i
    max_m = mtx[i][i].abs
    for i0 in ((i + 1)...$n)
      miia = mtx[i0][i].abs
      if max_m < miia
        max_m = miia
        max_i = i0
      end
    end

    if i != max_i
      t = mtx[max_i]; mtx[max_i] = mtx[i]; mtx[i] = t
      t = v[max_i]; v[max_i] = v[i]; v[i] = t
    end

    mii = mtx[i][i]
    for j in (i...m)
      mtx[i][j] /= mii
    end
    v[i] /= mii

    for i0 in ((i + 1)...$n)
      m0 = mtx[i0][i]
      for j in (i...m)
        mtx[i0][j] -= m0 * mtx[i][j]
      end
      v[i0] -= m0 * v[i]
    end
  end
  #p mtx
  #p v

  (m - 1).downto(0).each do |i|
    for j in ((i + 1)...m)
      v[i] -= mtx[i][j] * v[j]
    end
  end
  #p v

  v[0...m]
end

### main

loop do
  line = gets.strip
  break if line == '.'

  $n = 0
  $celmhash = {}
  $pos = 0

  ceq = cequation(line)
  #p line
  #p $celmhash
  #p ceq

  mtx = $n.times.map{[]}
  v = ceq[1].pop.map{|vi| Rational(vi)}

  for ml in ceq[0]
    for i in (0...$n)
      mtx[i] << Rational(ml[i])
    end
  end
  for ml in ceq[1]
    for i in (0...$n)
      mtx[i] << Rational(-ml[i])
    end
  end
  #p mtx
  #p v

  v0 = solve(mtx, v)
  v0 << Rational(1)

  lcm0 = v0.map{|vi| vi.denominator}.inject(1){|l, vi| l = l.lcm(vi)}
  v1 = v0.map{|vi| (vi * lcm0).to_i}

  puts v1.join(' ')
end