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

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    k = 0
    for j in range(N):
        if s[j] == v[k]:
            k += 1
        if k == 3:
            res += 1
            break
print(res)            


Fixed submission:
N = int(input())

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    tmp = s
    if v[0] in tmp:
        tmp = tmp[tmp.index(v[0])+1:]
    else:
        continue
    if v[1] in tmp:
        tmp = tmp[tmp.index(v[1])+1:]
    else:
        continue
    if v[2] in tmp:
        res += 1
print(res)

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

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    # ステップ1
    p1 = -1
    for j in range(N-2):
        if s[j] == v[0]:
            p1 = j
            break
    
    if p1 < 0: continue

    # ステップ2
    p2 = -1
    for j in range(p1+1,N-1):
        if s[j] == v[1]:
            p2 = j
            break
    
    if p2 < 0: continue

    # ステップ3
    p3 = -1
    for j in range(p2+1,N):
        if s[j] == v[2]:
            res += 1
            break
print(res)            


Fixed submission:
N = int(input())

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    tmp = s
    if v[0] in tmp:
        tmp = tmp[tmp.index(v[0])+1:]
    else:
        continue
    if v[1] in tmp:
        tmp = tmp[tmp.index(v[1])+1:]
    else:
        continue
    if v[2] in tmp:
        res += 1
print(res)

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

s = input()

res = 0

for i in range(1000):
    if 99 < i:
        v = str(i)
    elif 9 < i:
        v = '0'+str(i)
    else:
        v = '0'+'0'+str(i)
    
    # ステップ1
    p1 = -1
    for j in range(N-2):
        if s[j] == v[0]:
            p1 = j
            break
    
    if p1 < 0: continue

    # ステップ2
    p2 = -1
    for j in range(p1+1,N-1):
        if s[j] == v[1]:
            p2 = j
            break
    
    if p2 < 0: continue

    # ステップ3
    p3 = -1
    for j in range(p2+1,N):
        if s[j] == v[2]:
            res += 1
            break
print(res)            


Fixed submission:
N = int(input())

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    tmp = s
    if v[0] in tmp:
        tmp = tmp[tmp.index(v[0])+1:]
    else:
        continue
    if v[1] in tmp:
        tmp = tmp[tmp.index(v[1])+1:]
    else:
        continue
    if v[2] in tmp:
        res += 1
print(res)

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

s = list(input())

res = 0

for i in range(1000):
    if 99 < i:
        v = list(str(i))
    elif 9 < i:
        v = list('0'+str(i))
    else:
        v = list('0'+'0'+str(i))
    
    # ステップ1
    p1 = -1
    for j in range(N):
        if s[j] == v[0]:
            p1 = j
            break
    
    if p1 < 0: continue

    # ステップ2
    p2 = -1
    for j in range(p1+1,N):
        if s[j] == v[1]:
            p2 = j
            break
    
    if p2 < 0: continue

    # ステップ3
    p3 = -1
    for j in range(p2+1,N):
        if s[j] == v[2]:
            res += 1
            break
print(res)            


Fixed submission:
N = int(input())

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    tmp = s
    if v[0] in tmp:
        tmp = tmp[tmp.index(v[0])+1:]
    else:
        continue
    if v[1] in tmp:
        tmp = tmp[tmp.index(v[1])+1:]
    else:
        continue
    if v[2] in tmp:
        res += 1
print(res)