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):
int(input())
s = list(input())
ans = 0
for i in range(10):
    if str(i) in s:
        ss = s[s.index(str(i))+1:]
        for j in range(10):
            if str(j) in ss:
                sss = ss[ss.index(str(j))+1:]
                for k in range(10):
                    if str(k) in sss:
                        ans += 1
print(ans)

Solution (Python):
N=int(input())
S=input()
kouho=[]
for n in range(1000):
    st=str(n)
    if len(st)<=2:
        st='0'*(3-len(st))+st
    kouho.append(st)
ans=0
for k in kouho:
    number=0
    for s in S:
        if k[number]==s:
            number+=1
        if number==3:
            break
    if number == 3:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
c=0
for i in range(1000):
  t=format(i,"0>3")
  j=0
  for k in s:
    if k==t[j]:
      j+=1
      if j==3:
        c+=1
        break
print(c)

Solution (Python):
from collections import defaultdict

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

d = defaultdict(list)
for i in range(N):
  d[int(S[i])].append(i)
    
ans = 0
for n1 in range(10):
  if not d[n1]:continue
  for n2 in range(10):
    if not d[n2]:continue
    if d[n1][0]>d[n2][-1]: continue
    for n3 in range(10):
      if not d[n3]:continue
      if d[n1][0]>d[n3][-1] or d[n2][0]>d[n3][-1]:continue
      for idx in d[n2]:
        if idx>d[n1][0] and idx<d[n3][-1]:
          ans += 1
          break
            
print(ans)

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

ans = 0
tmp = [0 for _ in range(10)]
for i in range(len(S)):
    tmp[int(S[i])] += 1

for i in range(1000):
    flag = True

    if i < 10:
        dic = {"0": 2}
    elif i < 100:
        dic = {"0": 1}
    else:
        dic = {}
    for j in range(len(str(i))):
        if str(i)[j] in dic:
            dic[str(i)[j]] += 1
        else:
            dic[str(i)[j]] = 1

    for k, v in dic.items():
        if dic[k] > tmp[int(k)]:
            flag = False
            break

    if flag:
        if i < 10:
            tmp_i = "00" + str(i)
        elif i < 100:
            tmp_i = "0" + str(i)
        else:
            tmp_i = str(i)
        t = 0
        for j in range(len(S)):
            if tmp_i[t] == S[j]:
                t += 1
            if t == 3:
                ans += 1
                break

