Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline


def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

# mod=10**9+7
# rstrip().decode('utf-8')

import re

def main():
	n=II()
	s=input()
	ans=0
	for i in range(1000):
		j=str(i).zfill(3)
		now=0
		for k in s:
			if j[now]==k:
				now+=1
			if now==3:
				ans+=1
				break



	print(ans)



















if __name__ == "__main__":
	main()


Fixed submission:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
#import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
#from collections import defaultdict
# from collections import Counter
#from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n=int(input())
	s=input().rstrip().decode('utf-8')
	
	ans=0
	
	for a in range(10):
		a=str(a)
		aidx=s.index(a) if a in s else -1
		if aidx!=-1:
			ss=s[aidx+1:]
			for b in range(10):
				b=str(b)
				bidx = ss.index(b) if b in ss else -1
				if bidx != -1:
					sss=ss[bidx+1:]
					for c in range(10):
						c=str(c)
						if c in sss:
							ans+=1
	
	print(ans)
	
	
if __name__ == "__main__":
		main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline


def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

# mod=10**9+7
# rstrip().decode('utf-8')

import re

def main():
	n=II()
	s=input()
	ans=0
	for i in range(1000):
		a,b,c=str(i).zfill(3)
		m=re.search(r'%s.*%s.*%s'%(a,b,c),s)
		if m!=None:
			ans+=1
	print(ans)



















if __name__ == "__main__":
	main()


Fixed submission:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
#import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
#from collections import defaultdict
# from collections import Counter
#from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n=int(input())
	s=input().rstrip().decode('utf-8')
	
	ans=0
	
	for a in range(10):
		a=str(a)
		aidx=s.index(a) if a in s else -1
		if aidx!=-1:
			ss=s[aidx+1:]
			for b in range(10):
				b=str(b)
				bidx = ss.index(b) if b in ss else -1
				if bidx != -1:
					sss=ss[bidx+1:]
					for c in range(10):
						c=str(c)
						if c in sss:
							ans+=1
	
	print(ans)
	
	
if __name__ == "__main__":
		main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline


def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

# mod=10**9+7
# rstrip().decode('utf-8')

import re

def main():
	n=II()
	s=input()
	ans=0
	for i in range(1000):
		a,b,c=str(i).zfill(3)
		m=re.search(r'%s.*%s.*%s'%(a,b,c),s)
		if m!=None:
			ans+=1
	print(ans)



















if __name__ == "__main__":
	main()


Fixed submission:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
#import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
#from collections import defaultdict
# from collections import Counter
#from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n=int(input())
	s=input().rstrip().decode('utf-8')
	
	ans=0
	
	for a in range(10):
		a=str(a)
		aidx=s.index(a) if a in s else -1
		if aidx!=-1:
			ss=s[aidx+1:]
			for b in range(10):
				b=str(b)
				bidx = ss.index(b) if b in ss else -1
				if bidx != -1:
					sss=ss[bidx+1:]
					for c in range(10):
						c=str(c)
						if c in sss:
							ans+=1
	
	print(ans)
	
	
if __name__ == "__main__":
		main()