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 pprint import pprint
import sys

n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()

count = 0
for i in range(1000):
    pin = str(i).zfill(3)
    start = 0
    flags = [False] * 3
    for i, pin_i in enumerate(pin):
        flag = False
        for j, s_j in enumerate(s):
            if j < start:
                continue
            if s_j == pin_i:
                flag = True
                start = j + 1
                break
        flags[i] = flag
    if flags[0] and flags[1] and flags[2]:
        
        count += 1

print(count)

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

l_S=list(S)

count=0
for i in range(0,1000):
    i_1=int(i/100)
    i_2=int(i/10)-i_1*10
    i_3=i%10
    if str(i_1) in l_S[:-2]:
        idx_1=l_S[:-2].index(str(i_1))
        if str(i_2) in l_S[idx_1+1:-1]:
            idx_2=l_S[idx_1+1:-1].index(str(i_2))+idx_1+1
            if str(i_3) in l_S[idx_2+1:]:
                count+=1
print(count)

Solution (Python):
from itertools import product

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

cnt = 0
for i, j, k in product("0123456789", repeat=3):
    try:
        x = S.index(i)
        y = S.index(j, x + 1)
        z = S.index(k, y + 1)
    except:
        continue
    cnt += 1

print(cnt)

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

for i in range(1000):
    if len(str(i))==1:
        i=str(0)+str(0)+str(i)
    elif len(str(i))==2:
        i=str(0)+str(i)
    else:
        i=str(i)
    x=0
    for j in range(n):
        if s[j]==i[x]:
            x+=1
            if x==3:
                count+=1
                break
print(count)

Solution (Python):
n=int(input())
l=list(input())
ans=0
for i in range(10):
  for j in range(10):
    for k in range(10):
      now=str(i)
      count=0
      b=True
      f=1
      while count<n and b:
        if l[count]==now:
          if f==1:
            now=str(j)
            f+=1
          elif f==2:
            now=str(k)
            f+=1
          else:
            b=False
            ans+=1
        count+=1
print(ans)

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

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

print(ans)

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

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

print(ans)

Solution (Python):
n = int(input())
s = str(input())
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            i_pos = s.find(str(i))

            if i_pos == -1:
                continue

            j_pos = s.find(str(j), i_pos+1)

            if j_pos == -1:
                continue

            k_pos = s.find(str(k), j_pos+1)

            if k_pos == -1:
                continue

            ans += 1

print(ans)

Solution (Python):
n=int(input())
s=str(input())
 
def isThere(suji):
    flag1=False
    flag2=False
    flag3=False
    for i in s:
        if flag2==True and suji[2]==i:
            flag3=True
            break
        if flag1==True and suji[1]==i:
            flag2=True
        if suji[0]==i:
            flag1=True
    return flag3 
 
candidate=list(range(1000))
candidate=['0'+'0'+str(candidate[i]) if candidate[i]<10 else ('0'+str(candidate[i]) if 9<candidate[i]<100 else str(candidate[i])) for i in range(1000)]
ans=0
for suji in candidate:
    if isThere(suji):
        ans+=1
print(ans)

Solution (Python):
from itertools import product

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

cnt = 0
for i, j, k in product(range(10), repeat=3):
    try:
        x = s.index(str(i))
        y = s.index(str(j), x+1)
        z = s.index(str(k), y+1)
        cnt += 1
    except:
        continue

print(cnt)

Solution (Python):



def solve(*args: str) -> str:
    n = int(args[0])
    s = args[1]
    ret = 0

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

    for i in range(1000):
        iii = '{:03d}'.format(i)
        cur = -1
        found = False

        for e, j in enumerate(iii):
            found = False

            for k in index[int(j)]:
                if cur < k:
                    found = True
                    cur = k
                    break

            if not found:
                break

        if found:
            ret += 1

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
input()
a, b, c = set(), set(), set()
for x in input():
  c.update(y + x for y in b)
  b.update(y + x for y in a)
  a.add(x)
print(len(c))

Solution (Python):
N = int(input())
S = list(input())
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            n = 0
            while str(i) != S[n] and n < N-3:
                n += 1
            if S[n] != str(i):
                break
            n += 1
            while str(j) != S[n] and n < N-2:
                n += 1
            if S[n] != str(j):
                break
            n += 1
            while str(k) != S[n] and n < N-1:
                n += 1
            if S[n] == str(k):
                ans += 1
