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 math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    s = readline().rstrip()
    cnt = 0
    for i in range(1000):
        x = str(i).zfill(3)
        a = s[:-1].find(x[0])
        if a != -1:
            b = s[a + 1: -1].find(x[1])
            if b != -1:
                c = s[a + b + 2:].find(x[2])
                if c != -1:
                    cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

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

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

print(result)

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = [_ for _ in input()][::-1]

a = set()
ans=0
ii = set()
for i in range(n-2):
  if s[i] in ii:
    continue
  ii.add(s[i])
  jj = set()
  for j in range(i+1,n-1):
    if s[j] in jj:
      continue
    jj.add(s[j])
    kk = set()
    for k in range(j+1,n):
      if k not in kk:
        ans+=1
        kk.add(s[k])
        a.add(''.join([s[k],s[j],s[i]]))
    
print(len(a))

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

score = 0

for p in range(1000):
    
    pw = str(p).zfill(3)
    
    start = 0
    n_match = 0
    
    for j in range(3):
        for i in range(start, len(s)):
            
            if s[i] == pw[j]:
                start = i+1
                n_match = n_match+1
                
                if j == 3-1:
                    
                    score = score+1
                
                break
        if n_match <= j:
            break
            
print(score)

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):
from math import ceil
N = int(input())
S = input()
ans = [0]*1000
one = [0]*10
two = [0]*100

for s in S:
    s = int(s)
    for i in range(10):
        for j in range(10):
            if two[i*10+j]//1:
                ans[i*100+j*10+s] = 1 
            else:
                if one[i]//1 and two[i*10+s] == 0:
                    two[i*10+s] = 0.5
                elif one[s] == 0:
                    one[s] = 0.5        
    one = list(map(lambda x: ceil(x), one))
    two = list(map(lambda x: ceil(x), two))

print(sum(ans))

Solution (Python):
from math import ceil
N = int(input())
S = input()
ans = [0]*1000
one = [0]*10
two = [0]*100

for s in S:
    s = int(s)
    for i in range(10):
        for j in range(10):
            if two[i*10+j]//1:
                ans[i*100+j*10+s] = 1 
            else:
                if one[i]//1 and two[i*10+s] == 0:
                    two[i*10+s] = 0.5
                elif one[s] == 0:
                    one[s] = 0.5        
    one = list(map(lambda x: ceil(x), one))
    two = list(map(lambda x: ceil(x), two))

print(sum(ans))

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8').strip()
    ans = 0
    for i in range(10):
        x = S.find(str(i), 0, N - 2)
        if x != -1:
            for j in range(10):
                y = S.find(str(j), x + 1, N - 1)
                if y != -1:
                    for k in range(10):
                        z = S.find(str(k), y + 1, N)
                        if z != -1:
                            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = input()
ans = 0
lis = [0]*1000
one = [0]*10
two = [0]*100

for i in range(n):
  temp1 = int(s[i])
  if one[temp1]==1:
    continue
  else:
    one[temp1]=1
 
  for j in range(i+1, n):
    temp2 =  int("".join([s[i], s[j]]))
    if two[temp2]==1:
      continue
    else:
      two[temp2]=1
    
    for k in range(j+1, n):
      pin=int("".join([s[i], s[j], s[k]]))
      if lis[pin]==0:
        ans+=1
        lis[pin]=1
print(ans)

Solution (Python):
n = int(input())
s = input()
cou = 0
for i in range(1000):
  i = "{0:03d}".format(i)
  t = 0
  r = 0
  while r!=n:
    if s[r]==i[t]:
      t += 1
    if t==3:
      cou += 1
      r = n-1
    r += 1            
print(cou)

Solution (Python):
N = int(input())
S = input()
ans = 0
 
numlist = [str(i) for i in range(10)]
for a in numlist:
    idx_a = S.find(a)
    if idx_a == -1 or idx_a >= N - 2:
        continue
    
    for b in numlist:
        idx_b = S[idx_a+1:].find(b)
        if idx_b == -1 or idx_a + idx_b + 1 >= N - 1:
            continue
        
        for c in numlist:
            if c in S[idx_a + idx_b + 2:]:
                ans += 1
print(ans)

Solution (Python):


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

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    first = S.find(key[0])
    if first == -1:
        continue
    second = S[first + 1:].find(key[1])
    if second == -1:
        continue
    third = S[first + second + 2:].find(key[2])
    if not third == -1:
        
        ans += 1
print(ans)

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

