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

Solution (Python):
from collections import Counter

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

for i in range(1000):
    s = str(i).zfill(3)
    for i in range(N):
        if S[i]==s[0]:
            p = i
            break
    else:
        continue
    for i in range(p+1, N):
        if S[i]==s[1]:
            p = i
            break
    else:
        continue

    for i in range(p+1, N):
        if S[i]==s[2]:
            p = i
            break
    else:
        continue
    
    ans += 1

print(ans)

Solution (Python):
n=int(input())
s=str(input())
ans=0
i=0
while i<1000:
  temp=i//100
  cnt=0
  k=0
  for j in range(0,n):
    if temp==int(s[j]):
      cnt=cnt+1
      k=j
      break
  if cnt==0:
    i=i+100
  else:
    temp=(i-(i//100)*100)//10
    for j in range(k+1,n):      
      if temp==int(s[j]):
        cnt=cnt+1
        k=j
        break
    if cnt==1:
      i=i+10
    else:
      temp=i%10
      i=i+1
      for j in range(k+1,n):
        if temp==int(s[j]):
          ans=ans+1
          break
print(ans)

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

digit1 =[1,1,1,1,1,1,1,1,1,1]
digit2 =[1,1,1,1,1,1,1,1,1,1]
digit3 =[1,1,1,1,1,1,1,1,1,1]

array_code = []

for i in range(len(S)):
    if 1 in digit1:
        if digit1[int(S[i])]==1:
            for j in range(i+1,len(S)):
                if 1 in digit2:
                    if digit2[int(S[j])]==1:
                        for k in range(j+1,len(S)):
                            
                            if 1 in digit3:
                                if digit3[int(S[k])] ==1:
                                    array_code.append(S[i]+S[j]+S[k])
                                    digit3[int(S[k])] = 0
                            else:
                                for l in range(10):
                                    digit3[l]=1
                                break
                        digit2[int(S[j])]=0
                else:
                    for l in range(10):
                        digit2[l]=1
                    break
                for l in range(10):
                    digit3[l] = 1
            digit1[int(S[i])]=0
    else:
        break
    for l in range(10):
        digit2[l] = 1


print(len(array_code))

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


N = int(readline())
S = [x - ord('0') for x in read().rstrip()]
left_index = [[-1] * (N+1) for _ in range(10)]
for i,x in enumerate(S,1):
    for j in range(10):
        left_index[j][i] = left_index[j][i-1]
    left_index[x][i] = i
ans = 0
for a,b,c in itertools.product(range(10),repeat=3):
    i = N
    bl = True
    for x in [a,b,c]:
        i = left_index[x][i] - 1
        if i < -1:
            bl = False
            break
    if bl:
        ans += 1
print(ans)

Solution (Python):
import sys
from itertools import product
import bisect
N = int(sys.stdin.readline().rstrip())
S = sys.stdin.readline().rstrip()

d = {}
for i, s in enumerate(S):
    s = int(s)
    if s not in d:
        d[s] = [i]
    else:
        d[s].append(i)

ans = 0
for a, b, c in product(range(10), repeat=3):
    x = -1
    for i in [a, b, c]:
        if i not in d:
            break
        y = bisect.bisect_right(d[i], x)
        if y == len(d[i]):
            break
        x = d[i][y]
    else:
        ans += 1

print(ans)

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
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,S = read().decode('utf-8').split()
count = 0
for i in range(1000):
  s = str(i).zfill(3)
  index_all = 0
  for j in range(3):
    index = S[index_all:].find(s[j])
    if index == -1:
      break
    index_all += index+1
    if j ==2:
      count += 1
print(count)

Solution (Python):
from itertools import product

N=int(input())
S=input()
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0

for com in u:
  x_flag=False
  y_flag=False
  x=com[0]
  y=com[1]
  z=com[2]
    
  for i in range(N):
    if S[i]==x:
      x_flag=True
      break
  if x_flag:
    for j in range(i+1,N):
      if S[j]==y:
        y_flag=True
        break
  if y_flag:
    for k in range(j+1,N):
      if S[k]==z:
        ans+=1
        break
        
print(ans)

Solution (Python):
from itertools import product

N=int(input())
S=list(input())
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  x=com[0]
  y=com[1]
  z=com[2]
  
  if x in set(S):
    idx_x = S.index(x)
    tmp1 = S[idx_x+1:]
    if y in set(tmp1):
      idx_y = tmp1.index(y)
      tmp2 = tmp1[idx_y+1:]
      if z in set(tmp2):
        ans+=1
        continue
        
print(ans)

Solution (Python):
from itertools import product

N=int(input())
S=list(input())
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  x=com[0]
  y=com[1]
  z=com[2]
  
  if x in set(S):
    idx_x = S.index(x)
    tmp1 = S[idx_x+1:]
    if y in set(tmp1):
      idx_y = tmp1.index(y)
      tmp2 = tmp1[idx_y+1:]
      if z in set(tmp2):
        ans+=1
        continue
        
print(ans)

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

for i in range(10):
  x=s.find(str(i))
  if x!=-1:
    for j in range(10):
      y=s.find(str(j),x+1,n)
      if y!=-1:
        for k in range(10):
          z=s.find(str(k),y+1,n)
          if z!=-1:
            ans+=1
print(ans)

Solution (Python):
N = int(input())
S = input()
count = 0
for i in range(1000):
    t = str(i).zfill(3)
    a = S.find(t[0])
    b = S.find(t[1], a+1)
    c = S.find(t[2], b+1)
    if a != -1 and b != -1 and c != -1:
        count += 1
print(count)

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

ans = 0
for num in range(0, 1000):
    n0, n1, n2 = list(str(num).zfill(3))
    if n0 in S_set and n1 in S_set and n2 in S_set:
        idx0 = S.index(n0)
        idx2 = N - S[::-1].index(n2) - 1
        if idx0 < idx2:
            if n1 in S[idx0 + 1: idx2]:
                ans += 1
print(ans)

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

species_S_list = set(S)
ans = 0
for num in range(0, 1000):
    cnt = 0
    num_str = str(num).zfill(3)
    n0, n1, n2 = list(num_str)
    if n0 in species_S_list and n1 in species_S_list and n2 in species_S_list:
        index0 = S.index(n0)
        index2 = N - S[::-1].index(n2) - 1
        if index0 < index2:
            if n1 in S[index0 + 1: index2]:
                ans += 1
print(ans)

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

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

n=int(n)
sec_set = set()

for i in range(10):
    first = ln.find(str(i))
    if first == -1:
        continue
    for j in range(10):
        second = ln[(first+1):].find(str(j))
        if second == -1:
            continue
        for k in range(10):
            third = ln[(first + second+2):].find(str(k))
            if third == -1:
                continue
            else:
                sec_set.add(str(i)+str(j)+str(k))
print(len(sec_set))

Solution (Python):
N = int(input())
S = [int(x) for x in list(input())]
li = []
lj = []
lk = []
count = 0
for i_id, i in enumerate(S[0:N-2]):
  if i not in li:
    for j_id, j in enumerate(S[i_id+1:N-1]):
      if j not in lj:
        for k in S[i_id+j_id+2:N]:
          if k not in lk:
            count += 1
            lk.append(k)
        lj.append(j)
        lk.clear()
    li.append(i)
    lj.clear()
print(count)

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = int(input())
a = input()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    x = a.find(i[0])
    y = a.find(i[1], x+1)
    z = a.find(i[2], y+1)
    if x != -1 and y != -1 and z != -1:
        ans += 1
print(ans)

Solution (Python):

def main():
    import sys
    N = int(sys.stdin.readline())
    S = sys.stdin.readline().rstrip()
    cnt = 0
    for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                st1 = S.find(str(i))
                if st1 ==-1:
                    continue
                
                st2 = S[st1+1:].find(str(j))
                if st2 ==-1:
                    continue
              
                st3 = S[st1+st2+2:].find(str(k))
                if st3 ==-1:
                    continue
                
                cnt +=1
    print(cnt)


                    
    
   
    
if __name__=='__main__':
    main()

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

count = 0
for i in range(10):
    p1 = s.find(str(i))
    if p1 == -1:
        continue
    for j in range(10):
        p2 = s.find(str(j), p1 + 1)
        if p2 == -1:
            continue
        for k in range(10):
            p3 = s.find(str(k), p2+1)
            if p3 != -1:
                count += 1

print(count)

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

count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p1 = s.find(str(i))
            if p1 != -1:
                p2 = s.find(str(j), p1+1)
                if p2 != -1:
                    p3 = s.find(str(k), p2+1)
                    if p3 != -1:
                        count += 1

print(count)

Solution (Python):
def main():
  n = int(input())
  s = input()
  memo = []
  for i in range(10):
    for j in range(10):
      for k in range(10):
        memo.append(str(i) + str(j) + str(k))
  ans = 0
  for i in memo:
    x = 0
    for j in range(n):
      if i[x] == s[j]:
        x += 1
        if x == 3:
          ans += 1
          break

  print(ans)

if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
s = input()
memo = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      memo.append(str(i) + str(j) + str(k))
ans = 0
for i in memo:
  x = 0
  for j in range(n):
    if i[x] == s[j]:
      x += 1
      if x == 3:
        ans += 1
        break

print(ans)

Solution (Python):


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

cntset=set()
for i in range(1000):
    s=str(i)
    if i <10:
        s="00"+s
    if 10<=i<100:
        s="0"+s
    if S.find(s[0])==-1:
        continue
    if S[S.find(s[0])+1:].find(s[1])==-1:
        continue
    g=S.find(s[0])+S[S.find(s[0])+1:].find(s[1])
    if S[g+2:].find(s[2])==-1:
        continue
    cntset.add(s)
    
print(len(cntset))

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

cnt = 0
for i in range(1000):
  x = str(i).zfill(3)
  a = s.find(x[0])
  b = s[a+1:].find(x[1])
  c = s[a+b+2:].find(x[2])
  if -1 not in (a,b,c):
    cnt += 1
print(cnt)

Solution (Python):
def indexes(s, i):
  if i in s:
    return s.index(i)
  return -1

def check(s, num):
  for i in num:
    if indexes(s, i) < 0:
      return False
    index=indexes(s, i)
    s=s[index+1:]
  return True

l=int(input())
s=input()
pin=[]
cand=[str(i)[1:] for i in range(1000, 2000)]
for i in cand:
  if check(s, i):
    pin.append(i)
print(len(pin))

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




for i in range(1000):
    
    num = "0"*(3-len(str(i))) + str(i)
    first = S.find(num[0])
    if first != -1:
        
        
        
        second = S.find(num[1],first+1)
        if second != -1:
            third = S.find(num[2],second+1)
            if third != -1:
                
                counter+=1
print(counter)

Solution (Python):
n = int(input())
s = str(input())
cnt = 0
for i in range(1000):
    x = str(i).zfill(3)
    i1 = s.find(x[0])
    i2 = s[i1+1:].find(x[1])
    i3 = s[i1+i2+2:].find(x[2])
    if -1 not in (i1, i2, i3):
        cnt += 1
print(cnt)

Solution (Python):
import itertools
N=int(input())
S=list(input())
SS=set(S)
SS=list(SS)
num = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
num=[x for x in num if x in SS]
number=["".join(i) for i in itertools.product(num,repeat=3)]

ans=0
for i in number:
    count=0

    for s in range(N):
        if i[count]==S[s]:
            count+=1
            if count==2:
                if i[2] in S[s+1:]:
                    ans+=1
                break


print(ans)

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

ans = 0
for i in range(1000):
    key = '{:03d}'.format(i)

    for j in range(n):
        if s[j] == key[0]: break
    else: continue

    for k in range(j+1, n):
        if s[k] == key[1]: break
    else: continue

    for l in range(k+1, n):
        if s[l] == key[2]: break
    else: continue

    ans += 1

print(ans)

Solution (Python):
n = int(input())
ss = input()
li = []
li1 = []
li2 = []
ans = 0
for i in range(n-2):
    f = ss[i]
    if f in li:
        continue
    li.append(f)
    for j in range(i+1,n-1):
        s = ss[j]
        if f+s in li1:
            continue
        li1.append(f+s)
        li2 = []
        for k in range(j+1,n):
            if len(li2) == 10:
                break
            t = ss[k]
            if t in li2:
                continue
            ans += 1
            li2.append(t)
print(ans)

Solution (Python):
n = int(input())
s = input()
res = 0
pos = []
for i in range(10):
    pos.append([])

for i in range(len(s)):
    c = int(s[i])
    pos[c].append(i)
import bisect


res = 0
for num in range(0, 1000):
    numstr = format(num, '03d')
    iscan = True
    curpos = -2
    for i in range(3):
        curpos += 1
        val = int(numstr[i])
        ind = bisect.bisect_left(pos[val], curpos)
        if ind == len(pos[val]):
            iscan = False
            break
        curpos = pos[val][ind]

    if iscan:
        res += 1
print(res)

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

num = [0,1,2,3,4,5,6,7,8,9]
memo = []
for i in num:
  for j in num:
    for k in num:
      memo.append(str(num[i]) + str(num[j]) + str(num[k]))

ans = 0

for i in memo:
  x = 0
  for j in range(n):
    if i[x] == s[j]:
      x += 1
      if x == 3:
        break
  if x == 3:
    ans += 1
    
print(ans)

Solution (Python):

"""
Created on Mon Jun  1 16:47:45 2020

@author: NEC-PCuser
"""

N = int(input())
S = input()
count = 0
for i in range(0, 1000):
    j = 0
    a = str(i).zfill(3)
    b = S.find(a[0])
    if b == -1:
        continue
    c = S[b+1:].find(a[1])
    if c == -1:
        continue
    d= S[b+c+2:].find(a[2])
    if d != -1:
        count += 1
    
            
print(count)

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

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

ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            num = str(i) + str(j) + str(k)
            tmp = 0

            for s in S:
                if num[tmp] == s:
                    tmp += 1

                if tmp >= 3:
                    break

            if tmp == 3:
                ans += 1

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
S = input()
A = list(digits)

ans = 0
for x in product(A, repeat=3):
	i = 0
	for y in S:
		if y == x[i]:
			if i == 2:
				ans += 1
				break
			else:
				i += 1

print(ans)

Solution (Python):
n = int(input())
S = input()
l = set()
for i in range(1000):
    num = str(i).zfill(3)
    s = S
    if s.find(num[0]) == -1:
        continue
    s = s[s.index(num[0]) + 1:]
    if s.find(num[1]) == -1:
        continue
    s = s[s.index(num[1]) + 1:]
    if s.find(num[2]) == -1:
        continue
    l.add(num)
print(len(l))

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

num = []
for i in range(10):
    num.append(str(i))


cnt = 0
for i in num:
    for k in num:
        for j in num:
            for a in range(len(S)):
                if i == S[a]:
                    for b in range(a+1,len(S)):
                        if k == S[b]:
                            for c in range(b+1,len(S)):
                                if j == S[c]:
                                    cnt += 1
                                    break
                            break
                    break
print(cnt)

Solution (Python):
n=int(input())
S=input()
l=[]
for i in range(10**3):
    num=str(i).zfill(3)
    s=S
    if s.find(num[0])==-1: continue
    s=s[s.index(num[0])+1:]
    if s.find(num[1])==-1: continue
    s=s[s.index(num[1])+1:]
    if s.find(num[2])==-1: continue
    l.append(num)
print(len(set(l)))

Solution (Python):
_,s=open(0)
c=0
for i in range(1000):
 p=0;F=1
 for j in str(i).zfill(3):
  q=s[p:].find(j)
  if q<0:F=0;break
  p+=q+1
 c+=F
print(c)

Solution (Python):
_, s = open(0)
c = 0
for i in range(1000):
    p = 0
    F = 1
    for j in str(i).zfill(3):
        q = s[p:].find(j)
        if q < 0:
            F = 0
            break
        p += q + 1
    c += F
print(c)

Solution (Python):
n=int(input())
S=input()
l=[]
for i in range(10**3):
    num=str(i).zfill(3)
    s=S
    if s.find(num[0])==-1: continue
    s=s[s.index(num[0])+1:]
    if s.find(num[1])==-1: continue
    s=s[s.index(num[1])+1:]
    if s.find(num[2])==-1: continue
    l.append(num)
print(len(set(l)))

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

ans = 0

for i in range(10):
    if i in S[:N - 2]:
        i_index = S.index(i)
        for j in range(10):
            if j in S[i_index + 1: N - 1]:
                j_index = i_index + S[i_index + 1: N - 1].index(j) + 1
                for k in range(10):
                    if k in S[j_index + 1:]:
                        ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()
result = 0
for i in range(1000):
    x = format(i, "03")
    p = 0
    for j in range(n):
        if s[j]==x[p]:
            p += 1
            if p==3:
                result += 1
                break
print(result)

Solution (Python):
n = int(input())
s = list(map(int, list(input())))
numbers = [0 for _i in range(1000)]
right, left = [[0 for _j in range(10)] for _i in range(n)], [[0 for _j in range(10)] for _i in range(n)]
for i in range(1, n):
    left[i] = left[i-1].copy()
    left[i][s[i-1]] += 1
for i in range(2, n+1):
    right[-i] = right[-i+1].copy()
    right[-i][s[-i+1]] += 1

for i in range(n):
    for x in range(10):
        for y in range(10):
            if right[i][x]>0 and left[i][y]>0:
                numbers[100*x+10*s[i]+y] = 1
print(sum(numbers))

Solution (Python):
n = int(input())
S = list(str(input()))
ans = 0
for i in range(1000):
    q = 0
    p = list(str(i).zfill(3))
    s = p[q]
    for j in range(len(S)):
        if s == S[j]:
            q+=1
            if q == 3:
                break
            else:
                s = p[q]
        else:
            continue
    if q == 3:
        ans += 1
print(ans)

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

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

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

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

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

print(sum(dp_3))

Solution (Python):
n = int(input())
s = input()
count = 0
for a in range(10):
  for b in range(10):
    for c in range(10):
      check_1 = False
      check_2 = False
      check_3 = False
      for i in range(n):
          if s[i] == str(a):
            check_1 = True
            nex = i
            break
      if check_1 == True:
          for j in range(nex + 1,n):
            if s[j] == str(b):
              check_2 = True
              ne = j
              break
      if check_2 == True:
          for t in range(ne+1,n):
            if s[t] == str(c):
              count += 1
              break
print(count)

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

ans = 0
for i in range(10):
    if i in s[:n - 2]:
        x = s.index(i)

        for j in range(10):
            if j in s[x + 1:n - 1]:
                y = x + s[x + 1:n - 1].index(j) + 1

                for k in range(10):
                    if k in s[y + 1:]:
                        ans += 1

print(ans)

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

count = 0

for a in [str(a) for a in range(10)]:
    pos_a = S.find(a)
    if pos_a >= 0:
        for b in [str(b) for b in range(10)]:
            pos_b = S.find(b, pos_a+1)
            if pos_b >= 0:
                for c in [str(c) for c in range(10)]:
                    if S.find(c, pos_b+1) >= 0:
                        count += 1

print(count)

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

ans = 0

for i in range(1000):
    t = str(i).zfill(3)
    t_index = 0
    for s_index in range(n):
        if s[s_index] == t[t_index]:
            t_index += 1
            if t_index == 3:
                break
    if t_index == 3:
        ans += 1

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag_i = False
            flag_j = False
            flag_k = False
            for t in range(N):
                if not flag_i and S[t] == str(i):
                    flag_i = True
                elif flag_i and not flag_j and S[t] == str(j):
                    flag_j = True
                elif flag_i and flag_j and not flag_k and S[t] == str(k):
                    flag_k = True
            if flag_i and flag_j and flag_k:
                ans += 1
print(ans)

Solution (Python):
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                flag_i = False
                flag_j = False
                flag_k = False
                for t in range(N):
                    if not flag_i and S[t] == str(i):
                        flag_i = True
                    elif flag_i and not flag_j and S[t] == str(j):
                        flag_j = True                           
                    elif flag_i and flag_j and not flag_k and S[t] == str(k):
                        flag_k = True
                if flag_i and flag_j and flag_k:
                    ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
import numpy as np
from heapq import heapify, heappop, heappush
import copy
from collections import deque

from bisect import bisect_left, bisect_right









def main():
    N = int(input())
    S = input()
    most_left = {i: -1 for i in range(10)}
    for i in range(len(S)):
        s = int(S[i])
        if most_left[s] == -1:
            most_left[s] = i
    
    wholes = [False] * 1000
    sum_ = 0
    
    for i, first_idx in most_left.items():
        if first_idx == -1:
            continue
        alreadys = [False] * 10
        for second_idx in range(first_idx + 1, N):
            if alreadys[int(S[second_idx])]:
                continue
            alreadys[int(S[second_idx])] = True
            for third_idx in range(second_idx + 1, N):
                number = int(S[first_idx] + S[second_idx] + S[third_idx])
                if wholes[number] is False:
                    wholes[number] = True
                    sum_ += 1
    print(sum_)



        




if __name__ == '__main__':
    main()

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

ans = 0

for i in range(100):
    num = str(i).zfill(2)
    k = 0
    for j in range(len(s)):
        if num[k] == s[j]:
            k += 1
        if k == 2:
            ans += len(set(s[j+1:]))
            break

print(ans)

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

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)

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

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

Solution (Python):

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

num = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            num.append("{}{}{}".format(i, j, k))

ans = 0
for n in num:
    i = 0
    j = 0
    while j < N:
        
        if n[i] == S[j]:
            i += 1
            j += 1
        else:
            j += 1
        if i == 3:
            ans += 1
            break
print(ans)

Solution (Python):
n = int(input())
S = input()
count = 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 str(k) in S[b+1::]:
                count += 1
print(count)

Solution (Python):
n = int(input())
s = input()
cnt = 0
for i in range(1000):
    p = '{:03}'.format(i)
    s2 = s
    for j in range(3):
        if s2.find(p[j]) == -1:
            break
        s2 = s2[s2.find(p[j]) +1:]
    else:
        cnt+=1
print(cnt)

Solution (Python):
def m2():
    n = int(input())
    s = str(input())
    ALL = [str(i) for i in range(10)]
    ans = 0
    for a in ALL:
        for b in ALL:
            for c in ALL:
                flag = 0
                for i in range(n):
                    if s[i] == a and flag == 0:
                        flag = 1
                        continue
                    if s[i] == b and flag == 1:
                        flag = 2
                        continue
                    if s[i] == c and flag == 2:
                        flag = 3
                    if flag == 3:
                        ans += 1
                        break
    return ans

print(m2())

Solution (Python):


n = int(input())
s = input()
'''
for i in range(1000):
    a = '{0:03d}'.format(i)
    a1 = a[0]
    a2 =
'''
ans = 0

for i in range(10):
    

    if (str(i) not in s):
        continue
    else:
        tar1 = s.find(str(i))

    for j in range(10):
        temp = s[tar1 + 1:]
        if (str(j) not in temp):
            continue
        else:
            tar2 = temp.find(str(j))

        for k in range(10):
            temp = s[tar1 + 1:]
            temp = temp[tar2 + 1:]

            if (str(k) not in temp):
                continue
            else:
                ans += 1


print(ans)

Solution (Python):
def main():
    N_keta = int(input())
    S = input()

    total = 0

    for n in range(0, 1000):
        FLAG = True
        n_str = "{:03}".format(n)
        pos = 0
        
        for i in n_str:
            numberS = S[pos:]
            if (i not in numberS):
                FLAG = False
                break
            else:
                pos += numberS.index(i) + 1
        
        if (FLAG):
            total += 1

    print(total)


if __name__ == '__main__':
    main()

Solution (Python):
A=int(input())
l=input()
ans=0
for i in range(1000):
   s=str(i).zfill(3)
   x=l.find(s[0])
   y=l.find(s[1],x+1)
   z=l.find(s[2],y+1)
   if all([x <= y <= z,x!=-1,y!=-1,z!=-1]):
      ans+=1
print(ans)

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

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

cnt = 0
for pwd in kouho:
    point = 0
    for word in S:
        if word == pwd[point]:
            point += 1
            if point == 3:
                cnt += 1
                break

print(cnt)

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

print(cnt)