print(ans)

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

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

Solution (Python):
from itertools import product

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

p = product([str(i) for i in range(10)], repeat=3)

ans = 0

for i, j, k in p:
    x = s.find(i)
    if x != -1:
        y = s.find(j, x+1)
        if y != -1:
            z = s.find(k, y+1)
            if z != -1:
                ans += 1

print(ans)

Solution (Python):

N = int(input())
A = [int(x) for x in list(input())]
ans = 0

AA = [x for x in range(10)]

for i in AA:
    for j in AA:
        for k in AA:
            v = [i, j, k]
            now=0
            temp=v[now]
            for l in A:
                if (l ==temp):
                    now += 1
                    if (now == 3):
                        
                        break
                    temp = v[now]
            if (now == 3):
                ans += 1

print(ans)

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

count = 0

for i in range(1000):
  a = "{0:03d}".format(i)
  if a[0] in s:
    idx1 = s.index(a[0])
    s1 = s[idx1+1:]
    if a[1] in s1:
      idx2 = s1.index(a[1])
      s2 = s1[idx2+1:]
      if a[2] in s2:
        count += 1
print(count)

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

n = int(input())
s = input().split()[0]

ans = 0
for i in range(1000):
    num_str = str(i).zfill(3)
    a = s.find(num_str[0])
    if a==-1:
        continue
    b = s[a+1:].find(num_str[1])
    if b==-1:
        continue
    b += a+1
    c = s[b+1:].find(num_str[2])
    if c!=-1:
        ans += 1
print(ans)

Solution (Python):
import bisect
import collections

def read():
    N = int(input().strip())
    S = str(input().strip())
    return N, S

def dig(S, T, N):
    k0, k1, k2 = -1, -1, -1
    for i in range(N):
        if S[i] == T[0]:
            k0 = i
            break
    if k0 == -1:
        return False
    for i in range(k0+1, N):
        if S[i] == T[1]:
            k1 = i
            break
    if k1 == -1:
        return False
    for i in range(k1+1, N):
        if S[i] == T[2]:
            k2 = i
            break
    if k2 == -1:
        return False
    return True


def solve(N, S):
    d = [collections.deque() for i in range(10)]
    count = 0
    for p in range(1000):
        T = '{:03d}'.format(p)
        count += 1 if dig(S, T, N) else 0
    return count
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
	i=str(i)
	i=(3-len(i))*"0"+i
	r=0
	for j in range(n):
		if s[j]==i[r]:
			r+=1
		if r==3:
			break
	if r==3:
		ans+=1
print(ans)

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

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

ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            i_pos = s.find(str(i))

            if i_pos == -1:
                continue

            j_pos = s.find(str(j), i_pos+1)

            if j_pos == -1:
                continue

            k_pos = s.find(str(k), j_pos+1)

            if k_pos == -1:
                continue

            ans += 1

print(ans)

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

from itertools import product

p = product([str(i) for i in range(10)], repeat=3)

ans = 0
for i,j,k in p:
  x = S.find(i)
  if x<0:
    continue
  y = S[x+1:].find(j)
  if y<0:
    continue
  z = S[x+y+2:].find(k)
  if z<0:
    continue
  
  ans += 1
print(ans)

Solution (Python):
N = int(input())
S = input()
SS = S
ans = 0
an = []
for x in range(1000):
    check = True
    p = -1
    sx = str(x).zfill(3)
    a = []
    S = SS
    for y in range(3):
        idx = S.find(sx[y])
        if idx < 0:
            check = False
            break
        else:
            S = S[idx + 1:]
    if check:
        an.append(sx)
        ans += 1
print(ans)

Solution (Python):
from itertools import product

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

cnt = 0
for i, j, k in product(range(10), repeat=3):
    try:
        x = S.index(str(i))
        y = S.index(str(j), x + 1)
        z = S.index(str(k), y + 1)
    except:
        continue
    cnt += 1

print(cnt)

Solution (Python):
N = int(input())
S = list( input("") )
A =  set(S)
count = 0
for i in A:
    b = S.index(i) + 1
    B = set(S[b:])
    for j in B:
        c = S[b:].index(j) + 1
        C = set(S[b:][c:])
        count += len(C)
