require 'matrix'

def gcd(m, n)
	if m < n 
		gcd(n, m)
	elsif n == 0
		m
	else
		gcd(n, m % n)
	end 
end

loop do
	eq = gets.chomp.chop
	break if eq == ""

	alph = (?a..?z).to_a + (?A..?Z).to_a
	rename = {}

	eq.gsub!(/[A-Z][a-z]?/){|a| rename[a] ||= alph.shift}
	eq.gsub!(/[a-zA-Z](?!\d)/){|x| "#{x}1"}
	eq.gsub!(/\((.+?)\)(\d+)/){
		as, k = $1, $2.to_i
		as.gsub(/([a-zA-Z])(\d+)/){"#{$1}#{$2.to_i * k}"}
	}

	moles = eq.split(/->/).map{|ms| ms.split(?+)}
	l = moles[0].size
	moles.flatten!

	atoms = rename.values
	m = atoms.size
	n = moles.size - 1

	a = Matrix.build(m, n){|m, n|
		atom = atoms[m]
		k = 0
		moles[n].scan(/#{atom}(\d+)/).each{|arr|
			k += arr[0].to_i
		}

		if k > 0
			Rational(n >= l ? -k : k)
		else
			Rational(0)
		end
	}.to_a

	v = [0] * m
	moles[-1].scan(/([a-zA-Z])(\d+)/).each{|a, k|
		v[atoms.index(a)] = Rational(k.to_i)
	}

	order = (0..m-1).to_a
	(0..[m,n].min-1).each do |i|
		pivot = (i..m-1).max_by{|k| a[k][i].abs}
		break if a[pivot][i] == 0
		a[i], a[pivot] = a[pivot], a[i]
		v[i], v[pivot] = v[pivot], v[i]
		((0..m-1).to_a - [i]).each do |j|
			r = a[j][i] / a[i][i]	
			(i..n-1).each do |k|
				a[j][k] -= r * a[i][k]
			end
			v[j] -= r * v[i]
		end
	end

	while a.last.all?{|x| x == 0}
		a.pop
		v.pop
	end

	ans = (Matrix[*a].inv * Vector[*v]).to_a + [Rational(1)]

	ds = ans.map(&:denominator)
	lcm = ds.inject{|g, x| g * x / gcd(g, x)}
	puts ans.map{|x| (x * lcm).to_i} * ' '
end