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):
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools

def sRaw():
    return input().rstrip("\r")

def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    
def ZAlgo(s):
    l = len(s)
    A = [0]*l
    i =1
    j =0
    A[0]=l
    while i<l:
        while i+j<l and s[j] == s[i+j]:
            j+=1
        if j==0:
            i+=1
            continue
        A[i]=j
        k=1
        while (i+k<l) and (k+A[k]<j):
            A[i+k] =A[k]
            k+=1
        i+=k
        j-=k
    return A


DIV = 998244353

def main():
    N = iRaw()
    S = sRaw()
    dp = [[] for i in range(N+1)]
    dp[N] = [-1]*10
    for si in range(len(S)-1,-1,-1):
        dp[si] = [dp[si+1][d] for d in range(10)]
        dp[si][int(S[si])] = si
    ans = 0 
    for i in range(1000):
        d0 = i%10
        d1 = (i//10)%10
        d2 = (i//100)%10
        idx1 = dp[0][d0]
        if idx1 == -1:
            continue
        idx2 = dp[idx1+1][d1]
        if idx2 == -1:
            continue
        if dp[idx2+1][d2] != -1:
            ans+=1
    return ans

if __name__ == "__main__":
    print(main())

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



from bisect import bisect_left

N = I()
S = str(input())
d = defaultdict(list)

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

ans = 0
for i in range(1000):
    now = str(i).zfill(3)
    p = 0
    flag = True
    for j in now:
        p1 = bisect_left(d[j],p)
        if p1>=len(d[j]):
            flag = False
            break
        p = d[j][p1]+1
    if flag:
        ans += 1

print(ans)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

def count(poi):
    point = 0
    for i in range(poi):
        bango = str(i).zfill(3)
        count = 0
        for j in range(n):
            if s[j] == bango[count]:
                count += 1
            if count == 3:
                point += 1
                break
    return point

print(count(1000))

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

ans = 0
for i in range(1000):
    T = str(i).zfill(3)
    cur = 0
    for j in range(n):
        if S[j] == T[cur]:
            cur += 1
            if cur == 3:
                break
    if cur == 3:
        ans += 1

print(ans)

Solution (Python):
N = int(input())
S = input()
 
cnt = 0
for i in range(1000):
  c = str(i).zfill(3)
  if c[0] in S:
        index1 = S.index(c[0])
        if c[1] in S[index1+1:]:
            index2 = index1 + 1 + S[index1+1:].index(c[1])
            if c[2] in S[index2+1:]:
                cnt+=1
print(cnt)

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

def search(c, text):
    pos = -1
    for i, s in enumerate(text):
        if s == c:
            pos = i
            break
    return pos

cnt = 0
for i in range(10):
    ip = search(str(i), S[0:])
    if ip < 0:
        continue
    for j in range(10):
        jp = search(str(j), S[ip+1:])
        if jp < 0:
            continue
        for k in range(10):
            kp = search(str(k), S[ip+jp+2:])
            if kp < 0:
                continue
            cnt += 1

print(cnt)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
    if i<10:
        ss="00"+str(i)
    elif i<100:
        ss="0"+str(i)
    else:
        ss=str(i)
    now=0
    for j in range(n):
        if s[j]==ss[now]:
            now+=1
            if now==3:
                ans+=1
                break
print(ans)

Solution (Python):
def solve(n, s):
    ans = 0
    for v in range(1000):
        p = 0
        for x in str(v).zfill(3):
            p = s.find(x, p)
            if p < 0:
                break
            p += 1
        ans += int(p > 0)
    return ans

assert solve(4, "0224") == 3
assert solve(6, "123123") == 17
assert solve(19, "3141592653589793238") == 329

n = int(input())
s = input()
print(solve(n, s))

Solution (Python):
def solve(n, s):
    l = {s[i]: i for i in range(n-1, -1, -1)}
    r = {s[i]: i for i in range(n)}
    S = set()
    for j in range(n):
        y = s[j]
        for x, i in l.items():
            for z, k in r.items():
                if i < j < k:
                    S.add(x+y+z)
    return len(S)

n = int(input())
s = input()
print(solve(n, s))

Solution (Python):
from __future__ import print_function


import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )



from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random


def main():
    n = int(input().strip())
    S = input().strip()
    cnt=0
    for SS in range(1000):
        SSs=str(SS).zfill(3)
        
        
        a=str(SSs[0])
        b=str(SSs[1])
        c=str(SSs[2])
        success_flag=0
        ii=sys.maxsize
        jj=sys.maxsize
        kk=sys.maxsize
        for i in range(len(S)):
            if S[i]==a:
                ii=min(i,ii)
            if S[i]==b and i>ii:
                jj=min(i,jj)
            if S[i]==c and i>jj:
                kk=min(i,kk)
                success_flag=1
                
                
            
                
                
                
            
        if success_flag==1:
            cnt+=1
    print(cnt)
    return

if __name__ == '__main__':
    main()


'''


given n \in N, S \in {S}
(4 <= n == len(S) <= 3*10^4)

defun SS such that
	+ SS \in {String} and
	+ there exist (i,j,k) such that
		(i \in N and j \in N and k \in N)
		and
		(i<j<k<n) and S[i] = SS[0] and S[j] = SS[1] and S[k] = SS[2]
defun x is |{SS}|
find x


----------------------

'''

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

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

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

for i in range(1000):
    num = str(i).zfill(3)
    if num[0] in s:
        a1 = s.index(num[0])
        if num[1] in s[a1+1:]:
            a2 = a1+s[a1+1:].index(num[1])+1
            if num[2] in s[a2+1:]:
                count += 1

print(count)

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


nums=set()
numsidx=[-1 for i in range(10)]
for i in range(N-1,1,-1):
    if not S[i] in nums:
        nums.add(S[i])
        numsidx[int(S[i])]=i


nunums=set()
nunumsidx=[-1 for i in range(100)]
for i in range(N-2,0,-1):
    for m in range(10):
        if i<numsidx[m]:
            s=S[i]+str(m)
            if not s in nunums:
                nunums.add(s)
                nunumsidx[int(s)]=i

nums=set()
ans=set()
for i in range(N-2):
    if not S[i] in nums:
        nums.add(S[i])
        for m in range(100):
            if i<nunumsidx[m]:
                ans.add(S[i]+str(m))

print(len(ans))

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
  a=[str(i//100),str(i//10%10),str(i%10)]
  
  k=0
  b=0
  for j in range(n):
    if a[b]==s[j]:
      b+=1
    if b==3:
      k=1
      break
  if k:
    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 p in range(1000):
    p1, p2, p3 = str(p).zfill(3)

    i0 = -1
    for i in d[p1]:
        if i > i0:
            i1 = i
            break
    else:
        continue

    for i in d[p2]:
        if i > i1:
            i2 = i
            break
    else:
        continue

    for i in d[p3]:
        if i > i2:
            ans += 1
            break


print(ans)

Solution (Python):
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    S = [int(s) for s in input()]

    ret = 0
    for i in range(1000):
        code = [int(i / 10 ** j) % 10 for j in range(2, -1, -1)]
        
        j = 0
        for s in S:
            if code[j] == s:
                j += 1
            if j == 3:
                break
        if j == 3:
            ret += 1
    return ret


if __name__ == "__main__":
    print(main())

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

cnt = 0
for i in range(1000):
  c = str(i).zfill(3)
  if c[0] in S:
        index1 = S.index(c[0])
        if c[1] in S[index1+1:]:
            index2 = index1 + 1 + S[index1+1:].index(c[1])
            if c[2] in S[index2+1:]:
                cnt+=1
print(cnt)

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

key = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])

ans=0
for i in range(1000):
    if str(key[i][0]) in S:
        ind_0=S.index(str(key[i][0]))
        if str(key[i][1]) in S[ind_0+1:]:
            ind_1=ind_0 + 1 + S[ind_0+1:].index(str(key[i][1]))
            if str(key[i][2]) in S[ind_1+1:]:
                ans+=1
print(ans)

Solution (Python):
n=int(input())
s=input()
cnt=0
for i in range(1000):
    num=str(i).zfill(3)
    x=s.find(num[0])
    y=s.find(num[1],x+1)
    z=s.find(num[2],y+1)
    if x!=-1 and y!=-1 and z!=-1:
        cnt +=1
print(cnt)

Solution (Python):
n=int(input())
s=list(input())
cnt=0
for i in range(1000):
    num=str(i).zfill(3)
    base=s
    for k,j in enumerate(num):
        if j in base:base=base[base.index(j)+1:]
        else:break
        if k==2:cnt +=1
print(cnt)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 



 




 


 





 


 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    S = input()
    S = S[:-1]
    
    
    ans = 0
    for i in range(1000):
        i_str = str(i)
        i_str = i_str.zfill(3)
        
        flg1 = True
        cnt = 0
        for i in i_str:
            flg2 = False
            for j in range(cnt, len(S)):
                if i == S[j]:
                    flg2 = True
                    cnt = j+1
                    break
            if flg2 == False:
                flg1 = False
                break
                
        if flg1 == True:
            
            ans += 1
            
    print(ans)
    
if __name__ == "__main__":
	main()

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









count=0
NUM = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
for i in NUM:
    i_3d = i
    S_mid = S
    for j,i_s in enumerate(i_3d): 
        if i_s in S_mid: 
            ind = S_mid.index(i_s)
            if j == len(i_3d)-1:  
                count+=1
                break 
            elif ind+1 == len(S): 
                break
            S_mid = S_mid[ind+1:]
        else: 
            break
print(count)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def C(n,r):
    return math.factorial(n)//math.factorial(n-r)//math.factorial(r)

n = I()
s = input()
t = list(map(int,list(s)))
ans = 0
for i in range(10):
    for j in range(n):
        if i == t[j]:
            tmp = j
            break
    else:
        continue
    for j in range(100):
        if len(str(j)) == 2:
            x,y = list(str(j))
        else:
            x,y = '0',str(j)
        flg = False
        for k in range(tmp+1,n):
            if flg and y == str(t[k]):
                ans += 1
                break
            if x == str(t[k]):
                flg = True
print(ans)

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

dp1 = [set() for i in range(4)]
dp2 = [set() for i in range(4)]
dp1[0].add('')
for i, S_i in enumerate(S):
    for j, dp1_j in enumerate(dp1[:3]):
        for s in dp1_j:
            dp2[j].add(s)
            dp2[j + 1].add(s + S_i)
        dp2[3] = dp1[3]
    dp1 = dp2
    dp2 = [set() for i in range(4)]

print(len(dp1[-1]))

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

ans = 0

for i in range(1000):
    ss = str(i).zfill(3)
    if (ss[0] in s):
        ind1 = s.index(ss[0])
        if (ss[1] in s[ind1+1:]):
            ind2 = ind1+1 + s[ind1+1:].index(ss[1])
            if (ss[2] in s[ind2+1:]):
                ans += 1

print(ans)

Solution (Python):
n = int(input())
new_s = input()
pas = -1

ans = 0
lens = len(new_s)
for i in range(1000):
    ott = 0
    pas = int(pas)+1
    if pas < 10:
        pas = "00"+str(pas)
    elif pas < 100:
        pas = "0"+str(pas)
    pas = str(pas)
    idx = -1
    while idx < lens-1:
        idx += 1
        if ott == 0:
            if pas[0] == new_s[idx]:
                ott += 1
        elif ott == 1:
            if pas[1] == new_s[idx]:
                ott += 1
        elif ott == 2:
            if pas[2] == new_s[idx]:
                ott += 1
                ans += 1
        if ott == 3:
            break
print(ans)

Solution (Python):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



N = int(sys.stdin.buffer.readline())
S = sys.stdin.buffer.readline().decode().rstrip()

dp = [set() for _ in range(3)]
for i, c in enumerate(S):
    for s in dp[1]:
        dp[2].add(s + c)
    for s in dp[0]:
        dp[1].add(s + c)
    dp[0].add(c)
print(len(dp[2]))

Solution (Python):
n = int(input())
S = input()
res = 0
for i in range(1000) :
    T = str(i).zfill(3)
    a = 0
    b = 0
    f1 = 0
    f2 = 0
    f = 0
    for j,t in enumerate(T) :
        if f :
            break
        for k,s in enumerate(S) :
            if t == s :
                if not f1 :
                    f1 = 1
                    a = k
                    break
                elif f1 and not f2 and a < k :
                    f2 = 1
                    b = k
                    break
                elif f1 and f2 and b < k :
                    res += 1
                    f = 1
                    break
print(res)

Solution (Python):
N = int(input())
S = input()
lst = []
count = 0
for i in range(1000):
    num = str(i).zfill(3)
    if num[0] in S:
        a1 = S.index(num[0])
        if num[1] in S[a1+1:]:
            a2 = S[a1+1:].index(num[1]) + a1+1
            if num[2] in S[a2+1:]:
                count += 1
print(count)

Solution (Python):
N = int(input())
S = input()
data = set()
xd,yd = set(),set()
for i in range(N-2):
  x = S[i]
  if x in xd:
    continue
  else:
    xd.add(x)
    yd = set()
  for j in range(i+1,N-1):
    y = S[j]
    if y in yd:
      continue
    else:
      yd.add(y)
    for k in range(j+1,N):
      z = S[k]
      data.add(x+y+z)
print(len(data))

Solution (Python):
import copy

N = input()
S = input()

key_list = range(0, 1000)
key_list = tuple(map(lambda key: '0' * (3 - len(str(key))) + str(key), key_list))

ans_list = []
for key in key_list:
    flg = True
    cS = copy.copy(S)
    for i in key:
        index = cS.find(i)
        if index == -1:
            flg = False
            break
        cS = cS[index+1:]
    if flg:
        ans_list.append(key)
        
print(len(ans_list))

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

count=0

for i in range(1000):
    ss=s[:]
    st=str(i).rjust(3,"0")
    if st[0] in ss:
        del ss[0:ss.index(st[0])+1]
        if st[1] in ss:
            del ss[0:ss.index(st[1])+1]
            if st[2] in ss:
                count+=1

print(count)

Solution (Python):
n = input()
sl = input()
ans = 0
for i in range(1000):
    i_zero = str(i)
    i_zero = i_zero.zfill(3)
    if i_zero[0] in sl:
        a = sl.index(i_zero[0])+1
        if i_zero[1] in sl[a:]:
            a = sl[a:].index(i_zero[1])+a+1
            if i_zero[2] in sl[a:]:
                ans += 1
print(ans)

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


M = { }
A = set()
A.add(X[0]+X[1])
for i in range(2, N) :
    i = X[i]
    for j in tuple(A):
        M[j + i] = 1
        A.add(j[0]+i)
        A.add(j[1]+i)

    if len(M) == 1000:
        break
print(len(M))

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

ans = 0

for n in range(1000):
    pin = str(n).zfill(3)
    head = 0
    for c in S:
        if c == pin[head]:
            head += 1
        if head == 3:
            ans += 1
            break

print(ans)

Solution (Python):
n=int(input())
s=list(map(int,list(input())))
ans=0
for i in range(10):
    try:
        ss=s[s.index(i)+1:]
        for j in range(10):
            try:
                sss=ss[ss.index(j)+1:]
                for k in range(10):
                    if k in sss:ans+=1
            except:pass
    except:pass

print(ans)

Solution (Python):
n = int(input())
s = input()
num_list = [str(i).zfill(3) for i in range(1000)]
ans = 0
for i in range(1000):
    i100 = num_list[i][0]
    i10 = num_list[i][1]
    i1 = num_list[i][2]
    count = 0
    a = s.find(i100)
    if a != -1:
        count += 1
        a += 1
    b = s.find(i10, a)
    if b != -1:
        count += 1
        b += 1
    c = s.find(i1, b)
    if c != -1:
        count += 1
    if count == 3:
        ans += 1
print(ans)

Solution (Python):
import bisect
n = int(input())
s = input()
count = 0
num_ind_list = []
for i in range(10):
    num_ind_list.append([0])
for i in range(n):
    num_ind_list[int(s[i])].append(i)
for i in range(10):
    num_ind_list[i].append(30000)
for i in range(10):
    if len(num_ind_list[i]) != 2:
        for j in range(10):
            b = bisect.bisect_right(num_ind_list[j], num_ind_list[i][1])
            if num_ind_list[j][b] != 30000:
                for k in range(10):
                    c = bisect.bisect_right(num_ind_list[k], num_ind_list[j][b])
                    if num_ind_list[k][c] != 30000: count += 1
print(count)

Solution (Python):
n = int(input())
s = input()
index = 0
cnt = 0
for i in range(0, 1000):
    if i < 10:
        value = '00' + str(i)
    elif i < 100:
        value = '0' + str(i)
    else:
        value = str(i)

    for j in s:
        if value[index] == j:
            index += 1

        if index == 3:
            cnt += 1
            index = 0
            break
    index = 0

print(cnt)

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

cnt = 0
for i in range(1000):
    n = '{:03d}'.format(i)
    i = 0
    for d in n:
        try:
            i = S.index(d, i) + 1
        except ValueError:
            break
    else:
        cnt += 1

print(cnt)

Solution (Python):
n = int(input())
s = input()
z10 = [0 for _ in range(10)]
z100 = [0 for _ in range(100)]
z1000 = [0 for _ in range(1000)]
for i in range(n):
  x = int(s[i])
  for k in range(100):
    z1000[10*k+x] = z100[k]
  for j in range(10):
    z100[10*j+x] = z10[j]
  z10[x] = 1
print(sum(z1000))

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

str_dict = {}
for s in S:
    str_dict[s] = []

for i, s in enumerate(S):
    bisect.insort_right(str_dict[s], i)
cnt = 0
for i in range(10):
    for j in range(10):
        for t in range(10):
            test_str = str(i) + str(j) + str(t)
            now_idx = -1
            flg = True
            for k in test_str:
                if not k in str_dict.keys():
                    flg = False
                    break
                try:
                    tmp = str_dict[k][bisect.bisect_left(str_dict[k], now_idx+1)]
                    if tmp != now_idx:
                        now_idx = tmp
                    else:
                        flg = False
                        break
                except:
                    flg = False
                    break
            if flg:
                cnt += 1

print(cnt)

Solution (Python):



def main():
    n = int(input())
    s = input()
    ts = list()

    
    
    
    for i in range(10):
        for j in range(10):
            for k in range(10):
                t = ''
                t += str(i)
                t += str(j)
                t += str(k)

                ts.append(t)

    ans = 0

    for ti in ts:
        pos = 0

        for si in s:
            if si == ti[pos]:
                pos += 1

                if pos == 3:
                    break

        if pos == 3:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    n = int(input())
    s = input()
    ts = list()

    
    
    
    for i in range(10):
        for j in range(10):
            for k in range(10):
                t = ''
                t += str(i)
                t += str(j)
                t += str(k)

                ts.append(t)

    ans = 0

    for ti in ts:
        pos = 0

        for si in s:
            if si == ti[pos]:
                pos += 1

                if pos == 3:
                    break

        if pos == 3:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
S = list(input())
sS = set(S)
from itertools import product
sS = product(sS,repeat=3)
c = 0

for i in sS:
	if i[0] in S:
		a = S.index(i[0])
		if i[1] in S[a+1:]:
			b = S[a+1:].index(i[1]) + a + 1
			if i[2] in S[b+1:]:
				c += 1
print(c)

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

key = []
 
for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0

for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    flag1 = S.find(str(key[i][0]))
    
    if flag1 == -1:
        continue
        
    flag2 = S.find(str(key[i][1]),flag1+1)
    
    if flag2 == -1:
        continue
        
    flag3 = S.find(str(key[i][2]),flag2+1)
    
    if flag3 == -1:
        continue
                            
    if flag1 != -1 and flag2 != -1 and flag3 != -1:
        ans += 1
        
print(ans)

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

dp = [set(), set()]

dp[0].add("")
for i in range(n):
    dp[(i + 1) % 2] = dp[i % 2].copy()
    i1 = (i + 1) % 2
    i0 = (i + 0) % 2
    for j in dp[i0]:
        if len(j) < 3:
            dp[i1].add(j + s[i])

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        
        ans += 1

print(ans)

Solution (Python):
N = int(input())
S = input()
n = 0
for i in range(1000):
  ps_i = "%03d"%(i)
  s = S
  ps_i_ok = True
  for j in ps_i:
    if j in s: s = s[s.index(j)+1:]
    else:
      ps_i_ok = False
      break
  if ps_i_ok: n+=1
print(n)

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

def idx(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

n = int(input())
s = list(input())

cnt = 0
for abc in range(1000):
    abc = list(str(abc).zfill(3))
    i = 0
    for dig in s:
        if dig == abc[i]:
            i += 1
            if i == 3:
                break
    if i == 3:
        cnt += 1

print(cnt)

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

cnt=0
for i in range(1000):
    key=str(i).zfill(3)
    if key[0] in S:
        idx1=S.index(key[0])
    else:
        continue
    if key[1] in S[idx1+1:L-1]:
        idx2=S[idx1+1:L-1].index(key[1])+idx1+2
    else:
        continue
    if key[2] in S[idx2:L]:
        cnt+=1
    else:
        continue

print(cnt)

Solution (Python):
N = int(input())
S = tuple(map(int, input()))

ans = 0
for i in range(1000):
    ii = i
    key = ii%10
    count = 0
    for s in S:
        if key == s:
            count += 1
            if count == 3:
                ans += 1
                break
            ii //= 10
            key = ii%10

print(ans)

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

ans = 0
for a in range(10):
    ai = 0
    while ai < n:
        if s[ai] == str(a):
            break
        else:
            ai += 1
    if ai == n:
        continue
    for b in range(10):
        bi = ai + 1
        while bi < n:
            if s[bi] == str(b):
                break
            else:
                bi += 1
        if bi == n:
            continue
        for c in range(10):
            ci = bi + 1
            while ci < n:
                if s[ci] == str(c):
                    break
                else:
                    ci += 1
            if ci == n:
                continue
            else:
                ans += 1

print(ans)
exit(0)

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

t = [set() for _ in range(n)]
t[-1] = {int(s[-1])}

for i in range(1, n):
    base = t[n - i].copy()
    base.add(int(s[n - i - 1]))
    t[n - i - 1] = base

ans = 0
for a in range(10):
    ai = 0

    if a not in t[ai]:
        continue

    while ai < n:
        if s[ai] == str(a):
            break
        else:
            ai += 1
    if ai >= n - 2:
        continue
    for b in range(10):
        bi = ai + 1

        if b not in t[bi]:
            continue

        while bi < n:
            if s[bi] == str(b):
                break
            else:
                bi += 1
        if bi >= n - 1:
            continue
        for c in range(10):
            ci = bi + 1

            if c not in t[ci]:
                continue

            while ci < n:
                if s[ci] == str(c):
                    break
                else:
                    ci += 1
            if ci == n:
                continue
            else:
                ans += 1

print(ans)
exit(0)


x = int(input())
dp = [False for _ in range(x + 1)]
dp[0] = True
for item in [100, 101, 102, 103, 104, 105]:
    for i in range(x + 1):
        if i - item >= 0:
            if dp[i - item]:
                dp[i] = True

print(1 if dp[x] else 0)
exit(0)

Solution (Python):
import bisect
from collections import defaultdict
from itertools import product

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

d = defaultdict(list)
for i, c in enumerate(S):
    num = int(c)
    d[num].append(i)

counter = 0
for a, b, c in product(range(10), repeat=3):
    if not d[a]:
        continue
    ia = d[a][0]
    ib = bisect.bisect_right(d[b], ia)
    if len(d[b]) <= ib:
        continue
    ib = d[b][ib]
    ic = bisect.bisect_right(d[c], ib)
    if len(d[c]) <= ic:
        continue
    ic = d[c][ic]
    counter += 1

print(counter)

Solution (Python):
def search(string,n):
    cnt=0
    for i in range(1000):
        s=str(i)
        if len(s)==1:
            s='00'+s
        elif len(s)==2:
            s='0'+s
        k=0
        for j in range(n):
            if k==2 and s[k]==string[j]:
                cnt+=1
                
                break
            if s[k]==string[j]:
               k+=1
    
    return cnt
    
    

n=int(input())
s=input()
l=search(s,n)
print(l)

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

count = 0

for i in range(1000):
  ss = s[:]
  st = str(i).rjust(3, '0')
  if st[0] in ss:
    del ss[0:(ss.index(st[0])+1)]
    if st[1] in ss:
      del ss[0:(ss.index(st[1])+1)]
      if st[2] in ss:
        count += 1
else:
  print(count)

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

ans=0

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

Solution (Python):

N = int(input())
S = input()
L = list(S)
count = 0

for i in range(0,1000):

    fst = 0
    snd = 0
    thd = 0
    tmp = 0

    if(i<10):
        num = "00"+str(i)
    elif(i<100):
        num = "0"+str(i)
    else:
        num = str(i)

    if num[0] in L:
        fst = L.index(num[0]) + 1
        tmp += 1
    if num[1] in L[fst:]:
        snd = fst + L[fst:].index(num[1]) + 1
        tmp += 1
    if num[2] in L[snd:]:
        thd = snd + L[snd:].index(num[2]) + 1
        tmp += 1
    if tmp == 3:
        count+= 1
        


print(count)

Solution (Python):
def main():
  import bisect
  N = int(input())
  S = list(map(int,input()))
  ans = 0
  cnt = [list() for _ in range(10)]
  for id,s in enumerate(S):
    cnt[s].append(id)
  for i in range(10):
    for j in range(10):
      for k in range(10):
        if not cnt[i] or not cnt[j] or not cnt[k]:
          continue
        index = cnt[i][0] + 1
        index = bisect.bisect_left(cnt[j],index)
        if index == len(cnt[j]):
          continue
        index = cnt[j][index] + 1
        index = bisect.bisect_left(cnt[k],index)
        if index == len(cnt[k]):
          continue
        ans += 1
  print(ans)

main()