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
def input():
    return sys.stdin.readline()[:-1]

n = int(input())
s = input()
pass_list = list(map(lambda x: str(x).zfill(3), range(1000)))
res = 0

for p in pass_list:
    
    ptr = 0
    one = False
    two = False
    three = False
    
    for i in range(len(s)):
        if(s[i] == p[0]):
            ptr = i
            one = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[1]):
            ptr = i
            two = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[2]):
            ptr = i
            three = True
            break
    
    if(one and two and three): res += 1

print(res)

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

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    cand = list(''.join(p) for p in product(digits, repeat=3))

    res = set()
    for c in cand:
        i = s.find(c[0])
        if i == -1:
            continue
        j = s.find(c[1], i+1)
        if j == -1:
            continue
        k = s.find(c[2], j+1)
        if k == -1:
            continue
        
        res.add(c)
        
    ans = len(res)
    print(ans)

if __name__ == '__main__':
    main()

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

dp = [[0]*10 for _ in range(10)]

count = [0]*10

result = []

for i in range(n-2):
    if count[int(s[i])]==0:
        for j in range(i+1,n-1):
            if dp[int(s[i])][int(s[j])]==0:
                tem = "".join(set(s[j+1:]))
                for k in range(len(tem)):
                    result.append(s[i]+s[j]+tem[k])
                dp[int(s[i])][int(s[j])]=1
        count[int(s[i])]=1

ans = set(result)
print(len(ans))

Solution (Python):
n = int(input())
s = str(input())
c1 = [False for _ in range(10)]
c2 = [0 for _ in range(1000)]
count = 0
for i in range(n-2):
  si = int(s[i])
  if c1[si] != True:
    c1[si] = True
    c3 = [False for _ in range(10)]
    for j in range(i+1,n-1):
      sj = int(s[j])
      if c3[sj] != True:
        c3[sj] = True
        c4 = [False for _ in range(10)]
        for k in range(j+1,n):
          sk = int(s[k])
          if c4[sk] != True:
            c4[sk] = True
            count += 1
print(count)

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


for a in range (10):    
    for b in range (10):
        for c in range (10):
            x=S.find(str(a))
            if x != -1 and x<N-2:
                
                y=S.find(str(b),x+1)
                if y!= -1 and y<N-1:
                    z=S.find(str(c),y+1)
                    if z!= -1:ans=ans+1

print(ans)

Solution (Python):
import sys
from itertools import combinations, product
from string import digits
from collections import Counter

def main():
    n, s = sys.stdin.read().split()
    n = int(n)
    
    
    
    
    
    
    
    
    
    
    


    
    cand = list(''.join(p) for p in product(digits, repeat=3))
    
    
    
    
    
    

    res = set()
    for c in cand:
        i = s.find(c[0])
        if i == -1:
            continue
        j = s.find(c[1], i+1)
        if j == -1:
            continue
        k = s.find(c[2], j+1)
        if k == -1:
            continue
        
        res.add(c)
        
    ans = len(res)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect

def get_indexes(num):
  idx = -1
  idxs = []
  while idx != N-1:
    tmp_idx = S[idx+1:].find(str(num))
    if tmp_idx == -1:
      return idxs
    else:
      idx += tmp_idx+1
      idxs.append(idx)
  return idxs

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

ans = 0
S_idxs = []
for i in range(10):
  S_idxs.append(get_indexes(i))

for i in range(10):
  if S_idxs[i] == []:continue
  ii = min(S_idxs[i])
  for j in range(10):
    if S_idxs[j] == []:continue
    jj = max(S_idxs[j])
    for k in range(10):
      for kk in S_idxs[k]:
        if ii<kk and kk<jj:
          ans += 1
          break
          
print(ans)

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

L0=[]
L1=[]
ans=[]

for i in range(N-2):
    if S[i] in L0:
        continue
    else:
        L0.append(S[i])
    for j in range(i+1,N-1):
        temp=S[i]+S[j]
        if temp in L1:
            continue
        else:
            L1.append(temp)
        for k in range(j+1,N):
            ans.append(temp+S[k])


