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):


import sys
import math
import time

import collections
from collections import deque
import queue
import copy






N = int(input())
S = str(input())
ii = 0
jj = 0
kk = 0
ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      if(str(i) in S):
        ii = S.index(str(i))
        SS = S[ii+1:]
        if(str(j) in SS):
          jj = SS.index(str(j))
          SS = SS[jj+1:]
          if(str(k) in SS):
            
            ans+=1


print(ans)

Solution (Python):
import sys

from collections import defaultdict

def main():
    N = int(input())
    s = input()
    d1,d2,d3 = defaultdict(int),defaultdict(int),defaultdict(int) 
    
    for moji in s:
        for m2 in d2:
            d3[m2+moji] += 1
        for m1 in d1:
            d2[m1+moji] += 1
        d1[moji] += 1
    
    print(len(d3))
    
if __name__ == "__main__":
    main()

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

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

cnt = 0
for i in range(1000):
    tmp = S
    t = str(i).zfill(3)

    pos_1 = ind(tmp,t[0])
    if pos_1>=0:
        tmp = tmp[pos_1+1:]
    elif pos_1 == -1:
        continue

    pos_2 = ind(tmp,t[1])
    if pos_2>=0:
        tmp = tmp[pos_2+1:]
    elif pos_2 == -1:
        continue

    pos_3 = ind(tmp,t[2])
    if pos_3>=0:
        tmp = tmp[pos_3+1:]
    elif pos_3 == -1:
        continue
    cnt += 1
print(cnt)

Solution (Python):
from collections import defaultdict
n = int(input())
S = input()

d1 = defaultdict(int)
d2 = defaultdict(int)
d3 = defaultdict(int)

for s in S:
    for x in d2:
        d3[x+s]+=1
    for y in d1:
        d2[y+s]+=1
    d1[s]+=1

print(len(d3))

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

sum = 0
box = []
for i in range(n-2):
    if s[i] not in box:
        box.append(s[i])
    elif len(box) == 10:
        break
    else:
        continue
    box_1 = []
    for j in range(i+1, n-1):
        if s[j] not in box_1:
            box_1.append(s[j])
        elif len(box_1) == 10:
            break
        else:
            continue
        box_2 = []
        for k in range(j+1, n):
            if s[k] not in box_2:
                box_2.append(s[k])
            elif len(box_2) == 10:
                break
            else:
                continue
        sum += len(box_2)

print(sum)

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


ans_L = []
length = len(s)
count = 0

for i in range(1000):
    i = list(str(i).zfill(3))
    idx = 0
    cnt = 0
    for j in range(3):
        for k in range(idx,length):
            if str(i[j]) == str(s[k]):
                idx = k+1
                cnt += 1
                break
        if cnt ==0:
            break

    
    
    if cnt == 3:
        count +=1

print(count)

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

passwords = []
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            password = str(i) + str(j) + str(k)
            passwords.append(password)

char_hash = {}
for i, char in enumerate(S):
    if char in char_hash.keys():
        char_hash[char].append(i)
    else:
        char_hash[char] = [i]



count = 0
for password in passwords:
    exist_keys = char_hash.keys()
    
    if not(password[0] in exist_keys):
        continue
    if not(password[1] in exist_keys):
        continue
    if not(password[2] in exist_keys):
        continue
    first_index = min(char_hash[password[0]])
    second_indexes = char_hash[password[1]]
    second_index = -1
    for index in second_indexes:
        if index <= first_index:
            continue
        else:
            second_index = index
            break
    third_indexes = char_hash[password[2]]
    third_index = -1
    for index in third_indexes:
        if index <= second_index:
            continue
        else:
            third_index = index
            break
    
    if first_index < second_index and second_index < third_index:
        count += 1

print(count)

Solution (Python):

def main():
    n = int(input())
    s = input()
    cnt = 0
    for i in range(10):
        ind_i = s.find(str(i))  
        if ind_i == -1:
            continue
        for j in range(10):
            ind_j = s.find(str(j), ind_i+1)
            if ind_j == -1:
                continue
            for k in range(10):
                ind_k = s.find(str(k), ind_j+1)
                if ind_k == -1:
                    continue
                cnt += 1
    print(cnt)
main()

Solution (Python):
'''
https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
'''