print(count)

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

    ans = 0
    for i in range(0, 1000):
        num = str(i).rjust(3, '0')
        index = 0
        for i in s:
            if index == 3:
                ans += 1
                break
            elif num[index]==i:
                index += 1
        else:
            if index == 3:
                ans += 1

    print(ans)

    


if __name__ == '__main__':
    main()

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

    ans = 0
    for i in range(0, 1000):
        num = str(i)
        num = '0'*(3-len(num))+num
        index = 0
        for i in s:
            if index == 3:
                ans += 1
                break
            elif num[index]==i:
                index += 1
        else:
            if index == 3:
                ans += 1

    print(ans)

    


if __name__ == '__main__':
    main()

Solution (Python):

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

a = []
for i in range(10):
    a.append(str(i))
    
ans = 0    
s = 0
for i in a:
    for j in a:
        for k in a:
            for l in range(N):
                if S[l] == i and s == 0:
                    s = 1
                elif S[l] == j and s == 1:
                    s = 2
                elif S[l] == k and s == 2:
                    ans += 1
                    break
            s = 0
            
print(ans)

Solution (Python):
from itertools import product

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

cnt = 0
for i, j, k in product(range(10), repeat=3):
    x = S.find(str(i))
    if x == -1:
        continue
    y = S.find(str(j), x + 1)
    if y == -1:
        continue
    z = S.find(str(k), y + 1)
    if z == -1:
        continue
    cnt += 1

print(cnt)

Solution (Python):
N = int(input())
S = list(input())
ans = 0
fl = [False] * 10
sl = [False] * 10
tl = [False] * 10

for i in range(N - 2):
    if not fl[int(S[i])]:
        fl[int(S[i])] = True
        for j in range(i + 1, N - 1):
            if not sl[int(S[j])]:
                sl[int(S[j])] = True
                for k in range(j + 1, N):
                    if not tl[int(S[k])]:
                        tl[int(S[k])] = True
                        ans += 1
                tl = [False] * 10
        sl = [False] * 10

print(ans)

Solution (Python):

import sys

def solve(N: int, S: str):
    answer = 0
    for i in range(0,1000):
        i = str(i).zfill(3)
        index = 0
        for ss in S:
            if ss == i[index]:
                index += 1
                if index >= 3:
                    answer += 1
                    break

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = next(tokens)  
    solve(N, S)

if __name__ == '__main__':
    main()

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

ans = 0
for i in range(10):
    if str(i) in s:
        x = s.index(str(i))
        for j in range(10):
            if str(j) in s[x+1:]:
                y = s[x+1:].index(str(j))
                for k in range(10):
                    if str(k) in s[x+1:][y+1:]:
                        ans += 1

print(ans)

Solution (Python):
n = int(input())
s = input()
s += "_"
ans = 0
for i in range(10):
    if str(i) in s:
        x = s.index(str(i))
        for j in range(10):
            if str(j) in s[x+1:]:
                y = s[x+1:].index(str(j))
                for k in range(10):
                    if str(k) in s[x+1:][y+1:]:
                        ans += 1

print(ans)

Solution (Python):
def main():
    from itertools import accumulate as acc
    N=int(input())
    s=input()
    ind=[[0 for j in range(N)] for i in range(10)]
    first=[-1 for i in range(10)]
    last=[-1 for i in range(10)]


    for i in range(len(s)):
        k=int(s[i])
        if first[k]==-1: first[k]=i
        last[k]=i
        ind[k][i]=1
        
    for i in range(10):
        ind[i]=list(acc(ind[i]))

    ans=0
    for i in range(10):
        for j in range(10):
            f=first[i]
            l=last[j]
            if f!=-1 and f+1<l:
                for k in range(0,10):
                    if ind[k][f]<ind[k][l-1]: ans+=1
                    

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
num = [[] for _ in range(10)]
l = int(input())
s = input()
ans = []
for i in range(l):
    n = int(s[i])
    num[n].append(i)
for i in range(10):
    num[i].sort()
for i in range(10):
    if len(num[i])>0:
        start = num[i][0]
        for j in range(10):
            if len(num[j])>0:
                s=0; e = len(num[j])-1
                nd = -1
                while(s<e):
                    nx = (s+e)//2
                    if num[j][nx]<=start:
                        s= nx+1
                    elif num[j][nx]>start:
                        e = nx
                if num[j][e]>start:
                    nd = num[j][e]
                    for k in range(10):
                        if len(num[k]) > 0:
                            s = 0;
                            e = len(num[k]) - 1
                            while (s < e):
                                nx = (s + e) // 2
                                if num[k][nx] <= nd:
                                    s = nx + 1
                                elif num[k][nx] > nd:
                                    e = nx
                            if num[k][e] > nd:
                                ans.append((i,j,k))