print(len(set(ans)))

Solution (Python):
import collections as col
n = int(input())
s = list(input())
passwd = set()
pre = col.Counter({'0':0,'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,
                                '7':0,'8':0,'9':0})
post = col.Counter(s[1:])
for i in range(1,n-1):
    pre[s[i-1]] += 1
    post[s[i]] = max(0, post[s[i]]-1) 
    for c0 in pre:
        for c1 in post:
            if pre[c0] != 0 and post[c1] != 0:
                passwd.add(c0+s[i]+c1)
print(len(passwd))

Solution (Python):
input()
ns = [n for n in input()]
 
scores = 0
first = []
second = []
third = []
third_nums = None
 
for i in range(len(ns) - 2):
  if ns[i] in first:
    continue
  else:
    first.append(ns[i])
  for j in range(i+1, len(ns) - 1):
    if ''.join([ns[i], ns[j]]) in second:
      continue
    else:
      second.append(''.join([ns[i], ns[j]]))
      third_nums = set(ns[j+1:])
      scores += len(third_nums)
      
print(scores)

Solution (Python):
def main():
    n = int(input())
    s = input()
    ls_first = [-1 for _ in range(10)]
    ls_last = [-1 for _ in range(10)]


    for i,now in enumerate(s):
        ls_last[int(now)] = i
        if ls_first[int(now)] == -1:
            ls_first[int(now)] = i

    ans = 0
    for i in range(10):
        for j in range(10):
            if ls_first[i]==-1 or ls_last[j]==-1:
                pass
            else:
                now = set([])
                for k in range(ls_first[i]+1,ls_last[j]):
                    now.add(int(s[k]))
                ans += len(now)
    print(ans)    


if __name__ == "__main__":
    main()

Solution (Python):
import bisect

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

C = {0:[],1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[]}
for i in range(N):
  C[int(S[i])].append(i)