def main():
    n = int(input())
    s = input()
    ans = 0
    for i in range(1000):
        pas = format(i, '03d')
        k, cnt = 0, 0
        for j in pas:
            if j in s[k:]:
                cnt += 1
                k += s[k:].index(j) + 1
        if cnt == 3:
            ans += 1
    print(ans)


    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N=int(input())
    S=input()
    D=[0]*(N+1)
    s=set()
    for i in range(N-1,-1,-1):
        s.add(S[i])
        D[i]=len(s)
    ans=0
    for i in range(10):
        ni=S.find(str(i))
        if ni<0: continue
        for j in range(10):
            nj=S.find(str(j),ni+1)
            if nj>=0:
                ans+=D[nj+1]
    print(ans)

if __name__ == "__main__":
    main()

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):
            check_i = (s.find(str(i)))
            check_j = (s.find(str(j),check_i+1))
            check_k = (s.find(str(k),check_j+1))
            if(check_i >= 0 and check_j >= 0 and check_k >= 0):
                ans += 1
print(ans)

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

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

ans = 0
for i in range(1000):
    i = str(i).zfill(3)

    one, two, three = False, False, False
    for j in range(n):
        if one:
            if two:
                if three:
                    break
                else:
                    if s[j] == i[2]:
                        three = True
            else:
                if s[j] == i[1]:
                    two = True
        else:
            if s[j] == i[0]:
                one = True
    if three:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
brute=[str(i)[1:] for i in range(1000,2000)]
for i in brute:
  flag=0
  for j in s:
    if j==i[0] and flag==0:
      flag+=1
      continue
    if flag==1 and j==i[1]:
      flag+=1
      continue
    if flag==2 and j==i[2]:
      ans+=1
      break
print(ans)

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

dp1 = [[0 for i in range(10)] for _ in range(n + 1)]
dp2 = [[0 for i in range(100)] for _ in range(n + 1)]
dp3 = [[0 for i in range(1000)] for _ in range(n + 1)]

for i in range(n):
    dp1[i + 1][int(s[i])] = 1
    for j in range(10):
        if dp1[i][j]:
            dp2[i + 1][j * 10 + int(s[i])] = 1
            dp1[i + 1][j] = 1
    for j in range(100):
        if dp2[i][j]:
            dp3[i + 1][j * 10 + int(s[i])] = 1
            dp2[i + 1][j] = 1
    for j in range(1000):
        if dp3[i][j]:
            dp3[i + 1][j] = 1

print(sum(dp3[n]))

Solution (Python):
import bisect

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

index_map = {}
for i in range(10):
    index_map[str(i)] = []

for i, c in enumerate(S):
    index_map[c].append(i)

count = 0
for i in range(1000):
    K = "%03d" % i
    index = 0
    for c in K:
        next_index = bisect.bisect_left(index_map[c], index)
        if next_index == len(index_map[c]):
            index = -1
            break
        else:
            index = index_map[c][next_index] + 1
    if index != -1:
        count += 1
print(count)

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

ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            x= S[:-2].find(str(i))
            if x!=-1:
                y=S[x+1:-1].find(str(j))
                if y!=-1:
                    z=S[x+1+y+1:].find(str(k))
                    if z!=-1:
                        ans+=1

print(ans)

Solution (Python):
n = int(input())
s = input()
d1 = [0] * 10
d2 = [0] * 100
d3 = [0] * 1000
for i in s:
    seq = int(i)
    for j in range(100):
        if d2[j] == 1:
            d3[j * 10 + seq] = 1
    for k in range(10):
        if d1[k] == 1:
            d2[k * 10 + seq] = 1
    d1[seq] = 1
print(sum(d3))

Solution (Python):
n=int(input())
x=input()
ans=0
for i in range(0,10):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,100):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)

Solution (Python):
n=int(input())
S = input()
 
ans = 0
for i in range(1000):
    a, b, c = map(str, list(str(i).zfill(3)))
    mode = 'a'
    for j in S:
        if mode == 'a' and j == a:
            mode = 'b'
        elif mode == 'b' and j == b:
            mode = 'c'
        elif mode == 'c' and j == c:
            ans += 1
            break
print(ans)

Solution (Python):
import sys

N = int(sys.stdin.readline())
S = sys.stdin.readline()

