Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
#print(S)
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[False]*10 for _ in range(N+1)]
dpp = [[[False]*10 for _ in range(10)] for _ in range(N+1)]
dppp = [[[[False]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]
 
for i in range(N):
  now = S[i] #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = True
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = dp[i][x]|dp[i+1][x]
    for y in range(10):
      if y == now and dp[i][x]:
        dpp[i+1][x][y] = True
      else:
        dpp[i+1][x][y] = dpp[i][x][y]|dpp[i+1][x][y]
      for z in range(10):
        if z == now and dpp[i][x][y]:
          dppp[i+1][x][y][z] = True
        else:
          dppp[i+1][x][y][z] = dppp[i][x][y][z]|dppp[i+1][x][y][z]
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      if dppp[N][i][j][k]:
        ans += 1
        
print(ans)       

Fixed submission:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
L = [[] for _ in range(10)]
for i in range(N):
  L[S[i]].append(i)
#print(L)
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  if not L[a]:
    continue
  left = min(L[a])
  Flag = False
  for x in L[b]:
    if x > left:
      mid = x
      Flag = True
      break
  if not Flag:
    continue
  Flag = False
  for y in L[c]:
    if y > mid:
      right = y
      Flag = True
      break
  if not Flag:
    continue
  ans.add(v)
  #print(v,left,mid,right)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  for i in range(N):
    if a != S[i]:
      continue
    for j in range(i+1,N):
      if b != S[j]:
        continue
      for k in range(j+1,N):
        if c == S[k]:
          ans.add(v)
          break
print(len(ans))        

Fixed submission:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
L = [[] for _ in range(10)]
for i in range(N):
  L[S[i]].append(i)
#print(L)
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  if not L[a]:
    continue
  left = min(L[a])
  Flag = False
  for x in L[b]:
    if x > left:
      mid = x
      Flag = True
      break
  if not Flag:
    continue
  Flag = False
  for y in L[c]:
    if y > mid:
      right = y
      Flag = True
      break
  if not Flag:
    continue
  ans.add(v)
  #print(v,left,mid,right)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
#print(S)
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[0]*10 for _ in range(N+1)]
dpp = [[[0]*10 for _ in range(10)] for _ in range(N+1)]
dppp = [[[[0]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]

for i in range(N):
  now = S[i] #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = 1
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = max(dp[i][x],dp[i+1][x])
    for y in range(10):
      if y == now and dp[i][x] == 1:
        dpp[i+1][x][y] = 1
      else:
        dpp[i+1][x][y] = max(dpp[i][x][y],dpp[i+1][x][y])
      for z in range(10):
        if z == now and dpp[i][x][y] == 1:
          dppp[i+1][x][y][z] = 1
        else:
          dppp[i+1][x][y][z] = max(dppp[i][x][y][z],dppp[i+1][x][y][z])
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      ans += dppp[N][i][j][k]
        
print(ans)       

Fixed submission:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
L = [[] for _ in range(10)]
for i in range(N):
  L[S[i]].append(i)
#print(L)
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  if not L[a]:
    continue
  left = min(L[a])
  Flag = False
  for x in L[b]:
    if x > left:
      mid = x
      Flag = True
      break
  if not Flag:
    continue
  Flag = False
  for y in L[c]:
    if y > mid:
      right = y
      Flag = True
      break
  if not Flag:
    continue
  ans.add(v)
  #print(v,left,mid,right)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
#print(S)
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[0]*10 for _ in range(N+1)]
dpp = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]
dppp = [[[[0]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]

for i in range(N):
  now = S[i] #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = 1
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = max(dp[i][x],dp[i+1][x])
    for y in range(10):
      if y == now and dp[i][x] == 1:
        dpp[i+1][x][y] = 1
      else:
        dpp[i+1][x][y] = max(dpp[i][x][y],dpp[i+1][x][y])
      for z in range(10):
        if z == now and dpp[i][x][y] == 1:
          dppp[i+1][x][y][z] = 1
        else:
          dppp[i+1][x][y][z] = max(dppp[i][x][y][z],dppp[i+1][x][y][z])
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      ans += dppp[N][i][j][k]
        
print(ans)       

Fixed submission:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
L = [[] for _ in range(10)]
for i in range(N):
  L[S[i]].append(i)
#print(L)
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  if not L[a]:
    continue
  left = min(L[a])
  Flag = False
  for x in L[b]:
    if x > left:
      mid = x
      Flag = True
      break
  if not Flag:
    continue
  Flag = False
  for y in L[c]:
    if y > mid:
      right = y
      Flag = True
      break
  if not Flag:
    continue
  ans.add(v)
  #print(v,left,mid,right)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[0]*10 for _ in range(N+1)]
dpp = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]
dppp = [[[[0]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]

for i in range(N):
  now = int(S[i]) #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = 1
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = max(dp[i][x],dp[i+1][x])
    for y in range(10):
      if y == now and dp[i][x] == 1:
        dpp[i+1][x][y] = 1
      else:
        dpp[i+1][x][y] = max(dpp[i][x][y],dpp[i+1][x][y])
      for z in range(10):
        if z == now and dpp[i][x][y] == 1:
          dppp[i+1][x][y][z] = 1
        else:
          dppp[i+1][x][y][z] = max(dppp[i][x][y][z],dppp[i+1][x][y][z])
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      ans += dppp[N][i][j][k]
        
print(ans)       

Fixed submission:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
L = [[] for _ in range(10)]
for i in range(N):
  L[S[i]].append(i)
#print(L)
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  if not L[a]:
    continue
  left = min(L[a])
  Flag = False
  for x in L[b]:
    if x > left:
      mid = x
      Flag = True
      break
  if not Flag:
    continue
  Flag = False
  for y in L[c]:
    if y > mid:
      right = y
      Flag = True
      break
  if not Flag:
    continue
  ans.add(v)
  #print(v,left,mid,right)
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = str(input())
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[0]*10 for _ in range(N+1)]
dpp = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]
dppp = [[[[0]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]

for i in range(N):
  now = int(S[i]) #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = 1
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = max(dp[i][x],dp[i+1][x])
    for y in range(10):
      if y == now and dp[i][x] == 1:
        dpp[i+1][x][y] = 1
      else:
        dpp[i+1][x][y] = max(dpp[i][x][y],dpp[i+1][x][y])
      for z in range(10):
        if z == now and dpp[i][x][y] == 1:
          dppp[i+1][x][y][z] = 1
        else:
          dppp[i+1][x][y][z] = max(dppp[i][x][y][z],dppp[i+1][x][y][z])
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      ans += dppp[N][i][j][k]
        
print(ans)       

Fixed submission:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
L = [[] for _ in range(10)]
for i in range(N):
  L[S[i]].append(i)
#print(L)
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  if not L[a]:
    continue
  left = min(L[a])
  Flag = False
  for x in L[b]:
    if x > left:
      mid = x
      Flag = True
      break
  if not Flag:
    continue
  Flag = False
  for y in L[c]:
    if y > mid:
      right = y
      Flag = True
      break
  if not Flag:
    continue
  ans.add(v)
  #print(v,left,mid,right)
print(len(ans))