ans = 0
for i in range(1000):
  a = i//100
  if len(C[a]) == 0:
    continue
  amin = C[a][0]
  b = (i//10)%10
  if len(C[b]) == 0:
    continue
  bi = bisect.bisect_right(C[b], amin)
  if bi == len(C[b]):
    continue
  bmin = C[b][bi]
  c = i%10
  if len(C[c]) == 0:
    continue
  ci = bisect.bisect_right(C[c], bmin)
  if ci < len(C[c]):
    
    ans += 1
print(ans)

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

ans = 0
for i in range(1000):
    if i <= 9:
        if S.count("0") >= 2:
            first = S.index("0")
            SS = S[first+1:]
            second = SS.index("0")
            SSS = SS[second+1:]
            tmp = str(i)
            if SSS.count(tmp) == 0:
                continue
            ans += 1
            
        else:
            continue
    elif i <= 99:
        if S.count("0") >= 1:
            first = S.index("0")
            SS = S[first+1:]
            tmp = str(i)
            if SS.count(tmp[0]) == 0:
                continue
            second = SS.index(tmp[0])
            SSS = SS[second+1:]
            if SSS.count(tmp[1]) == 0:
                continue
            ans += 1
            
        else:
    
            continue
    else:
        tmp = str(i)
        
        if S.count(tmp[0]) == 0:
            continue
        first = S.index(tmp[0])
        SS = S[first+1:]
        if SS.count(tmp[1]) == 0:
            continue
        second = SS.index(tmp[1])
        SSS = SS[second+1:]
        if SSS.count(tmp[2]) == 0:
            continue
        
        ans += 1

print(ans)

Solution (Python):
def main():
	s = set()
	ss = set()
	sss = set()
	n=int(input())
	ins = input()
	for i in range(n):
		for t in ss:
			sss.add(t+ins[i])
		for t in s:
			ss.add(t+ins[i])
		s.add(ins[i])
	print(len(sss))

main()

Solution (Python):
def main():
    n = int(input())
    s = list(input())
    sset = set(s)
    d = {}
    for i in sset:
        d[i] = []
    for i in range(n):
        d[s[i]].append(i)
    dk = d.keys()
    ans = 0
    for i in dk:
        for j in dk:
            for k in dk:
                a = d[i][0]
                f = False
                b = ""
                if d[j][-1] > a:
                    for x in d[j]:
                        if x > a:
                            f = True
                            b = x
                            break
                if f:
                    if d[k][-1] > b:
                        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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

cnt = 0
S1 = list(set(S[:-2]))
for s1 in S1:
    i1 = S.index(s1)
    SS = S[i1+1:-1:]
    S2 = list(set(SS))
    for s2 in S2:
        i2 = S[i1+1:].index(s2) + i1+1
        SSS = S[i2+1::]
        S3 = set(SSS)
        cnt += len(S3)

print(cnt)

Solution (Python):
import sys
input = sys.stdin.readline
lists = ['{0:03d}'.format(i) for i in range(1000)]
import re
def check(target, a):
    ans = re.search(a, target)
    if ans == None:
        return None
    else:
        return target[ans.start()+1:]

def print_ans(N, S):
    """Test Case
    >>> print_ans(4, "0224")
    3
    >>> print_ans(6, "123123")
    17
    >>> print_ans(19, "3141592653589793238")
    329
    """
    
    
    
    
    
    
    ans = 0
    for a in lists:
        tmp = S
        for i in range(3):
            tmp = check(tmp, a[i])
            if tmp == None:
                break
        if tmp != None:
            ans += 1
    print(ans)


    


    
if __name__ == '__main__':
    N = int(input().rstrip())
    S = input().rstrip()
    print_ans(N, S)

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

cnt = 0
for i in range(1000):
	sec = str('%03d' % i)
	if sec[0] in s and sec[1] in s and sec[2] in s:
		nex = 0
		for j in range(n):
			if nex == 0 and s[j] == sec[0]:
				nex += 1
			elif nex == 1 and s[j] == sec[1]:
				nex += 1
			elif nex == 2 and s[j] == sec[2]:
				cnt += 1
				break
print(cnt)

Solution (Python):
N = int(input())
S = input()
S_uniquie = ''.join(set(S))
answer = 0
for left_s in S_uniquie:
    for i in range(N):
        if S[i] == left_s:
            left_pos = i
            break
    for right_s in S_uniquie:
        for i in range(N - 1, -1, -1):
            if S[i] == right_s:
                right_pos = i
                if left_pos + 2 <= right_pos:
                    answer += len(''.join(set(S[left_pos + 1:right_pos])))
                break

print(answer)

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

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

count = 0

ls_si = []
for i in range(n-2):
    
    if s[i] in ls_si:
        pass
    else:
        ls_si.append(s[i])
        ls_sj = []
        for j in range(i+1,n-1):
            if s[j] in ls_sj:
                pass
            else:
                ls_sj.append(s[j])
                
                
                
                
                
                
                count += len(set(list(s[j+1:-1])))



print(count)

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

def first_idx(s,n):
    for i in range(len(s)):
        if s[i] == n:
            return i
    return -1

ans = 0
for first_pin in range(10):
    tmp = first_idx(S, first_pin)
    if tmp == -1 or tmp >= N-2:
        continue
    tmp_s = S[tmp+1:]
    for second_pin in range(10):
        tmp2 = first_idx(tmp_s, second_pin)
        if tmp2 == -1 or tmp2 == N-1:
            continue
        tmp_s_2 = tmp_s[tmp2+1:]
        ans += len(set(tmp_s_2))

print(ans)

Solution (Python):
n= int(input())
s = input()
ans = 0
h = set()
for i in range(n-2):
  ten = set()
  if s[i] not in h:
    h.add(s[i])
    for j in range(i+1,n-1):
      if s[j] not in ten:
        ten.add(s[j])
        ans += len(set(s[j+1:]))
print(ans)

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

S10 = [0 for i in range(10)]
S100 = [list(S10) for i in range(10)]
S1000 =[list([list(S10) for i in range(10)]) for i in range(10)]

for n in S:
    for i in range(10):
        for j in range(10):
            if list(S100)[i][j] == 1:
                S1000[i][j][int(n)] = 1
        if list(S10)[i] == 1:
            S100[i][int(n)] = 1
    S10[int(n)] = 1
    


ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if S1000[i][j][k] == 1:
                ans += 1

print(ans)

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

count = 0
for i in range(10):
  idx = S.find(str(i))
  if idx == -1 or idx >= N-2:
    continue
  for j in range(10):
    idx2 = S.find(str(j), idx+1)
    
    if idx2 == -1 or idx2 >= N-1:
      continue
    set1 = set()
    for k in range(idx2+1, N):
      if S[k] not in set1:
        set1.add(S[k])
        if len(set1) >= 10:
          
          count += 10
          break
    else:
      
      count += len(set1)

print(count)

Solution (Python):
import numpy as np
from collections import Counter
N = int(input())
S = input()
length = len(S)
first = list()
res = 0
for n in range(length-2):
    if S[n] not in first:
        first.append(S[n])
    else:
        continue
    second = list()
    for m in range(n+1, length-1):
        if S[m] not in second:
            second.append(S[m])
        else:
            continue
        third = list()
        for k in range(m+1, length):
            if S[k] not in third:
                third.append(S[k])
            else:
                continue
            res += 1
print(res)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = list(input().strip())
A = [int(S[i]) for i in range(N)]

k1 = [-1]*10
for i in range(N-2):
    if k1[A[i]] == -1:
        k1[A[i]] = i

k2 = [[-1]*10 for i in range(10)]
for i in range(10):
    if k1[i] == -1:
        continue
    else:
        for j in range(k1[i]+1, N-1):
            if k2[i][A[j]] == -1:
                k2[i][A[j]] = j

ans = 0
for i in range(10):
    for j in range(10):
        if k2[i][j] == -1:
            continue
        
        L = [0]*10
        for l in range(k2[i][j]+1 , N):
            if L[A[l]] == 0:
                ans += 1
                L[A[l]] = 1

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

N=int(input())
s=input()


G1 = []
G2 = [[] for i in range(10)]
G3 = [[[] for i in range(10)] for j in range(10)]

def dfs3(x,y,new):
	if new not in G3[x][y]:
		G3[x][y].append(new)


def dfs2(x,new):
	for i in G2[x]:
		dfs3(x,i,new)
	if new not in G2[x]:
		G2[x].append(new)



def dfs1(new):
	for i in G1:
		dfs2(i,new)
	if new not in G1:
		G1.append(new)




for i in s:
	dfs1(int(i))

ans = 0
for i in range(10):
	for j in range(10):
		ans += len(G3[i][j])
print(ans)

Solution (Python):

import sys

def solve(N: int, S: str):
    def nx(S):
        res = [[N+1] * 10 for _ in range(N+1)]
        for i in range(N-1, -1, -1):
            for j in range(10):
                res[i][j] = res[i+1][j]
            res[i][int(S[i])] = i
        return res
    dp = [[0] * 3 for _ in range(N+1)]
    dp[1] = [1, 0, 0]
    res = nx(S)
    for i in range(0, N+1):
        for j in range(10):
            if res[i][j] >= N: continue
            if res[0][j] == res[i][j]:
                dp[res[i][j]+1][0] = 1
            dp[res[i][j]+1][1] += dp[i][0]
            dp[res[i][j]+1][2] += dp[i][1]
    res = 0
    for i in range(N+1):
        res += dp[i][2]
    print(res)
    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):