N = int(input())
S = input()
sl = list(S)
setS = set(S)
ans = 0
for i in range(10):
    if str(i) not in setS:
        continue
    else:
        i100_ind = sl.index(str(i))
        S10 =sl[i100_ind+1:-1]
        S10set = set(S10)
        for j in range(10):
            if str(j) not in S10set:
                continue
            else:
                i10_ind = S10.index(str(j))
                S1 = S10[i10_ind+1:]
                S1.append(sl[-1])
                ans += len(set(S1))
print(ans)

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

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      if i in S:
        a = S.index(i)
        if j in S[a+1:]:
          b = S[a+1:].index(j) + a + 1
          if k in S[b+1:]:
            ans += 1
          else:
            continue
        else:
          continue
      else:
        continue

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, 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
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

N = input()
S = input()

ans = 0

for i in range(1000):
    x = str(i).zfill(3)
    idx = 0
    for s in S:
        if x[idx] == s:
            idx += 1
        if idx == 3:
            break
    if idx == 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, radians
from itertools import accumulate, permutations, combinations, 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
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

N = input()
S = input()

ans = 0

for i in range(1000):
    x = str(i).zfill(3)
    begin_idx = -1
    idx = 0
    while idx <= 2:
        begin_idx = S.find(x[idx], begin_idx+1)
        if begin_idx == -1:
            break
        idx += 1
    else:
        ans += 1
print(ans)

Solution (Python):

N=int(input())
S=list(input())
numlist=range(1000)
ans=0

for i in numlist:
    num=str(i)
    if len(num)==1:
        num="00"+num
    if len(num)==2:
        num="0"+num
    if num[0] in S[:N-1]:
        num1=S.index(num[0])
        if num[1] in S[num1+1:N-1]:
            S2=S[num1+1:N-1]
            num2=S2.index(num[1])+num1+1
            if num[2] in S[num2+1:]:
                ans+=1
print(ans)

Solution (Python):
n = int(input())
s = input()
ans = []
first = []
for i in range(n - 2):
    if s[i] in first:continue
    first.append(s[i])
    second = []
    for j in range(i + 1, n - 1):
        if s[j] in second:continue 
        second.append(s[j])
        third = []
        for k in range(j + 1, n):
            if s[k] in third:continue  
            third.append(s[k])
            ans.append(s[i] + s[j] + s[k])
            
print(len(ans))

Solution (Python):
import collections
N = int(input())
S = input()
S_list = [S[i] for i in range(N)]
S_c = collections.Counter(S_list)
list12 = []
list1 = []

ans = 0
for i in range(N-2):
    s1 = S_list[i]

    S_c[s1] = S_c[s1]-1
    if s1 in list1:
        continue

    S_c23 = S_c.copy()
    list1.append(s1)
    for j in range(i+1,N-1):
        s2 = S_list[j]
        
        S_c23[s2] = S_c23[s2] - 1
        if (s1+s2) in list12:
            continue
        else:
            list12.append(s1+s2)
            for key in S_c23.keys():
                if S_c23[key] != 0:
                    ans+=1
print(ans)

Solution (Python):
import sys
from itertools import product


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    s = input().strip().decode()
    ans = 0
    for p in product(range(10), repeat=3):
        matched = 0
        for i in range(n):
            if s[i] == str(p[matched]):
                matched += 1
            if matched == 3:
                ans += 1
                break
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from itertools import product


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    s = input().strip().decode()
    ans = 0
    for p in product(range(10), repeat=3):
        pointer = 0
        for c in map(str, p):
            while pointer < n:
                if s[pointer] == c:
                    pointer += 1
                    break
                pointer += 1
            else:
                break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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



S=list(input())
d=list('0123456789')
ans=0
for d1 in d:
    for d2 in d:
        for d3 in d:
            v=d1+d2+d3
            i=0
            p=0
            while i < N :
                if v[p]==S[i]:
                    p+=1
                    if p == 3:
                        break
                i+=1
            if p==3 :
                ans+=1
print(ans)

Solution (Python):

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

count = 0
for N in range(1000):
    password = list(f"{N:03d}")
    i = 0
    p = password[i]
    for x in S:
        if x == p:
            if i < 2:
                i += 1
                p = password[i]
            else:
                count += 1
                break

