require 'set'

U_ALPH = (?A..?Z).to_a
L_ALPH = (?a..?z).to_a

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

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

	op_hash = {}
	num_hash = {}

	s.gsub!(/\((-\d+)\)/o){ U_ALPH[num_hash.size].tap{|c| num_hash[c] = $1.to_i} }
	s.gsub!(/\d+/o){|x| U_ALPH[num_hash.size].tap{|c| num_hash[c] = x.to_i} }
	s.gsub!(/(?<=[A-Z])[-+*\/](?=[A-Z])/o){|x| L_ALPH[op_hash.size].tap{|c| op_hash[c] = x} }
	
	op_hash.each do |c, op|
		d = s.dup
		begin
			d.sub!(/(\w)#{c}(\w)/) do
				x, y = num_hash[$1], num_hash[$2]
				raise if op == ?/ && y == 0

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

				z < 0 ? "(#{z})" : z.to_s
			end
			f(d.gsub(/[a-z]/o){|l| op_hash[l]}.gsub(/[A-Z]/o){|l| x = num_hash[l]; x < 0 ? "(#{x})" : "#{x}"})
		rescue
		end
	end
end

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