_,s=open(0)

dp=[[0]*1000for _ in range(4)]

dp[0][0]=1

for c in map(int,s[:-1]):

  for i in range(3,0,-1):

    for j in range(10**(i-1)):

      dp[i][j*10+c]|=dp[i-1][j]

print((sum(dp[3][i]for i in range(1000))))
eval(input())

a=set(),set(),set(),{''}

for s in eval(input()):

 for b,c in zip(a,a[1:]):b|={t+s for t in c}

print((len(a[0])))
_, s = open(0)
dp = [[0] * 1000 for _ in range(4)]
dp[0][0] = 1
for c in map(int, s[:-1]):
    for i in range(3, 0, -1):
        for j in range(10 ** (i - 1)):
            dp[i][j * 10 + c] |= dp[i - 1][j]
print((sum(dp[3][i] for i in range(1000))))

eval(input())
a = set(), set(), set(), {""}
for s in eval(input()):
    for b, c in zip(a, a[1:]):
        b |= {t + s for t in c}
print((len(a[0])))

-_, s = open(0) -dp = [[0] * 1000 for _ in range(4)] -dp[0][0] = 1 -for c in map(int, s[:-1]): -    for i in range(3, 0, -1): -        for j in range(10 ** (i - 1)): -            dp[i][j * 10 + c] |= dp[i - 1][j] -print((sum(dp[3][i] for i in range(1000)))) +eval(input()) +a = set(), set(), set(), {""} +for s in eval(input()): +    for b, c in zip(a, a[1:]): +        b |= {t + s for t in c} +print((len(a[0])))