Problem:
 Score: 400 points    Problem Statement  AtCoder Inc. has decided to lock the door of its office with a 3 -digit PIN code.  The company has an N -digit lucky number, S . Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.  How many different PIN codes can he set this way?  Both the lucky number and the PIN code may begin with a 0 .      Constraints   4 \leq N \leq 30000  S is a string of length N consisting of digits.         Input  Input is given from Standard Input in the following format:  N  S       Output  Print the number of different PIN codes Takahashi can set.        Sample Input 1 4
0224      Sample Output 1 3  Takahashi has the following options:   Erase the first digit of S and set 224 .  Erase the second digit of S and set 024 .  Erase the third digit of S and set 024 .  Erase the fourth digit of S and set 022 .   Thus, he can set three different PIN codes: 022 , 024 , and 224 .       Sample Input 2 6
123123      Sample Output 2 17       Sample Input 3 19
3141592653589793238      Sample Output 3 329

Solution (Python):
n = int(input())
s = input()


ans = 0
for i in range(10):
  a = s.find(str(i))
  for j in range(10):
    b = s.find(str(j), a+1) 
    for k in range(10):
      c = s.find(str(k), b+1) 
      if a == -1 or b == -1 or c == -1: continue
      else: ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()

cnt = 0
for i in range(1000):
    pin = '%03d' % i
    try:
        i0 = s.index(pin[0])
        i1 = i0 + 1 + s[i0+1:].index(pin[1])
        i2 = i1 + 1 + s[i1+1:].index(pin[2])
        cnt += 1
    except ValueError:
        pass

print(cnt)

Solution (Python):
from itertools import product

N = int(input())
S = input()
pins = list(product([i for i in range(10)], repeat=3))
ans = 0
for pin in pins:
  i = 0
  for s in S:
    if pin[i] == int(s):
      i += 1
    if i == 3:
      ans += 1
      break
print(ans)

Solution (Python):

import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

N = int(input())    
S = input()     

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            src = i
            num = 0
            for s in S:
                if int(s) == src:
                    if num == 0:
                        src = j
                        num = 1
                    elif num == 1:
                        src = k
                        num = 2
                    elif num == 2:
                        res += 1
                        break

print("{}".format(res))

Solution (Python):

N = int(input())
S = input()

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a = S.find(str(i))
            if a == -1:
                continue
            b = S.find(str(j),a+1)
            if b == -1:
                continue
            c = S.find(str(k),b+1)
            if c == -1:
                continue
            cnt += 1
print(cnt)

Solution (Python):
n = int(input())
L = input()

S = set()
cnt = 0
for i in range(1000):
    i = str(i).zfill(3)
    num = 0
    for j in range(n):
        if L[j] == i[0] and num == 0:
            num =1
        elif L[j] == i[1] and num == 1:
            num =2
        elif L[j] == i[2] and num == 2:
            S.add(i)
            
print(len(S))

Solution (Python):
N = int(input())
S = input()
d = {}
k1 = [0 for i in range(10)]
for i in range(N-2):
    if k1[int(S[i])] != 0: continue
    k1[int(S[i])] += 1
    k2 = [0 for i in range(10)]
    for j in range(i+1, N-1):
        if k2[int(S[j])] != 0: continue
        k2[int(S[j])] += 1
        for k in range(j+1, N):
            st = ''.join([S[i], S[j], S[k]])
            d[st] = True
print(len(d))

Solution (Python):
n=int(input())
S=input()
anslist=[]
c=0

for i in range(1000):
    c=0
    if i<10:
        i="00"+str(i)
    elif i<100:
        i="0"+str(i)
    else:
        i=str(i)
    tmp=""
    j=0
    while j<n:
        if S[j]==i[0]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[1]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[2]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    if tmp==i:
        anslist.append(tmp)
                        

print(len(anslist))

Solution (Python):
n=int(input())
s=list(input())
num=list(range(10))
for i in range(10):
    num[i]=str(num[i])
ans=0
for i in range(n-2):
    if len(num)==0:
        break
    if s[i] in num:
        num2=[str(_) for _ in range(10)]
        num.remove(s[i])
        for j in range(i+1,n):
            if len(num2)==0:
                break
            if s[j] in num2:
                num2.remove(s[j])
                ans+=len(set(s[j+1:]))
print(ans)

Solution (Python):
N = int(input())
S = input()
res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tnp = [i,j,k]
            flag = 0
            for s in S:
                if int(s) == tnp[flag]:
                    flag += 1
                if flag == 3:
                    res += 1
                    break