print(count)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
def snx(s, target=None, reverse=False, loop=False):
    """文字列sの各要素について、cがiより→で最初に現れる位置n[i][c]
    loop=Trueのとき周回した先のインデックスまで求める
    """
    if target is None:
        target = [chr(v) for v in range(ord("a"), ord("z")+1)]
    d = {c:None for c in target}
    nx = [[None]*len(target) for _ in range(len(s))]
    if not reverse:
        i = len(s)-1
        for c in reversed(s):
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i -= 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[0][j]
    else:
        i = 0
        for c in s:
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i += 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[-1][j]
    return nx
nx = snx(s, target=list(map(str, range(10))))
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            try:
                if nx[0][i] is not None and nx[nx[0][i]+1][j] is not None and nx[nx[nx[0][i]+1][j]+1][k] is not None:

                    ans += 1
            except IndexError:
                pass
print(ans)

Solution (Python):
n=int(input())
s=input()
from itertools import product

cnt=0
for i,j in product("0123456789",repeat=2):
    try:
        ind_i=s.index(i)
    except:
        continue
    try:
        ind_j=s.rindex(j)
    except:
        continue
    if ind_i>ind_j:
        continue
    for k in "0123456789":
        cnt+=(k in s[ind_i+1:ind_j])
        
print(cnt)

Solution (Python):

import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
s = S()
ciphers = [f'{i:03}' for i in range(1000)]
ans = 0
for v in ciphers:
    j = 0
    for i in range(n):
        if s[i] == v[j]:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)

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

for N in range(1000):
    tgt = str(N).zfill(3)
    if tgt[0] in s:
        i = s.index(tgt[0])
        if tgt[1] in s[i+1:]:
            j = s[i+1:].index(tgt[1]) + i
            if tgt[2] in s[j+2:]:
                cnt += 1
print(cnt)

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):
            c = s.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)

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

for N in range(1000):
    tgt = str(N).zfill(3)
    if tgt[0] in s:
        i = s.index(tgt[0])
        if tgt[1] in s[i+1:]:
            j = s[i+1:].index(tgt[1]) + i
            if tgt[2] in s[j+2:]:
                cnt += 1
print(cnt)

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

ans = 0

for i in range(1000):
    t = str(i)
    t = t.zfill(3)
    now = t[0]
    count = 0
    for j in S:
        if count == 0 and now == j:
            now = t[1]
            count += 1
            continue
        if count == 1 and now == j:
            now = t[2]
            count += 1
            continue
        if count == 2 and now == j:
            ans += 1
            break

print(ans)

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

Solution (Python):
n=int(input())
s=list(input())
ans=0
for i in range(10):
  for j in range(10):
    for k in range(10):
      x=[str(i),str(j),str(k)]
      cnt=0
      for y in range(len(s)):
        if s[y]==x[cnt]:
          cnt+=1
        if cnt==3:
          ans+=1
          cnt+=1
          break
print(ans)

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

    for i in range(1000):
        c = [int(i / 100), int(i / 10) % 10, int(i % 10)]
        f = 0

        for j in range(N):
            if S[j] == ('0' + str(c[f])) or S[j] == str(c[f]):
                f += 1
            if f == 3:
                break

        if f == 3:
            cnt += 1
    print(cnt)
    return

resolve()