import sys
from itertools import combinations
from collections import Counter


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    N = len(S)
    trees = {}

    trees[S[0]] = {S[1]: set(S[2])}

    prev = S[2]
    prevprev = S[1]
    for i, c in enumerate(S):
        if i <= 2:
            continue

        for first in trees.keys():
            for second in trees[first].keys():
                trees[first][second].add(c)
            if prev not in trees[first]:
                trees[first][prev] = set(c)
        if prevprev not in trees:
            trees[prevprev] = {prev: set(c)}
        prevprev = prev
        prev = c

    count = 0
    for first in trees:
        for second in trees[first]:
            count += len(trees[first][second])
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Solution (Python):
import numpy as np

N = int(input())
S = input()
d = {}
for i in range(N):
  c = S[i]
  if c not in d.keys():
    d[c] = [i]
  else:
    
    
    
    d[c].append(i)


ans=0
for i in range(1000):
  code = str(i)
  while len(code)<3:
    code = "0" + code
  if code[0] not in d.keys() or code[1] not in d.keys() or code[2] not in d.keys():
    continue
  first = np.array(d[code[0]])
  current = first[0]
  
  second = np.array(d[code[1]])
  if len(second[second>current])==0:
    continue
  current = second[second>current][0]
  
  third = np.array(d[code[2]])
  if len(third[third>current])==0:
    continue
  ans+=1
  