ans = 0
for i in range(1000):
    password = str(i).zfill(3)
    p_i = 0
    s_i = 0
    while s_i < len(S) and p_i < 3:
        
        if S[s_i] == password[p_i]:
            p_i += 1
        s_i += 1
    if p_i == 3:
        ans += 1
print(ans)

Solution (Python):
N = int(input())
S = input().strip()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag = 0
            for n in range(N):
                if flag==0 and S[n]==str(i):
                    flag = 1
                elif flag==1 and S[n]==str(j):
                    flag = 2
                elif flag==2 and S[n]==str(k):
                    flag = 3
                    break
            if flag==3:
                cnt += 1
print(cnt)

Solution (Python):
import bisect

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

X = []
for i in range(10):
    X.append([])
for i in range(N):
    X[int(S[i])].append(i)

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if len(X[i]) > 0:
                ind = bisect.bisect_left(X[j],X[i][0] + 1)
                if ind < len(X[j]):
                    ind = X[j][ind] + 1
                    ind = bisect.bisect_left(X[k],ind)
                    if ind < len(X[k]):
                        ans += 1
print(ans)

Solution (Python):
import bisect

n=int(input())
s=input()
fpos=[-1]*10
npos=[[-1] for _ in range(10)]
for i in range(n):
  if fpos[int(s[i])]==-1:
    fpos[int(s[i])]=i
  npos[int(s[i])].append(i)
lpos=[len(npos[i]) for i in range(10)]
ans=0
for i in range(10):
  if fpos[i]==-1:
    continue
  for j in range(10):
    spos=bisect.bisect_right(npos[j],fpos[i])
    if spos>=lpos[j]:
      continue
    spos=npos[j][spos]
    for k in range(10):
      tpos=bisect.bisect_right(npos[k],spos)
      if tpos>=lpos[k]:
        continue
      ans+=1
print(ans)

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

ans = 0
for num in range(1000):
    num_s = str(num).zfill(3)
    
    s_index_0 = s.find(num_s[0])
    if s_index_0 == -1 :
        continue
    s_index_1 = s.find(num_s[1],s_index_0+1)
    if s_index_1 == -1 :
        continue

    s_index_2 = s.find(num_s[2],s_index_1+1)
    if s_index_2 == -1:
        continue

    ans +=1 

        
    
print(ans)

