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

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  center = -1
  for r in range(1, N-1):
    if S[N-r] == z[2]:
      right = N-r
      break
  if right == -1:
    continue
  for c in range(1, right):
    if S[right-c] == z[1]:
      center = right-c
      break
  if center == -1:
    continue
  if z[0] in S[:center]:
    ans += 1
print(ans)


Fixed submission:
N = int(input())
S = str(input())
R = S[::-1]

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  left = -1
  if z[2] in R:
    r = R.index(z[2]) + 1
    right = N-r
  else:
    continue
  if z[0] in S:
    left = S.index(z[0]) + 1
  else:
    continue
  if z[1] in S[left:right]:
    ans += 1
print(ans)

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

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  center = -1
  for r in range(1, N-1):
    if S[N-r] == z[2]:
      right = N-r
      break
  if right == -1:
    continue
  for c in range(1, right):
    if S[right-c] == z[1]:
      center = right-c
      break
  if center == -1:
    continue
  for l in range(1, center+1):
    if S[center-l] == z[0]:
      ans += 1
      break
print(ans)

Fixed submission:
N = int(input())
S = str(input())
R = S[::-1]

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  left = -1
  if z[2] in R:
    r = R.index(z[2]) + 1
    right = N-r
  else:
    continue
  if z[0] in S:
    left = S.index(z[0]) + 1
  else:
    continue
  if z[1] in S[left:right]:
    ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
S = str(input())

l = []
li = deque([])
for i in range(1, N-1):
  if S[N-i] not in l:
    l.append(S[N-i])
    li.appendleft(N-i)
    
lis = []
ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    s = S[i] + S[j]
    if s not in lis:
      lis.append(s)
      for k in range(len(li)):
        if j < li[k]:
          ans += len(li)-k
          break

print(ans)

Fixed submission:
N = int(input())
S = str(input())
R = S[::-1]

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  left = -1
  if z[2] in R:
    r = R.index(z[2]) + 1
    right = N-r
  else:
    continue
  if z[0] in S:
    left = S.index(z[0]) + 1
  else:
    continue
  if z[1] in S[left:right]:
    ans += 1
print(ans)

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

l = []
for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      s = S[i]+S[j]+S[k]
      l.append(s)

l = set(l)
ans = len(l)
print(ans)

Fixed submission:
N = int(input())
S = str(input())
R = S[::-1]

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  left = -1
  if z[2] in R:
    r = R.index(z[2]) + 1
    right = N-r
  else:
    continue
  if z[0] in S:
    left = S.index(z[0]) + 1
  else:
    continue
  if z[1] in S[left:right]:
    ans += 1
print(ans)

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

ans = 0
l = []
for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      s = S[i]+S[j]+S[k]
      if s not in l:
        l.append(s)
        ans += 1
print(ans)

Fixed submission:
N = int(input())
S = str(input())
R = S[::-1]

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  left = -1
  if z[2] in R:
    r = R.index(z[2]) + 1
    right = N-r
  else:
    continue
  if z[0] in S:
    left = S.index(z[0]) + 1
  else:
    continue
  if z[1] in S[left:right]:
    ans += 1
print(ans)