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

ans = 0

for i in range(1000):
    filled_num = str(i).zfill(3)
    target = list(filled_num)
    ok1 = False
    ok2 = False
    ok3 = False

    for k in range(len(S)):
        if S[k] == target[2] and ok2:
            ok3 = True
        elif S[k] == target[1] and ok1:
            ok2 = True
        elif S[k] == target[0]:
            ok1 = True

        if ok3:
            break
    if ok3:
        ans += 1
print(ans)


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    ans = 1
    N = int(input())
    s = input()
    ans = 0
    for i in range(1000):
        t = str(i).zfill(3)
        t_index = 0 
        for s_index in range(N):
            if s[s_index] == t[t_index]:
                t_index += 1
                if t_index == 3:
                    break
        if t_index == 3:
            ans += 1
    print(ans)
solve()

Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

Buggy python submission (verdict: Time Limit Exceeded):
def test(i, results):
    filled_num = str(i).zfill(3)
    target = list(filled_num)
    index = 0
    j = 0
    for k in range(index, len(S), 1):
        if S[k] == target[j]:
            index = k + 1
            j += 1
            if j == 3:
                results.add(filled_num)
                return


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

results = set()

for i in range(1000):
    test(i, results)

print(len(results))


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

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

results = set()

for i in range(1000):
    # 対象となる3桁の数字を用意
    filled_num = str(i).zfill(3)
    target = list(filled_num)
    count = 0
    index = 0
    j = 0
    for k in range(index, len(S), 1):
        if S[k] == target[j]:
            count += 1
            index = k + 1
            j += 1
            if j == 3:
                results.add(filled_num)
                break

print(len(results))


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

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

results = set()

for i in range(1000):
    # 対象となる3桁の数字を用意
    filled_num = str(i).zfill(3)
    target = list(filled_num)
    count = 0
    index = 0
    for j in range(3):
        for k in range(index, len(S), 1):
            if S[k] == target[j]:
                count += 1
                index = k + 1
                break
    if count == 3:
        # print(filled_num)
        results.add(filled_num)

print(len(results))


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

Buggy python submission (verdict: Time Limit Exceeded):
def test(original: list, array: list, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(array) == 1:
        if "".join(array) in results_1:
            return
        results_1.add("".join(array))
    if len(array) == 2:
        if "".join(array) in results_2:
            return
        results_2.add("".join(array))
    if len(array) == 3:
        # print("".join(array))
        results.add("".join(array))
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        new_array = array[:]
        new_array.append(
            original[i])
        test(
            original,
            new_array,
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, [], 0, N - 3, results, results_1, results_2)

print(len(results))


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

Buggy python submission (verdict: Time Limit Exceeded):
def test(original: list, array: list, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(array) == 1:
        if "".join(array) in results_1:
            return
        results_1.add("".join(array))
    if len(array) == 2:
        if "".join(array) in results_2:
            return
        results_2.add("".join(array))
    if len(array) == 3:
        # print("".join(array))
        results.add("".join(array))
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        new_array = array[:]
        new_array.append(
            original[i])
        test(
            original,
            new_array,
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, [], 0, N - 3, results, results_1, results_2)

print(len(results))


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

Buggy python submission (verdict: Time Limit Exceeded):
def test(original: list, array: list, index: int,
         remain_count: int, results: set):
    # 3桁抽出したら終了
    if len(array) == 3:
        # print("".join(array))
        results.add("".join(array))
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        new_array = array[:]
        new_array.append(
            original[i])
        test(
            original,
            new_array,
            i + 1,
            remain_count,
            results)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, [], 0, N - 3, results)

print(len(results))


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

Buggy python submission (verdict: Runtime Error):
def test(original: list, array: list, index: int,
         remain_count: int, results: set):
    # 3桁抽出したら終了
    if len(array) == 3:
        # print("".join(array))
        results.add("".join(array))
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    # この桁を抽出対象とするパターン
    test(original, array[:], index + 1, remain_count - 1, results)

    # この桁を抽出対象としないパターン
    new_array = array[:]
    new_array.append(
        original[index])
    test(
        original,
        new_array,
        index + 1,
        remain_count,
        results)


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

results = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, [], 0, N - 3, results)

print(len(results))


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))

Buggy python submission (verdict: Runtime Error):
def test(original: list, array: list, index: int,
         remain_count: int, results: set):
    if index == len(original):
        if remain_count == 0:
            # print("".join(array))
            results.add("".join(array))
        return
    if remain_count > 0:
        test(original, array[:], index + 1, remain_count - 1, results)
    new_array = array[:]
    new_array.append(
        original[index])
    test(
        original,
        new_array,
        index + 1,
        remain_count,
        results)


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

results = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, [], 0, N - 3, results)

print(len(results))


Fixed submission:
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


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

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))