print(ans)

Solution (Python):
import re

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

num_list = ['{:0=3}'.format(i) for i in range(1, 1000)]
pattern_list = [j[0]+"[0-9]*?"+j[1]+"[0-9]*?"+j[2] for j in num_list]



count = 0
for i in range(10):
  mi = re.search(str(i), S)
  if mi:
    for j in range(10):
      mj = re.search(str(j), S[mi.start()+1:])
      if mj:
        for k in range(10):
          if re.search(str(k), S[mi.start()+mj.start()+2:]):
            
            count += 1
print(count)

Solution (Python):



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

    Na = [0] * 10
    NNa = [[0] * 10 for _ in Na]
    NNNa = [[[0] * 10 for _ in Na] for _ in Na]

    for Sc in S:
        Si = int(Sc)

        for i, NNi in enumerate(NNa):
            for j, NNj in enumerate(NNi):
                NNNa[i][j][Si] = NNj

        for j, Nj in enumerate(Na):
            NNa[j][Si] = Nj

        Na[Si] = 1
        

    Count = 0
    for NNi in NNNa:
        for Nj in NNi:
            for Nk in Nj:
                Count += Nk


    print(Count)
        



if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    strings = list(input())

    
    ans = 0
    for i in range(1000):
        flag = True
        temp_strings = strings[:]
        for j in range(3):
            i_str = '{:03d}'.format(i)
            number = str(list(i_str)[j])
            if number in temp_strings:
                idx = temp_strings.index(number)
                temp_strings = temp_strings[idx+1:]
            else:
                flag = False
        if flag:
            
            ans += 1
        else:
            continue

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

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

one = set()
two = set()
three = set()
for s in S:
    for tw in two:
        three.add(tw + s)
    for on in one:
        two.add(on + s)
    one.add(s)
print(len(three))

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

min_dict = {}
max_dict = {}
for i in range(10):
    for j in range(n):
        if s[j] == str(i):
            min_dict[i] = j
            break
    for j in range(n-1, -1, -1):
        if s[j] == str(i):
            max_dict[i] = j
            break

res = 0
for k1, v1 in min_dict.items():
    for k2, v2 in max_dict.items():
        if v1 >= v2:
            continue
        else:
            res += len(list(set(list(s[v1+1:v2]))))

print(res)

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

Answer_dict = {}
used_i = list()
used_j = [[] for j in range(10)]

for i in range(N-2):
  if S[i] in used_i:
    continue

  for j in range(i+1,N-1):
    if S[j] in used_j[int(S[i])]:
      continue

    for k in range(j+1,N):
      Answer_dict[S[i]+S[j]+S[k]] = 1

    used_j[int(S[i])].append(S[j])
  used_i.append(S[i])

print(len(Answer_dict))

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

S = list(S)


number_place_dict={}
for i in range(10):
  number_place_dict[i]=list()



for i in range(len(S)):
  
  number_place_dict[int(S[i])].append(i)



ans = 0