Solution (Python):
N=int(input())
S=input()
ans=0
for i in range(1000):
  l=[]
  for j in range(3):
    l.append(i//10**(2-j)%10)
  k=0
  for j in range(N):
    if int(S[j])==l[k]:
      k+=1
      if k==3:
        ans += 1
        break
print(ans)

Solution (Python):


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

def kanou(s, i1, i2, i3):
    target = [i1, i2, i3]
    target_iter = target.__iter__()
    now = next(target_iter)
    for c in s:
        if c == now:
            try:
                now = next(target_iter)
            except StopIteration:
                return True
    return False

res = 0
for i in range(0, 1000):
    if i <= 9:
        i1 = "0"
        i2 = "0"
        i3 = str(i)
    elif i <= 99:
        tmp = str(i)
        i1 = "0"
        i2 = tmp[0]
        i3 = tmp[1]
    else:
        tmp = str(i)
        i1 = tmp[0]
        i2 = tmp[1]
        i3 = tmp[2]
    if kanou(S, i1, i2, i3):
        res += 1

print(res)

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

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

print(cnt)

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

result = 0
for i in range(0, 1000):
    number = ''.join(['00', str(i)])[-3:]
    number_i = 0
    for s in S:
        if number[number_i] == s:
            number_i += 1
            if number_i == 3:
                result += 1
                break

print(result)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
l=[0]*1000
for _ in range(n):
    i=s[_]
    for j in range(1000):
        k=str(j).zfill(3)
        if k[0]==i and l[j]==2:
            l[j]=3
        if k[1]==i and l[j]==1:
            l[j]=2
        if k[2]==i and l[j]==0:
            l[j]=1
ans=0
for i in l:
    if i==3:
        ans+=1
print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
l=[0]*1000
for _ in range(n):
    i=s[_]
    for j in range(1000):
        k=str(j).zfill(3)
        if k[0]==i:
            if l[j]==2:
                l[j]=3
        if k[1]==i:
            if l[j]==1:
                l[j]=2
        if k[2]==i:
            if l[j]==0:
                l[j]=1
ans=0
for i in l:
    if i==3:
        ans+=1
print(ans)

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

numlist = [str(i) for i in range(10)]
for a in numlist:
    idx_a = S.find(a)
    if idx_a == -1 or idx_a >= N - 2:
        continue
    
    for b in numlist:
        idx_b = S[idx_a+1:].find(b)
        if idx_b == -1 or idx_a + idx_b + 1 >= N - 1:
            continue
        
        for c in numlist:
            if c in S[idx_a + idx_b + 2:]:
                ans += 1
print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re












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

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

Solution (Python):
def chk(x):
    cur = 0
    cnt = 0
    while cur<N:
        if S[cur]==str(x[cnt]):
            cnt += 1
            if cnt==3:
                break
        cur += 1
    if cnt==3:
        return 1
    else:
        return 0

N = int(input())
S = input().strip()
cnt = 0
for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            cnt += chk((i,j,k))
print(cnt)

Solution (Python):
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
from bisect import *
def solve():
  ans = 0
  N = int(input())
  S = input()
  d = defaultdict(lambda: [])
  for i,s in enumerate(S):
    d[int(s)].append(i)
  for p in product(range(10),repeat=3):
    if not len(d[p[0]]):
      continue
    ind1 = d[p[0]][0]
    ind2 = bisect_right(d[p[1]],ind1)
    if ind2==len(d[p[1]]):
      continue
    ind2 = d[p[1]][ind2]
    ind3 = bisect_right(d[p[2]],ind2)
    if ind3==len(d[p[2]]):
      continue
    ans += 1
  return ans
print(solve())

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):
import sys
from collections import defaultdict, deque, Counter
import math
 

from bisect import bisect_left, bisect_right

 

 

input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 

def main():
    n = getN()
    S = getS()
    dp = [0] * (11*11*11)
    dp[0] = 1
    for c in S:
        tmp = [0] * (11*11*11)
        for i, d in enumerate(dp):
            if d == 1:
                tmp[i] = 1
                tmp[(i%121) * 11 + int(c) + 1] = 1

        dp = tmp
        
        

    print(sum(dp[(11*11):]))


 
if __name__ == "__main__":
    main()

Solution (Python):

n = int(input())
s = list(input())
ans = 0
for i in range(1000):
    t = list(f"{i:0>3}")
    j = 0
    tmp = ""
    for c in s:
        if t[j] == c:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)

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

Solution (Python):
N = int(input())
S = input()
P, Q = [], [] 
t = 0
for i in range(N-2):
  if S[i] not in P:
    P.append(S[i]) 
    for j in range(i+1, N-1):
      if S[j] not in Q:
        Q.append(S[j])
        t += len(set(S[j+1:]))
    Q.clear()
print(t)

Solution (Python):
n = int(input())
s = input()
a = [False for _ in range(1000)]
for j in range(1000):
  t = str(j).zfill(3)
  if(s.find(t[0:1]) > -1):
    s1 = s[s.find(t[0:1])+1:]
    if(s1.find(t[1:2]) > -1):
      s2 = s1[s1.find(t[1:2])+1:]
      if(s2.find(t[2:3]) > -1):
        a[j] = True
ans = 0
for i in range(1000):
  if(a[i]):
    ans += 1
print(ans)

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

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

count = 0
for i in range(len(pin)):
    l, m, n = pin[i][0], pin[i][1], pin[i][2]
    l_idx, m_idx, n_idx = -1, -1, -1
    for i in range(N):
        if S[i] == l:
            l_idx = i
            break
    if l_idx != -1:
        for i in range(l_idx+1, N):
            if S[i] == m:
                m_idx = i
                break
    if m_idx != -1:
        for i in range(m_idx+1, N):
            if S[i] == n:
                n_idx = i
                break
    if l_idx != -1 and m_idx != -1 and n_idx != -1:
        count += 1