print(len(ans))

Solution (Python):
n = int(input())
s = input()
passwords = []

firsts = []
firsts_seconds = [[]*10 for _ in range(10)]
firsts_seconds_thirds = [[]*10 for _ in range(100)]

for i in range(n-2):
    if len(firsts) == 10:
        break
    first =  s[i]
    if first in firsts:
        continue
    firsts.append(first)
    for j in range(i+1,n-1):
        if len(firsts_seconds[int(first)]) == 10:
            break
        second = s[j]
        first_second = first + second
        if first_second in firsts_seconds[int(first)]:
            continue
        firsts_seconds[int(first)].append(first_second)
        for k in range(j+1, n):
            password = first_second + s[k]
            if password not in firsts_seconds_thirds[int(first_second)]:
                firsts_seconds_thirds[int(first_second)].append(password)
                passwords.append(password)

print(len(passwords))

Solution (Python):
n = int(input())
s = input()
passwords = []

firsts = []
firsts_seconds = [[]*10 for _ in range(10)]
firsts_seconds_thirds = [[]*10 for _ in range(100)]

for i in range(n-2):
    if len(firsts) == 10:
        break
    first =  s[i]
    if first in firsts:
        continue
    firsts.append(first)
    for j in range(i+1,n-1):
        if len(firsts_seconds[int(first)]) == 10:
            break
        second = s[j]
        first_second = first + second
        if first_second in firsts_seconds[int(first)]:
            continue
        firsts_seconds[int(first)].append(first_second)
        for k in range(j+1, n):
            password = first_second + s[k]
            if password not in firsts_seconds_thirds[int(first_second)]:
                firsts_seconds_thirds[int(first_second)].append(password)
                passwords.append(password)

print(len(passwords))

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

ans_count =0

for i in range(10):
    for j in range(10):
        for k in range(10):
            i_pos = s.find(str(i))

            if i_pos < 0:
                continue

            j_pos = s.find(str(j),i_pos+1)

            if j_pos < 0:
                continue

            k_pos = s.find(str(k), j_pos +1)

            if k_pos < 0:
                continue

            ans_count += 1

print(ans_count)

Solution (Python):



n=int(input())
s=list(input())
info=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            info.append(str(i)+str(j)+str(k))
ans=0
kind=0
while kind<=999:
    point=0
    check=info[kind]
    for i in range(n):
        if point==0:  
            if check[0]==s[i]:
                point+=1
                continue
        if point==1:
            if check[1]==s[i]:
                point+=1
                continue
        if point==2:
            if check[2]==s[i]:
                point+=1
                break
    if point==3:
        ans+=1
        
    kind+=1
print(ans)

Solution (Python):
def main():
    N=int(input())
    s=input()
    ind=[[0 for j in range(10)] for i in range(N)]
    first=[-1 for i in range(10)]
    last=[-1 for i in range(10)]

    k=int(s[0])
    first[k]=0
    last[k]=0
    ind[0][k]=1

    for i in range(1,len(s)):
        k=int(s[i])
        if first[k]==-1: first[k]=i
        last[k]=i
        ind[i]=[ind[i-1][j] for j in range(10)]
        ind[i][k]=ind[i-1][k]+1

    ans=0
    for i in range(10):
        for j in range(10):
            f=first[i]
            l=last[j]
            if f!=-1 and f+1<l:
                for k in range(0,10):
                    if ind[f][k]<ind[l-1][k]: ans+=1
                    

    print(ans)

if __name__ == '__main__':
    main()

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

ans = set()
for i in range(10):
  for j in range(10):
    for k in range(10):
      iflg = False
      jflg = False
      for s in S:
        if not iflg and s == i:
          iflg = True
        elif (not jflg) and iflg and s == j:
          jflg = True
          continue
        elif iflg and jflg and s == k:
          ans.add((i,j,k))
          break
print(len(ans))

Solution (Python):

N = int(input())
S = input()
ans = 0
anslst = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            anslst.append(str(i) + str(j) + str(k))

