Problem:
 Score: 400 points    Problem Statement  AtCoder Inc. has decided to lock the door of its office with a 3 -digit PIN code.  The company has an N -digit lucky number, S . Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.  How many different PIN codes can he set this way?  Both the lucky number and the PIN code may begin with a 0 .      Constraints   4 \leq N \leq 30000  S is a string of length N consisting of digits.         Input  Input is given from Standard Input in the following format:  N  S       Output  Print the number of different PIN codes Takahashi can set.        Sample Input 1 4
0224      Sample Output 1 3  Takahashi has the following options:   Erase the first digit of S and set 224 .  Erase the second digit of S and set 024 .  Erase the third digit of S and set 024 .  Erase the fourth digit of S and set 022 .   Thus, he can set three different PIN codes: 022 , 024 , and 224 .       Sample Input 2 6
123123      Sample Output 2 17       Sample Input 3 19
3141592653589793238      Sample Output 3 329

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

def judge(S,A): 
    dig,pt = 0,0
    while dig < 3 and pt < N:
        if S[pt] == A[dig]:
            dig += 1
            pt += 1
        else:
            pt += 1
        if dig == 3:
            break

    if dig == 3:
        return True
    else:
        return False

count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            if judge(S,[str(a),str(b),str(c)]):
                count += 1

print(count)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    s = list(input())
    ans = 0
    for i in range(1000):
        k = str(i)
        while len(k) < 3:
            k = "0"+k
        l = 0
        for j in range(n):
            if k[l] == s[j]:
                l += 1
                if l == 3:
                    ans += 1
                    break
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
N  = int (input())
S = input()
s = set()
s.add("")
for c in S:
    new = []
    for c2 in s:
        if len(c2) < 3:
            new.append(c2 + c)
    for temp in new:
        s.add(temp)
ans = 0
for temp in s:
    if len(temp) == 3:
        ans += 1
print(ans)

Solution (Python):

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

for i in range(1000):
    one = S.find(pin[i][0])
    two = S.find(pin[i][1], one + 1)
    three = S.find(pin[i][2], two + 1)
    if one != -1 and two != -1 and three != -1:
        cnt += 1

print(cnt)

Solution (Python):
def password():
    for i in range(10):
        for j in range(10):
            for k in range(10):
                yield [str(i), str(j), str(k)]


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

ans = 0
for perm in password():
    if perm[0] in s:
        a = s.find(perm[0])
        if perm[1] in s[a + 1 :]:
            b = s[a + 1 :].find(perm[1])
            if perm[2] in s[a + 1 :][b + 1 :]:
                ans += 1

print(ans)

Solution (Python):
def solve():
    N = int(input())
    S = input()
    
    ans = 0
    memo1 = set()
    for i in range(N - 2):
        si = int(S[i])
        if si in memo1:
            continue
        memo1.add(si)
        memo2 = set()
        for j in range(i + 1, N - 1):
            sj = int(S[j])
            if sj in memo2:
                continue
            memo2.add(sj)
            ans += len(set(S[j + 1:]))
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
N=int(input())
S=list(input())
cnt=0
number=[str(i) for i in range(10)]
for i in range(10):
    try:
        first=S.index(number[i])
        if first>=N-2:
            continue
        for k in range(10):
            try:
                second=S[first+1:].index(number[k])
                if second>=len(S[first+1:])-1:
                    continue
                for l in range(10):
                    if number[l] in S[first+1:][second+1:]:
                        cnt+=1
            except:
                continue
    except:
        continue
print(cnt)

Solution (Python):
import copy
n = int(input())
s = input()
slist = list(s)

def search(slist, plist):
    s2 = copy.copy(slist)
    for k in plist:
        if k in s2:
            start = s2.index(k)+1
            s2 = s2[start:]
        else:
            return False
    return True


count = 0
for i in range(1000):
    
    p = format(i, "03")
    plist = list(str(p))
    if search(slist, plist):
        count += 1
print(count)

Solution (Python):

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

