Buggy python submission (verdict: Time Limit Exceeded):
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnt = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            n = 0
            abc = [a,b,c]
            for i in range(N):
                if int(s[i]) == abc[n]:
                    n += 1
                if n == 3:
                    cnt += 1
                    break
print(cnt)

Fixed submission:
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnt = 0
for a in range(10):
    for b in range(10):
        n = 0
        ab = [a,b]
        for i in range(N):
            if int(s[i]) == ab[n]:
                n += 1
            if n == 2:
                for c in range(10):
                    for j in range(i+1,N):
                        if int(s[j]) == c:
                            cnt += 1
                            break
                else:
                    break
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = [i for i in S()]
#print(s)

a = [-1 for i in range(N)]
v = []
n = 0
for i in range(N)[::-1]:
  if s[i] not in v:
    v.append(s[i])
    n += 1
  a[i] = n

finished = [[-1]*10 for i in range(10)]
ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    if finished[int(s[i])][int(s[j])] == True:
      continue
    else:
      ans += a[j + 1]
    finished[int(s[i])][int(s[j])] = True
print(ans)

Fixed submission:
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnt = 0
for a in range(10):
    for b in range(10):
        n = 0
        ab = [a,b]
        for i in range(N):
            if int(s[i]) == ab[n]:
                n += 1
            if n == 2:
                for c in range(10):
                    for j in range(i+1,N):
                        if int(s[j]) == c:
                            cnt += 1
                            break
                else:
                    break
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = [i for i in S()]
#print(s)

a = [-1 for i in range(N)]
v = []
for i in range(N)[::-1]:
  v.append(s[i])
  v = list(set(v))
  a[i] = len(v)

finished = []
t = ""
ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    t = str(s[i]) + str(s[j])
    if t in finished:
      continue
    else:
      ans += a[j + 1]
    finished.append(t)
print(ans)

Fixed submission:
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnt = 0
for a in range(10):
    for b in range(10):
        n = 0
        ab = [a,b]
        for i in range(N):
            if int(s[i]) == ab[n]:
                n += 1
            if n == 2:
                for c in range(10):
                    for j in range(i+1,N):
                        if int(s[j]) == c:
                            cnt += 1
                            break
                else:
                    break
print(cnt)