Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

D = [set() for _ in range(N+1)]
D[0].add((3,""))

for i in range(N):
    for curr in D[i]:
        l = curr[0]
        s = curr[1]
        # そのまま
        D[i+1].add((l,s))
        # 末尾の1文字を採用する場合
        if l-1 >= 0:
            D[i+1].add((l-1,s+S[i]))

r = filter(lambda x:x[0]==0, D[N])
print(len(list(r)))

Fixed submission:
N = int(input())
S = input()

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

D = [set() for _ in range(N+1)]
D[0].add((3,""))

for i in range(N):
    for curr in D[i]:
        l = curr[0]
        s = curr[1]
        # そのまま
        D[i+1].add((l,s))
        # 末尾の1文字を採用する場合
        if l-1 >= 0:
            D[i+1].add((l-1,s+S[i]))

r = filter(lambda x:x[0]==0, D[N])
print(len(list(r)))

Fixed submission:
N = int(input())
S = input()

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

K = set()
K.add(S[0:3])
K2 = set()
K2.add(S[0]+S[1])
K2.add(S[0]+S[2])
K2.add(S[1]+S[2])


for i in range(3,N):   
    c = S[i]
    tmp = set()
    tmp2 = set()
    for k in K2:
        tmp.add(k+c)
        tmp2.add(k[0]+c)
        tmp2.add(k[1]+c)
    K = K.union(tmp)
    K2 = K2.union(tmp2)

print(len(K))

Fixed submission:
N = int(input())
S = input()

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

K = set()
K.add(S[0:3])

for i in range(3,N):   
    c = S[i]
    tmp = set()
    for k in K:
        tmp.add(k[0]+k[1]+c)
        tmp.add(k[0]+k[2]+c)
        tmp.add(k[1]+k[2]+c)
    K = K.union(tmp)

print(len(K))

Fixed submission:
N = int(input())
S = input()

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

K = set()
K.add(S[0:3])

for i in range(3,N):   
    c = S[i]
    tmp = set()
    for k in K:
        tmp.add(k[0]+k[1]+c)
        tmp.add(k[0]+k[2]+c)
        tmp.add(k[1]+k[2]+c)
    K = K.union(tmp)

print(len(K))

Fixed submission:
N = int(input())
S = input()

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)




Fixed submission:
N = int(input())
S = input()

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)