cnt=0
for i in range(0,1000):
    t='0'*(3-len(str(i)))+str(i)
    flg1,flg2,flg3=[False]*3
    for j in range(n):
        if flg1:
            if flg2:
                if s[j]==t[2]:
                    flg3=True
                    break
            else:
                if s[j]==t[1]:
                    flg2=True
        else:
            if s[j]==t[0]:
                flg1=True
    cnt+=1 if flg3 else 0
    
print(cnt)

Solution (Python):
n=int(input())
s=input()
A=[int(i) for i in range(10)]
ans=0
import itertools
for a,b,c in itertools.product(A,repeat=3):
  a,b,c=str(a),str(b),str(c)
  chk=0
  for ss in s:
    if chk==0 and ss==a:
      chk=1
    elif chk==1 and ss==b:
      chk=2
    elif chk==2 and ss==c:
      chk=3
  if chk==3:
    ans+=1
print(ans)

Solution (Python):
def str_find(S, target, start):
    for i in range(start, len(S)):
        if S[i] == target:
            return i

    return 10**9+7

N = int(raw_input())
S = str(raw_input())

candidates = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            candi = str(i)+str(j)+str(k)
            candidates.append(candi)


ans = 0
for candi in candidates:
    x = candi[0]
    i = str_find(S, x, 0)

    y = candi[1]
    j = str_find(S, y, i+1)

    z = candi[2]
    k = str_find(S, z, j+1)

    if i+j+k< 10**8:
        ans = ans + 1

print ans

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    count = 0
    for i in range(1000):
        left = 0
        not_found = False
        for c in '{:03}'.format(i):
            for j in range(left, N):
                if S[j] == c:
                    left = j + 1
                    break
            else:
                not_found = True
                break
            if not_found:
                break
        if not not_found:
            count += 1
    print(count)


if __name__ == "__main__":
    main()

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

for i in range(0,1000):
    v = str(i).zfill(3)
    p1 = s.find(v[0],0)
    p2 = s.find(v[1],p1+1)
    p3 = s.find(v[2],p2+1)
    if p1 != -1 and p2 != -1 and p3 != -1:
        ans.append(v)

print(len(ans))

Solution (Python):


import itertools

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












def can_make_pw(S, password):
    
    v1 = password[0]
    p1 = S.find(v1)
    if p1 == -1:
        return False
    
    v2 = password[1]
    p2 = S.find(v2, p1+1)
    if p2 == -1:
        return False
    
    v3 = password[2]
    p3 = S.find(v3, p2+1)
    if p3 == -1:
        return False
    return True

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


count = 0
for password in passwords:
    if can_make_pw(S, password):
        
        count += 1

print(count)

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

cnt = 0
for i in range(10):
    s_ = s
    if str(0) in s_:
        s_ = s_[s_.index(str(0))+1:]
        if str(0) in s_:
            s_ = s_[s_.index(str(0))+1:]
            if str(i) in s_:
                cnt += 1

for i in range(10,100):
    s_ = s
    if str(0) in s_:
        s_ = s_[s_.index(str(0))+1:]
        if str(i)[0] in s_:
            s_ = s_[s_.index(str(i)[0])+1:]
            if str(i)[1] in s_:
                cnt += 1

for i in range(100,1000):
    s_ = s
    if str(i)[0] in s_:
        s_ = s_[s_.index(str(i)[0])+1:]
        if str(i)[1] in s_:
            s_ = s_[s_.index(str(i)[1])+1:]
            if str(i)[2] in s_:
                cnt += 1  

print(cnt)

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

ans = 0
for i in range(1000):
    
    if len(str(i)) != 3:
        V = "0" * (3- len(str(i))) + str(i)
    else:
        V = str(i)
    
    cnt = 0
    for j in S:
        if V[cnt] == j:
            cnt += 1
            
        if cnt == 3:
            ans += 1
            break
print(ans)

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

Solution (Python):
n = int(input())
S = input()
ans = 0
for i in range(10):
    a = S.find(str(i))
    if a != -1:
        for j in range(10):
            b = S[a+1:].find(str(j))
            if b != -1:
                for k in range(10):
                    c = S[a+1:][b+1:].find(str(k))
                    if c!=-1:
                        ans+=1
                        

