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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    for j in range(N):
        if key[i][0] == int(S[j]):
            flag1 = 1
            break
            
    if flag1 == 0:
        continue
            
    for k in range(j+1,N):
        if key[i][1] == int(S[k]):
            flag2 = 1
            break
            
    if flag2 == 0:
        continue
                
    for l in range(k+1,N):
        if key[i][2] == int(S[l]):
            flag3 = 1
            break
                            
    if flag1 == 1 and flag2 == 1 and flag3 == 1:
        ans += 1
        
print(ans)

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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    flag1 = S.find(str(key[i][0]))
    
    if flag1 == -1:
        continue
        
    flag2 = S.find(str(key[i][1]),flag1+1)
    
    if flag2 == -1:
        continue
        
    flag3 = S.find(str(key[i][2]),flag2+1)
    
    if flag3 == -1:
        continue
                            
    if flag1 != -1 and flag2 != -1 and flag3 != -1:
        ans += 1
        
print(ans)

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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    for j in range(N):
        if key[i][0] == int(S[j]):
            flag1 = 1
            break
            
    if flag1 == 0:
        continue
            
    for k in range(j+1,N):
        if key[i][1] == int(S[k]):
            flag2 = 1
            break
            
    if flag2 == 0:
        continue
                
    for l in range(k+1,N):
        if key[i][2] == int(S[l]):
            flag3 = 1
            break
                            
    if flag1 == 1 and flag2 == 1 and flag3 == 1:
        ans += 1
        
print(ans)

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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    flag1 = S.find(str(key[i][0]))
    
    if flag1 == -1:
        continue
        
    flag2 = S.find(str(key[i][1]),flag1+1)
    
    if flag2 == -1:
        continue
        
    flag3 = S.find(str(key[i][2]),flag2+1)
    
    if flag3 == -1:
        continue
                            
    if flag1 != -1 and flag2 != -1 and flag3 != -1:
        ans += 1
        
print(ans)

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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    for j in range(N):
        if key[i][0] == int(S[j]):
            flag1 = 1
            break
            
    for k in range(j+1,N):
        if key[i][1] == int(S[k]):
            flag2 = 1
            break
                
    for l in range(k+1,N):
        if key[i][2] == int(S[l]):
            flag3 = 1
            break
                            
    if flag1 == 1 and flag2 == 1 and flag3 == 1:
        ans += 1
        
print(ans)

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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    flag1 = S.find(str(key[i][0]))
    
    if flag1 == -1:
        continue
        
    flag2 = S.find(str(key[i][1]),flag1+1)
    
    if flag2 == -1:
        continue
        
    flag3 = S.find(str(key[i][2]),flag2+1)
    
    if flag3 == -1:
        continue
                            
    if flag1 != -1 and flag2 != -1 and flag3 != -1:
        ans += 1
        
print(ans)