Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    for j in range(N):
        if i[0] == S[j]:
            for k in range(j + 1, N):
                if i[1] == S[k]:
                    for n in range(k + 1, N):
                        if i[2] == S[n]:
                            ans += 1
                            break
                    break
        if tmp != ans:
            tmp = ans
            break
print(ans)

Fixed submission:

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    a, b, c = i
    index1 = S.find(a)
    index2 = S.find(b, index1 + 1)
    index3 = S.find(c, index2 + 1)
    if index1 != -1 and index2 != -1 and index3 != -1:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    for j in range(N):
        if i[0] == S[j]:
            for k in range(j + 1, N):
                if i[1] == S[k]:
                    for n in range(k + 1, N):
                        if i[2] == S[n]:
                            ans += 1
                            break
                    break
        if tmp != ans:
            tmp = ans
            break
print(ans)

Fixed submission:

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    a, b, c = i
    index1 = S.find(a)
    index2 = S.find(b, index1 + 1)
    index3 = S.find(c, index2 + 1)
    if index1 != -1 and index2 != -1 and index3 != -1:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

slen = list(itertools.combinations(S, N - (N - 3)))
setlen = set(slen)

print(len(setlen))


Fixed submission:

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    a, b, c = i
    index1 = S.find(a)
    index2 = S.find(b, index1 + 1)
    index3 = S.find(c, index2 + 1)
    if index1 != -1 and index2 != -1 and index3 != -1:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

slen = list(itertools.combinations(S, N - (N - 3)))
setlen = set(slen)

print(len(setlen))

Fixed submission:

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    a, b, c = i
    index1 = S.find(a)
    index2 = S.find(b, index1 + 1)
    index3 = S.find(c, index2 + 1)
    if index1 != -1 and index2 != -1 and index3 != -1:
        ans += 1
print(ans)