print(res)

Solution (Python):
digits = int(input())
num_list = [int(i) for i in list(input())]
flag1 = 0
flag2 = 0
counter = 0


for num1 in range(10):
	for num2 in range(10):
		for num3 in range(10):
			flag1 = 0
			flag2 = 0
			for digit in range(digits):
				if flag1 == 0 and flag2 == 0 and num1 == num_list[digit]:
					flag1 = 1
					continue
				if flag1 == 1 and num2 == num_list[digit]:
					flag2 = 1
					flag1 = 0
					continue
				if flag2 == 1 and num3 == num_list[digit]:
					counter += 1
					flag2 = 0
					break
print(counter)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(10):
  a = s.find(str(i))
  for j in range(10):
    b = s.find(str(j), a+1)
    for k in range(10):
      c = s.find(str(k), b+1)
      if a == -1 or b == -1 or c == -1:
        continue
      else:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(10):
  idx1=s.find(str(i))
  for j in range(10):
    idx2=s.find(str(j),idx1+1,n)
    for k in range(10):
      idx3=s.find(str(k),idx2+1,n)
      if idx1==-1 or idx2==-1 or idx3==-1:
        continue
      else:
        ans+=1
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tar=str(i)+str(j)+str(k)
            now=0
            for l in range(n):
                
                if tar[0+now]==s[l]:now+=1
                if now==3:
                    ans+=1
                    break
print(ans)

Solution (Python):
N = int(input())
S = str(input())
num = []
for _ in range(10):
    num.append([])

for i in range(N):
    num[int(S[i])].append(i)

ans = 0
for X1 in range(0, 10):
    for X2 in range(0, 10):
        for X3 in range(0, 10):
            X = str(X1) + str(X2) + str(X3)
            if num[X1] != [] and num[X2] != [] and num[X3] != []:
                if num[X1][0] < num[X2][-1]:
                    for i in num[X2]:
                        if num[X1][0] < i < num[X3][-1]:
                            ans += 1
                            break

print(ans)

Solution (Python):

import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N = int(input())
S = input()

cnt = 0
for num in range(1000):
    snum = str(num).zfill(3)
    
    ind = 0
    chkind = 0
    
    for s in S:
        if chkind >= 3:
            break
        if s == snum[chkind]:
            chkind += 1
    if chkind == 3:
        cnt += 1
print(cnt)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(10):
    if str(i) in s[:-2]:
        s1=s.index(str(i))

        for j in range(10):
            if str(j) in s[s1+1:-1]:
                s2=s[s1+1:].index(str(j))+s1+1

                for k in range(10):
                    if str(k) in s[s2+1:]:
                        ans+=1

print(ans)

Solution (Python):
n = int(input())
num_list = list(map(int,input()))

cnt = 0

for i in range(10):
    if i not in num_list:
        continue
    else:
        first_pwd = num_list.index(i)
        new_num_list = num_list[first_pwd + 1:]
        for j in range(10):
            if j not in new_num_list:
                continue
            else:
                second_pwd = new_num_list.index(j)
                new_new_num_list = new_num_list[second_pwd+1:]
                for k in range(10):
                    if k not in new_new_num_list:
                        continue
                    else:
                        cnt += 1

print(cnt)

Solution (Python):
n = int(input())
num = input()
 
password_list = []
initial_list = []
initial_list2 = []
initial_list3 = []
 
for i in range(len(num)-2):
    initial_list2 = []
    if num[i] in initial_list:
        continue
    elif len(initial_list) == 10:
        break
    else:
        initial_list.append(num[i])
        for j in range(i+1,len(num)-1):
            initial_list3 = []
            if num[j] in initial_list2:
                continue
            elif len(initial_list2) == 10:
                break
            else:
                initial_list2.append(num[j])
                for k in range(j+1,len(num)):
                    if num[k] in initial_list3:
                        continue
                    elif len(initial_list3) == 10:
                        break
                    else:
                        initial_list3.append(num[k])
                        target = num[i] + num[j] + num[k]
                        if target not in password_list:
                            password_list.append(target)
                            
print(len(password_list))

Solution (Python):
n=int(input())
s=input()

all=[]
for i in range(10):
	for j in range(10):
		for k in range(10):
			all.append(str(i) + str(j) + str(k))

output=0
for i in range(n):
	tmps=s[i]
	tmplist=[]
	
	for j,x in enumerate(all):
		if x[0] == tmps:
			if len(x)==1:
				tmplist.append(x)
				output += 1
			else:
				all[j] = x[1:]
	
	for tmp in tmplist:
		all.remove(tmp)