print(ans)

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

d = [defaultdict(int) for i in range(3)]
for s in S:
    for x in d[1]:
        d[2][x+s]+=1
    for x in d[0]:
        d[1][x+s]+=1
    d[0][s]+=1
print(len(d[2]))

Solution (Python):
N = int(input())
S = input()
dp = {}
si = set()
for i in range(N-2):
  if S[i] in si:
    continue
  si.add(S[i])
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set(S[j+1:]))
print(sum(dp.values()))

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

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)

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

n = int(input())
s = input()
ans = 0

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for S in s:
        if S == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    tg = str(i + 1000)[1:]
    if tg[0] not in s:
        continue
    else:
        x2 = s[s.index(tg[0]) + 1:]
        if tg[1] not in x2:
            continue
        else:
            x3 = x2[x2.index(tg[1]) + 1:]
            if tg[2] not in x3:
                continue
            else:
                ans += 1
print(ans)

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

for i in range(0, 1000):
    i = str(i).zfill(3)
    idx = 0
    for j in range(3):
        if i[j] in S[idx:]:
            idx += S[idx:].index(i[j])+1
            continue
        else:
            break
    else:
        ans += 1

    


print(ans)

Solution (Python):
N = int(input())
S = input()
st = set()
nums = [str(i) for i in range(10)]
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = False
            flag2 = False
            for l in range(N):
                if not flag1 and S[l] == nums[i]:
                    flag1 = True
                elif flag1 and not flag2 and S[l] == nums[j]:
                    flag2 = True
                elif flag1 and flag2 and S[l] == nums[k]:
                    st.add(nums[i] + nums[j] + nums[k])
                
print(len(st))

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

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

    try:
        id1 = s.index(i[0])
        id2 = s.index(i[1], id1+1)
        id3 = s.index(i[2], id2+1)
        ans += 1
    except ValueError:
        continue

print(ans)

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


count = 0
for n in range(0, 1000):
    password = "{:03d}".format(n)
    p1, p2, p3 = password

    i1 = S.find(str(p1))
    if i1 < 0:
        continue
    i2 = S[i1+1:].find(str(p2))
    if i2 < 0:
        continue
    i3 = S[i1+1:][i2+1:].find(str(p3))
    if i3 < 0:
        continue
    count += 1
print(count)

Solution (Python):
n = int(input())
s = list(input())
ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            t = str(i) + str(j) + str(k)
            tmp = []
            for z in s:
                if t[len(tmp)] == z:
                    tmp.append(0)
                if len(tmp) == 3:
                    ans += 1
                    break
print(ans)

Solution (Python):
from itertools import combinations


n = int(input())
s = input()
ans = 0
for i in range(1000):
    num = '{:0=3}'.format(i)
    inds = 0
    indnum = 0
    while inds < len(s) and indnum < 3:
        if s[inds] == num[indnum]:
            indnum += 1
        inds += 1
    if indnum == 3:
        ans += 1
print(ans)

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

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

    try:
        id1 = s.index(x[0])
        id2 = s.index(x[1], id1+1)
        id3 = s.index(x[2], id2+1)
        ans += 1
    except ValueError:
        continue

print(ans)

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

nums = tuple(str(i) for i in range(10))

ans = 0
for i in nums:
    pi = s.find(i)
    if pi == -1:
        continue

    for j in nums:
        pj = s.find(j, pi + 1)
        if pj == -1:
            continue

        for k in nums:
            pk = s.find(k, pj + 1)
            if pk == -1:
                continue

            ans += 1

print(ans)

Solution (Python):
from itertools import product

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

nums = [str(i) for i in range(10)]

ans = 0
for pat in product(nums, repeat=3):
    i = 0
    for e in s:
        if e == pat[i]:
            i += 1

        if i == 3:
            break

    if i == 3:
        ans += 1

print(ans)