for i in range(0,1000):
  i = list(str(i))
  if len(i) == 1:
    i = [0] + [0] + i
  elif len(i) == 2:
    i = [0] + i
  elif len(i) == 0:
    i = [0] + [0] + [0]
  
  

  next_place_confition = -1

  for j in range(0,3):
    
    place_list = number_place_dict[int(i[j])]
    index = bisect.bisect_right(place_list, next_place_confition)
    if index == len(place_list):
      
      break
    else:
      next_place_confition = place_list[index]
      
  else:
    
    ans += 1

print(ans)

Solution (Python):

N=int(input())
S=input()
cnt =0
for i in range(1000):
  s=str(i).zfill(3)

  if s[0] in S:
    s_0_index = S.index(s[0])
    S_0 = S[s_0_index+1:]

    if s[1] in S_0:
      s_1_index = S_0.index(s[1])
      S_1 = S_0[S_0.index(s[1])+1:]
 
      if s[2] in S_1:
        s_2_index = S_1.index(s[2])
        S_2 = S[s_2_index+1:]
        
        cnt+=1
print(cnt)

Solution (Python):
n = int(input())
s = input()
tmp = set()
si = set()
for i in range(n-2):
  if s[i] in si:
    continue
  else:
    si.add(s[i])
    sj = set()
    for j in range(i+1,n-1):
      if s[j] in sj:
        continue
      else:
        sj.add(s[j])
        sk = set()
        for k in range(j+1, n):
          if k in sk:
            continue
          else:
            sk.add(s[k])
       	    tmp.add(s[i] + s[j] + s[k])
print(len(tmp))

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

ss = s[::-1]

ans = 0

for i in range(1000):
    if i < 100:
        a = 0
    else:
        a = i // 100
    if i < 10:
        b = 0
    else:
        b = (i-a*100)//10
    c = i-(a*100+b*10)
    if str(a) in s and str(c) in s:
        k = s.index(str(a))
        l = n-1-ss.index(str(c))
        for j in range(k+1,l):
            if s[j] == str(b):
                ans += 1
                break
            
print(ans)

Solution (Python):
N = int(input())
S = list(input())
S = [int(S[i]) for i in range(N)]
count = 0
for i in range(10):
    for l in range(10):
        for q in range(10):
            t = 0
            for s in range(N):
                if t == 1:
                    break
                if S[s] == i:
                    p = s
                    for r in range(p + 1, N):
                        if t == 1:
                            break
                        if S[r] == l:
                            p = r
                            for b in range(p + 1, N):
                                if t == 1:
                                    break
                                if S[b] == q:
                                    count += 1
                                    t = 1
                                    break
                                elif b == N - 1:
                                    t = 1
                        elif r == N-1:
                            t = 1
                elif s == N - 1:
                    t = 1
print(count)

Solution (Python):
import bisect

n = int(input())
s = input()
ans = 0
INDEX = [list() for i in range(10)]
len_index = []
for key,i in enumerate(s):
  i = int(i)
  INDEX[i].append(key)
for i in INDEX:
  len_index.append(len(i))
for first in range(10):
  if len_index[first]:
    f = INDEX[first][0]
    for second in range(10):
      r = bisect.bisect_right(INDEX[second],f)
      if r < len_index[second]:
        s = INDEX[second][r]
        for third in range(10):
          t = bisect.bisect_right(INDEX[third],s)
          if t < len_index[third]:
            ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
count=0
for i in range(10):
  left=s.find('0')
  if left>=0:
    mid=s[left+1:].find('0')
    if mid>=0:
      right=s[left+mid+2:].find(str(i))
      if right>=0:
        count+=1

for i in range(10,100):
  left=s.find('0')
  if left>=0:
    mid=s[left+1:].find(str(i)[0])
    if mid>=0:
      right=s[left+mid+2:].find(str(i)[1])
      if right>=0:
        count+=1

for i in range(100,1000):
  left=s.find(str(i)[0])
  if left>=0:
    mid=s[left+1:].find(str(i)[1])
    if mid>=0:
      right=s[left+mid+2:].find(str(i)[2])
      if right>=0:
        count+=1
print(count)

Solution (Python):

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd



def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)



show_flg = False


