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

passwords = []
for i in range(len(S) - 2):
    for j in range(i + 1, len(S) - 1):
        # for k in range(j + 1, len(S)):
        for char in list(set(S[j + 1:])):
            password = S[i] + S[j] + char
            passwords.append(password)


# print(len(passwords))
# print(passwords)
# print(set(passwords))
print(len(list(set(passwords))))


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

passwords = []
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            password = str(i) + str(j) + str(k)
            passwords.append(password)

char_hash = {}
for i, char in enumerate(S):
    if char in char_hash.keys():
        char_hash[char].append(i)
    else:
        char_hash[char] = [i]

# print(char_hash

count = 0
for password in passwords:
    exist_keys = char_hash.keys()
    # print(password[0] in char_hash.keys())
    if not(password[0] in exist_keys):
        continue
    if not(password[1] in exist_keys):
        continue
    if not(password[2] in exist_keys):
        continue
    first_index = min(char_hash[password[0]])
    second_indexes = char_hash[password[1]]
    second_index = -1
    for index in second_indexes:
        if index <= first_index:
            continue
        else:
            second_index = index
            break
    third_indexes = char_hash[password[2]]
    third_index = -1
    for index in third_indexes:
        if index <= second_index:
            continue
        else:
            third_index = index
            break
    # print(first_index, second_index, third_index)
    if first_index < second_index and second_index < third_index:
        count += 1

print(count)
# print(len(passwords))
# print(passwords)
# print(set(passwords))
# print(len(list(set(passwords))))

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

passwords = []
for i in range(len(S) - 2):
    for j in range(i + 1, len(S) - 1):
        for k in range(j + 1, len(S)):
            password = S[i] + S[j] + S[k]
            passwords.append(password)


# print(len(passwords))
# print(passwords)
# print(set(passwords))
print(len(list(set(passwords))))


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

passwords = []
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            password = str(i) + str(j) + str(k)
            passwords.append(password)

char_hash = {}
for i, char in enumerate(S):
    if char in char_hash.keys():
        char_hash[char].append(i)
    else:
        char_hash[char] = [i]

# print(char_hash

count = 0
for password in passwords:
    exist_keys = char_hash.keys()
    # print(password[0] in char_hash.keys())
    if not(password[0] in exist_keys):
        continue
    if not(password[1] in exist_keys):
        continue
    if not(password[2] in exist_keys):
        continue
    first_index = min(char_hash[password[0]])
    second_indexes = char_hash[password[1]]
    second_index = -1
    for index in second_indexes:
        if index <= first_index:
            continue
        else:
            second_index = index
            break
    third_indexes = char_hash[password[2]]
    third_index = -1
    for index in third_indexes:
        if index <= second_index:
            continue
        else:
            third_index = index
            break
    # print(first_index, second_index, third_index)
    if first_index < second_index and second_index < third_index:
        count += 1

print(count)
# print(len(passwords))
# print(passwords)
# print(set(passwords))
# print(len(list(set(passwords))))

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

passwords = []
for i in range(len(S)):
    for j in range(i + 1, len(S)):
        for k in range(j + 1, len(S)):
            password = S[i] + S[j] + S[k]
            passwords.append(password)


# print(len(passwords))
# print(passwords)
# print(set(passwords))
print(len(list(set(passwords))))


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

passwords = []
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            password = str(i) + str(j) + str(k)
            passwords.append(password)

char_hash = {}
for i, char in enumerate(S):
    if char in char_hash.keys():
        char_hash[char].append(i)
    else:
        char_hash[char] = [i]

# print(char_hash

count = 0
for password in passwords:
    exist_keys = char_hash.keys()
    # print(password[0] in char_hash.keys())
    if not(password[0] in exist_keys):
        continue
    if not(password[1] in exist_keys):
        continue
    if not(password[2] in exist_keys):
        continue
    first_index = min(char_hash[password[0]])
    second_indexes = char_hash[password[1]]
    second_index = -1
    for index in second_indexes:
        if index <= first_index:
            continue
        else:
            second_index = index
            break
    third_indexes = char_hash[password[2]]
    third_index = -1
    for index in third_indexes:
        if index <= second_index:
            continue
        else:
            third_index = index
            break
    # print(first_index, second_index, third_index)
    if first_index < second_index and second_index < third_index:
        count += 1

print(count)
# print(len(passwords))
# print(passwords)
# print(set(passwords))
# print(len(list(set(passwords))))