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 = input()
S = list(map(int, input()[:]))
ans = 0
for num in range(1000):
    n1,n2,n3 = 0, 0, num%10
    n2= (num %100-n3)// 10
    n1 = (num-n2*10- n3) //100
    f1 = False
    f2 = False
    f3 = False
    for n in S:
        if not f1:
            if n == n1:
                f1 = True
        elif not f2:
            if n == n2:
                f2 = True
        elif not f3:
            if n == n3:
                f3 = True
                break
    if f1 and f2 and f3:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()
count = 0
for i in range(0,1000):
    tmp = 0
    for nun,j in enumerate(list(str(i).zfill(3))):
        pretmp = tmp
        tmp = s[tmp:].find(j)
        if tmp < 0:
            break
        if nun == 2 and tmp >= 0:
            count +=1
        tmp = tmp + pretmp + 1
print(count)

Solution (Python):
import copy

N = input()
S = list(map(int, input()[:]))
left = [False for i in range(10)]
right = [0 for i in range(10)]

for n in S[1:]:
    right[n] += 1
left[S[0]] = True
flag = [[[False for i in range(10)] for j in range(10)] for k in range(10)]
for n in S[1:-1]:
    right[n] -= 1
    for i, l in enumerate(left):
        if l:
            for j, r in enumerate(right):
                if r > 0:
                    flag[n][i][j] = True
    left[n] = True
count = 0
for i in flag:
    for j in i:
        for k in j:
            if k:
                count += 1
print(count)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    S = input().strip("\n")
    Left = [set() for _ in range(N)]
    Right = [set() for _ in range(N)]
    Left[0] |= {S[0]}
    Right[N-1] |= {S[N-1]}
    for i in range(1, N):
        Left[i] = Left[i-1] | {S[i]}
        Right[N-i-1] = Right[N-i] | {S[N-i-1]}
    used = set()
    for i in range(1, N - 1):
        mid = S[i]
        for l in Left[i-1]:
            for r in Right[i+1]:
                used |= {l + mid + r}
    print(len(used))

    return 0

if __name__ == "__main__":
    solve()

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


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

one = set()
two = set()
thi = set()
for s in S:
    for t in two:
        thi.add(t+s)
    for o in one:
        two.add(o+s)
    one.add(s)

print(len(thi))

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

ans = 0
for i in range(1000):
    judge = False
    p = 0
    if i >= 0 and i < 10:
        number = "00" + str(i)
    elif i >= 10 and i < 100:
        number = '0' + str(i)
    else:
        number = str(i)
    
    for j in range(N):
        if number[p] == S[j]:
            p += 1
            if p == 3:
                ans += 1
                break
            

print(ans)

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

N = int(input())
S = input()[:-1]
ans = 0

for i in range(1000):
    s = '0'*(3-len(str(i)))+str(i)
    now = 0
    
    for j in range(N):
        if S[j]==s[now]:
            now += 1
    
            if now==3:
                break
    
    if now==3:
        ans += 1

print(ans)

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

s = set()
L = [[set() for i in range(2)] for j in range(N+1)]

ans = set()

for i in range(N):
    L[i+1][0].add(S[i])
    for k in L[i][0]:
        L[i+1][0].add(k)
        L[i+1][1].add(k + S[i])
    for k in L[i][1]:
        L[i+1][1].add(k)
        ans.add(k + S[i])

print(len(ans))

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    lucky = str(i)
    if 0 <= i <= 9:
        lucky = "00" + lucky
    elif 10 <= i <= 99:
        lucky = "0" + lucky
    else:
        pass
    now = 0
    index = 0
    while index < N:
        if lucky[now] == S[index]:
            now += 1
        if now == 3:
            ans += 1
            break
        index += 1
print(ans)

