N = int(eval(input()))

S = eval(input())



single_flag = [False]*10

dual_flag = {}

ans = {}

for i in range(10):

    for j in range(10):

        dual_flag[(i, j)] = False

        ans[(i, j)] = set()



for s in S:

    for i in range(10):

        for j in range(10):

            if dual_flag[i, j]:

                ans[(i, j)].add(int(s))

    for i in range(10):

        if single_flag[i]:

            dual_flag[(i, int(s))] = True

    single_flag[int(s)] = True



tmp = 0

for v in list(ans.values()):

    tmp += len(v)

print(tmp)

N = int(eval(input()))

S = eval(input())



single_flag = [False]*10

dual_flag = {}

ans = {}

for i in range(10):

    for j in range(10):

        dual_flag[(i, j)] = False

        ans[(i, j)] = set()



for s in S:

    for i in range(10):

        for j in range(10):

            if dual_flag[i, j]:

                ans[(i, j)].add(s)

    for i in range(10):

        if single_flag[i]:

            dual_flag[(i, int(s))] = True

    single_flag[int(s)] = True



tmp = 0

for v in list(ans.values()):

    tmp += len(v)

print(tmp)

N = int(eval(input()))
S = eval(input())
single_flag = [False] * 10
dual_flag = {}
ans = {}
for i in range(10):
    for j in range(10):
        dual_flag[(i, j)] = False
        ans[(i, j)] = set()
for s in S:
    for i in range(10):
        for j in range(10):
            if dual_flag[i, j]:
                ans[(i, j)].add(int(s))
    for i in range(10):
        if single_flag[i]:
            dual_flag[(i, int(s))] = True
    single_flag[int(s)] = True
tmp = 0
for v in list(ans.values()):
    tmp += len(v)
print(tmp)

N = int(eval(input()))
S = eval(input())
single_flag = [False] * 10
dual_flag = {}
ans = {}
for i in range(10):
    for j in range(10):
        dual_flag[(i, j)] = False
        ans[(i, j)] = set()
for s in S:
    for i in range(10):
        for j in range(10):
            if dual_flag[i, j]:
                ans[(i, j)].add(s)
    for i in range(10):
        if single_flag[i]:
            dual_flag[(i, int(s))] = True
    single_flag[int(s)] = True
tmp = 0
for v in list(ans.values()):
    tmp += len(v)
print(tmp)

-                ans[(i, j)].add(int(s)) +                ans[(i, j)].add(s)