def main():
    N = int(input())
    S = input()
    pos = [[] for i in range(10)]
    ans = 0

    for i in range(len(S)):
        pos[int(S[i])].append(i)

    show(pos)

    NUM = 10
    for i in range(NUM):
        for j in range(NUM):
            for k in range(NUM):
                cur = -1
                
                pos_i = [m for m in pos[i]]

                pos_j = [m for m in pos[j]]
                if j == i and len(pos_j) > 1:
                    pos_j.pop(0)

                pos_k = [m for m in pos[k]]
                if k == i and len(pos_k) > 1:
                    pos_k.pop(0)
                if k == j and len(pos_k) > 1:
                    pos_k.pop(0)

                if len(pos_i) == 0:
                    show('len(pos_i) == 0:')
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                cur = pos_i.pop(0)

                

                if len(pos_j) == 0:
                    show('len(pos_j) == 0:')
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                
                idx = bisect.bisect_right(pos_j, cur)
                
                if len(pos_j) <= idx:
                    show('pos_j', idx, cur, pos_j)
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                if cur > pos_j[idx]:
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue
                cur = pos_j[idx]
                
                
                
                
                
                
                

                
                
                
                

                

                if len(pos_k) == 0:
                    show('len(pos_k) == 0:')
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                idx = bisect.bisect_right(pos_k, cur)
                
                if len(pos_k) <= idx:
                    show('pos_k', idx, cur, pos_k)
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                if cur > pos_k[idx]:
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue
                cur = pos_k[idx]
                
                
                
                
                
                

                
                
                
                

                
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict
import bisect

N = int(input())
S = input()
dst = [[] for i in range(10)]
for i,x in enumerate(S):
    y = int(x)
    dst[y].append(i)

bs = bisect.bisect_right
ans = 0

for k in range(10):
    for j in range(10):
        for i in range(10):
            if dst[i] == [] or dst[j] == [] or dst[k] == []:
                continue
            else:
                A = dst[i][0]
                if A >= dst[j][-1]:
                    continue
                else:
                    b = bs(dst[j],A)
                    B = dst[j][b]
                    if B >= dst[k][-1]:
                        continue
                    else:
                        ans += 1            
            
print(ans)

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

next = [[-1] * 10 for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
    for j in range(10):
        next[i][j] = next[i + 1][j]
    next[i][S[i]] = i

c = 0
for i in range(10):
    p0 = next[0][i]
    if p0 < 0 or p0 > N - 3:
        continue
    for j in range(10):
        p1 = next[p0 + 1][j]
        if p1 < 0 or p1 > N - 2:
            continue
        for k in range(10):
            p2 = next[p1 + 1][k]
            if p2 > 0:
                c += 1
print(c)

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

a=[]
b=[]
c=[]
m=0
for i in range(n-2):
    if l[i] in a:
        continue
    a.append(l[i])
    for j in range(i+1,n-1):
        if l[j] in b:
            continue
        b.append(l[j])
        for k in range(j+1,n):
            if l[k] in c:
                continue
            c.append(l[k])
            m+=1
        c=[]
    b=[]

print(m)

Solution (Python):
def count_2chr(li):
    ans = [0 for _ in range(10)]
    s = li.copy()
    while len(s) >= 2:
        i = s.pop(0)
        if ans[i] == 0:
            ans[i] = len(set(s))
    
    return sum(ans)

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

count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

while len(s) >= 3:
    i = s.pop(0)
    if count[i] == 0:
        count[i] = count_2chr(s)

print(sum(count))

Solution (Python):
def main():
    n=int(input())
    s=input()
    S=[int(x) for x in list(s)]
    Pass1={S[0],S[1],S[2]}
    Pass2={S[0]*10+S[1],S[0]*10+S[2],S[1]*10+S[2]}
    Pass3={S[0]*100+S[1]*10+S[2]}
    for k in S[3:]:
        for i in Pass2:
            Pass3.add(i*10+k)
        for i in Pass1:
            Pass2.add(i*10+k)
        Pass1.add(k)
    print(len(Pass3))
    
if __name__=='__main__':
    main()