Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j in range(N):
        if v[idx] == S[j]:
            idx += 1
            if idx == 3:
                ans += 1
                break
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j, s in enumerate(S):
        if v[idx] in S[j:]:
            if v[idx] == s:
                idx += 1
                if idx < 3 and v[idx] not in S[j+1:]:
                    break
            if idx == 3:
                ans += 1
                break
        else:
            break
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j, s in enumerate(S):
        if v[idx] == s:
            idx += 1
            if idx < 3 and v[idx] not in S[j+1:]:
                break
        if idx == 3:
            ans += 1
            break
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j, s in enumerate(S):
        if v[idx] == s:
            idx += 1
            if v[idx] not in S[j+1:]:
                break
        if idx == 3:
            ans += 1
            break
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j, s in enumerate(S):
        if v[idx] in S[j:]:
            if v[idx] == s:
                idx += 1
            if idx == 3:
                ans += 1
                break
        else:
            break
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j, s in enumerate(S):
        if v[idx] in S[j:]:
            if v[idx] == s:
                idx += 1
            if idx == 3:
                ans += 1
                break
        else:
            break
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

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

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [s for s in input()]
num = {s:[] for s in S}
for i, s in enumerate(S):
    num[s].append(i)
ans = 0
for i in range(1000):
    s = str(i).zfill(3)
    if s[0] in num.keys() and s[1] in num.keys() and s[2] in num.keys():
        for a in num[s[0]]:
            for b in num[s[1]]:
                for c in num[s[2]]:
                    if a < b < c:
                        ans += 1
                        break
                else:
                    continue
                break
            else:
                continue
            break
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from operator import mul
from functools import reduce
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
N = int(input())
S = [int(s) for s in input()]
num = {s:[] for s in S}
for i, s in enumerate(S):
    num[s].append(i)
ans = combinations_count(N, 3)
check = []
for i in list(num.keys()):
    for j in list(num.keys()):
        for k in list(num.keys()):
            s = str(i) + str(j) + str(k)
            if s not in check and (len(num[i]) > 1 or len(num[j]) > 1 or len(num[k]) > 1):
                temp = 0
                check.append(s)
                for a in num[i]:
                    for b in num[j]:
                        for c in num[k]:
                            if a < b < c:
                                temp += 1
                #print(i, j, k, temp)
                if temp > 0:
                    ans -= (temp-1)
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
from operator import mul
from functools import reduce
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
N = int(input())
S = [int(s) for s in input()]
num = {s:[] for s in S}
for i, s in enumerate(S):
    num[s].append(i)
ans = combinations_count(N, 3)
#print(ans)
check = []
for i in list(num.keys()):
    for j in list(num.keys()):
        for k in list(num.keys()):
            s = str(i) + str(j) + str(k)
            if s not in check and (len(num[i]) > 1 or len(num[j]) > 1 or len(num[k]) > 1):
                temp = 0
                check.append(s)
                for a in num[i]:
                    for b in num[j]:
                        for c in num[k]:
                            if a < b < c:
                                temp += 1
                #print(i, j, k, temp)
                if temp > 0:
                    ans -= (temp-1)
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N = int(input())
S = [s for s in input()]
ans = []
for (i, j, k) in itertools.combinations(S, 3):
    s = i + j + k
    #print(s)
    if s not in ans:
        ans.append(s)
print(len(ans))

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    c = 0
    idx_now = 0
    for j in range(3):
        idx = S[idx_now:].find(v[j])
        if idx == -1:
            break
        else:
            idx_now += idx + 1
            c += 1
    if c == 3:
        ans += 1
print(ans)