print(output)

Solution (Python):


N = int(input())
S = input()

ans = 0
for i in range(1000):
    pw = list("{0:03d}".format(i))

    if pw[0] in S:
        w1 = S.index(pw[0])
        if pw[1] in S[w1+1:]:
            w2 = w1+1 + S[w1+1:].index(pw[1])
            if pw[2] in S[w2+1:]:
                ans += 1

print(ans)

Solution (Python):


N = int(input())
S = list(input())

ans = 0
for i in range(1000):
    pw = list("{0:03d}".format(i))

    if pw[0] in S:
        w1 = S.index(pw[0])
        if pw[1] in S[w1+1:]:
            w2 = w1+1 + S[w1+1:].index(pw[1])
            if pw[2] in S[w2+1:]:
                ans += 1

print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
  i='0'*(3-len(str(i)))+str(i)
  if i[0] in s:
    if i[1] in s[s.index(i[0])+1:]:
      if i[2]in s[s.index(i[0])+s[s.index(i[0])+1:].index(i[1])+2:]:
        ans+=1
print(ans)

Solution (Python):
from collections import defaultdict

N = int(input())
S = input()

d = defaultdict(list)
for i, s in enumerate(S):
    d[s].append(i)
ans = 0

for i in range(1000):
    T = '%03d' % i
    j = -1
    for t in T:
        flag = True
        for k in d[t]:
            if k > j:
                flag = False
                j = k
                break
        if flag:
            break
    if not(flag):
        ans += 1

print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
    n = int(input())
    s = tuple(map(int, tuple(input())))
    num_pos = [] 
    for num in range(10):
        if num in s:
            num_pos.append(n - s[::-1].index(num) - 1)
    unique_num = [0] * n 
    for i1 in range(n):
        unique_num[i1] = sum([np >= i1 for np in num_pos])
    unique_num.append(0)
    r = 0
    for keta1 in range(10):
        if keta1 in s:
            keta1_pos = s.index(keta1)
            for keta2 in range(10):
                if keta2 in s[keta1_pos + 1:]:
                    keta2_pos = s[keta1_pos + 1:].index(keta2) + keta1_pos + 1
                    r += unique_num[keta2_pos + 1]
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
    n = int(input())
    s = tuple(map(int, tuple(input())))
    num_pos = [] 
    for num in range(10):
        if num in s:
            num_pos.append(n - s[::-1].index(num) - 1)
    unique_num = [0] * n 
    for i1 in range(n):
        unique_num[i1] = sum([np >= i1 for np in num_pos])
    unique_num.append(0)
    r = 0
    for keta1 in range(10):
        if keta1 in s:
            keta1_pos = s.index(keta1)
            for keta2 in range(10):
                if keta2 in s[keta1_pos + 1:]:
                    keta2_pos = s[keta1_pos + 1:].index(keta2) + keta1_pos + 1
                    r += unique_num[keta2_pos + 1]
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
N=int(input())
S=input()

ans=0

for i in itertools.product(range(0,10),repeat=3):

    isOK=[False]*3
    
    for x in range(len(S)):
        if isOK[0] and isOK[1]:
            if int(S[x])==i[2]:
                ans+=1
                break
        elif isOK[0]:
            if int(S[x])==i[1]:
                isOK[1]=True
        else:
            if int(S[x])==i[0]:
                isOK[0]=True

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    c = 0
    for j in range(N):
        if S[j] == i[c]:
            c += 1
        
        if c == 3:
            ans += 1
            break

print(ans)

Solution (Python):
N = int(input())
S = input()

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = 0
            for l, value in enumerate(S):
                if tmp == 0:
                    if value == str(i):
                        tmp = 1
                elif tmp == 1:
                    if value == str(j):
                        tmp = 2
                elif tmp == 2:
                    if value == str(k):
                        ans += 1
                        break
print(ans)

Solution (Python):
n = int(input())
s = input()
cnt = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c != -1:
                cnt += 1
print(cnt)

Solution (Python):
N=int(input())
S=input()
ans=0
for i in range(1000):
 l=str(i).zfill(3);k=0
 for j in range(N):
  if S[j]==l[k]:
   k+=1
   if k==3:ans+=1;break
print(ans)

Solution (Python):
N=int(input())
s=list(input())
S=[0]*N
for i in range(N):
  S[i]=int(s[i])