Solution (Python):
N = int(input())
S = str(input())
ans = 0
for i in range(0, 1000):
    x = str(i).zfill(3)
    try:
        idx1 = S.index(x[0])
        idx2 = S.index(x[1], idx1+1)
        idx3 = S.index(x[2], idx2+1)
        ans += 1
    except ValueError:
        continue
print(ans)

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

num='0123456789'
ans=0

for first_num in num:
    for second_num in num:
        for third_num in num:
            temp_lock=first_num+second_num+third_num
            temp_cnt=0
            for i in s:
                if temp_cnt==0 and i==temp_lock[0]:
                    temp_cnt=1
                elif temp_cnt==1 and i==temp_lock[1]:
                    temp_cnt=2
                elif temp_cnt==2 and i==temp_lock[2]:
                    ans+=1
                    break
print(ans)

Solution (Python):
N = int(input())
S = input()
re = 0
for i in range(1000):
    ans = [0]*3
    for j in range(3):
        ans[j] = str(i % 10)
        i = i // 10
    ans.reverse()
    flag = False
    idx_left = S.find(ans[0])
    idx_right = S.rfind(ans[2])
    if idx_left != -1 and idx_right != -1 and idx_left < idx_right:
        if ans[1] in S[idx_left+1:idx_right]:
            flag = True
    if flag:
        re += 1
print(re)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = 0
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(len(a_alr) == 10):
        break
    if(s[i] in a_alr):
        continue

    for j in range(i+1,n-1):
        if(len(b_alr[s[i]]) == 10):
            break
        if(s[j] in b_alr[s[i]]):
            continue
        
        ans += len(set(s[j+1:]))
        
        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(ans)

Solution (Python):
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  
def grid(n): return [s_list() for _ in range(n)]


def main():
    n = int(input())
    s = input()
    count = 0
    for i in range(1000):
        key = str(i + 1000)[1:]
        if key[0] in s:
            s2 = s[s.index(key[0]) + 1:]

            if key[1] in s2:
                s3 = s2[s2.index(key[1])+1:]

                if key[2] in s3:
                    count += 1

                else:
                    continue
    print(count)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = input()
count = 0
for i in range(1000):
    v = str(i).zfill(3)
    k=0
    for j in range(n):
        if v[k] == s[j]:
            k+=1
        if k==3:
            count+=1
            break

print(count)

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

ans = 0

def dfs(depth, id):
    global ans
    for i in range(10):
        for j in range(id, n):
            if i == s[j]:
                if depth < 2:
                    dfs(depth + 1, j + 1)
                else:
                    ans += 1
                break

dfs(0, 0)
print(ans)

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

ans = 0

def dfs(depth, id):
    global ans
    for i in range(10):
        for j in range(id, n):
            if i == s[j]:
                if depth < 2:
                    dfs(depth + 1, j + 1)
                else:
                    ans += 1
                break

dfs(0, 0)
print(ans)

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

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

ans = 0
for x in range(0, 1000):
    pin = str(x).zfill(3)

    i = S.find(pin[0])
    if i == -1:
        continue
    i = S.find(pin[1], i + 1)
    if i == -1:
        continue
    i = S.find(pin[2], i + 1)
    if i == -1:
        continue
    ans += 1

print(ans)

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

ans = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue

    for j in range(10):
        b = s.find(str(j), a+1)
        if b == -1:
            continue

        for k in range(10):
            if s.find(str(k), b+1) != -1:
                ans += 1

print(ans)

Solution (Python):
n = int(input())
s = input()
z = ['0','1','2','3','4','5','6','7','8','9']

count = 0
point_i=0

for s_i in z:
    point = point_i
    point_j = n
    for i in range(point,n):
        if s[i]==s_i:
            point_j = i+1
            break
            
    for s_j in z:
        point = point_j
        point_k = n
        for j in range(point,n):
            if s[j]==s_j:
                point_k = j+1
                break
            
        for s_k in z:
            point = point_k
            
            for k in range(point,n):
                if s[k]==s_k:
                    
                    count +=1
                    break
print(count)

