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
input = sys.stdin.readline



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




import re

def main():
	n=II()
	s=input()
	ans=0
	for i in range(1000):
		j=str(i).zfill(3)
		now=0
		for k in s:
			if j[now]==k:
				now+=1
			if now==3:
				ans+=1
				break



	print(ans)



















if __name__ == "__main__":
	main()

Solution (Python):
n=int(input())
s=input()
ans=0
for aim in range(100):
  sa=str(aim)
  if aim<=9:sa="0"+sa
  cnt=0;k=-1
  for i in range(n):
    if sa[cnt]==s[i]:cnt+=1
    if cnt==2:k=i;break
  else:continue
  ans+=len(set(list(s[k+1:])))
print(ans)

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

res = 0
for i in range(10):
  idx_1 = S.find(str(i))
  if (idx_1 == -1) or (idx_1 > N-3):
    continue
  for j in range(10):
    idx_2 = S[idx_1+1:].find(str(j))
    if (idx_2 == -1) or (idx_2 > N-2):
      continue
    for k in range(10):
      idx_3 = S[idx_1+1+idx_2+1:].find(str(k))
      if idx_3 != -1:
        res += 1

print(res)

Solution (Python):
import re

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

res = 0
fmt = "[0-9]*{}[0-9]*{}[0-9]*{}[0-9]*"
for i in range(10):
  idx_1 = S.find(str(i))
  if (idx_1 == -1) or (idx_1 > N-3):
    continue
  for j in range(10):
    idx_2 = S[idx_1+1:].find(str(j))
    if (idx_2 == -1) or (idx_2 > N-2):
      continue
    for k in range(10):
      idx_3 = S[idx_1+1+idx_2+1:].find(str(k))
      if idx_3 != -1:
        res += 1

print(res)

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

import collections as co
d=co.defaultdict(list)
for x,i in enumerate(a):
    d[i].append(x)

se=set()
for i in d.keys():
    se.add(i)

for pin in range(1000):
    pin=str(pin)
    pin=pin.zfill(3)
    now=-1
    cnt=0
    flag=True
    
    for num in pin:
        if num not in se:
            flag=False
    
        for i in d[num]:
            if i>now:
                now=i
                cnt+=1
                break

    if cnt==3 and flag==True:
        ans+=1
print(ans)

Solution (Python):
n = int(input())
s = input()
result = 0
for i in range(1000):
    x = format(i, "03")
    indx = s.find(x[0],0)
    indx1 = s.find(x[1], indx+1)
    indx2 = s.find(x[2], indx1+1)
    if indx>=0 and indx1>0 and indx2>0:
        result += 1

print(result)

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

s1 = set()
s2 = set()
s3 = set()

for s in input():
  if s2:
    for s2_sub in s2:
      s3 |= {s2_sub+s}
  if s1:
    for s1_sub in s1:
      s2 |= {s1_sub+s}
  s1 |= {s}
  
print(len(s3))

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

print(result)

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

    ans = set()
    for i in range(1000):
        str_i = str(i).zfill(3)
        idx1 = S.find(str_i[0], 0)
        idx2 = S.find(str_i[1], idx1 + 1)
        idx3 = S.find(str_i[2], idx2 + 1)
        if idx1 != -1 and idx2 != -1 and idx3 != -1:
            ans.add(str_i)


    return print(len(ans))

if __name__ == "__main__":
    resolve()

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

    ans = 0
    for i in range(1000):
        pw = str(i).zfill(3)
        pw_ind = 0
        for s in S:
            if s == pw[pw_ind]:
                pw_ind += 1
                if pw_ind == 3:
                    break
        if pw_ind == 3:
            ans += 1

    return print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input())
S = input()
anss = []
for i in range(1000):
    str_i = str(i).zfill(3)
    idx1 = S.find(str_i[0], 0)
    idx2 = S.find(str_i[1], idx1 + 1)
    idx3 = S.find(str_i[2], idx2 + 1)
    if idx1 != -1 and idx2 != -1 and idx3 != -1:
        anss.append(str_i)

print(len(set(anss)))

