# Path: tryalgo/our_std.py
# def readint():
#     """
#     function to read an integer from stdin
#     """
#     return int(stdin.readline())
# 
# def readstr():
#     """
#     function to read a string from stdin
#     """
#     return stdin.readline().strip()


from sys import argv
from tryalgo.our_std import readint, readstr
import sys
    not_zero = ''                   # letters that cannot be 0
    for word in S:
        not_zero += word[0]
    tab = ['@'] * (10 - len(letters)) + letters  # minimal lex permutation
    count = 0
    while True:
        ass = {tab[i]: i for i in range(10)}  # dict = associative array
        if tab[0] not in not_zero:
            difference = -convert(S[n - 1], ass)  # do the addition
            for word in S[:n - 1]:
                difference += convert(word, ass)
            if difference == 0:                   # does it add up?
                count += 1
        if not next_permutation(tab):
            break
    return count
# snip}


if __name__ == "__main__":
    if len(argv) > 1:
        L = argv[1:]
        if len(L) == 1:
            L = list(L[0])
        while True:
            print(L)
            if not next_permutation(L):
                sys.exit(0)

    n = readint()

# Path: tryalgo/our_std.py
# def readint():
#     """
#     function to read an integer from stdin
#     """
#     return int(stdin.readline())
# 
# def readstr():
#     """
#     function to read a string from stdin
#     """
#     return stdin.readline().strip()


# Path: tryalgo/next_permutation.py
from sys import argv
from tryalgo.our_std import readint, readstr
import sys

    not_zero = ''                   # letters that cannot be 0
    for word in S:
        not_zero += word[0]
    tab = ['@'] * (10 - len(letters)) + letters  # minimal lex permutation
    count = 0
    while True:
        ass = {tab[i]: i for i in range(10)}  # dict = associative array
        if tab[0] not in not_zero:
            difference = -convert(S[n - 1], ass)  # do the addition
            for word in S[:n - 1]:
                difference += convert(word, ass)
            if difference == 0:                   # does it add up?
                count += 1
        if not next_permutation(tab):
            break
    return count
# snip}


if __name__ == "__main__":
    if len(argv) > 1:
        L = argv[1:]
        if len(L) == 1:
            L = list(L[0])
        while True:
            print(L)
            if not next_permutation(L):
                sys.exit(0)

    n = readint()

    S = [readstr() for _ in range(n)]