Solution (Python):
def func1(i,N,S):
  indexS = 0 
  indexI = 0 
  i2 = str(i).zfill(3) 
  
  while indexS < N:
    if indexI > 2:
      break 
    if i2[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  return 1 if indexI >2 else 0

def main():
  N = int(input())
  S = input()
  print(sum([func1(i,N,S) for i in range(1000)]))

if __name__ == '__main__':
  main()

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
	a = '{:0=3}'.format(i)
	b = [False] * 3
	for j in S:
		if j == a[0] and not b[0]:
			b[0] = True
		elif j == a[1] and b[0] and not b[1]:
			b[1] = True
		elif j == a[2] and b[0] and b[1] and not b[2]:
			b[2] = True
	if all(b):
		ans += 1
print(ans)

Solution (Python):
def main():
    from itertools import product
    n=int(input())
    s=input()
    
    cnt=0
    num='0123456789'
    for pw in product(num,repeat=3):
        j=0
        for i in range(n):
            if pw[j]==s[i]:
                j+=1
                if j==3:
                    cnt+=1
                    break
    
    print(cnt) 
if __name__=='__main__':
    main()

Solution (Python):
def main():
    _ = int(input())
    s = input()
    ans = 0
    for i in range(10):
        a = s.find(str(i))
        if a == -1:
            continue
        for j in range(10):
            b = s.find(str(j), a+1)
            if b == -1:
                continue
            for k in range(10):
                if s.find(str(k), b+1) != -1:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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

N = int(input())
S = input().rstrip()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    idx1 = S.find(i[0])
    if idx1 < 0:
        continue
    idx2 = S.find(i[1], idx1 + 1)
    if idx2 < 0:
        continue
    idx3 = S.find(i[2], idx2 + 1)
    if idx3 < 0:
        continue
    ans += 1
print(ans)

Solution (Python):



import itertools
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')
sys.setrecursionlimit(10**5)

def main():
    n = int(input())
    s = input()
    ans = 0
    pin = list(itertools.product(range(10), repeat=3))

    for cur in pin:
        a, b, c = map(str,cur)
        if a in s:
            aidx = s.index(a)
            if b in s[aidx+1:]:
                bidx = s[aidx+1:].index(b) + (aidx + 1)
                if c in s[bidx+1:]:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0
for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue

    for j in range(10):
        b = s.find(str(j), a+1)
        if b == -1:
            continue

        for k in range(10):
            if s.find(str(k), b+1) != -1:
                ans += 1

print(ans)

Solution (Python):
n = int(input())
s = input()
d = {str(i):[] for i in range(10)}
for i,x in enumerate(s):
    d[x].append(i)
_sum = 0
for i in range(10):
    if len(d[str(i)]) != 0:
        for j in range(10):
            if len(d[str(j)]) != 0:
                for k in range(10):
                    if len(d[str(k)]) != 0:
                        st = d[str(i)][0]
                        en = d[str(k)][-1]
                        for idx in d[str(j)]:
                            if idx>st and idx<en:
                                _sum+=1
                                break
                            elif idx>=en:
                                break
print(_sum)

Solution (Python):
from collections import defaultdict

n = int(input())
S = input()



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

pw = []
for i in d.keys():
    for j in d.keys():
        for k in d.keys():
            first = d[i][0]
            for l in d[j]:
                if l > first:
                    second = l
                    break
            else:
                continue
            for m in d[k]:
                if m > second:
                    third = m
                    break
            else:
                continue
            pw.append(S[first]+S[second]+S[third])
print(len(set(pw)))

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



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

ans = 0
for pattern in patterns:
    i = j = 0
    while i < n:
        if s[i] == pattern[j]:
            i += 1
            j += 1
            if j == 3:
                ans += 1
                break
        else:
            i += 1
print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for s in range(0, 1000):
    s = str(s).zfill(3)
    i = 0
    for d in s:
        if d in S[i:]:
            i += S[i:].index(d) + 1
        else:
            break
    else:
        ans += 1
print(ans)

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

_ = input()
N = list(map(int, input()))

cnt = [defaultdict(int) for _ in range(len(N) + 1)]
left = [10 ** 10] * 10
right = [-1] * 10

for i, n in enumerate(N):
    left[n] = min(left[n], i)
    right[n] = max(right[n], i)

    for j in range(10):
        cnt[i + 1][j] = cnt[i][j]
    cnt[i + 1][n] += 1

ans = 0
for l, m, r in product(range(10), repeat=3):
    l = left[l]
    r = right[r]

    if l < r and cnt[r][m] - cnt[l + 1][m] > 0:
        ans += 1

print(ans)

Solution (Python):
def solve():
    N = int(input())
    S = list(input())
    right = [set() for _ in range(N)]
    for i in reversed(range(N - 1)): right[i] = right[i + 1] | {S[i + 1]}
    left = {S[0]}
    PIN = set()
    for i in range(1, N - 1):
        for ln in left:
            for rn in right[i]:
                p = ln + S[i] + rn
                PIN |= {p}
        left |= {S[i]}
    print(len(PIN))

    return 0

if __name__ == "__main__":
    solve()

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

ans = 0
history_i = set()
for i in range(N-2):

    if S[i] in history_i:
        continue

    history_j = set()
    for j in range(i+1, N-1):

        if S[j] in history_j:
            continue

        history_k = set()
        for k in range(j+1, N):

            if S[k] in history_k:
                continue
            history_k.add(S[k])
            ans += 1
            if len(history_k) == 10:
                break
        
        history_j.add(S[j])
        if len(history_j) == 10:
            break

    history_i.add(S[i])
    if len(history_i) == 10:
        break

print(ans)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right


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


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")





def main():
    N = i_inpl()
    base_S = input()
    ans = set()
    for i in range(1000):
        S = copy.deepcopy(base_S)
        find_num = str(i).zfill(3)
        k = S.find(find_num[0])
        if k == -1:
            continue

        S = S[k+1:]
        k = S.find(find_num[1])
        if k == -1:
            continue

        S = S[k+1:]
        k = S.find(find_num[2])
        if k == -1:
            continue

        ans.add(find_num)
    print(len(ans))

if __name__ == "__main__":
    main()

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right


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


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")





def main():
    N = i_inpl()
    base_S = input()
    ans = set()
    for i in range(1000):
        S = copy.deepcopy(base_S)
        find_num = str(i).zfill(3)
        k = S.find(find_num[0])
        if k == -1:
            continue

        S = S[k+1:]
        k = S.find(find_num[1])
        if k == -1:
            continue

        S = S[k+1:]
        k = S.find(find_num[2])
        if k == -1:
            continue

        ans.add(find_num)
    print(len(ans))

if __name__ == "__main__":
    main()

Solution (Python):

def solve():
  n = int(input())
  s = input()
  dp = [[] for _ in range(4)]

  for i in range(n):
    number = s[i]
    

    for k in dp[2]:
      dp[3].append(k+number)
    for l in dp[1]:
      dp[2].append(l+number)  
    dp[1].append(number)
    
    for i in range(4):
      dp[i] = list(set(dp[i]))
  print(len(dp[3]))
    
      
solve()

Solution (Python):
n=int(input())
s=input()
ans=0
fi=lambda x,y:x.find(str(y))
for i in range(10):
  f1=fi(s,i)
  if f1==-1:
    continue
  s1=s[f1+1:]
  for j in range(10):
    f2=fi(s1,j)
    if f2==-1:
      continue
    s2=s1[f2+1:]
    for k in range(10):
      f3=fi(s2,k)
      if f3>=0:
        ans+=1
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = readline().decode().rstrip()

ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    idx = 0
    flag = True

    for s in num:
        acc = S[idx:].find(s)
        if acc == -1:
            flag = False
            break
        else:
            idx += acc + 1
    if flag:
        ans += 1

print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = readline().decode().rstrip()

ans = 0
for i in range(1000):
    i_ = '{:>03}'.format(i)
    idx = 0

    for s in S:
        if s == i_[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)

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

count = 0
for i in range(1000):
  tmp = format(i, '03')
  k = 0
  for j in s:
    if j == tmp[k]:
      k+=1
    if k == 3:
      count+=1
      break
print(count)