Solution (Python):
def ABC106_B():
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)
        
        return divisors
    N = I()
    ans = 0
    for i in range((N+1)//2):
        cur = i*2+1
        if len(make_divisors(cur))==8:
            ans += 1
    print(ans)
    return

def ABC122_B():
    S = SI()
    ans = 0
    cur = 0
    d = {"A","C","G","T"}
    for s in S:
        if s in d:
            cur += 1
        else:
            ans = max(ans,cur)
            cur = 0
    ans = max(ans,cur)
    print(ans)
    return

def paken2019_C():
    N, M = LI()
    A = [LI()for _ in range(N)]
    T = [i for i in range(M)]
    ans = 0
    for t1,t2 in itertools.permutations(T,2):
        cur = 0
        for i in range(N):
            cur += max(A[i][t1],A[i][t2])
        ans = max(ans,cur)
    print(ans)
    return

def ABC95_C():
    A, B, C, X, Y = LI()
    if A+B<=C*2:
        ans = A*X+B*Y
    else:
        if X>Y:
            ans = Y*C*2 + min(A,C*2)*(X-Y)
        else:
            ans = X*C*2 + min(B,C*2)*(Y-X)
    print(ans)
    return

def SMTB_D():
    def flag(n,s):
        for l in range(n,N):
            if S[l]==str(s):
                return l
        return N
    N = I()
    S = SI()
    ans = 0
    for i in range(10):
        L1 = flag(0,i)
        for j in range(10):
            L2 = flag(L1+1,j)
            for k in range(10):
                L3 = flag(L2+1,k)
                if L3<N:
                    ans += 1
                    
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    SMTB_D()

"""

"""

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

a = 0
ii = [0]*10
for i in range(n-2):
  si = int(s[i])
  if sum(ii) == 10:
    break
  elif ii[si] == 1:
    continue
  else:
    ii[si] = 1
  jj = [0]*10
  for j in range(i+1,n-1):
    sj = int(s[j])
    if sum(jj) == 10:
      break
    elif jj[sj] == 1:
      continue
    else:
      jj[sj] = 1
    kk = [0]*10
    for k in range(j+1,n):
      sk = int(s[k])
      if sum(kk) == 10:
        break
      else:
        kk[sk] = 1
    a += sum(kk)
print(a)

Solution (Python):
N = int(input())
S = input()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x = S.find(str(i))
            if x >=0 and x < len(S) - 2:
                y = S[x+1:].find(str(j))
                if y >= 0 and x+y < len(S) -1:
                    z = S[x+y+2:].find(str(k))
                    if z >= 0:
                        cnt += 1
print (cnt)

Solution (Python):
import itertools

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

    ans = 0
    output_list = []

    for i in range(1000):
        if len(str(i)) == 1:
            a = 0
            b = 0
            c = i
        elif len(str(i)) == 2:
            a = 0
            b = i // 10
            c = i - b * 10
        else:
            a = i // 100
            b = (i - a * 100) // 10
            c = i - a * 100 - b * 10
        tmp = str(a) + str(b) + str(c)
        output_list.append(tmp)
    
    for i in range(1000):
        a = output_list[i][0]
        b = output_list[i][1]
        c = output_list[i][2]
        first_flag = False
        second_flag = False
        for j in range(n):
            if not first_flag and s[j] == a:
                first_flag = True
                continue
            if first_flag and not second_flag and s[j] == b:
                second_flag = True
                continue
            if first_flag and second_flag and s[j] == c:
                ans += 1
                break

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left
n = int(input())
ss = input()
ans = 0

d = {str(i):[] for i in range(10)}
for i,c in enumerate(ss):
    d[c].append(i)

for i in range(1000):
    a,b,c = str(i).zfill(3)
    if d[a] == [] or d[b] == [] or d[c] == []:
        continue
    x,z = d[a][0], d[c][-1]
    y = bisect_left(d[b], x+1)
    if y >= len(d[b]):
        continue
    tmp = [x, d[b][y], z]
    if tmp[0] < tmp[1] and tmp[1] < tmp[2]:
        ans += 1

print(ans)

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

ans = 0

for i in range(1000):
    p = str(i).zfill(3)

    s_index_100 = s.find(p[2])
    if s_index_100 == -1:
        continue

    s_index_10 = s.find(p[1], s_index_100+1)
    if s_index_10 == -1:
        continue

    s_index_1 = s.find(p[0], s_index_10+1)
    if s_index_1 == -1:
        continue
    ans += 1

print(ans)

Solution (Python):
def ok(target, S):
    for t in target:
        if t in S:
            S = S[S.index(t)+1:]
        else:
            return False
    return True


N = int(input())
S = input()
ans = 0

for i in range(0, 999+1):
    target = str(i).zfill(3)
    ans += ok(target, S)

print(ans)

Solution (Python):
from itertools import product
from string import digits

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

ret = 0
for perm in product(digits, repeat=3):
    i = 0
    for c in s:
        if c == perm[i]:
            i += 1
            if i == 3:
                break
    if i == 3:
        ret += 1

print(ret)

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

def can_made(string, num):
    flag = False
    start_ind = string.find(num[0])
    if start_ind >= 0:
        second_str = string[start_ind+1::]
        second_ind = second_str.find(num[1])
        if second_ind >= 0:
            third_str = second_str[second_ind+1::]
            if third_str.find(num[2]) >= 0:
                flag = True
    
    return flag


for i in range(1000):
    num = str(i).zfill(3)
    if can_made(s, num): ans += 1
print(ans)

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

import itertools

ans = 0
for x, y, z in itertools.product(range(10), repeat=3):
    pin = str(x) + str(y) + str(z)
    cur = 0
    for i in range(n):
        if s[i] == pin[cur]:
            cur += 1
            if cur == 3:
                break
    if cur == 3:
        ans += 1
    
print(ans)

Solution (Python):
n=int(input())
s=input()
l=[[] for i in range(10)]
for i in range(n):
    j=int(s[i])
    l[j].append(i)
ans=0
for i in range(1000):
    i=str(i).rjust(3,"0")
    a,b,c=[int(j) for j in i]
    if l[a] and l[b] and l[c]:
        p,q=l[a][0],l[c][-1]
        if p<q:
            for j in l[b]:
                if p<j<q:
                    ans+=1
                    break
print(ans)

Solution (Python):
from collections import defaultdict
import bisect
n = int(input())
d = defaultdict(list)
for i,j in enumerate(input()):
  j = int(j)
  d[j].append(i)
c = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      if d[i] != [] and d[j] != [] and d[k] != []:
        b = bisect.bisect_right(d[j],d[i][0])
        if b != len(d[j]) and d[j][b] < d[k][-1]:
          c += 1
print(c)

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

ans = 0
for i in range(10):
    n = s.find(str(i))
    if n == -1:
        continue
    for j in range(10):
        m = s.find(str(j), n+1)
        if m == -1:
            continue
        for k in range(10):
            if str(k) in s[m+1:]:
                ans += 1
print(ans)

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

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

print(cnt)

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

ind_table = [[] for _ in range(10)]
for i in range(N):
	ind_table[int(S[i])].append(i)

ind_table = np.array(ind_table)


num_list = ['1','2','3','4','5','6','7','8','9','0']

ans = 0
for nums in itertools.product(num_list,num_list,num_list):
	tmp = 0
	cond = 1
	for i in range(3):
		num = int(nums[i])
		L = len(ind_table[num])
		if L == 0:
			cond = 0
			break

		ind = np.searchsorted(ind_table[num], tmp)
		if ind == L:
			cond = 0
			break
		else:
			tmp = ind_table[num][ind] + 1

	if cond:
		ans += 1


print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def divisor(n):
        i = 1
        table = []
        while i * i <= n:
            if n % i == 0:
                table.append(i)
                table.append(n // i)
            i += 1
        table = list(set(table))
        return table


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)

    def list(self):
        return self.__q

    def length(self):
        return len(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e30)


def main():
    
    N = Scanner.int()
    S = Scanner.string()
    ans = 0
    for i in range(1000):
        s = str(i).rjust(3, "0")
        p = 0
        for j in range(N):
            if S[j] == s[p]:
                p += 1
                if p == 3:
                    break
        if p == 3:
            ans += 1
    print(ans)
    return


if __name__ == "__main__":
    main()

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

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

done = []
cnt = 0
for i in range(1000):
    tmp = str(i).rjust(3, '0')
    n1,n2,n3 = int(tmp[0]), int(tmp[1]), int(tmp[2])
    mi = -1
    mx = -1
    if len(lst[n1])!=0:
        mi = lst[n1][0]
    if len(lst[n3])!=0:
        mx = lst[n3][-1]
    
    if mi>=0 and mx>=0:
        for y in lst[n2]:
            if mi<y<mx:
                done.append(tmp)
    else:
        continue
print(len(set(done)))

Solution (Python):


def main():
    N = int(input())
    S = tuple(map(int,input()))

    ans = 0

    
    for Rnum in range(1000):
        R = list(map(int,str(Rnum).zfill(3)))

        for s in reversed(S):
            if s == R[-1]:
                R.pop()
            if not R:
                ans += 1
                break

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):


