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, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    S = INPUT()

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  

N = I()
S = LI2()
ans = 0
for i in range(1000):
    x = str(i).zfill(3)
    X = [int(x[0]),int(x[1]),int(x[2])]
    j = 0
    k = 0
    while j < N:
        if S[j] == X[k]:
            if k == 2:
                ans += 1
                break
            else:
                k += 1
        j += 1

print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
alist=[0]*10
for i in range(n):
  alist[int(s[i])]=i
for i in range(10):
  flag1=False
  for a in range(n-2):
    if s[a]==str(i):
      flag1=True
      break
  if flag1:
    for j in range(10):
      flag2=False
      for b in range(a+1,n-1):
        if s[b]==str(j):
          flag2=True
          break
      if flag2:
        for k in range(10):
          if b<alist[k]:
            ans+=1
print(ans)

Solution (Python):
def is_passcode_exist(S,passcode):
    passcode_idx = 0
    passcode_is_exist = False
    for c in S:
        if passcode_idx == 3:
            passcode_is_exist = True
            break
        if passcode[passcode_idx] == c:
            passcode_idx += 1
    if passcode_idx == 3:
        passcode_is_exist = True
    return passcode_is_exist

if __name__ == "__main__":
    N = int(input())
    S = input()
    count = 0
    for i in range(0,1000):
        if is_passcode_exist(S,str(i).zfill(3)):
            count += 1
    print(count)

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

ans=0
for i in range(10):
    if str(i) in s:
        first=s.index(str(i))
        ss=s[first+1:]
        for j in range(10):
            if str(j) in ss:
                sec=ss.index(str(j))

                for k in range(10):
                    if str(k) in ss[sec+1:]:
                        ans+=1

print(ans)

Solution (Python):
N = int(input())
S = input()
S1 = S
Comb = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            S = S1
            a, b, c = map(str, [i, j, k])
            if S.find(a) != -1:
                S = S[S.find(a)+1::]
                if S.find(b) != -1:
                    S = S[S.find(b)+1::]
                    if S.find(c) != -1:
                        Comb += 1
print(Comb)

Solution (Python):
N = int(input())
S = input()
'''
Editorialのヒントを参照しました。
000 ~ 999の実現可能性を考えます。
'''
L = []
s = ''
Comb = 0
key_k = False
for i in range(0, 10):
    for j in range(0, 10):
        if key_k is not True:
            s += str(j)
        else:
            s += str(i)
            s += str(j)
            key_k = False
        for k in range(0, 10):
            s += str(k)
            L.append(s)
            s = ''
            s += str(i)
            s += str(j)
        s = ''
        key_k = True
L.remove(L[0])
L.append('000') 
S_copy = S
A = []
for el in L:
    c0 = el[0]
    c1 = el[1]
    c2 = el[2]
    S = S_copy
    N0 = S.find(c0)
    if N0 == -1:
        continue
    else:
        S = S[N0+1::]
        N1 = S.find(c1)
        if N1 == -1:
            continue
        else:
            S = S[N1+1::]
            N2 = S.find(c2)
            if N2 == -1:
                continue
            else:
                Comb += 1
print(Comb)

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            s = ["0", "0", "0"]
            s[0] = str(i)
            s[1] = str(j)
            s[2] = str(k)

            ind = 0
            cnt = 0
            while cnt < 3 and ind < N:
                if S[ind] == s[cnt]:
                    cnt += 1
                ind += 1

                if cnt == 3:
                    ans += 1

print(ans)

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