Solution (Python):
N = int(input())
S = str(input())
x = '000'
ans = 0
while int(x) < 1000:
  st = 0
  cnt = 0
  if x[0] in S:
    for i in range(N):
      if x[0] == S[i]:
        st = i+1
        cnt += 1
        break
  if x[1] in S[st:]:
    for j in range(st, N):
      if x[1] == S[j]:
        st = j+1
        cnt += 1
        break
  if x[2] in S[st:]:
    for k in range(st, N):
      if x[2] == S[k]:
        st = k+1
        cnt += 1
        break
                
  if cnt == 3:
    ans += 1
  x = '{:03d}'.format(int(x)+1)
print(ans)

Solution (Python):
N=int(input())
S=input()
A=[0]*N
for i in range(N):
 A[i]=int(S[i])
b=0
for i in range(1000):
 i1=int(i/100)
 i2=int((i-i1*100)/10)
 i3=i%10
 a=0
 for j in range(N):
  if a==0:
   if A[j]==i1:
    a+=1
  elif a==1:
   if A[j]==i2:
    a+=1
  else:
   if A[j]==i3:
    b+=1
    break
print(b)

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

for i in range(1000):
  num = str(i).zfill(3)
  check1 = S.find(num[0])
  check2 = S.find(num[1], check1+1)
  check3 = S.find(num[2], check2+1)
  if check1 != -1 and check2 != -1 and check3 != -1:
    cnt += 1
print(cnt)

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

for i in range(1000):
    num = str(i).zfill(3)
    check1 = S.find(num[0])
    check2 = S.find(num[1],check1+1)
    check3 = S.find(num[2],check2+1)
    if check1 != -1 and check2 != -1 and check3 != -1:
        cnt += 1
print(cnt)

Solution (Python):

import sys




def solve(N: int, S: str):
    ans = 0
    for i in range(1000):
        si = format(i, '03')

        idx = 0
        for j in range(len(S)):
            if idx >= len(si):
                break
            elif si[idx] == S[j]:
                idx += 1

        if idx == len(si):
            ans += 1

    print(ans)
    
    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 = str(next(tokens))  
    solve(N, S)

if __name__ == '__main__':
    main()

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

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

ans = 0
for i in range(1000):
    pin = str(i).zfill(3)
    p = s.find(pin[0])
    if p == -1 or p >= n - 1:
        continue
    q = s.find(pin[1], p+1)
    if q == -1 or q == n - 1:
        continue
    r = s.find(pin[2], q+1)
    if r == -1:
        continue
    ans += 1

print(ans)

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

done_1 = set()
done_2 = set()
done_3 = set()
for i in range(n):
    if s[i] in done_1:
        continue
    for j in range(i+1, n):
        if s[i] + s[j] in done_2:
            continue
        for k in range(j+1, n):
            pin = s[i] + s[j] + s[k]
            done_3.add(pin)
        done_2.add(pin[:2])
    done_1.add(pin[0])
print(len(done_3))

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
s = input()
ct = 0
for p in range(1000):
    step = 0
    p = str(p).zfill(3)
    for i in range(n):
        if s[i] == p[0]:
            step += 1
            idx = i
            break
    if step == 1:
        for i in range(idx+1, n):
            if s[i] == p[1]:
                step += 1
                idx = i
                break
    if step == 2:
        for i in range(idx+1, n):
            if s[i] == p[2]:
                
                ct += 1
                break
print(ct)

Solution (Python):

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




ans = 0
for i in range(0,1000):
    number = str(i).zfill(3)
    digit = 0
    for j in s:
        if number[digit] == j:
            digit += 1
            if digit == 3:
                ans += 1
                break

print(ans)
"""
pos = [[0 for i in range(4)] for j in range(10)] 

for i in range(n):
    
    current_em = pos[int(s[i])][3]
    if current_em < 3:
        pos[int(s[i])][current_em] = i
        pos[int(s[i])][3] += 1
print(pos)
current_pos = -1
ans = 0
for i in range(10):
    if len([x for x in pos[i] if x > current_pos]) == 0:break
    current_pos = min([x for x in pos[i] if x > current_pos])
    for j in range(10):
        if len([x for x in pos[j] if x > current_pos]) == 0:break
        current_pos = min([x for x in pos[j] if x > current_pos])
        for k in range(10):
            if len([x for x in pos[k] if x > current_pos]) == 0:break
            ans += 1
print(ans)"""