def main():
    N = int(input())
    S = tuple(map(int,input()))

    ans = 0

    
    for Rnum in range(1000):
        R = list(map(int,str(Rnum).zfill(3)))

        for s in S:
            if s == R[-1]:
                R.pop()
            if not R:
                ans += 1
                break

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):



N = int(input())
S = input()
"""
SからN-3個取り除くのは制限的にしんどい。nCr(40000,3)とかになるので
3桁の数字を作ればいいので、000~999が作れるか試す。
"""
ans = 0
for i in range(0,1000):
    pin = str(i).zfill(3)

    idx = 0
    for s in S:
        if pin[idx] == s:
            idx += 1

        if idx == 3:
            ans += 1
            break

print(ans)

Solution (Python):
n=int(input())
s=input()
t=0
for i in range(10):
  for a in range(n):
    if s[a]==str(i):
      for j in range(10):
        for b in range(a+1,n)[::-1]:
          if s[b]==str(j):
            t+=len(set(list(s[a+1:b])))
            break
      break
print(t)

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

s=input() 

ans = 0

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

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

lc = [0]
for c in S:
    lc.append(lc[-1] | (1<<int(c)))
rc = [0]
for c in S[::-1]:
    rc.append(rc[-1] | (1<<int(c)))
rc.reverse()

