#NEWLINE# def solve_word_addition( S ) : #NEWLINE# #INDENT# n = len ( S ) #NEWLINE# letters = sorted ( list ( set ( '' . join ( S ) ) ) ) #NEWLINE# not_zero = '' #NEWLINE# for word in S : #NEWLINE# #INDENT# not_zero += word [ 0 ] #NEWLINE# #UNINDENT# tab = ( ( [ '@' ] * ( 10 - len ( letters ) ) ) + letters ) #NEWLINE# count = 0 #NEWLINE# while True : #NEWLINE# #INDENT# ass = { tab [ i ] : i for i in range ( 10 ) } #NEWLINE# if ( tab [ 0 ] not in not_zero ) : #NEWLINE# #INDENT# sum = ( - convert ( S [ ( n - 1 ) ] , sum ) ) #NEWLINE# for word in S [ : ( n - 1 ) ] : #NEWLINE# #INDENT# sum += convert ( word , ass ) #NEWLINE# #UNINDENT# if ( sum == 0 ) : #NEWLINE# #INDENT# count += 1 #NEWLINE# #UNINDENT# #UNINDENT# if ( not next_permutation ( tab ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return count