Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

N = int(input())
S = input()

ans = 0
pattern = []
for x in range(N):
    for y in range(x + 1, N):
        if (S[x] + S[y]) not in pattern:
            ans += len(set(S[y + 1:]))
            pattern.append(S[x] + S[y])

print(ans)

Fixed submission:
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

N = int(input())
S = input()
#
# ans = 0
# pattern = []
# for x in range(N):
#     for y in range(x + 1, N):
#         if (S[x] + S[y]) not in pattern:
#             ans += len(set(S[y + 1:]))
#             pattern.append(S[x] + S[y])
#
# print(ans)
ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1 or first == N:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1 or (first + second + 2) == N:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        # print(first, first + second + 1, first + second + third + 2, key)
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S = input()

ans = 0
pattern = []
for x in range(N):
    for y in range(x + 1, N):
        if (S[x] + S[y]) not in pattern:
            ans += len(set(S[y + 1:]))
            pattern.append(S[x] + S[y])

print(ans)


Fixed submission:
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

N = int(input())
S = input()
#
# ans = 0
# pattern = []
# for x in range(N):
#     for y in range(x + 1, N):
#         if (S[x] + S[y]) not in pattern:
#             ans += len(set(S[y + 1:]))
#             pattern.append(S[x] + S[y])
#
# print(ans)
ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1 or first == N:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1 or (first + second + 2) == N:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        # print(first, first + second + 1, first + second + third + 2, key)
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

N = int(input())
S = input()

pattern = []
for x in range(N):
    for y in range(x + 1, N):
        for z in range(y + 1, N):
            pattern.append(S[x] + S[y] + S[z])

print(len(set(pattern)))


Fixed submission:
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

N = int(input())
S = input()
#
# ans = 0
# pattern = []
# for x in range(N):
#     for y in range(x + 1, N):
#         if (S[x] + S[y]) not in pattern:
#             ans += len(set(S[y + 1:]))
#             pattern.append(S[x] + S[y])
#
# print(ans)
ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1 or first == N:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1 or (first + second + 2) == N:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        # print(first, first + second + 1, first + second + third + 2, key)
        ans += 1
print(ans)