tmp = ans
for i in anslst:
    a, b, c = i
    index1 = S.find(a)
    index2 = S.find(b, index1 + 1)
    index3 = S.find(c, index2 + 1)
    if index1 != -1 and index2 != -1 and index3 != -1:
        ans += 1
print(ans)

Solution (Python):

MOD = 10 ** 9 + 7

import math



def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

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


def main():


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

    count=0
    temp=0
    keta=[0,0,0]
    for i in range(1000):
        temp = 0
        if i <10:
            keta[0]=0
            keta[1]=0
            keta[2]=i
        elif i >=10 and i<100:
            keta[0]=0
            keta[1]=int(str(i)[0])
            keta[2]=int(str(i)[1])
        else:
            keta[0] = int(str(i)[0])
            keta[1] = int(str(i)[1])
            keta[2] = int(str(i)[2])
        for j in range(n):
            if keta[temp]==s[j]:
                 if temp<=1:
                    temp+=1
                 else:
                    count+=1
                    temp=0
                    break




    print(count)






            

if __name__ == "__main__":
    main()

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

a = []
for i in range(10):
    for j in range(10):
        for z in range(10):
            a.append([i,j,z])

s = list(S)
s = [int(i) for i in s]
ans = 0
for n in a:
    flag = 0
    for i,name in enumerate(s):
        if name == n[0]:
            n = n[1:]
            flag += 1
        if flag == 3:
            ans += 1
            break

print(ans)

Solution (Python):
n=int(input())
s=input()
def chk(x):
  x=str(x).zfill(3)
  res=False
  cur=0
  xx=x[0]
  for i in range(n):
    ss=s[i]
    if cur<2 and xx==ss:
      cur+=1
      xx=x[cur]
    elif xx==ss:
      res=True
      break
  return res

ans=0
for i in range(1000):
  if chk(i):
    ans+=1
print(ans)

Solution (Python):
n=int(input())
s=input()
inf=float("inf")
A=[[inf]*10 for _ in range(n+1)]
for i in reversed(range(n)):
  ss=s[i]
  for j in range(10):
    if j==int(ss):
      A[i][j]=i
    else:
      A[i][j]=A[i+1][j]
ans=0
for x in range(1000):
  x=str(x).zfill(3)
  cur=0
  for xx in x:
    xx=int(xx)
    cur=A[cur][xx]+1
    if cur==inf:
      break
  if cur!=inf:
    ans+=1
print(ans)

Solution (Python):
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(10)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)

Solution (Python):
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

cnt = 0
for a in range(10):
    for b in range(10):
        n = 0
        ab = [a,b]
        for i in range(N):
            if int(s[i]) == ab[n]:
                n += 1
            if n == 2:
                for c in range(10):
                    for j in range(i+1,N):
                        if int(s[j]) == c:
                            cnt += 1
                            break
                else:
                    break
print(cnt)

Solution (Python):
N = int(input())
S100 = input()
S100list = list(S100)
X100 = set(S100list)
PIN = 0
for i in X100:
    S10 = S100[S100.find(i)+1:]
    X10 = set(list(S10))
    for j in X10:
        S1 = S10[S10.find(j)+1:]
        X1 = set(list(S1))
        PIN += len(X1)
    
print(PIN)

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

targets = tuple("{:0>3}".format(i) for i in range(1000))
ans = []
for target in targets:
    a, b, c = target
    a_index = S.find(a)
    b_index = S.find(b, a_index + 1)
    c_index = S.find(c, b_index + 1)
    ret = (a_index, b_index, c_index)
    if -1 not in ret:
        
        ans.append(ret)
print(len(ans))

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

ans = 0
for i in range(1000):
    a = '{0:03d}'.format(i)
    if a[0] in S:
        idx1 = S.index(a[0])
        S1 = S[idx1+1:]
        if a[1] in S1:
            idx2 = S1.index(a[1])
            S2 = S1[idx2+1:]
            if a[2] in S2:
                ans += 1

print(ans)

Solution (Python):


def hantei(s, p):
    for c in p:
        i = s.find(c)
        if i < 0:
            return False
        s = "" if i+1 >= len(s) else s[i+1:]
    return True


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

    ps = ["%03d" % i for i in range(1000)]
    seen = set()
    ans = 0
    for p in ps:
        if p not in seen and hantei(s, p):
            ans += 1
            seen.add(p)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

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