ans = 0
for i in range(1000):
    s = ["0", "0", "0"]
    s[0] = str(i // 100)
    s[1] = str((i//10) % 10)
    s[2] = str(i % 10)

    ind = 0
    cnt = 0
    while cnt < 3 and ind < N:
        if S[ind] == s[cnt]:
            cnt += 1
        ind += 1

        if cnt == 3:
            ans += 1

print(ans)

Solution (Python):
import itertools
n = int(input())
s = list(input())
a = ['0','1','2','3','4','5','6','7','8','9']
cnt=0
for i in list(itertools.product(a, repeat=3)):
  d =0
  e =0
  while d < n:
    if s[d] == i[e]:
      e+=1
    d+=1
    if e==3:
      cnt+=1
      break
print(cnt)

Solution (Python):
n = int(input())
s = list(input())
a = ['0','1','2','3','4','5','6','7','8','9']
g = []
for i in a:
  for j in a:
    for k in a:
      g.append([i,j,k])
cnt=0
for i in g:
  d =0
  e =0
  while d < n:
    if s[d] == i[e]:
      e+=1
    d+=1
    if e==3:
      cnt+=1
      break
print(cnt)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
ans = 0
for i in range(1000):
    t1, t2, t3 = list("00" + str(i))[-3:]
    f1, f2, f3 = False, False, False
    for j in range(n):
        if not f1 and s[j] == t1:
            f1 = True
        elif f1 and not f2 and s[j] == t2:
            f2 = True
        elif f2 and not f3 and s[j] == t3:
            f3 = True

    if f3:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
d=[[30005,-1] for i in range(10)]
ans=set([])
for i in range(n):
    p=int(s[i])
    if d[p][0]==30005:
        d[p][0]=i
        d[p][1]=i
    else:
        d[p][1]=i

for i in range(1,n-1):
    for j in range(10):
        if d[j][0]<i:
            for k in range(10):
                if d[k][1]>i:
                    ans.add(str(j)+str(s[i])+str(k))

print(len(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):
      p,q,r=str(i),str(j),str(k)
      if p in S:
        x=S.index(p)
        S_=S[x+1:]
        if q in S_:
          y=S_.index(q)
          S__=S_[y+1:]
          if r in S__:
            ans+=1
print(ans)

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

passwords = [str(i).zfill(3) for i in range(1000)]
for pw in passwords:
    S_copy = S
    for digit in pw:
        try:
            S_copy = S_copy[S_copy.index(digit)+1:]
        except ValueError:
            break
    else:
        ans += 1

print(ans)

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



s = list(input())
ans = 0


for i in range(1000):
    t = ''
    t += str(i % 10)
    t += str((i//10) % 10)
    t += str(i//100)
    t = t[::-1]
    i = 0
    j = 0
    while i < n and j < 3:
        if s[i] == t[j]:
            j += 1
        i += 1
    if j == 3:
        ans += 1
print(ans)

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

num1, num2, num3 = set(), set(), set()
for i in range(n):
    if s[i] in num1:
        continue
    num1.add(s[i])
    for j in range(i + 1, n):
        tmp2 = s[i] + s[j]
        if tmp2 in num2:
            continue
        num2.add(tmp2)
        for k in range(j + 1, n):
            num3.add(tmp2 + s[k])
print(len(num3))

Solution (Python):
N, S = open(0).read().split()
S = list(map(int, list(S)))
N = int(N)

cnt = 0
for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                try:
                    n = S.index(i)
                    m = S[n+1:].index(j)
                    o = S[n+m+2:].index(k)
                    cnt += 1
                except ValueError:
                    pass
print(cnt)

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):
                i_index = S.find(str(i))
                if i_index == -1:
                    continue

                j_index = S.find(str(j), i_index + 1)
                if j_index == -1:
                    continue

                k_index = S.find(str(k), j_index + 1)
                if k_index != -1:
                    ans += 1

    print(ans)


if __name__ == "__main__":
    main()

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):
                i_index = S.find(str(i))
                j_index = S.find(str(j), i_index + 1)
                k_index = S.find(str(k), j_index + 1)
                if i_index != -1 and j_index != -1 and k_index != -1:
                    ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    s = input()
    one_set = set([])
    two_set = set([])
    three_set = set([])

    count = 0
    for i in range(n):
        if i==0:
            one_set.add(s[0])
            continue

        if 2<=i:
            for two in two_set:
                if two + s[i] not in three_set:
                    three_set.add(two + s[i])
                    count+=1

        for one in one_set:
            two_set.add(one + s[i])
        one_set.add(s[i])

    print(count)

if __name__=="__main__":
    main()

Solution (Python):
n = int(input())
S = input()
ans = 0
def ok(i):
    v = str(i).zfill(3)
    j = 0
    for s in S:
        if s == v[j]:
            j += 1
            if j == 3:
                return True
    else:
        return False

for i in range(1000):
    ans += ok(i)
print(ans)

Solution (Python):
import re

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

cnt = 0
for i in range(10):
    fir = S.find(str(i))
    if fir == -1:
        continue
    for j in range(10):
        sec = S.find(str(j), fir + 1)
        if sec == -1:
            continue
        for h in range(10):
            thi = S.find(str(h), sec + 1)
            if thi == -1:
                continue
            cnt += 1
print(cnt)

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


count = 0
for i in range(1000):
  if i < 100:
    target_1 = "0"
    if i < 10:
      target_2 = "0"
      target_3 = str(i)
    else:
      target_2 = str(i)[0]
      target_3 = str(i)[1]
  else:
    target_1 = str(i)[0]
    target_2 = str(i)[1]
    target_3 = str(i)[2]
  
  step = 1
  for j in range(N):
    if S[j] == target_1 and step == 1:
      step = 2
      pass
    
    elif S[j] == target_2 and step == 2:
      step = 3
      
    elif S[j] == target_3 and step == 3:
      count += 1
      break

print(count)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
s=list(map(int,list(SI())))
pos=[[-1,-1] for i in range(10)]
for i in range(n):
    j=n-i-1
    if pos[s[i]][0]==-1:
        pos[s[i]][0]=i
    if pos[s[j]][1]==-1:
        pos[s[j]][1]=j

count=0
for i in range(10):
    for j in range(10):
        lis=[0 for i in range(10)]
        if pos[i][0]<0 or pos[j][0]<0:
            continue
        for k in range(pos[i][0]+1,pos[j][1]):
            lis[s[k]]+=1
        for l in range(10):
            if lis[l]>0:
                count+=1
print(count)

Solution (Python):
n = int(input())
s = input()
s1, s2, s3 = set(), set(), set()
for i in s:
    for j in s2:
        s3.add(j+i)
    for j in s1:
        s2.add(j+i)
    s1.add(i)
print(len(s3))

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

    for i in range(1000):
        
        
        pin = f'{i:0>3}'

        
        p1 = s.find(pin[0])

        if p1 != -1:
            p2 = s.find(pin[1], p1 + 1)
            if p2 != -1:
                p3 = s.find(pin[2], p2 + 1)
                if p3 != -1:
                    ans += 1

    print(ans)

if __name__ == '__main__':
    sumitrust2019_d_01()

Solution (Python):
import sys
import math


sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
S = input()

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

print(ans)

Solution (Python):
N = int(input())
S = input()
S1 = set([])
S2 = set([])
S3 = set([])
for i in S:
    for s3 in S2:
        S3.add(s3+i)
    for s2 in S1:
        S2.add(s2+i)
    S1.add(i)
print(len(S3))

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

    ans = 0

    for i in range(1000):
        
        
        current_digit = 0
        pin = f'{i:0>3}'
        search_num = pin[current_digit]

        for num in s:
            
            
            
            if num == search_num:
                current_digit += 1

                
                if current_digit == 3:
                    ans += 1
                    break
                
                elif current_digit < 3:
                    search_num = pin[current_digit]

    print(ans)

if __name__ == '__main__':
    sumitrust2019_d()

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

    ans = 0

    for i in range(1000):
        
        
        current_digit = 0
        pin = f'{i:0>3}'
        search_num = pin[current_digit]

        for num in s:
            
            
            
            if num == pin[current_digit]:
                current_digit += 1

                
                if current_digit == 3:
                    ans += 1
                    break
                
                elif current_digit < 3:
                    search_num = pin[current_digit]

    print(ans)

if __name__ == '__main__':
    sumitrust2019_d()

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

ans = 0

for i in range(1000):
    
    current_digit = 0
    pin = f'{i:0>3}'
    
    k = pin[current_digit]

    for num in s:
        
        if num == k:
            current_digit += 1
            
            if current_digit <= 2:
                k = pin[current_digit]

            elif current_digit == 3:
                ans += 1
                break

print(ans)

Solution (Python):
N = int(input())
S = list(map(int, input()))
ans = 0
first = [0] * 10
a = 0
for i in range(N):
  if first[S[i]] == 0:
    first[S[i]] = 1
    a += 1
    second = [0] * 10
    b = 0
    for j in range(i+1, N):
      if second[S[j]] == 0:
        second[S[j]] = 1
        b += 1
        third = [0] * 10
        c = 0
        for k in range(j+1, N):
          if third[S[k]] == 0:
            third[S[k]] = 1
            ans += 1
            c += 1
            if c == 10:
              break
        if b == 10:
          break
    if a == 10:
      break
print(ans)

Solution (Python):
N = int(input())
S = list(input())
ans = 0
for x in range(1000) :
    X = list(str(x).zfill(3))
    i = 0
    j = 0
    if X[0] in S[:N-2] :
        i = S.index(X[0])
    else :
        continue
    if X[1] in S[i+1:N-1] :
        j = S[i+1:N-1].index(X[1])+i+1
    else :
        continue
    if X[2] in S[j+1:N] :
        ans += 1
                        
print(ans)

Solution (Python):
N = int(input())
S = list(input())
sumi, result = [], 0
while len(sumi)<10 and N>0:
  x = S.pop(0)
  N -= 1
  if x in sumi:
    continue
  sumi.append(x)
  sumi_2, i = [], 0
  for i in range(N-1):
      s = S[i]
      if s in sumi_2:
        continue
      sumi_2.append(s)
      result += len(set(S[i+1:]))
print(result)

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

for i in range(10):
    x100 = S.find(str(i))
    if x100 == -1:
        continue
    for j in range(10):
        x10 = S.find(str(j), x100 + 1)
        if x10 == -1:
            continue
        for k in range(10):
            if S.find(str(k), x10 + 1) != -1:
                cnt += 1

print(cnt)

Solution (Python):


def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    S = input()

    return N, S


def main(N: int, S: str) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 桁数(4 <= N <= 30000)
        S (str): ラッキーナンバー(半角数字からなる長さNの文字列)
    """
    
    ans = 0
    S_i_list = []
    for i in range(N - 2):
        S_i = S[i]
        if S_i in S_i_list:
            continue
        S_j_list = []
        for j in range(i + 1, N - 1):
            S_j = S[j]
            if S_j in S_j_list:
                continue
            ans += len(set(S[j + 1: N]))
            S_j_list.append(S_j)
        S_i_list.append(S_i)

    
    print(ans)


if __name__ == "__main__":
    
    N, S = get_input()

    
    main(N, S)

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

S = set()
cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            dig = 1
            t = str(i)+str(j)+str(k)

            for r in range(n):
                if dig == 1 and t[0] == s[r]:
                    dig +=1

                elif dig == 2 and t[1] == s[r]:
                    dig +=1
                    
                elif dig == 3 and t[2] == s[r]:
                    S.add(t)

print(len(S))

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

cnt = 0

for i in range(10):
    x100 = S.find(str(i))
    if x100 == -1:
        continue
    for j in range(10):
        x10 = S.find(str(j), x100 + 1)
        if x10 == -1:
            continue
        for k in range(10):
            if S.find(str(k), x10 + 1) != -1:
                cnt += 1
print(cnt)

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

cnt = 0

for i in range(1000):
    if 0 <= i < 10:
        a = "00" + str(i)
    elif 10 <= i < 100:
        a = "0" + str(i)
    elif 100 <= i:
        a = str(i)
    
    idx = 0
    for j in range(N):
        if S[j] == a[idx]:
            idx += 1
            if idx == 3:
                cnt += 1
                break

print(cnt)

Solution (Python):


import sys
stdin = sys.stdin
from itertools import product

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    s = ns()
    ans = 0

    for a in product(range(10), repeat=3):
        i = 0
        for si in s:
            if int(si) == a[i]:
                i += 1
            if i == 3:
                ans += 1
                break
    print(ans)

if __name__ == "__main__":
    main()

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

for i in range(0, 1000):
    count = 0
    val = list(str(i).zfill(3))
    k = val[count]
    for j in s:
        if j == k:
            count += 1
            if count <= 2:
                k = val[count]
            elif count == 3:
                ans += 1
                break
print(ans)

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

pin = []
cnt = 0

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


for i in range(0, 1000):
    k = 0
    for j in range(len(s)):
        if pin[i][k] == s[j]:
            k += 1
            if k == 3:
                cnt += 1
                break
                
print(cnt)

Solution (Python):
import copy
import math
import time
 

def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

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

def get_string_char_list():
    return list(str(input()))




'''
while (idx < n) and ():
 
    idx += 1
'''
 
def main():
    start = time.time()
 
    n = get_int()
    s_list = get_string_char_list()
    s_list = [int(x) for x in s_list]
 
    
    
 
    
 
    
    
    
    
 
    
 
    ans = 0
 
    for i in range(0, 1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
 
        find_a = False
        find_b = False
        for ii in s_list:
 
            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):
 
                ans += 1
                break
    print(ans)
 
    
 
if __name__ == '__main__':
    main()

Solution (Python):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
s = S()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    if s.find(num[0]) == -1:
        continue
    s1 = s[s.find(num[0])+1:]
    if s1.find(num[1]) == -1:
        continue
    s2 = s1[s1.find(num[1])+1:]
    if s2.find(num[2]) == -1:
        continue
    ans+=1
print(ans)

Solution (Python):
N=int(input())
S=input()
S=list(map(int,S))
ans=0
for s in range(1000):
      A=s//100
      B=(s-A*100)//10
      C=s-A*100-B*10
      isOne=0
      isTen=0
      isHundred=0
      for i in range(N) :
        if isOne==0:
          if S[i]==A: 
            isOne=1
        elif isTen==0:
          if S[i]==B: 
            isTen=1
        elif isHundred==0:
          if S[i]==C:
            isHundred=1
            ans+=1
        else:
          break

print(ans)

Solution (Python):
import copy
import math
import time


def get_int():
    return int(input())

def get_string():
    return input()

def get_int_list():
    return [int(x) for x in input().split()]

def get_string_list():
    return input().split()

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

def get_string_char_list():
    return list(str(input()))




'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()

    n = get_int()
    s_list = get_string_char_list()
    s_list = [int(x) for x in s_list]

    
    

    

    
    
    
    

    

    ans = 0

    for i in range(0, 1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10

        find_a = False
        find_b = False
        for ii in s_list:

            if (find_a == False) and (ii == a):
                find_a = True
            elif (find_a == True) and (find_b == False) and (ii == b):
                find_b = True
            elif (find_b == True) and (ii == c):

                ans += 1
                break
    print(ans)

    

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

def solve():     
    N = int(input())
    S = input()
    l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    p = itertools.product(l,repeat=3)
    count = 0
    for v in p:
        S_temp = S
        dig_0_index = S_temp.find(v[0])
        if dig_0_index != -1:
            S_temp = S_temp[dig_0_index+1::]
            dig_1_index = S_temp.find(v[1])
            if dig_1_index != -1:
                S_temp = S_temp[dig_1_index+1::]
                dig_2_index = S_temp.find(v[2])
                if dig_2_index != -1:
                    count += 1
    print(count)

if __name__ == "__main__":
    solve()

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

count=0

for i in range(0,10):
    if str(i) in s[:-2]:
        index_1=s.index(str(i))

        for j in range(0,10):
            if str(j) in s[index_1+1:-1]:
                index_2=s[index_1+1:-1].index(str(j))+index_1+1

                for k in range(0,10):
                    if str(k) in s[index_2+1:]:
                        count+=1
print(count)

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

sapp = [[0] * n for _ in range(10)]
for idx, s in enumerate(S):
    sapp[int(s)][idx] = 1

from itertools import accumulate
sacc = [list(accumulate(sa)) for sa in sapp]

pins = set()
for i in range(1, n-1):
    for lnum in range(10):
        if sacc[lnum][i-1] == 0:
            continue
        for rnum in range(10):
            
            rnumc = sacc[rnum][-1] - sacc[rnum][i]
            if rnumc > 0:
                pins.add(100*lnum + 10*int(S[i]) + rnum)

print(len(pins))

Solution (Python):
n = int(input())
s = list(input())
ans = 0
for i in range(1000):
    pin = list(str(i).zfill(3))
    idx = 0
    for c in s:
        if c == pin[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break
print(ans)

Solution (Python):

import sys
from copy import deepcopy
input = sys.stdin.readline


def RD(): return input().rstrip()
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))

def main():
    d = [[]]*10
    keta = I()
    num = input().rstrip()
    for i in range(keta):
        temp = int(num[i])
        if len(d[temp]) == 0:
            d[temp] = [int(keta-i)]
        else:
            d[temp].append(int(keta-i))
    result = 0
    for j in range(1000):
        a = j // 100
        b = (j % 100) // 10
        c = ((j % 100) % 10)
        try:
            a_num = d[a][0]
        except:
            continue
        try:
            if a == b:
                b_num = d[b][1]
            else:
                index = 0
                while True:
                    b_num = d[b][index]
                    if b_num < a_num:
                        break
                    else:
                        index += 1
        except:
            continue
        try:
            if a == c and a == b:
                c_num = d[c][2]
            elif a == c or b == c:
                c_num = min(d[c][1:])
            else:
                c_num = min(d[c])
        except:
            continue
        if a_num > b_num and b_num > c_num:
            result += 1

    print(result)

if __name__ == "__main__":
    main()

Solution (Python):

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

ans = 0
for n in range(1000):
    target = "{:03}".format(n)
    j = 0
    for i in range(N):
        if S[i] == target[j]:
            j += 1
        if j == 3:
            ans += 1
            break

print(ans)

Solution (Python):
n = int(input())
S = input()
ans = 0
nums = list(map(str, range(10)))
for i in nums:
    s1 = S.find(i)
    if s1 < 0:
        continue
    for j in nums:
        s2 = S.find(j, s1+1)
        if s2 < 0:
            continue
        for k in nums:
            s3 = S.find(k, s2+1)
            if s3 > 0:
                ans += 1
print(ans)

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

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

Solution (Python):
from itertools import product

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

for i in product(range(10), repeat = 3):
    a = s.find(str(i[0]))
    if a != -1 and a != n - 1:
        b = s[a + 1:].find(str(i[1]))
        if b != -1:
            b += a + 1
            if b != n - 1:
                c = s[b + 1:].find(str(i[2]))
                if c != -1:
                    ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000):
    i=str(i).zfill(3)
    a=0
    for c in s:
        if c==i[a]:
            a+=1
        if a==3:
            ans+=1
            break
print(ans)

Solution (Python):
N = int(input())
S = input()
pattern = [False] * 1000

for i in range(1000):
    str_i = str(i)
    str_i = str_i.zfill(3)
    now = 0
    for c in S:
        if c == str_i[now]:
            now += 1
        if now == 3:
            pattern[i] = True
            break
print(sum(pattern))

Solution (Python):
n=int(input())
s=[int(x) for x in list(input())]
ans=0
for a in range(10):
  for i in range(n):
    if s[i]==a:
      a_dx=i
      break
  else:
    continue
  for b in range(10):
    for i in range(a_dx+1,n):
      if s[i]==b:
        b_dx=i
        break
    else:
      continue
    for c in range(10):
      for i in range(b_dx+1,n):
        if s[i]==c:
          ans+=1
          break
      else:
        continue

print(ans)

Solution (Python):
def input_li():
    return list(map(int, input().split()))


def input_int():
    return int(input())


N = input_int()
S = input()
ans = 0
for i in range(1000):
    str_i = str(i)
    s = '0' * (3 - len(str_i)) + str_i
    idx = 0
    for j in range(N):
        if S[j] == s[idx]:
            idx += 1
            if idx == 3:
                ans += 1
                break
print(ans)