print(count)

Solution (Python):

N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = 0
            while tmp<N and int(S[tmp])!=i:
                tmp += 1
            if tmp==N:
                continue
            tmp += 1
            while tmp<N and int(S[tmp])!=j:
                tmp += 1
            if tmp==N:
                continue
            tmp += 1
            while tmp<N and int(S[tmp])!=k:
                tmp += 1
            if tmp==N:
                continue
            ans += 1            
print(ans)

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

ans = 0






for x in range(10):
    if S.find(str(x)) >= 0:
        temp1 = S[S.find(str(x)) + 1:]

        
        for y in range(10):
            if temp1.find(str(y)) >= 0:
                temp2 = temp1[temp1.find(str(y)) + 1:]

                
                for z in range(10):
                    if temp2.find(str(z)) >= 0:
                        ans += 1

print(ans)

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

for x in range(10):
    if s.find(str(x)) > -1:
        tmp = s[s.find(str(x)) + 1:]
        for y in range(10):
            if tmp.find(str(y)) > -1:
                tmp2 = tmp[tmp.find(str(y)) + 1:]
                for z in range(10):
                    if tmp2.find(str(z)) > -1:
                        ans += 1

print(ans)

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

for x in range(10):
    if s.find(str(x)) > -1:
        tmp = s[s.find(str(x)) + 1:]
        for y in range(10):
            if tmp.find(str(y)) > -1:
                tmp2 = tmp[tmp.find(str(y)) + 1:]
                for z in range(10):
                    if tmp2.find(str(z)) > -1:
                        ans += 1

print(ans)

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

N=int(input())

S=input()


T=[[0] * 10 for _ in range(30000)]
for i in range(N):
    if i!=0:
        T[i]=copy.deepcopy(T[i-1])
    T[i][int(S[i])]+=1


dic={}
flag=[False]*10
for i in range(N-2):
    if flag[int(S[i])]==True:
        continue
    flag[int(S[i])]=True
    for j in range(i+1,N-1):
        tmp2=copy.deepcopy(T[N-1])
        tmp3=copy.deepcopy(T[j])
        tmp4=""
        for k in range(10):
            if tmp2[k]-tmp3[k]!=0:
                tmp4=S[i]+S[j]+str(k)
                
                if tmp4 in dic:
                    pass
                else:    
                    dic[tmp4]=1
           
print(len(dic))

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

f = [0]*1000

rnum = [0]*10
lnum = [0]*10

for i in s:
    rnum[i] += 1

rnum[s[0]] -= 1
lnum[s[0]] += 1

for i in range(1, n-1):
    rnum[s[i]] -= 1
    for j in range(10):
        for k in range(10):
            if lnum[j] >= 1 and rnum[k] >= 1:
                f[j*100+s[i]*10+k] = 1
    lnum[s[i]] += 1

cnt = 0
for i in f:
    if i == 1:
        cnt += 1
    
print(cnt)

Solution (Python):
N = int(input())
S = list(input())
S.append("a")
n = list(map(str,range(0,10)))
ans = 0
for i in n:
    for j in n:
        for k in n:
            num = i+j+k
            now = 0

            for l in range(N+1):
                if now == 3:
                    ans += 1
                    break
                if num[now] == S[l]:
                    now += 1
print(ans)

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

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

Solution (Python):
import itertools

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

counter = 0
for a,b,c in itertools.product(range(10), repeat=3):
  
  a_ind = S.find(str(a))
  if a_ind==-1:
    continue
  else:
    b_ind = S[a_ind+1:].find(str(b))
    if b_ind==-1:
      continue
    else:
      c_ind = S[a_ind+1+b_ind+1:].find(str(c))
      if c_ind==-1:
        continue
      else:
        counter += 1
        
        
print(counter)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            nums = [str(x) for x in [i, j, k]]
            for s in S:
                if s == nums[0]:
                    nums = nums[1:]
                    if len(nums) == 0:
                        ans += 1
                        break
print(ans)

Solution (Python):
def find(fr, target):
    for i in range(fr, len(S)):
        if S[i] == target:
            return i
    return -1

N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            now = find(0, str(i))
            if now == -1: continue
            now = find(now+1, str(j))
            if now == -1: continue
            now = find(now+1, str(k))
            if now == -1: continue
            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):
            a = [i, j, k]
            l = 0
            for s in S:
                if l < 3  and a[l] == int(s):
                    l += 1
            if l == 3:
                ans += 1

print(ans)