ans = 0

for cmb in product(range(10), range(10), range(10)):
    idx = -1
    for i in cmb:
        idx = s.find(str(i), idx + 1)
        if idx < 0:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
def main():
    N=int(input())
    s=input()
    first=[-1 for i in range(10)]
    last=[-1 for i in range(10)]
    for i in range(len(s)):
        k=int(s[i])
        if first[k]==-1: first[k]=i
        last[k]=i

    ans=0
    for i in range(10):
        for j in range(10):
            f=first[i]
            l=last[j]
            if f!=-1 and f+1<l:
                for k in range(0,10):
                    if s.find(str(k),f+1,l)!=-1: ans+=1
                    

    print(ans)
     
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
S = list(input())
lis = [ str(i) for i in range(1000)]
ans = 0
for l in lis:
    if int(l) == 0:
        l0,l1,l2 = 0,0,0
    if int(l) < 10:
        l0 = 0
        l1 = 0
        l2 = l[0]
    elif int(l) < 100:
        l0 = 0
        l1 = l[0]
        l2 = l[1]
    else:
        l0 = l[0]
        l1 = l[1]
        l2 = l[2]
    try:
        id0 = S.index(str(l0))
        id1 = S[id0+1:].index(str(l1))
        id2 = S[id0+id1+2:].index(str(l2))
    except:
        continue
    ans += 1
print(ans)

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

ans = []
a1 = []
for i in range(N-2):
    if S[i] in a1:continue
    a1.append(S[i])
    a2 = []
    for j in range(i+1,N-1):
        if S[j] in a2:continue
        a2.append(S[j])
        a3 = []
        for k in range(j+1,N):
            if S[k] in a3:continue
            a3.append(S[k])
            ans.append(S[i]+S[j]+S[k])
ans_set = set(ans)
print(len(ans_set))

Solution (Python):
N = int(input())
S = list(map(int,list(input())))
def judge(x,l):
  ret = False
  num = 0
  for a,n in enumerate(l):
    if n==x:
      ret = True
      num = a
      break
      
  return ret,num

ans = 0
for i in range(10):
  tf1,n1 = judge(i,S)
  if tf1:
    for j in range(10):
      tf2,n2 = judge(j,S[n1+1:])
      if tf2:
        for k in range(10):
          tf3,n3=judge(k,S[n1+n2+2:])
          if tf3:
            ans+=1

print(ans)

Solution (Python):
import math

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

arr = list(str(S))
cnt = 0

for i in range(1000):
  a = math.floor(i/100)
  b = math.floor((i-a*100)/10)
  c = i-a*100-b*10
  
  if str(a) in arr:
    an = arr.index(str(a))
    del arr[:an+1]
    
    if str(b) in arr:
      bn = arr.index(str(b))
      del arr[:bn+1]
      
      if str(c) in arr:
        cnt = cnt + 1
        
  arr = list(str(S))
      
print(cnt)

Solution (Python):
def main():
    N = int(input())
    S = input()
    ans = 0
    for v in range(1000):
        cur = 0
        v_s = str(v)
        if len(v_s) == 1:
            v_s = "00" + v_s
        elif len(v_s) == 2:
            v_s = "0" + v_s
        for s in S:
            if v_s[cur] == s:
                cur += 1
            if 2 < cur:
                ans += 1
                break
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

MOD = 10 ** 9 + 7

import math
 

 
def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
 
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
 
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
 
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
 
    return result
 
def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta
 
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
 
 
def main():


    n=int(input())
    s=list(map(str,input()))
    a=[]
    for i in range(1000):
        if i<10:
            a.append("00"+str(i))
        elif i>=10 and i<100:
            a.append("0"+str(i))
        else:
            a.append(str(i))


    count=0
    for i in range(1000):
        keta1=a[i][0]
        keta2=a[i][1]
        keta3=a[i][2]
   
        x=my_index(s,keta1,n+1)
        if x>=n-1:
            continue
 
        y = my_index(s[x+1:], keta2,n+1)
        if y>=len(s[x+1:])-1:
            continue
        z = my_index(s[x+y+2:], keta3,n+1)
        if z>len(s[x+y+2:]):
            continue
        if x!=n+1 and y!=n+1 and z!=n+1:
        
            count+=1
    print(count)
 

 
 
 
 
            
 
if __name__ == "__main__":
    main()