Solution (Python):
from bisect import bisect
N = int(input())
S = input()
A = [[] for i in range(10)]
for i in range(N):
    s = S[i]
    A[int(s)].append(i)
for i in range(10):A[i].append(float("inf"))
ans = 0
for i in range(1000):
    s = str(i).zfill(3)
    a = A[int(s[0])][0]
    if a==float("inf"):continue
    b = A[int(s[1])][bisect(A[int(s[1])],a)]
    if b==float("inf"):continue
    c = A[int(s[2])][bisect(A[int(s[2])],b)]
    if c==float("inf"):continue
    ans+=1
print(ans)

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

N = I()
s = S()

ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      num = str(i) + str(j) + str(k)
      st = 0
      for n in num:
        for x in range(st, N):
          if s[x] == n:
            st = x+1
            break
        else:
          break
      else:
        ans += 1

print(ans)

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

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

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

for i in range(100):
    num_set = set()
    target = str(i).zfill(2)
    j = 0
    for s in S:
        if j<2 and s == target[j]:
            j += 1
        elif j==2:
            num_set.add(s)
    cnt += len(num_set)
print(cnt)

Solution (Python):
def search_substr(S, subs):
    idx = 0
    ret = False
    for s in S:
        if s == subs[idx]:
            idx += 1
            if idx == len(subs):
                ret = True
                break
                
    return ret

def solve():
    N = int(input())
    S = input()
    
    
    
    ret = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                subs = '{0}{1}{2}'.format(i,j,k)
                if search_substr(S, subs):
                    ret += 1
                    
    print(ret)
    
solve()

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

count = 0
for i in range(10):
  try:
    ii = s.index(str(i))
  except:
    continue
  for j in range(10):
    try:
      ji = s[ii + 1:].index(str(j))
    except:
      continue
    for k in range(10):
      try:
        ki = s[ii + ji + 2:].index(str(k))
        count += 1
      except:
        continue
print(count)

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

a = 0
for i in range(1000):
    i = '%03d' % i
    ss = s
    for c in i:
        p = ss.find(c)
        if p == -1:
            break
        ss = ss[p + 1:]
    else:
        a += 1

print(a)

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

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

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

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