mem = [set() for _ in range(10)]
for c,l,r in zip(S,lc,rc[1:]):
    c = int(c)
    for i in range(10):
        if l&(1<<i)==0: continue
        for j in range(10):
            if r&(1<<j)==0: continue
            mem[c].add(10*i+j)
print(sum(len(m) for m in mem))

Solution (Python):
n=int(input())
s=input()
S=[]
for i in range(n):
  S.append(int(s[i]))
ans=0
A=[0,1,2,3,4,5,6,7,8,9]
for i in range(n-2):
  if len(A)==0:
    break
  if S[i] not in A:
    continue
  B=[0,1,2,3,4,5,6,7,8,9]
  for j in range(i+1,n-1):
    if len(B)==0:
      break
    if S[j] not in B:
      continue
    C=[0,1,2,3,4,5,6,7,8,9]
    for k in range(j+1,n):
      if len(C)==0:
        break
      if S[k] not in C:
        continue
      ans=ans+1
      C.remove(S[k])
    B.remove(S[j])
  A.remove(S[i])
print(ans)

Solution (Python):

import sys


def solve(N: int, S: str):

    result = 0
    for i in range(0, 9 + 1):
        first = S.find(str(i))
        if first == -1:
            
            continue

        for j in range(0, 9 + 1):
            second = S.find(str(j), first + 1)
            if second == -1:
                
                continue

            for k in range(0, 9 + 1):
                if S.find(str(k), second + 1) != -1:
                    result += 1

    print(result)
    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()

l = [30010] * 11
r = [-1] * 11
for i in range(n):
    c = int(s[i])
    r[c] = max(r[c], i)
    l[c] = min(l[c], i)
st = set([])
for i in range(n):
    c = int(s[i])
    for j in range(10):
        for k in range(10):
            if l[j] < i < r[k]:
                number = chr(j) + s[i] + chr(k)
                st.add(number)
print(len(st))

Solution (Python):

import sys

def solve(N: int, S: str):
    answer = 0
    for i in range(1000):
        target = str(i).zfill(3)
        index = 0
        for i in range(N):
            if S[i] == target[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())
Ss = list(input())
S = [int(i) for i in Ss]

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            val = [i,j,k]
            idx = 0
            for s in S:
                if s==val[idx]:idx+=1
                if idx>2:
                    ans += 1
                    break
print(ans)

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

def solve(n, s):
    
    cnt = 0
    for v in range(0, 1000):
        v = str(v)
        v = "0" * (3 - len(v)) + v
        idx = 0
        for i in range(len(s)):
            if s[i] == v[idx]:
                idx += 1
            if idx == 3:
                cnt += 1
                break
    print(cnt)
solve(n, s)

Solution (Python):
n = int(input())
s = input()
s1 = [False for i in range(10)]
s2 = [False for i in range(100)]
s3 = [False for i in range(1000)]


for c in s:
    a = int(c)

    for i in range(100):
        if s2[i]:
            s3[10 * i + a] = True
    for i in range(10):
        if s1[i]:
            s2[10 * i + a] = True
    s1[a] = True

print(sum(s3))

Solution (Python):
N = int(input())
S = input()
he, ta = {}, {}

for i in range(N):
  if not S[i] in he:
    he[S[i]] = i
  if len(he) >= 10:
    break

for i in range(N-1,-1,-1):
  if not S[i] in ta:
    ta[S[i]] = i
  if len(ta) >= 10:
    break


ans = 0
for hek, hep in he.items():
  for tak, tap in ta.items():
    if hep>=tap:
      continue
    wk = set()
    for i in range(hep+1, tap):
      wk.add(S[i])
      if len(wk) >= 10:
        break
    ans += len(wk)
    
print(ans)

Solution (Python):
def search(a):
    x=0
    a="".join(["0"*(3-len(a)),a])
    for i in range(n):
        if a[x]==s[i]:
            x+=1
            if x==3:
                return True
    return False
n=int(input())
s=input()
ans=0
k=[False]*1000
for i in range(1000):
    k[i]=search(str(i))
for i in k:
    if i:
        ans+=1
print(ans)