ct=0
for i in range(10):
  if not i in S:
    continue
  T=S[S.index(i)+1:]
  for j in range(10):
    if not j in T:
      continue
    U=T[T.index(j)+1:]
    for k in range(10):
      if k in U:
        ct+=1
print(ct)

Solution (Python):
def main():
    n = int(input())
    T = tuple(map(int, input()))
    ans = 0
    for i in range(0, 1000):
        a = i // 100
        b = (i // 10) % 10
        c = i % 10
        flag1 = False
        flag2 = False
        flag3 = False
        for t in T:
            if flag2:
                if t == c:
                    flag3 = True
                    break
            if flag1:
                if t == b:
                    flag2 = True
                    continue
            if t == a:
                flag1 = True

        if flag3:
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    T = tuple(map(int, input()))
    ans = 0
    for i in range(0, 1000):
        a = i // 100
        b = (i // 10) % 10
        c = i % 10
        flag1 = False
        flag2 = False
        flag3 = False
        for t in T:
            if flag2:
                if t == c:
                    flag3 = True
                    break
            if flag1:
                if t == b:
                    flag2 = True
                    continue
            if t == a:
                flag1 = True

        if flag3:
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):




N = int(input())

S = input()

cnt = 0

for i in map(lambda x: str(x).zfill(3), range(1000)):
    f = 0
    for s in S:
        if s == i[f]:
            f += 1
        if f == 3:
            break
    if f == 3:
        cnt += 1

print(cnt)

Solution (Python):
n=int(input())
s=input()
ans=0

def my_index(l,x,default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

for i in range(10**3):
    i=str(i).zfill(3)
    if my_index(s,i[0])!=-1:
        s2=s[my_index(s,i[0])+1:]
        if my_index(s2,i[1])!=-1:
            s3=s2[my_index(s2,i[1])+1:]
            if my_index(s3,i[2])!=-1:
                ans+=1
print(ans)

Solution (Python):
N = int(input())
S = input()

A = [0]*1000 
ans = 0

for i in range(1000):
  if i < 10:
    s = '00' + str(i)
  elif i < 100:
    s = '0' + str(i)
  else:
    s = str(i)
    
  for j in range(N):
    if S[j] == s[0]:
      for k in range(j+1,N):
        if S[k] == s[1]:
          for l in range(k+1,N):
            if S[l] == s[2]:
              A[i] = 1
              break
          break
      break

print(A.count(1))

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(10):
    if str(i) in s[:-2]:
        s1=s.index(str(i))

        for j in range(10):
            if str(j) in s[s1+1:-1]:
                s2=s[s1+1:].index(str(j))+s1+1

                for k in range(10):
                    if str(k) in s[s2+1:]:
                        ans+=1

print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0

for i in range(1000): 
  flg1 = False 
  flg2 = False 
  flg3 = False 
  one = str(i//100) 
  two = str(i%100//10) 
  three = str(i%10) 
  t = 0
  
  for j in range(n-2):
    if s[j] == one:
      flg1 = True
      t = j+1
      break
  for j in range(t,n-1):
    if s[j] == two:
      flg2 = True
      t = j+1
      break
  for j in range(t,n):
    if s[j] == three:
      flg3 = True
      t = j+1
      break
  if flg1 and flg2 and flg3:
    ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()

num = '0123456789'
cnt = 0
for i in num:
    for j in num:
        for k in num:
            if i in s:
                idx1 = s.find(i)
                if j in s[idx1 +1 :]:
                    idx2 = s.find(j, idx1 + 1)
                    if k in s[idx2 + 1:]:
                        idx3 = s.find(k, idx2 + 1)
                        cnt += 1
print(cnt)

Solution (Python):
n = int(input())
s = str(input())
cnt = 0
def f(x):
	tgt = [ x[0], x[1], x[2] ]
	now = 0
	global n
	for i in range(n):
		if s[i] == tgt[now]: now += 1
		if now == 3: return True
	return False
for i in range(1000):
	if len(str(i)) == 1: t = "00"+str(i)
	elif len(str(i)) == 2: t = "0"+str(i)
	else: t = str(i)
	if f(t): cnt += 1
print(cnt)

Solution (Python):
def getval():
    n = int(input())
    s = input()
    return n,s 

def main(n,s):
    pos = [-1 for i in range(10)]
    for i in range(n):
        temp = int(s[i])
        if pos[temp]==-1:
            pos[temp] = i 
    flag1 = [[[False for i in range(10)] for i in range(10)] for i in range(10)]
    flag2 = [[False for i in range(10)] for i in range(10)]
    for i in range(10):
        if pos[i]==-1 or pos[i]>=n-1:
            continue
        for j in range(pos[i]+1,n):
            f = flag2[i]
            temp = int(s[j])
            for k in range(10):
                if f[k]:
                    flag1[i][k][temp] = True 
            if not f[temp]:
                flag2[i][temp] = True
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if flag1[i][j][k]:
                    ans += 1
    print(ans)

if __name__=="__main__":
    n,s = getval()
    main(n,s)

Solution (Python):
n = int(input())
S = input()

ans = 0
for i in range(1000):
    nows = S
    istr = str(i).zfill(3)
    idx = nows.find(istr[0])
    if idx == -1:  continue
    nows = nows[idx+1:]
    idx = nows.find(istr[1])
    if idx == -1:  continue
    nows = nows[idx+1:]
    idx = nows.find(istr[2])
    if idx == -1:  continue
    ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()

cnt = 0
for i in range(1000):
    si = str(i).zfill(3)
    k = 0
    for cn in range(n):
        if s[cn] == si[k]:
            if k == 2:
                cnt += 1
                break
            else:
                k += 1
print(cnt)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
  a = [i//100, (i//10)%10, i%10]
  cnt = 0
  for j in range(n):
    if cnt <= 2 and a[cnt] == int(s[j]): cnt+=1
  if cnt == 3: ans += 1
print(ans)

Solution (Python):
n = int(input())
lst = list(input())

ans = []
for i in range(1000):
    s = str(i).zfill(3)
    pos = 0
    is_exist = True
    for j in range(3):
        if s[j] in lst[pos:]:
            pos += lst[pos:].index(s[j]) + 1
        else:
            is_exist = False
            break
    if is_exist:
        ans.append(s)
print(len(ans))

Solution (Python):
n = int(input())
lst = list(input())

ans = {}
for i in range(1000):
    s = str(i).zfill(3)
    pos = 0
    is_exist = True
    for j in range(3):
        if s[j] in lst[pos:]:
            pos += lst[pos:].index(s[j]) + 1
        else:
            is_exist = False
            break
    if is_exist:
        ans[s] = 0
print(len(ans))

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
s = v()

s1,s2,s3 = set(),set(),set()
for x in s:
    for z in s2:
        s3.add(z+x)
    for y in s1:
        s2.add(y+x)
    s1.add(x)
print(len(s3))

Solution (Python):
n=int(input())
s=input()
se=[set() for _ in range(3)]
for a in s:
  for pre in se[1]:
    se[2].add(a+pre)
  for pre in se[0]:
    se[1].add(a+pre)
  se[0].add(a)
print(len(se[2]))

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            fi = False
            fj = False
            for ss in s:
                ss = int(ss)
                if not fi and ss == i:
                    fi = True
                    continue
                if fi and not fj and ss == j:
                    fj = True
                    continue
                if fj and ss == k:
                    ans += 1
                    break
print(ans)

Solution (Python):
N = int(input())
S = input()
s = set()
for i in range(1000):
  p = str(i).zfill(3)
  if S.find(p[0])==-1:
    continue
  S1 = S[S.find(p[0])+1:]
  if S1.find(p[1])==-1:
    continue
  S2 = S1[S1.find(p[1])+1:]
  if S2.find(p[2])==-1:
    continue
  s.add(p)
print(len(s))

Solution (Python):
N = int(input())
S = input()
k = 1
ans_list = []
for i in range(1000,2000):
    ansyo = str(i)
    for j in range(0,N):
        if ansyo[k] == S[j]:
            k += 1
        if k == 4:
            ans_list.append(ansyo)
            k = 1
        if j == N-1:
            k = 1
ans_list = set(ans_list)
print(len(ans_list))

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
  p = str(i).zfill(3)
  if S.find(p[0])==-1:
    continue
  S1 = S[S.find(p[0])+1:]
  if S1.find(p[1])==-1:
    continue
  S2 = S1[S1.find(p[1])+1:]
  if S2.find(p[2])==-1:
    continue
  ans+=1
print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
  p = str(i).zfill(3)
  if S.find(p[0])==-1:
    continue
  S1 = S[S.find(p[0])+1:]
  if S1.find(p[1])==-1:
    continue
  S2 = S1[S1.find(p[1])+1:]
  if S2.find(p[2])==-1:
    continue
  ans+=1
print(ans)

Solution (Python):
n=int(input())
s=input()

lst = [0]*1000
sm = 0
first = [False]*10
second = [False]*100
for i in s:
    i = int(i)
    for j in range(100):
        if not second[j]:
            continue
        tmp = 10*j + i
        if lst[tmp] == 0:
            sm +=1
            lst[tmp]+=1

    for j in range(10):
        if first[j]:
            tmp = 10*j + i
            if not second[tmp]:
                second[tmp] = True

    if not first[i]:
        first[i] = True

print(sm)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N=intput()
S=input()
L1=set()
L2=set()
L3=set()
for i in range(N-1,-1,-1):
    x=int(S[i])
    for y in L2:
        L3.add(100*x+y)
    for y in L1:
        L2.add(10*x+y)
    L1.add(x)
print(len(L3))

Solution (Python):
N = input()
S = list(input())
count = 0
num_count = [False]*10
for i in range(len(S)-2):
    s_i = int(S[i])
    if num_count[s_i]:
        continue
    num_count[s_i] = True
    num_count_2 = [False]*10
    for j in range(i+1, len(S)-1):
        s_j = int(S[j])
        if num_count_2[s_j]:
            continue
        num_count_2[s_j] = True
        num_count_3 = [False] * 10
        for k in range(j+1, len(S)):
            s_k = int(S[k])
            if num_count_3[s_k]:
                continue
            num_count_3[s_k] = True
            count += 1
print(count)

Solution (Python):
n = int(input())
s = input()
ans = 0

for i in range(1000):
        i = '0' * (3 - len(str(i))) + str(i)
        keep = 0

        for j in range(n):
                if s[j] == i[keep]:
                        keep += 1
                if keep == 3:
                        ans += 1
                        break

print(ans)

Solution (Python):
N = int(input())
S = list(map(int, list(input())))
ans = 0

for a in range(10):
    for b in range(10):
        for c in range(10):
            targets = (a, b, c)
            target_idx = 0
            for i in range(len(S)):
                if S[i] == targets[target_idx]:
                    target_idx += 1
                    if target_idx == len(targets):
                        ans += 1
                        break

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

n = int(readline())
s = readline().rstrip()

from collections import deque
q = deque([])

ss = set(s)

for i in ss:
    q.append(["",0,str(i)])

ans = 0
while q:
    num, ind, target = q.popleft()
    
    while ind < len(s):
        if s[ind] == target: 
            break
        ind += 1
    else:
        continue
    num += target
    if len(num) == 3:
        ans += 1
        continue
    sss = set(s[ind+1:])
    for i in sss:
        q.append([num, ind +1, str(i)]) 

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

n = int(readline())
s = readline().rstrip()

from collections import deque
q = deque([])

ss = set(s)

for i in ss:
    q.append(["",0,str(i)])

ans = 0
while q:
    num, ind, target = q.popleft()
    
    while ind < len(s):
        if s[ind] == target: 
            break
        ind += 1
    else:
        continue
    num += target
    if len(num) == 3:
        ans += 1
        continue
    for i in range(10):
        q.append([num, ind +1, str(i)]) 

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

n = int(readline())
s = readline().rstrip()

from collections import deque
q = deque([])

for i in range(10):
    q.append(["",0,str(i)])

ans = 0
while q:
    num, ind, target = q.popleft()
    
    while ind < len(s):
        if s[ind] == target: 
            break
        ind += 1
    else:
        continue
    num += target
    if len(num) == 3:
        ans += 1
        continue
    for i in range(10):
        q.append([num, ind +1, str(i)]) 

print(ans)

Solution (Python):
N = int(input())
S = str(input())

ans = 0

for i in range(0, 10):
    a = S.find(str(i))
    if a == -1:
        continue
    for j in range(0, 10):
        b = S.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(0, 10):
            c = S.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)

Solution (Python):
N = int(input())
S = input()

ans = 0
for i in range(0, 1000):
    if 0 <= i and i <= 9:
        num = "00"+str(i)
    elif 10 <= i and i <= 99:
        num = "0"+str(i)
    else:
        num = str(i)

    num_pos = 0
    s_pos = 0
    while True:
        if S[s_pos] == num[num_pos]:
            num_pos += 1
            if num_pos == 3:
                ans += 1
                break
        s_pos += 1
        if s_pos == N:
            break
print(ans)

Solution (Python):

N = int(input())
S = input()

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a = S.find(str(i))
            if a == -1:
                continue
            
            b = S.find(str(j),a+1)
            if not(a < b):
                continue
            
            c = S.find(str(k),b+1)
            if not(b < c):
                continue
            
            ans += 1
print(ans)