ans = 0
for i in range(1000):
    temp = [str(i // 100), str((i // 10) % 10), str(i % 10)]
    count = 0
    for j in range(n):
        if temp[count] == s[j]:
            count += 1
        if count == 3:
            ans += 1
            break
print(ans)

Solution (Python):

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


import collections, bisect
n_indices_dict = [[] for _ in range(10)]
for i, n in enumerate(S):
    n_indices_dict[int(n)].append(i)

candidates = [(n1, n2, n3)
                for n1 in range(10)
                   for n2 in range(10)
                       for n3 in range(10)]







ret = 0
for n1, n2, n3 in candidates:
    if n_indices_dict[n1]:
        v1 = n_indices_dict[n1][0]

        if n_indices_dict[n2]:
            i2 = bisect.bisect_right(n_indices_dict[n2], v1)
            if i2 == len(n_indices_dict[n2]):
                continue

            v2 = n_indices_dict[n2][i2]
            if v1 >= v2:
                continue


            if n_indices_dict[n3]:
                i3 = bisect.bisect_right(n_indices_dict[n3], v2)
                if i3 == len(n_indices_dict[n3]):
                    continue

                v3 = n_indices_dict[n3][i3]
                if v2 >= v3:
                    continue

                ret += 1
                


print(ret)

Solution (Python):
N = int(input())
S = input()
 
cnt = [0]*11
i = 0
T = ''
for s in S:
  cnt[int(s)]+=1
  if min(cnt)<=3:
    T += s

ans = 0
P = []
for a in range(10):
  A = str(a)
  k = 0
  ind1 = -1
  while k < len(T)-2:
    t = T[k]
    if A == t:
      ind1 = k
      break
    k += 1
  if ind1 == -1:
    continue
  for b in range(10):
    B = str(b)
    l = ind1+1
    ind2 = -1
    while l < len(T)-1:
      t = T[l]
      if B == t:
        ind2 = l
        break
      l += 1
    
    if ind2 == -1:
      continue
    for c in range(10):
      C = str(c)
      m = ind2+1
      while m < len(T):
        t = T[m]
        if C == t:
          ans += 1
          break
        m += 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):
            x=s.find(str(i))
            if x!=-1:
                y=s.find(str(j),x+1)
                if y!=-1:
                    z=s.find(str(k),y+1)
                    if z!=-1:
                        ans+=1
print(ans)

Solution (Python):
n = int(input())
s = list(map(int, input()))
cnt = 0
for i1 in range(10):
    for i2 in range(10):
        for i3 in range(10):
            for i in range(n):
                if s[i]==i1: 
                    for j in range(i+1, n):
                        if s[j]==i2:
                            for k in range(j+1, n):
                                if s[k]==i3:
                                    cnt += 1
                                    
                                    break
                            break
                    break

print(cnt)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    key = str(i)
    key = "0"*(3-len(key)) + key

    cur = 0
    for s in S:
        if s == key[cur]:
            cur += 1
        if cur >= 3:
            ans += 1
            break

print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    seq = "{:03d}".format(i)
    cnt = 0
    for j in s:
        if seq[cnt] == j:
            cnt += 1
            if cnt == 3:
                break
    if cnt == 3:
        ans += 1
print(ans)

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

left = [set() for _ in range(n)]
right = [set() for _ in range(n)]

for i in range(1, n):
    x = left[i - 1].copy()
    x.add(s[i - 1])
    left[i] = x

for i in range(n - 2, -1, -1):
    x = right[i + 1].copy()
    x.add(s[i + 1])
    right[i] = x

t = [False for _ in range(1000)]
for i in range(1, n - 1):
    for c in left[i]:
        for d in right[i]:
            t[int(c + s[i] + d)] = True

print(t.count(True))

Solution (Python):
import glob
import numpy as np
import sys
import time



REL_PATH = 'smbc2019\\D'


TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):
        start_time = time.time()

        N = int(self.input_data())
        S = self.input_data()
        lucky_nums = [int(s) for s in S]

        array_first = [0 for i in range(10)]
        array_last =[0 for i in range(10)]

        for i in range(10):
            index = S.find(str(i))
            array_first[i] = index
            index = S.rfind(str(i))
            array_last[i] = index

        count = 0
        for i in range(10):
            if array_first[i] == -1:
                continue
            for j in range(10):
                if array_first[i]+1 >= array_last[j]:
                    continue
                for k in range(10):
                    if k in lucky_nums[array_first[i]+1:array_last[j]]:
                        count += 1

        print(str(count))

solver = Solver(REL_PATH)
solver.exec_resolve()

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

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

print(ans)

Solution (Python):
N = int(input())
L = list(map(int, list(input().strip())))

cnt = 0
for d1 in range(10):
    for d2 in range(10):
        for d3 in range(10):
            find1 = False
            find2 = False
            for i, n in enumerate(L):
                if not find1 and L[i] == d1:
                    find1 = True
                    continue
                if find1 and not find2 and L[i] == d2:
                    find2 = True
                    continue
                if find1 and find2 and L[i] == d3:
                    cnt += 1
                    break
print(cnt)

Solution (Python):

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1000):
        target = str(i).zfill(3)
        pointer = 0
        subS = S
        for digit in target:
            pointer = subS.find(digit)
            if pointer == -1:
                break
            else:
                subS = subS[pointer+1:]
        if pointer != -1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache




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

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i in s:
                ci=s.index(i)
                if j in s[ci+1:]:
                    cj=s[ci+1:].index(j)
                    if k in s[ci+1:][cj+1:]:
                        ans+=1
print(ans)

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

