require 'set'

def f(s)
	0 while s.gsub!(/\(\((-?\d+)\)\)/, '(\1)')
	0 while s.gsub!(/\((\d+)\)/, '\1')
	return if $checked[s]
	$checked[s] = 0

	op_hash = {}
	num_hash = {}
	if s.scan(/\d+/).size == 1
		$set << eval(s)
		return
	end

	s.gsub!(/\((-?\d+)\)/) do
		c = ((?A.ord) + num_hash.size).chr
		num_hash[c] = $1.to_i
		c
	end

	s.gsub!(/\d+/) do |x|
		c = ((?A.ord) + num_hash.size).chr
		num_hash[c] = x.to_i
		c
	end

	
	s.gsub!(/(?<=[A-Z]|\([A-Z]\))[-+*\/](?=[A-Z]|\([A-Z]\))/) do |x|
		c = ((?a.ord) + op_hash.size).chr
		op_hash[c] = x
		c
	end
	
	op_hash.each do |c, op|
		d = s.dup
		begin
			if d.sub!(/([A-Z]|\([A-Z]\))#{c}([A-Z]|\([A-Z]\))/){|x|
				x = num_hash[$1[0] == ?( ? $1[1..-2] : $1]
				y = num_hash[$2[0] == ?( ? $2[1..-2] : $2]
				raise if op == ?/ && y == 0

				z = if x * y < 0 && op == ?/
						-(x.abs.send(op, y.abs))
					else
						x.send(op, y)
					end

				if z < 0
					"(#{z})"
				else
					z.to_s
				end
			}
				next_s = d.gsub(/[a-z]/){|l| op_hash[l]}.gsub(/[A-Z]/){|l| ?( + num_hash[l].to_s + ?)}
				f(next_s)
			end
		rescue
		end
	end
end

loop do
	s = gets.chomp
	break if s == ?#
	$set = Set.new
	$checked = {}
	f(s)
	p $set.size
end