Solution (Python):
import sys
import math
n=int(input())
s=str(input())
ans_lis=[]
ans=0
for i in range(1000):
    tmp=[str(i//100),str((i%100)//10),str((i%100)%10)]
    f=0
    for j in range(n):
        if s[j]==tmp[f]:f+=1
        if f==3:
            ans+=1
            break
print(ans)

Solution (Python):
n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)

Solution (Python):


import math



from collections import deque
from collections import Counter




n=int(input())
a=list(input())
a=list(map(int,a))
ans=0
for i in range(10):
    s=set(a)
    if i in s:
        p=a.index(i)
        for j in range(10):
            s=set(a[p+1:])
            if j in s:
                q=a[p+1:].index(j)+p+1
                for k in range(10):
                    s=set(a[q+1:])
                    if k in s:
                        ans+=1
print(ans)

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

len1 = set()
len2 = set()
len3 = set()

for d in S:
    for l2 in len2:
        len3.add(l2+d)
    for l1 in len1:
        len2.add(l1+d)
    len1.add(d)
print(len(len3))

Solution (Python):
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1000):
        d0 = str(i % 10)
        d1 = str((i // 10) % 10)
        d2 = str((i // 100) % 10)
        j = 0
        found = False
        while j < N:
            if S[j] == d0:
                found = True
                j += 1
                break
            j += 1
        if not found:
            continue
        found = False
        while j < N:
            if S[j] == d1:
                found = True
                j += 1
                break
            j += 1
        if not found:
            continue
        found = False
        while j < N:
            if S[j] == d2:
                found = True
                j += 1
                break
            j += 1
        if not found:
            continue
        if found:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())
s = input()
c = 0
for i in range(10):
    a = s.find(str(i))
    if a > -1:
        for j in range(10):
            b = s.find(str(j), a + 1)
            if b > -1:
                c += len(set(s[b + 1:]))
print(c)

Solution (Python):

n = int(input())
s = input()
c = 0
for i in range(10):
    for j in range(10):
        a = s.find(str(i))
        if a > -1:
            b = s.find(str(j), a + 1)
            if b > -1:
                c += len(set(s[b + 1:]))
print(c)

Solution (Python):

n = int(input())
s = input()
s = [int(i) for i in s]
c = 0
for i in range(10):
    for j in range(10):
        if i in s:
            t = s[s.index(i) + 1:]
            if j in t:
                c += len(set(t[t.index(j) + 1:]))
print(c)

Solution (Python):

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

c = 0

for i in range(10):
    i = str(i)
    for j in range(10):
        j = str(j)
        for k in range(10):
            k = str(k)
            if i in s:
                t = s[s.index(i)+1:]
                if j in t:
                    u = t[t.index(j)+1:]
                    if k in u:
                        c+=1
print(c)

Solution (Python):
N = int(input())
S = str(input())
s = S
count = 0
for i in range(10):
  i = str(i)
  for j in range(10):
    j = str(j)
    for k in range(10):
      k = str(k)
      if i in s:
        s=s[s.index(i)+1:]
        if j in s:
          s=s[s.index(j)+1:]
          if k in s:
            count += 1
      s = S
print(count)

Solution (Python):
N = int(input())
S = input()
count = 0
for i in range(10):
    
    if S.find(str(i)) == -1:
        
        continue
    for j in range(10):
        if S.find(str(j),S.find(str(i))+1) == -1:
            
            continue
        for k in range(10):
            if S.find(str(k),S.find(str(j),S.find(str(i))+1)+1) != -1:
                
                count += 1
print(count)

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

cnt = 0

for a in range(10):
    s_index = s.find(str(a)) 
    if s_index == -1:
        continue
    for b in range(10):
        t_index = s.find(str(b),s_index+1)
        if t_index==-1:
            continue
        for c in range(10):
            u_index = s.find(str(c),t_index+1)
            if u_index != -1:
                cnt+=1
                    
               
        
print(cnt)

Solution (Python):
n = int(input())
S = input()
ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    for s in S:
        if s == t[0]:
            t = t[1:]
        if t == '':
            ans += 1
            break
print(ans)

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

count = 0
for p in range(10):
    s = S.find(str(p))
    if s == -1:
        continue
    for q in range(10):
        t = S.find(str(q), s + 1)
        if t == -1:
            continue
        for r in range(10):
            u = S.find(str(r), t + 1)
            if u != -1:
                count += 1
print(count)

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

SETF=[set() for i in range(N)]
SETE=[0 for i in range(N)]
ANSSET=set()
SETF[0]=set()
SETF[0].add(S[0])


import copy
for i in range(1,N):
    SETF[i]=copy.deepcopy(SETF[i-1])
    SETF[i].add(S[i])


SETE[0]=set()
SETE[0].add(S[-1])

for i in range(1,N):
    SETE[i]=copy.deepcopy(SETE[i-1])
    SETE[i].add(S[N-1-i])
SETE=SETE[::-1]

for i in range(1,N-1):
    for f in SETF[i-1]:
        for e in SETE[i+1]:
            ANSSET.add(f+S[i]+e)
print(len(ANSSET))

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

count=0
for p in range(10):
    s=S.find(str(p))
    if s==-1:
        continue
    for q in range(10):
        t=S.find(str(q),s+1)
        if t==-1:
            continue
        for r in range(10):
            u=S.find(str(r),t+1)
            if u!=-1:
                count+=1
print(count)

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

def is_include(t: str, S: str) -> bool:
    tlis = list(t)
    slis = list(S)
    pointer = 0
    len_t = len(tlis)
    for s in slis:
        if s == tlis[pointer]:
            pointer += 1
        if pointer == len_t:
            return True
    return False

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            t = str(i)+str(j)+str(k)
            if is_include(t, S):
                cnt += 1

print(cnt)

Solution (Python):
n, s = open(0).read().split()

s = list(map(int, list(s)))

from itertools import product,repeat

ans = 0
for a,b,c in product(range(10), range(10), range(10)):
    abc = [a,b,c]
    tmp = 0
    for dig in s:
        if dig == abc[tmp]:
            tmp += 1
            if tmp == 3:
                ans += 1
                break

print(ans)

Solution (Python):
N = int(input())
S = input()
NUMS = list(map(int, S))
ans = 0
for i in range(10):
    for j in range(10):
        iok = False
        jok = False
        k = set()
        for num in NUMS:
            if jok:
                k.add(num)
            elif iok:
                if num == j:
                    jok = True
            else:
                if num == i:
                    iok = True
        ans += len(k)
print(ans)

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

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


d = defaultdict(list)
for i in range(n):
    d[s[i]].append(i)

def canCreate(x,y,z):
    pos = 0
    for c in map(str, [x,y,z]):
        pos = bisect.bisect_left(d[c], pos)
        if pos == len(d[c]):
            return False
        pos = d[c][pos] + 1
    return True

ans = sum([canCreate(x, y, z) for x,y,z in product(range(10), repeat=3)])

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

Solution (Python):
n=int(input())
s=input()
c=0
for i in range(10):
  a=s.find(str(i))
  if -1<a<n-2:
    
    for j in range(10):
      b=s[a+1:].find(str(j))
      if -1<b<len(s[a+1:])-1:
    
        for k in range(10):
          if s[a+b+2:].find(str(k))>-1:
            c+=1
print(c)

Solution (Python):
n = int(input())
S = input()
L = []
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      cnt = 0
      iflag = 0
      jflag = 0
      while True:
        if cnt >= n:
          break
        if iflag == 0 and S[cnt] == str(i):
          iflag = 1
          cnt += 1
          continue
        if iflag == 1 and jflag == 0 and S[cnt] == str(j):
          jflag= 1
          cnt += 1
          continue
        if jflag == 1 and S[cnt] == str(k):
          ans += 1
          break
        cnt += 1

print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
I = []
for i in range(n-2):
    if s[i] not in I:
        I.append(s[i])
    else:
        continue
    J = []
    for j in range(i+1, n-1):
        if s[j] not in J:
            J.append(s[j])
        else:
            continue
        K = []
        for k in range(j+1, n):
            if s[k] not in K:
                K.append(s[k])
                ans += 1
print(ans)

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

ok = [0,0,0,0,0,0,0,0,0,0]
ans = 0

for i in range(n):
    if sum(ok) == 10:
        break
    if ok[int(s[i])] == 1:
        continue
    ok[int(s[i])] = 1
    nd = [0,0,0,0,0,0,0,0,0,0]
    for j in range(i+1,n):
        if sum(nd) == 10:
            break
        if nd[int(s[j])] == 1:
            continue
        nd[int(s[j])] = 1
        rd = [0,0,0,0,0,0,0,0,0,0]
        for k in range(j+1, n):
            if sum(rd) == 10:
                break
            if rd[int(s[k])] == 1:
                continue
            rd[int(s[k])] = 1
            ans += 1

print(ans)

Solution (Python):
n = int(input())
S = input()
ans = 0
def ok(i):
    pin = '{:0=3}'.format(i)
    j = 0
    for s in S:
        if s == pin[j]:
            j += 1
            if j == 3:
                return True
    else:
        return False

for i in range(1000):
    ans += ok(i)
print(ans)

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

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    tmp = s
    if v[0] in tmp:
        tmp = tmp[tmp.index(v[0])+1:]
    else:
        continue
    if v[1] in tmp:
        tmp = tmp[tmp.index(v[1])+1:]
    else:
        continue
    if v[2] in tmp:
        res += 1
print(res)

Solution (Python):
N = int(input())
S = [str(i) for i in input()]

search = [("00"+str(s))[-3:] for s in range(0,1000)]
ans = []
for num in search:
    tmp_S = S
    if num[0] in tmp_S:
        tmp_S = tmp_S[tmp_S.index(num[0])+1:] 
    else:
        continue
    if num[1] in tmp_S:
        tmp_S = tmp_S[tmp_S.index(num[1])+1:] 
    else:
        continue
    if num[2] in tmp_S:
        ans.append(num)

print(len(ans))

Solution (Python):


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    S = input()

    return N, S


def main(N: int, S: str) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 桁数
        S (str): ラッキーナンバー
    """
    
    ans = 0
    x_bit = [False for n in range(10)]
    for x in range(N):
        S_x = int(S[x])
        if x_bit[S_x]:
            continue
        x_bit[S_x] = True
        y_bit = [False for n in range(10)]
        for y in range(x + 1, N):
            S_y = int(S[y])
            if y_bit[S_y]:
                continue
            y_bit[S_y] = True
            z_bit = [False for n in range(10)]
            for z in range(y + 1, N):
                S_z = int(S[z])
                if z_bit[S_z]:
                    continue
                z_bit[S_z] = True
                ans += 1

    
    print(ans)


if __name__ == "__main__":
    
    N, S = get_input()

    
    main(N, S)

Solution (Python):


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


ans = 0
x_bit = [False for n in range(10)]
for x in range(N):
    S_x = int(S[x])
    if x_bit[S_x]:
        continue
    x_bit[S_x] = True
    y_bit = [False for n in range(10)]
    for y in range(x + 1, N):
        S_y = int(S[y])
        if y_bit[S_y]:
            continue
        y_bit[S_y] = True
        z_bit = [False for n in range(10)]
        for z in range(y + 1, N):
            S_z = int(S[z])
            if z_bit[S_z]:
                continue
            z_bit[S_z] = True
            ans += 1


print(ans)

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    S = input()

    cnt = 0
    for i in range(1000):
        words = '{:0>3}'.format(i)
        k = 0
        for item in S:
            if item == words[k]:
                
                k += 1

            if k == 3:
                cnt +=1
                break

    print(cnt)



if __name__ == "__main__":
    resolve()

Solution (Python):
""" tutorial06
    https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
"""
import sys
import math
from functools import reduce

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def main(N, S):
    """ main
    """
    count = 0
    skip1 = []
    skip2 = []
    skip3 = []

    for i in range(0, N):
        if S[i] in skip1:
            continue
        skip1.append(S[i])
        for j in range(i+1, N):
            if S[j] in skip2:
                continue
            skip2.append(S[j])
            for k in range(j+1, N):
                if S[k] in skip3:
                    continue
                skip3.append(S[k])
                count += 1
            skip3 = []
        skip2 = []

    return count

if __name__ == "__main__":
    _N = readInteger()
    _S = readString()

    print(main(_N, _S))

Solution (Python):


def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    
    

    
    
    
    
    
    
    
    
        
    

    N = II()
    S = input()

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
S=input()
count=0
I=[]
for i in range(N-2):
    if S[i] not in I:
        I.append(S[i])
    else:
        continue
    J=[]
    for j in range(i+1,N-1):
        if S[j] not in J:
            J.append(S[j])
        else:
            continue
        K=[]
        for k in range(j+1,N):
            if S[k] not in K:
                K.append(S[k])
                count+=1
print(count)

Solution (Python):
import sys
import math
 
N = int(input())
S = input()
ans = 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):
            if S.find(str(k), b+1) != -1:
                ans += 1
 
 
print(ans)

Solution (Python):
from collections import defaultdict


def main():
    _ = input()
    S = input()
    S_idx = defaultdict(list)
    num_combs = 0
    for i in range(len(S)):
        S_idx[S[i]].append(i)

    for i in range(10):
        for j in range(10):
            for k in range(10):
                if not ((len(S_idx[str(i)]) == 0) or (len(S_idx[str(j)]) == 0) or (len(S_idx[str(k)]) == 0)):
                    s1_idx = S_idx[str(i)][0]
                    if not s1_idx >= S_idx[str(j)][-1]:
                        s2_idx = binary_search(S_idx[str(j)], s1_idx)
                        if not (s2_idx == -1 or s2_idx >= S_idx[str(k)][-1]):
                            num_combs += 1
    print(num_combs)


def binary_search(A, x):
    ok = len(A)
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if A[mid] > x:
            ok = mid
        else:
            ng = mid
    if ok < len(A):
        return A[ok]
    else:
        return -1


if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())
s = [int(i) for i in input()]

def myindex(l,x,ind):

    global n
    if ind == n:
        return -1
    for i in range(ind,n):
        if l[i] == x:
            return i
    return -1

c=0

for i in range(10):
    x1 = myindex(s,i,0)
    if x1 != -1:
        for j in range(10):
            x2 = myindex(s,j,x1+1)
            if x2 != -1:
                for k in range(10):
                    x3 = myindex(s,k,x2+1)
                    if x3 != -1:
                        c+=1

print(c)

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

s=list(map(int,list(s)))

password=[str(i).zfill(3) for i in range(1000)]

cnt=0
can=[]
for word in password:
    w1=int(word[0])
    w2=int(word[1])
    w3=int(word[2])

    i=0
    while i<n-2:
        if s[i]==w1:
            i_1=i
            break
        else:
            i+=1

        if i==n-3 and s[i]!=w1:
            i_1=-1
            break
    
    if i_1==-1:
        continue

    j=i+1
    while j<n-1:
        if s[j]==w2:
            i_2=j
            break
        else:
            j+=1

        if j==n-2 and s[j]!=w2:
            i_2=-1
            break
    
    if i_2==-1:
        continue

    k=j+1
    while k<n:
        if s[k]==w3:
            i_3=k
            break
        else:
            k+=1
        
        if k>=n-1 and s[n-1]!=w3:
            i_3=-1
            break

    if i_3==-1:
        continue
    elif i_1<i_2 and i_2<i_3:
        cnt+=1
        can.append(word)


print(cnt)

Solution (Python):
import sys
import math

N = int(input())
S = input()
ans = 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):
            if S.find(str(k), b+1) != -1:
                ans += 1


print(ans)

Solution (Python):
n = int(input())
S = [int(x) for x in input()]
all_num = 0

all_dict = {}
for i in range(len(S)-2):
  s_0 = S[i]
  if s_0 in all_dict.keys():
    pass
  else:
    all_dict[s_0] = dict()
    for j in range(i+1, len(S)-1):
      s_1 = S[j]
      if s_1 in all_dict[s_0].keys():
        pass
      else:
        all_dict[s_0][s_1] = len(set(S[j+1:]))
        all_num += len(set(S[j+1:]))
        
print(all_num)

Solution (Python):
n = int(input())
s = [int(x) for x in input()]

dp_1 = [False] * 10
dp_2 = [False] * 100
dp_3 = [False] * 1000

for x in s:
    for i in range(100):
        if dp_2[i]:
            dp_3[i * 10 + x] = True
    for i in range(10):
        if dp_1[i]:
            dp_2[i * 10 + x] = True
    dp_1[x] = True

print(sum(dp_3))

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
s = ns()

ans = 0

for a in range(10):
    for b in range(10):
        now = 1
        ss = set()
        for i in range(n):
            if now == 1 and s[i] == str(a):
                now = 2
            elif now == 2 and s[i] == str(b):
                now = 3
            elif now == 3:
                ss.add(s[i])
        ans += len(ss)

print(ans)

Solution (Python):
n=int(input())
s=input()
a=0
for i in range(1000):
    t=str(i).zfill(3)
    p=0
    for j in s:
        if j==t[p]:
            p+=1
        if p==3:
            
            break
    if p==3:
        a+=1
print(a)

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

output = 0
for idx1 in range(10):
    digit1 = s.find(str(idx1))
    if digit1 == -1:
        continue

    for idx2 in range(10):
        digit2 = s.find(str(idx2), digit1 + 1)
        if digit2 == -1:
            continue

        for idx3 in range(10):
            digit3 = s.find(str(idx3), digit2 + 1)
            if digit3 == -1:
                continue
            output += 1
print(output)

Solution (Python):
N = int(input())
S = input()
s1 = set()
s2 = set()
s3 = set()

for i in S:
  for j in s2:
    s3.add(j+i)
  for k in s1:
    s2.add(k+i)
  s1.add(i)
print(len(s3))

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

count = 0
numberlist = [str(i) for i in range(10)]

for a in numberlist:
    idx1 = S.find(a)
    if idx1 == -1 or idx1 >= N - 2:
        continue
    
    for b in numberlist:
        idx2 = S[idx1+1:].find(b)
        if idx2 == -1 or idx2 >= N - 1:
            continue

        count += len(set(S[idx1+idx2+2:]))

print(count)

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

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

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

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

for i in S:
  for j in s2:
    s3.add(j+i)
  for k in s1:
    s2.add(k+i)
  s1.add(i)

print(len(s3))

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

ans = 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:
        ans += 1

print(ans)

Solution (Python):
N = int(input())
S = [int(i) for i in input()]

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      Flag1 = True
      Flag2 = False
      Flag3 = False
      for x in S:
        if Flag3:
          if x == k:
            ans += 1
            break
        if Flag2:
          if x == j:
            Flag2 = False
            Flag3 = True
        if Flag1:
          if x == i:
            Flag1 = False
            Flag2 = True

print(ans)

Solution (Python):
n=int(input())
s=list(input())
for i in range(n):
    s[i]=int(s[i])

def idx(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

lst=[idx(s,j) for j in range(10)]
len_lst=[len(lst[i]) for i in range(10)]

ans=0
switch=0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if len_lst[i]>=1:
                place_num1=lst[i][0]
                for l in lst[j]:
                    if l>place_num1:
                        place_num2=l
                        switch=1
                        break
                if switch==1:
                    switch=0
                    for m in lst[k]:
                        if m>place_num2:
                            ans+=1
                            break

print(ans)

Solution (Python):
N = int(input())
S = input()
cnt = 0
for i in range(0,1000):
  if i >= 100:
    i = str(i)
  elif i >= 10:
    i = "0" + str(i)
  else:
    i = "00" + str(i)
  checker = 0
  for j in range(N):
    if S[j] == i[checker]:
      checker += 1
    if checker == 3:
      cnt += 1
      break
print(cnt)

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

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            i_ok = False
            j_ok = False
            k_ok = False
            check = str(i)
            for l in range(N):
                if S[l] == check:
                    if not i_ok:
                        i_ok = True
                        check = str(j)
                    elif not j_ok:
                        j_ok = True
                        check = str(k)
                    elif not k_ok:
                        k_ok = True
                        break
    
            if i_ok and j_ok and k_ok:
                res += 1

print(res)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()
    num = list(set(s))
    res = 0
    for i in num:
        for j in num:
            for k in num:
                ss = i + j + k
                pos = 0
                for l in range(len(s)):
                    if ss[pos] == s[l]:
                        pos += 1
                        if pos == 3:
                            res += 1
                            break
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction

sys.setrecursionlimit(int(pow(10,6)))


mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]



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

ans = 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:
                continue
            ans += 1
print(ans)

Solution (Python):
from itertools import product
N = int(input())
S = input()
res = 0
for pair in product(range(10), repeat=3):
  s = S[::]
  found = True
  for i,num in enumerate(pair):
    idx = s.find(str(num))
    if idx == -1:
      found = False
      break
    else:
      if idx+1 == N:
        if i != len(pair)-1:
          found = False
        break
      s = s[idx+1:]

  if found:
    res += 1

print(res)

Solution (Python):
n = int(input())
s = input()
res=0
for i in range(1000):
    digits=str(i)
    if i<100:
        digits='0'*(3-len(str(i)))+digits
        
    cnt = 0
    for j in s:
        if j==digits[cnt]:
            
            cnt+=1
        if cnt>=3:
            res+=1
            break
print(res)

Solution (Python):


def solve(s):
    s = str(s)
    c = 0
    for i in range(1000):
        v = [i//100, i//10%10, i%10]
        f = 0
        for j in range(len(s)):
            if int(s[j]) == v[f]:
                f += 1
            if f == 3:
                break
        if f == 3:
            c += 1
    return c

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


if __name__ == '__main__':
    main()