print(ans)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    s = list(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):
'''
Created on 2020/09/04

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N=int(pin())
  S=pin()[:-1]

  cnt=0
  l=["0","1","2","3","4","5","6","7","8","9"]
  for i in l:
    for j in l:
      for k in l:
        c=[i,j,k]
        n=0
        for m in S:
          if m==c[n]:
            if n==2:
              cnt+=1
              break
            else:
              n+=1
  print(cnt)
  return
main()

Solution (Python):
n = int(input())
lst = list(input())
cnt = 0
Num = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            s = [str(i),str(j),str(k)]
            Num.append(s)

for num in Num:
    flag1 = False
    flag2 = False
    memo1 = 0
    memo2 = 0
    for x in range(n-2):
        if num[0] == lst[x]:
            flag1 = True
            memo1 = x
            break
    if flag1:
        for y in range(memo1+1,n-1):
            if num[1] == lst[y]:
                flag2 = True
                memo2 = y
                break
        if flag2:
            for z in range(memo2+1,n):
                if num[2] == lst[z]:
                    cnt += 1
                    break
print(cnt)

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[a+1:].find(str(j))
            if b==-1:
                continue
            b+=a+1
            c=s[b+1:].find(str(k))
            if c==-1:
                continue
            cnt+=1

print(cnt)

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(k))
            if a != -1 :
                b = s.find(str(j), a + 1)
                if b != -1 :
                    c = s.find(str(i), b + 1)
                    if c != -1 :
                        cnt += 1
                    
print(cnt)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    f = True
    x = -1
    for j in range(3):
        x = s.find(i[j],x+1)
        f = f and bool(x >= 0)
    ans += f
print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    ind = 0
    a = 0
    for ij in i:
        while(ind < len(s)):
            if s[ind] == ij:
                a += 1
                ind += 1
                break
            ind += 1
    ans += a == 3
print(ans)

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

DP = [[0] * 10 for _ in range(10)]
D = [0] * 10
L = [0] * 1000
for i in range(N):
  for j in range(10):
    for k in range(10):
      if DP[j][k] == 1:
        L[j * 100 + k * 10 + int(S[i])] = 1
  for j in range(10):
    if D[j] == 1:
      DP[j][int(S[i])] = 1
  D[int(S[i])] = 1

print(sum(L))

Solution (Python):
n = int(input())
s = list(input())
c = 0

for i in range(1000) :
    num_1 = i // 100
    num_2 = (i - num_1*100) // 10
    num_3 = (i - num_1*100 - num_2*10) % 100
    if str(num_1) not in s :
        continue
    if str(num_2) not in s :
        continue
    if str(num_3) not in s :
        continue
    for j in range(n-2) :
        if int(s[j]) == num_1 :
            for k in range(j+1,n-1) :
                if int(s[k]) == num_2 :
                    for l in range(k+1,n) :
                        if int(s[l]) == num_3 :
                            c += 1
                            break
                    break
            break

print(c)

Solution (Python):
def mitsui2019d_lucky_pin():
    import itertools
    n = int(input())
    s = input()
    cnt = 0
    for t in itertools.product(range(0, 10), repeat=2):
        si = ''.join(map(str,t))
        for i in range(n - 2):
            if si[0] != s[i]: continue
            for j in range(i + 1, n - 1):
                if si[1] != s[j]: continue
                ss = set(list(s[j+1:]))
                cnt += len(ss)
                break
            break
    print(cnt)


mitsui2019d_lucky_pin()

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    S = input()

    ans = 0
    for x in range(0, 1000):
        t = "{:0=3}".format(x)
        j = 0
        for i in range(N):
            if t[j] == S[i]:
                j += 1
            if j == 3:
                ans += 1
                break

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

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

ans = 0
for num in range(1000):
    target = str(num).zfill(3)
    cur = 0
    for s in S:
        if s == target[cur]:
            cur += 1
        if cur == 3:
            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([])

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):
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 = input()

ans = 0
for d1 in "0123456789":
    p1 = S.find(d1)
    if p1 == -1: continue

    for d2 in "0123456789":
        p2 = S[p1+1:].find(d2)
        if p2 == -1: continue

        for d3 in "0123456789":
            if d3 in S[p1+p2+2:]:
                ans += 1

print(ans)

Solution (Python):
import itertools

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

s_l = list(map(int, s))


l = [i for i in range(10)]
ans = 0
for v1, v2, v3 in itertools.product(l, repeat=3):
    

    
    if not v1 in s_l:
        continue
    else:
        index1 = s_l.index(v1)
    
    
    
    
    s_l_1 = s_l[index1 + 1:]
        
    if not v2 in s_l_1:
        continue
    else:
        index2 = s_l_1.index(v2)
        
    s_l_2 = s_l_1[index2 + 1:]
        

    if not v3 in s_l_2:
        continue
    

    
    ans += 1
print(ans)

Solution (Python):
N = int(input())
S =list(str(input()))
a=[]
ans=0
for i in range(10):
    for u in range(10):
        for y in range(10):
            moji=[str(i),str(u),str(y)]
            ti=0
            for t in range(N):
                if S[t]==moji[ti]:
                    ti+=1
                    if ti==3:
                        break
            if ti==3:
                ans+=1
                            
                
print(ans)

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

cnt = 0
for i in range(1000):
    num = "{:03d}".format(i)
    fst = S.find(num[0])
    if fst == -1:
        continue
    sec = S.find(num[1], fst+1)
    if sec == -1:
        continue
    thr = S.find(num[2], sec+1)
    if thr == -1:
        continue

    cnt += 1

print(cnt)

Solution (Python):
import itertools

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


if __name__ == "__main__":
        
    N = int(input())
    S = [int(c) for c in input()]
    table = list(range(10))

    count = 0
    for p in itertools.product(table, repeat=3): 
        target = list(p)

        s1_index = my_index(S, target[0])
        if s1_index == -1:
            continue
        s1 = S[s1_index+1:]

        s2_index = my_index(s1, target[1])
        if s2_index == -1:
            continue
        s2 = s1[s2_index+1:]
        
        s3_index = my_index(s2, target[2])
        if s3_index == -1:
            continue
        
        count += 1

    print(count)

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

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        ii = S.find(str(i))
        if ii == -1:
            break
        for k in range(10):
            jj = S[ii+1::].find(str(j))
            if jj == -1:
                break
            jj += ii+1
            kk = S[jj+1::].find(str(k))
            if kk != -1:
                ans += 1
print(ans)

Solution (Python):

def main():
    N = int(input())
    S = input()

    seen = set()
    ans = 0
    for i in range(N - 2):
        if S[i] in seen:
            continue
        seen.add(S[i])
        for j in range(i + 1, N - 1):
            if S[i] + S[j] in seen:
                continue
            seen.add(S[i] + S[j])
            for k in range(j + 1, N):
                if S[i] + S[j] + S[k] in seen:
                    continue
                seen.add(S[i] + S[j] + S[k])
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

tried_first_digit = {}
tried_second_digit = {}
password = {}

for i in range(N-2):
    if S[i] not in tried_first_digit:
        tried_first_digit[S[i]] = 0
        for j in range(i+1, N-1):
            if S[i]+S[j] not in tried_second_digit:
                tried_second_digit[S[i]+S[j]] = 0
                for k in range(j+1, N):
                    if S[i]+S[j]+S[k] not in password:
                        password[S[i]+S[j]+S[k]] = 0

print(len(password))

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

seen = {}

for i in range(n):
    if s[i] in seen:
        seen[s[i]].append(i)
    else:
        seen[s[i]] = [i]

cnt = 0

for a, ai in seen.items():
    for b, bi in seen.items():
        if ai[0] >= bi[-1]:
            continue

        lower = ai[0]
        upper = bi[-1]

        for c, ci in seen.items():
            search = ci
            if a == c:
                search = search[1:]
            if b == c:
                search = search[:-1]

            
            l = 0
            r = len(search)-1
            found = False

            while l <= r:
                mid = (l+r)//2

                if lower < search[mid] < upper:
                    found = True
                    break
                elif search[mid] >= upper:
                    r = mid-1
                else:
                    l = mid+1

            if found:
                cnt += 1

print(cnt)

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

ans=0
for i in range(1000):
    cs=str(i).zfill(3)
    p=0
    for c in cs:
        p=s.find(c,p)

        if p==-1:
            break
        p+=1

    else:
        ans+=1

print(ans)

Solution (Python):
from itertools import product

n = int(input())
s = input()
ans = 0
for a, b, c in product(map(str, range(10)), repeat=3):
    ai = s.find(a)
    bi = s.find(b, ai + 1)
    ci = s.find(c, bi + 1)
    if ai != -1 and bi != -1 and ci != -1:
        ans += 1
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
from itertools import product

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

A = [[] for _ in range(10)]
for i in range(n):
    x = int(s[i])
    A[x].append(i)

use = set((i for i in range(10) if len(A[i]) > 0))
ans = 0
for a, b, c in product(use, repeat=3):
    ai = A[a][0]
    ci = A[c][-1]
    k = bisect_right(A[b], ci - 1) - bisect_left(A[b], ai + 1)
    if k > 0:
        ans += 1
print(ans)

Solution (Python):
import itertools
N = int(input())
S = list(input())
S = list(map(int, S))
first = [-1] * 10


ans = 0
for i in range(N):
    if first[S[i]] == 1:
        continue
    second = [-1] * 10
    for j in range(i + 1, N):
        if second[S[j]] == 1:
            continue
        third = [-1] * 10
        for k in range(j + 1, N):
            if third[S[k]] == 1:
                continue
            
            ans += 1
            third[S[k]] = 1
        second[S[j]] = 1
    first[S[i]] = 1
print(ans)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy








def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
S = input()

s1 = set()
s2 = set()
s3 = set()

for s in S:
    for ss2 in s2:
        s3.add(ss2+s)
    for ss1 in s1:
        s2.add(ss1+s)
    s1.add(s)

print(len(s3))

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

    cnt = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                ii = s.find(str(i))
                if ii == -1:
                    continue
                jj = s[ii+1:].find(str(j))
                if jj == -1:
                    continue
                jj += ii+1
                kk = s[jj+1:].find(str(k))
                if kk == -1:
                    continue
                cnt += 1


    print(cnt)


main()

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

    cnt = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                ii = s.find(str(i))
                if ii == -1:
                    continue
                jj = s[ii+1:].find(str(j))
                if jj == -1:
                    continue
                jj += ii+1
                kk = s[jj+1:].find(str(k))
                if kk == -1:
                    continue
                cnt += 1


    print(cnt)


main()

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy








def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
S = input()

ans = 0
for a,b,c in itertools.product(map(str,range(10)),repeat=3):
    aa = False
    bb = False
    for s in S:
        if aa == False and s == a:
            aa = True
            continue
        if bb == False and aa == True and s == b:
            bb = True
            continue
        if aa == True and bb == True and s == c:
            ans += 1
            break

print(ans)

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

S += 'eeee'

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            
            m = 0
            while S[m] != str(i):
                m += 1
                if m >= l:
                    break
            m += 1
            while S[m] != str(j):
                m += 1
                if m >= l:
                    break
            m += 1
            while S[m] != str(k):
                m += 1
                if m >= l:
                    break
            if m < l:
                cnt += 1

print(cnt)

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
def isok(num,val):
    return num<=val
def bisect(ls,val): 
    ok = -1
    ng = len(ls)
    x = (ok+ng)//2
    while ng-ok>1:
        num = ls[x]
        if isok(num,val):
            ok = x
        else:
            ng = x
        x = (ok+ng)//2
    return ok 

n = ni()
s = input()
idxs =[[] for i in range(10)]
for i in range(n):
    num= int(s[i])
    idxs[num].append(i)
ans = 0
for i in range(10):
    if not idxs[i]:
        continue
    i0 = idxs[i][0]
    for j in range(10):
        t1 = bisect(idxs[j],i0)
        if t1==len(idxs[j])-1:
            continue
        i1 = idxs[j][t1+1]
        for k in range(10):
            t2 = bisect(idxs[k],i1)
            if t2==len(idxs[k])-1:
                continue
            else:
                ans+=1
                
print(ans)

Solution (Python):
import sys


def main():
    N = int(sys.stdin.readline().rstrip())
    S = sys.stdin.readline().rstrip()

    cnt = 0
    for i in range(10):
        pos_1 = S.find(str(i))
        if pos_1 == -1 or pos_1 > N - 3:
            continue

        for j in range(10):
            pos_2 = S[pos_1 + 1:].find(str(j))
            if pos_2 == -1 or pos_2 > N - 2:
                continue

            for k in range(10):
                pos_3 = S[pos_1 + 1 + pos_2 + 1:].find(str(k))
                if pos_3 != -1:
                    cnt += 1

    print(cnt)


main()

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

cnt = [0]*10
for x in S:
    cnt[int(x)] += 1

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

ans = 0
for tar in tars:
    id = 0
    copy_cnt = copy.copy(cnt)
    if copy_cnt[int(tar[0])] == 0 or copy_cnt[int(tar[1])] == 0 or copy_cnt[int(tar[2])] == 0:
        continue
    while S[id] != tar[0]:
        copy_cnt[int(S[id])] -= 1
        id += 1
    copy_cnt[int(S[id])] -= 1
    id += 1
    if copy_cnt[int(tar[1])] == 0 or copy_cnt[int(tar[2])] == 0:
        continue
    while S[id] != tar[1]:
        copy_cnt[int(S[id])] -= 1
        id += 1
    copy_cnt[int(S[id])] -= 1
    if copy_cnt[int(tar[2])] == 0:
        continue
    else:
        ans += 1

print(ans)

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

top_used = set()
used = set()
ans = 0
for i in range(n - 1):
    if int(s[i]) in top_used:
        continue
    top_used.add(int(s[i]))
    for j in range(i + 1, n):
        top = s[i] + s[j]
        if top not in used:
            ans += len(set(s[j + 1:]))
            used.add(top)


print(ans)

Solution (Python):
def main():
    N = int(input())
    S = input()[::-1]
    digits_1 = [0] * 10
    digits_2 = [[0 for _ in range(10)] for _ in range(10)]
    digits_3 = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(10)]
    for i, d in enumerate(S):
        d = int(d)
        for d1 in range(10):
            for d2 in range(10):
                if digits_2[d2][d1] == 1:
                    digits_3[d][d2][d1] = 1
        for d1 in range(10):
            if digits_1[d1] == 1:
                digits_2[d][d1] = 1
        digits_1[d] = 1
    ans = 0
    for d3 in range(10):
        for d2 in range(10):
            for d1 in range(10):
                ans += digits_3[d3][d2][d1]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
0224"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6
123123"""
        output = """17"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """19
3141592653589793238"""
        output = """329"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    S = input()

    ans = 0
    o = []
    for i in range(10):
        ip = S.find(str(i))
        if ip >= N-2 or ip == -1:
            continue
        for j in range(10):
            jp = S[ip+1:].find(str(j))
            if jp == -1:
                continue
            if ip + 1 + jp >= N-1:
                continue
            jp += ip+1
            for k in range(10):
                kp = S[jp+1:].find(str(k))
                if kp == -1:
                    continue
                t = str(i)+str(j)+str(k)
                if t not in o:
                    ans += 1
                    o.append(t)
    print(ans)


if __name__ == "__main__":
     
     resolve()

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

for i in range(1000):
  if i//10 == 0:
    numlst.append("00"+str(i))
  elif i//100 == 0:
    numlst.append("0"+str(i))
  else:
    numlst.append(str(i))

for i in range(1000):
  judge = False
  a, b, c = numlst[i][0], numlst[i][1], numlst[i][2]
  
  for j in range(n-2):
    if s[j] == a:
      for k in range(j+1, n-1):
        if s[k] == b:
          for l in range(k+1, n):
            if s[l] == c:
              judge = True
          break
      break
      
  if judge:
    ans += 1
     
print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

ans = 0
for i in range(1000):
    tmp = str(i).zfill(3)
    cnt = 0
    for j in range(N):
        if S[j] == tmp[cnt]:
            cnt += 1
            if cnt == 3:
                ans += 1
                break
print(ans)

Solution (Python):
N=int(input())
S=list(input())
x=list(map(str,list(range(10))))
cnt=0
for i in x:
  if i in S:
    p=S.index(i)
    S1=S[p+1:]
    for j in x:
      if j in S1:
        q=S1.index(j)
        S2=S1[q+1:]
        for k in x:
          if k in S2:
            cnt+=1
print(cnt)

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    sys.setrecursionlimit(10**5)
    n = I()
    s = S()
    global cnt
    cnt = 0
    def tansaku(st,depth):
        global cnt
        for i in range(10):
            index = st.find(str(i))
            if index != -1:
                if depth == 0:
                    cnt += 1
                    
                
                else:
                    tansaku(st[index+1:],depth-1)
    tansaku(s,2)

    print(cnt)

main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = input()
S = list(map(int, list(L)))


cnt = 0

for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            num = 0
            flag = False
            exist = [False] * 3
            while num != N and flag != True:
                
                if exist[0] == False:
                    
                    if S[num] != i:
                        num += 1
                    elif S[num] == i:
                        num += 1
                        exist[0] = True
                else:
                    if exist[1] == False:
                        if S[num] != j:
                            num += 1
                        elif S[num] == j:
                            num += 1
                            exist[1] = True
                    else:
                        if exist[2] == False:
                            if S[num] != k:
                                num += 1
                            elif S[num] == k:
                                num += 1
                                exist[2] == True
                                flag = True
            if flag == True:
                cnt += 1            
print(cnt)

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

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

print(ans)