answer=0
for i in range(1000):
  i0=i//100
  i1=(i//10)%10
  i2=i%10

  flag_num=0
  for s in S:
    if flag_num==0 and s==i0:
      flag_num+=1
    elif flag_num==1 and s==i1:
      flag_num+=1
    elif flag_num==2 and s==i2:
      answer+=1
      break
      
print(answer)

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

answer=0
for i in range(1000):
  i0=i//100
  i1=(i//10)%10
  i2=i%10

  flag_num=0
  for s in S:
    if flag_num==0 and s==str(i0):
      flag_num+=1
    elif flag_num==1 and s==str(i1):
      flag_num+=1
    elif flag_num==2 and s==str(i2):
      answer+=1
      break
      
print(answer)

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

N = int(input())
S = input().rstrip('\r\n')
ans = 0
for i in range(1000):
    target = str(i).zfill(3)
    indices = [-1] * 3
    for m, c in enumerate(target):
        if m == 0:
            idx = S.find(c)
            if idx == -1:
                break
            indices[0] = idx
            continue
        for n in range(indices[m-1]+1, N):
            if c == S[n]:
                
                indices[m] = n
                break
        if indices[0] > -1 and indices[1] > -1 and indices[2] > -1:
            ans += 1
print(ans)

Solution (Python):
N = int(input())
S = str(input())
ans = 0
for i in range(1000):
  s = str(i).zfill(3)
  idx = -1
  Count = True
  for j in range(3):
    idx = S.find(s[j], idx+1)
    if idx==-1:
      Count = False
      break
  if Count:
    ans += 1
print(ans)

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

print(count)

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







count = 0


















for i in range(1000):
    v = [i // 100, (i // 10) % 10, i % 10]
    first = s[:-2].find(str(v[0]))
    if first == -1:
        continue
    second = s[first + 1:-1].find(str(v[1]))
    if second == -1:
        continue
    third = s[first + 1 + second + 1:].find(str(v[2]))
    if third == -1:
        continue
    
    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):
            tmp_number=str(i) + str(j) + str(k)
            a = S.find(tmp_number[0])
            if a == -1:
                continue
            b = S[(a+1):].find(tmp_number[1])
            
            if b == -1:
                continue
            c = S[(a+b+2):].find(tmp_number[2])
            
            if c == -1:
                continue
            count+=1
            
            
print(count)

Solution (Python):
n = int(input())
s = list(input())
numcount = [0] * 10
ans = 0
for i in s:
    numcount[int(i)] += 1
for i in range(10):
    for j in range(10):
        for k in range(10):
            c = 0
            if numcount[i] == 0 or numcount[j] == 0 and numcount[k] == 0:
                continue
            elif ((i == j or i == k) and numcount[i] <= 1) or (j == k and numcount[j] <= 1):
                continue
            elif i == j == k and numcount[i] <= 2:
                continue
            else:
                c, l = 0, 0
                m = [i, j, k]
                while True:
                    if m[l] == int(s[c]):
                        l += 1
                    c += 1
                    if l == 3:
                        ans += 1
                        break
                    if c == n:
                        break
print(ans)

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

ans = 0
for i in range(10**3):
    mm = 0
    num = str(i).zfill(3)
    for j in range(N):
        if num[mm]==S[j]:
            mm += 1
        if mm==3:
            ans += 1
            break
print(ans)

Solution (Python):
def main():
    length = int(input())
    lucky_num = input()
    answer = 0
    for i in range(1000):
        target = str(i).zfill(3)
        index = [-1, -1, -1]
        index[0] = lucky_num.find(target[0])
        if index[0] >= 0:
            index[1] = lucky_num.find(target[1], index[0] + 1)
            if index[1] > index[0]:
                index[2] = lucky_num.find(target[2], index[1] + 1)
                if index[2] > index[1]:
                    answer += 1
    print(answer)


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 = list(str(input()))
s = [int(c) for c in s]

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


ans = 0
import bisect
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i not in d or j not in d or k not in d:
                continue
            a = min(d[i])
            b = max(d[k])
            p = bisect.bisect_right(d[j], a)
            q = bisect.bisect_left(d[j], b)
            if q-p >= 1:
                ans += 1
                
print(ans)

Solution (Python):
n = int(input())
s = list(str(input()))
s = [int(c) for c in s]

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


ans = 0
import bisect
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i not in d or j not in d or k not in d:
                continue
            a = min(d[i])
            b = max(d[k])
            p = bisect.bisect_right(d[j], a)
            q = bisect.bisect_left(d[j], b)
            if q-p >= 1:
                ans += 1
                
print(ans)

Solution (Python):
n = int(input())
s = str(input())
ans = set()
for i in range(10):
    if str(i) in s:
        for j in range(10):
            if str(j) in s[s.find(str(i))+1:]:
                for k in range(10):
                    if str(k) in s[s.find(str(j), s.find(str(i))+1)+1:]:
                        ans.add((i,j,k))
print(len(ans))

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

candidates = [0 for i in range(10 ** 3)]

count = 0
for i in range(1000):
    tmp_pass = '{:03}'.format(i)

    index_0 = s.find(tmp_pass[0])
    if index_0 != -1 and index_0 < len(s) - 2:
        s_1 = s[index_0 + 1:]
        index_1 = s_1.find(tmp_pass[1])
        if index_1 != -1 and index_1 < len(s_1) - 1:
            s_2 = s_1[index_1 + 1:]
            
            
            
            
            if s_2.find(tmp_pass[2]) != -1:
                count += 1

print(count)

Solution (Python):
n = int(input())
s = str(input())
ans = set()
for i in range(10):
    if str(i) in s:
        for j in range(10):
            if str(j) in s[s.find(str(i))+1:]:
                for k in range(10):
                    if str(k) in s[s.find(str(j), s.find(str(i))+1)+1:]:
                        ans.add((i,j,k))
print(len(ans))

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

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

    first = s.find(i[0])
    if first == -1:
        continue

    second = s.find(i[1], first+1)
    if second == -1:
        continue

    third = s.find(i[2], second+1)

    if third != -1:
        ans += 1

print(ans)

Solution (Python):
n = int(input())
s = list(input())
total = 0
for i in range(1000):
  t = list(str(i).zfill(3))
  j = 0
  for c in range(len(s)):
    if (j<=len(t)-1):
      if(s[c] == t[j]):
        j += 1
  if (j == 3):
    total += 1
print(total)

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

for i in range(1000):
    str_i = '{:03}'.format(i)
    found = 0
    for s in S:
        if(s==str_i[found]):
            found += 1
            if(found == 3):
                cnt += 1
                break
print(cnt)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1000):
    tmp = str(i).zfill(3)
    count = 0
    for k in S:
        if k == tmp[count]:
            count += 1
        if 3 == count:
            ans += 1
            break
print(ans)

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

cnt = 0

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

    head = S.find(pin[0])
    middle = S.find(pin[1], head + 1)
    tail = S.find(pin[2], middle + 1)

    if head != -1 and middle != -1 and tail != -1:
        cnt += 1

print(cnt)

Solution (Python):
N = int(input())
S = input()
first_check = [0] * 10
ans = 0
for i in range(N):
    if first_check[int(S[i])] == 1:
        continue
    second_check = [0] * 10
    for k in range(i+1,N):
        if second_check[int(S[k])] == 1:
            continue
        ans += len(set(list(S[k+1:])))
        second_check[int(S[k])] = 1
    first_check[int(S[i])] = 1
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
d=dict()
for i in range(1000):
  num='0'*(3-len(str(i)))+str(i)
  if num[0] in s:
    j=s.index(num[0])
    if num[1] in s[j+1:]:
      k=s[j+1:].index(num[1])
      if num[2] in s[j+2+k:]:
        ans+=1
print(ans)

Solution (Python):
N = input()
S = input()
count = 0
for i in range(1000):
    n = "{:03d}".format(i)
    n1, n2, n3 = n[0], n[1], n[2]
    i1 = S.find(n1)
    if -1 < i1 < len(S) - 2:
        i2 = S.find(n2, i1 + 1)
        if -1 < i2 < len(S) - 1:
            i3 = S.find(n3, i2 + 1)
            if -1 < i3:
                count += 1
                continue
print(count)

Solution (Python):
N = input()
S = input()
count = 0
for i in range(1000):
    n = "{:03d}".format(i)
    n1, n2, n3 = n[0], n[1], n[2]
    i1 = S.find(n1)
    if -1 < i1 < len(S) - 2:
        S1 = S[i1 + 1:]
        i2 = S1.find(n2)
        if -1 < i2 < len(S1) - 1:
            S2 = S1[i2 + 1:]
            i3 = S2.find(n3)
            if -1 < i3:
                count += 1
                continue
print(count)