Buggy python submission (verdict: Time Limit Exceeded):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = set()
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(len(a_alr) == 10):
        break
    if(s[i] in a_alr):
        continue

    for j in range(i+1,n-1):
        if(len(b_alr[s[i]]) == 10):
            break
        if(s[j] in b_alr[s[i]]):
            continue
        c_alr = set()
        for k in range(j+1,n):
            c_alr = c_alr | set([s[k]])   
            tmp = s[i]+s[j]+s[k]
            ans = ans | set([tmp])
            if(len(c_alr) == 10):
                break

        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(len(ans))

Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = 0
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(len(a_alr) == 10):
        break
    if(s[i] in a_alr):
        continue

    for j in range(i+1,n-1):
        if(len(b_alr[s[i]]) == 10):
            break
        if(s[j] in b_alr[s[i]]):
            continue
        
        ans += len(set(s[j+1:]))
        
        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = set()
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(s[i] in a_alr):
        continue
    for j in range(i+1,n-1):
        if(s[j] in b_alr[s[i]]):
            continue
        c_alr = set()
        for k in range(j+1,n):
            c_alr = c_alr | set([s[k]])   
            tmp = s[i]+s[j]+s[k]
            ans = ans | set([tmp])
            if(len(c_alr) == 10):
                break

        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(len(ans))

Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = 0
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(len(a_alr) == 10):
        break
    if(s[i] in a_alr):
        continue

    for j in range(i+1,n-1):
        if(len(b_alr[s[i]]) == 10):
            break
        if(s[j] in b_alr[s[i]]):
            continue
        
        ans += len(set(s[j+1:]))
        
        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = set()
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(s[i] in a_alr):
        continue
    for j in range(i+1,n-1):
        if(s[j] in b_alr[s[i]]):
            continue
        for k in range(j+1,n):
            tmp = s[i]+s[j]+s[k]
            ans = ans | set([tmp])

        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(len(ans))

Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = 0
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(len(a_alr) == 10):
        break
    if(s[i] in a_alr):
        continue

    for j in range(i+1,n-1):
        if(len(b_alr[s[i]]) == 10):
            break
        if(s[j] in b_alr[s[i]]):
            continue
        
        ans += len(set(s[j+1:]))
        
        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(ans)