# 解法:# 总的有效符号为 8 种 + - * ( ) 0 1 =# 全排列枚举将有效符合去替换字母,通过 Python 的 eval 函数去判断等式左边 = 右边? (...我选择用 Python 过此题的唯一原因)# 同时题面中还有部分限制规则需要判断。# Python eval 计算二进制数需形如 eval('0b101+0b10') 。
lst = ['0', '1', '+', '-', '*', '(', ')', '=']
flg = [0for i in range(8)]
ans = [0for i in range(8)]
pos = [0for i in range(256)]
chr = [0for i in range(200)]
ok = list()
s = str()
cnt = 0
tot = [0]
defjug(t):for i in range(len(t)):
if t[i] in'+*':
if i == 0or t[i-1] in'(+*-':
returnTrueelif t[i] == '0':
if (i > 0and t[i-1] notin'01') and (i+1 < len(t) and t[i+1] in'01'):
returnTrueelif t[i] == '(':
if i+1 < len(t) and t[i+1] == ')':
returnTruereturnFalsedefjugQ():
tmp = s[:]
t = s[:]
for i in range(1, cnt+1):
t = t.replace(chr[i], ans[i-1])
whileTrue:
flag = Falsefor i in range(1, len(t)):
if (t[i-1] in'(+-*=') and (t[i] in'01'):
t = t[:i] + 'b' + t[i:]
flag = Truebreakif flag == False:
breakif t[0] in'01':
t = 'b' + t[:]
t = t.replace('b', '0b')
try:
t1, t2 = t.split('=')
if jug(t1) or jug(t2):
return
a1 = eval(t1)
a2 = eval(t2)
if a1 == a2 and t notin ok:
ok.append(t)
# print(tmp)# print(t)
tot[0] += 1except:
returndefdfs(idx):if idx == 8:
# print(ans)
jugQ()
for i in range(8):
if flg[i]:
continueelse:
ans[idx] = lst[i]
flg[i] = 1
dfs(idx+1)
flg[i] = 0if __name__ == "__main__":
s = input()
for c in s:
if (c >= 'a'and c <= 'z') or (c >= 'A'and c <= 'Z'):
if pos[ord(c)] > 0:
continueelse:
cnt+=1
pos[ord(c)] = cnt
chr[cnt] = c
if cnt > 8:
print(0)
else:
dfs(0)
print(tot[0])