Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    u = len(set(list(S)))
    tmp = set()
    ans = 0
    for index, i in enumerate(range(N - 2)):
        second = set()
        for j in range(index + 1, N - 1):
            if j in second:
                continue
            if S[i] + S[j] not in tmp:
                second.add(j)
                tmp.add(S[i] + S[j])
                ans += len(set(list(S[j + 1:])))
                if len(tmp) == u ** 2:
                    print(ans)
                    quit()
            if len(second) == u:
                break
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    ans = 0
    for i in range(1000):
        i = str(i).zfill(3)
        prev = -1
        for s in i:
            pos = S.find(s, prev + 1)
            if pos > prev:
                prev = pos
            else:
                break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input().rstrip()
    u = len(set(list(S)))
    first = set()
    tmp = set()
    ans = 0
    for index, i in enumerate(range(N - 2)):
        if i in first:
            continue
        first.add(i)
        for j in range(index+1, N-1):
            if S[i] + S[j] not in tmp:
                tmp.add(S[i] + S[j])
                ans += len(set(list(S[j + 1:])))
                if len(tmp) == u ** 2:
                    print(ans)
                    quit()
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    ans = 0
    for i in range(1000):
        i = str(i).zfill(3)
        prev = -1
        for s in i:
            pos = S.find(s, prev + 1)
            if pos > prev:
                prev = pos
            else:
                break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    tmp = set()
    ans = 0
    for index, i in enumerate(range(N-2)):
        for j in range(index+1, N-1):
            if S[i] + S[j] not in tmp:
                tmp.add(S[i] + S[j])
                ans += len(set(list(S[j + 1:])))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    ans = 0
    for i in range(1000):
        i = str(i).zfill(3)
        prev = -1
        for s in i:
            pos = S.find(s, prev + 1)
            if pos > prev:
                prev = pos
            else:
                break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    tmp = set()
    second = list()
    ans = 0
    for index, i in enumerate(range(N-2)):
        for j in range(index+1, N-1):
            if S[i] + S[j] not in tmp:
                tmp.add(S[i] + S[j])
                second.append(int(j))

    for k in second:
        ans += len(set(list(S[k+1:])))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    ans = 0
    for i in range(1000):
        i = str(i).zfill(3)
        prev = -1
        for s in i:
            pos = S.find(s, prev + 1)
            if pos > prev:
                prev = pos
            else:
                break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()