require 'matrix'
loop do
  s = gets.chomp.chop
  break if s == ''
  
  s.gsub!(/([A-Z\)])(?![a-z\d])/, '\11')
  s.gsub!(/([A-Z][a-z])(?!\d)/, '\11')
  s.gsub!(/\((.+?)\)(\d*)/){
    as, n = $1, $2
    as.gsub(/([a-zA-Z])(\d+)/){"#{$1}#{$2.to_i * n.to_i}"}
  }
  atoms = s.scan(/[A-Z][a-z]?/).uniq
  l = s.split('->')[0].count('+') + 1
  molecules = s.split(/\->|\+/)
  m = molecules.size - 1
  n = atoms.size
  
  a = Matrix.build(n, m){|y, x|
    sum = 0
    molecules[x].scan(/#{atoms[y]}(\d+)/).each{ |a|
      x < l ? sum += a[0].to_i : sum -= a[0].to_i
    }
    sum.to_r
  }.to_a
  
  b = [0] * n
  atoms.each do |atom|
    molecules[-1].scan(/(#{atom})(\d+)/).each{ |a, k|
      b[atoms.index(a)] = k.to_r
    }
  end

  ans = Matrix[*a].lup.solve(b).select{|v| v != 0} + [1.to_r]
  lcm = ans.map(&:denominator).reduce(&:lcm)
  puts ans.map{|x| (x * lcm).to_i} * ' '
end