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

Solution (Python):
n=int(input())
s=input()
ans=0
from collections import Counter
c=Counter(s)
for i in range(1000):
    x=str(i)
    if len(x)==1:
        x="00"+x
    elif len(x)==2:
        x="0"+x
    k=0
    for j in range(n):
        if s[j]==x[k]:
            k+=1
        if k==3:
            ans+=1
            break
        
print(ans)

Solution (Python):
N=int(input())
S=input()
code=list(set(list(S)))
ans=0
for i in code:
    for j in code:
        for k in code:
            count=0
            for s in S:
                if count==0:
                    if s==i:
                        count+=1
                elif count==1:
                    if s==j:
                        count+=1
                elif count==2:
                    if s==k:
                        count+=1
                if count==3:
                    ans+=1
                    break
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):
            count=0
            for s in S:
                if count==0:
                    if s==str(i):
                        count+=1
                elif count==1:
                    if s==str(j):
                        count+=1
                elif count==2:
                    if s==str(k):
                        count+=1
                if count==3:
                    ans+=1
                    break
print(ans)

Solution (Python):
n=int(input())
s=list(input())
fa=[n+1]*10
la=[-1]*10
for i in range(n):
    s[i]=int(s[i])
    if fa[s[i]]>n:
        fa[s[i]]=i
    la[s[i]]=i
ans=0
for i in range(10):
    for j in range(10):
        if fa[i]<la[j]:
            num=[0]*10
            for k in range(fa[i]+1,la[j]):
                num[s[k]]=1
            ans+=num.count(1)
print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = input()

    import re
    num_li = [False]*1000
    for i in range(10):
        first_ = S.find(str(i),0,N-2)
        if first_==-1:
            continue
        for j in range(10):
            second_ = S.find(str(j),first_+1,N-1)
            if second_==-1:
                continue
            for k in range(10):
                third_ = S.find(str(k),second_+1,N)
                if third_==-1:
                    continue
                num_li[i*100+j*10+k]=True
            
    print(sum(num_li))

if __name__=='__main__':
    main()

Solution (Python):
n = int(input())
s = list(input())
t = []
ans = 0
for i in range(1000):
    t.append(str(i//100))
    t.append(str(i//10%10))
    t.append(str(i%10))
    k = 0
    p = 0
    for j in range(3):
        if t[j] in s[k:]:
            p = s[k:].index(t[j]) + 1
            k += p
        else:
            p = -1
            break
    if p != -1:
        ans += 1
    t.clear()
print(ans)

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

num = "1234567890"

ans = 0
for a in num:
    pa = S.find(a)
    if pa == -1:
        continue
    for b in num:
        pb = S.find(b, pa + 1)
        if pb == -1:
            continue
        for c in num:
            pc = S.find(c, pb + 1)
            if pc == -1:
                continue
            ans += 1
print(ans)

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    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
                else:
                    ans += 1
    print(ans)

if __name__=="__main__":
    main()

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
S = S()
after_lis = [set() for _ in range(N+1)]
i = N-1
for s in reversed(S):
    after_lis[i] = (after_lis[i] | after_lis[i+1])
    after_lis[i].add(int(s))
    i -= 1

left_index = {}
for i, s in enumerate(S):
    if s not in left_index:
        left_index[s] = i

ans_lis = np.zeros([10, 10, 10], dtype=np.int32)

for char in left_index:
    s_100 = int(char)
    for i_10 in range(left_index[char]+1, N-1):
        
        s_10 = int(S[i_10])
        ans_lis[s_100, s_10, list(after_lis[i_10+1])] = 1

        

print(np.sum(ans_lis))

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

ret = 0
for x in range(10):
    for y in range(10):
        for z in range(10):
            a = S.find(str(x))
            if a != -1:
                b = S.find(str(y), a + 1)
                if b != -1:
                    c = S.find(str(z), b + 1)
                    if c != -1:
                        ret += 1
print(ret)

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

for i in range(0,1000):
    num = str(i)
    if i < 10:
        num = "00"+num
    elif i <100:
        num = "0" + num
    f = 0
    for j in range(n):
        if s[j] == num[f]:
            f += 1
        if f == 3:
            break
    if f==3:
        ans +=1
print(ans)

Solution (Python):






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





ans = 0
for i in range(10):
    str_i = str(i)
    i_index = S.find(str_i)
    if i_index == -1:
        continue
    for j in range(10):
        str_j = str(j)
        j_index = S.find(str_j, i_index+1)
        if j_index == -1:
            continue
        for k in range(10):
            str_k = str(k)
            k_index = S.find(str_k, j_index+1) 
            if k_index != -1:
                ans += 1
print(ans)

Solution (Python):
N = int(input())
S = input()
third = [[[False]*10 for _ in range(10)] for __ in range(10)]
second = [[False]*10 for _ in range(10)]
first = [False]*10
for s in S:
    s = int(s)
    for i in range(10):
        if first[i]:
            for j in range(10):
                if second[i][j]:
                    third[i][j][s] = True
            second[i][s] = True
    first[s] = True

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if third[i][j][k]:
                
                res += 1
print(res)

Solution (Python):
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
L = [[] for _ in range(10)]
for i in range(N):
  L[S[i]].append(i)

for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  if not L[a]:
    continue
  left = min(L[a])
  Flag = False
  for x in L[b]:
    if x > left:
      mid = x
      Flag = True
      break
  if not Flag:
    continue
  Flag = False
  for y in L[c]:
    if y > mid:
      right = y
      Flag = True
      break
  if not Flag:
    continue
  ans.add(v)
  
print(len(ans))

Solution (Python):
n = int(input())
s = input()
l = [0,1,2,3,4,5,6,7,8,9]
ans = 0
for i in l:
    for j in l:
        for k in l:
            a,b,c = i,j,k
            
            for m in s:
                
                if a==int(m):
                    
                    a = -1
                elif a==-1 and b==int(m):
                    b = -1
                elif b==-1 and c==int(m):
                    ans+=1
                    
                    break
print(ans)

Solution (Python):
N=int(input())
S=input()
ans=0
for i in range(10):
  str_i = str(i)
  i_index=S.find(str_i)
  if i_index==-1:
    continue
  for j in range(10):
    str_j=str(j)
    j_index=S.find(str_j, i_index+1)
    if j_index==-1:
      continue
    for k in range(10):
      str_k=str(k)
      k_index=S.find(str_k, j_index+1) 
      if k_index!=-1:
        ans+=1
print(ans)

Solution (Python):
n=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:
   if s.find(i[2],b+1)!=-1:ans+=1
print(ans)

Solution (Python):
n=int(input())
s=input()
ans,a=0,[]
for i in range(n):
    if s[i] not in a:
        a+=[s[i]]
        b=[]
        for j in range(i+1,n):
            if s[j] not in b:
                b+=[s[j]]
                c=[]
                for k in range(j+1,n):
                    if s[k] not in c:
                        c+=[s[k]]
                        ans+=1
print(ans)

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

s=list(input())

ans = 0

for i in range(1000):
    i = str(i)
    keta = len(list(i))
    code = '0'*(3-keta)+i
    code = list(code)
    index = 0
    for j in s:
        if j == code[index]:
            index += 1
        if index == 3:
            break
    if index == 3:
        
        ans += 1
print(ans)

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

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

Solution (Python):
n = int(input())
S = input()
cnt = 0
set_ = set()
for val in range(1000):
    val = str(val).zfill(3)
    a =val[0]
    b = val[1]
    c = val[2]
    flag = False
    for i in range(n):
        if S[i]==a and flag == False:
            for j in range(i+1,n):
                if S[j]==b and flag == False:
                    for k in range(j+1,n):
                        if S[k]==c and flag == False: 
                            cnt += 1
                            flag = True
                            break
                    break
            break
print(cnt)

Solution (Python):
N = int(input())
S = input()
L = [[] for _ in range(10)]
for i,s in enumerate(S):
    n = int(s)
    L[n].append(i)

count = 0
import bisect
for i in range(1000):
    s = str(i)
    s = s.zfill(3)
    if L[int(s[2])] and L[int(s[0])]:
        r = int(L[int(s[2])][-1])
        l = int(L[int(s[0])][0])
        r2 = bisect.bisect_left(L[int(s[1])], r)
        l2 = bisect.bisect_right(L[int(s[1])], l)
        if r2-l2>0:
            count+=1

print(count)

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

import itertools
ans=0

for num in range(1000):
	num=str(num).zfill(3)
	a0=S.find(str(num[0]))
	if a0>=0:
		S1=S[(a0+1):]
		a1=S1.find(str(num[1]))
		if a1>=0:
			S2=S1[(a1+1):]
			if str(num[2]) in S2:
				ans+=1

		



print(ans)

Solution (Python):
def Binary_Search_Count(A,x,sort=True,equal=False):
    """2分探索によって,x未満の要素の個数を調べる.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"未満"がx"以下"になる
    """
    if sort:
        A.sort()
        
    N=len(A)
    if A[-1]<=x:
        return N
    elif x<A[0] or (not equal and x==A[0]):
        return 0

    L,R=0,N
    while R-L>1:
        C=L+(R-L)//2
        if x<A[C] or (not equal and x==A[C]):
            R=C
        else:
            L=C
    return R

def Binary_Search_High_Value(A,x,sort=True,equal=False):
    """Aのxを超える要素の中で最小のものを出力する.

    A:リスト
    x:調べる要素
    sort:ソートをする必要があるかどうか(Trueで必要)
    equal:Trueのときはx"を超える"がx"以上"になる
    ※全ての要素がx以下(未満)場合はNoneが返される.
    """
    
    if sort:
        A.sort()

    K=Binary_Search_Count(A,x,sort=False,equal=not equal)
    if K==len(A):
        return None
    else:
        return A[K]

N=int(input())
T={i:[] for i in range(10)}

S=input()
for i in range(N):
    T[int(S[i])].append(i)

X=0
for k in range(10**3):
    a,b,c=(k//100),(k//10)%10,k%10

    if T[a]:
        x=T[a][0]
        if T[b]:
            y=Binary_Search_High_Value(T[b],x,False,False)
            if y!=None and T[c]:
                z=Binary_Search_High_Value(T[c],y,False,False)
                if z!=None:
                    X+=1
print(X)

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

ans=0
import itertools
itr=itertools.product(list("1234567890"),repeat=3)

for it in itr:
    cnt=0
    for i in range(n):
        if S[i]==it[cnt]:
            cnt+=1
        if cnt==3:
            ans+=1
            break

print(ans)

Solution (Python):
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    S = input()
    cnt = 0
    for i in range(1000):
        ptn = str(i).zfill(3)
        j = 0
        flg = 0
        while j < N:
            if S[j] == ptn[flg]:
                flg += 1
                if flg == 3:
                    cnt += 1
                    break
            j += 1
    print(cnt)


if __name__ == '__main__':
    main()

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

cnt = 0
for key in range(1000):
    key = '{:0>3}'.format(str(key))    
    i0 = s.find(key[0])
    if 0 <= i0 < N-2:
        i1 = s.find(key[1], i0+1)
        if 0 < i1 < N-1:
            i2 = s.find(key[2], i1+1)
            if i2 != -1:
                cnt += 1                                 
print(cnt)

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

ans = 0
for i in range(10):
    idx0 = S[: N - 2].find(str(i))
    if idx0 != -1:
        for j in range(10):
            idx1 = S[idx0 + 1 : N - 1].find(str(j))
            if idx1 != -1:
                for k in range(10):
                    idx2 = S[idx0 + idx1 + 2 :].find(str(k))
                    if idx2 != -1:
                        ans += 1

print(ans)

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

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

print(ans)

Solution (Python):
N=int(input())
S=input()
ans=0
for i in range(1000):
    one=str(i//100)
    two=str((i%100)//10)
    three=str(i%10)
    f1,f2,f3=False,False,False
    ptr=0
    for j in range(ptr,N-2):
        if S[j]==one:
            f1=True
            ptr=j+1
            break
    if f1:
        for j in range(ptr,N-1):
            if S[j]==two:
                f2=True
                ptr=j+1
                break
        if f2:
            for j in range(ptr,N):
                if S[j]==three:
                    f3=True
                    ans+=1
                    break
print(ans)

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

cnt = 0
for key in range(1000):
    key = '{:0>3}'.format(str(key))    
    i0 = s.find(key[0])
    if 0 <= i0 < N-2:
        i1 = s.find(key[1], i0+1)
        if 0 < i1 < N-1:
            i2 = s.find(key[2], i1+1)
            if i2 != -1:
                cnt += 1
            else:
                continue
        else:
            continue        
    else:
        continue
                                   
print(cnt)

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

ans = 0

for x in [0,1,2,3,4,5,6,7,8,9]:
  if x in S:
    x_index = S.index(x)
    for y in [0,1,2,3,4,5,6,7,8,9]:
      if y in S[x_index+1:]:
        y_index = S[x_index+1:].index(y)
        for z in [0,1,2,3,4,5,6,7,8,9]:
          if z in S[x_index + 1 + y_index+1:]:
            ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
cnt=0
def judge(n):
    pos=0
    pos=s.find(n[0],pos)
    if pos==-1:
        return 0
    pos=s.find(n[1],pos+1)
    if pos==-1:
        return 0
    pos=s.find(n[2],pos+1)
    if pos==-1:
        return 0
    return 1
for i in range(1000):
    p=str(i).rjust(3,'0')
    if judge(p):
        cnt+=1
print(cnt)

Solution (Python):
n = int(input())
s = input()
ans = 0
for pin in range(10**3):
    str_pin = str(pin)
    str_pin = str_pin.zfill(3)
    nex = 0
    for i in range(n):
        searching_for = str_pin[nex]
        now_s = s[i]
        if searching_for == now_s:
            nex += 1
            if nex == 3:
                ans += 1
                break
print(ans)

Solution (Python):
import bisect
N = int(input())
S = input()
pairs = []
for i in range(len(S)):
    pairs.append([int(S[i]),i])

pairs = sorted(pairs)
cnt = 0

numlists = [[] for i in range(10)]

for i in range(N):
    numlists[pairs[i][0]].append(pairs[i][1])

ans = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            if(len(numlists[i]) == 0):
                continue
            indi = min(numlists[i])


            if(len(numlists[j]) == 0):
                continue
            if(max(numlists[j]) <= indi):
                continue
            
            
            indj = bisect.bisect_right(numlists[j],indi)
            indj = numlists[j][indj]
            if(len(numlists[k]) == 0):
                continue
            if(max(numlists[k]) <= indj):
                continue

            

            cnt += 1
            

print(cnt)

Solution (Python):
n = int(input())
s = list(map(int, input()))
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p = 0
            while p < len(s) and s[p] != i: p += 1
            p += 1
            while p < len(s) and s[p] != j: p += 1
            p += 1
            while p < len(s) and s[p] != k: p += 1
            if p < len(s):
                ans += 1
print(ans)

Solution (Python):


from collections import Counter
import sys
input = sys.stdin.readline  
N = int(input())
*S, =input().strip()
"""
c =Counter(S)
ans =combinations_count(N, 3) -len(c)
"""
count =0
x100=0
x10=0
x1=0
for i in range(10):
    if str(i) not in S:
        continue
    else:
        x100 =S.index(str(i)) +1
        for j in range(10):
            if str(j) not in S[x100:]:
                continue
            else:
                x10 =S[x100:].index(str(j)) +1
                for k in range(10):
                    if str(k) in S[x100 +x10:]:
                        x1 =S[x100+x10:].index(str(k)) +1
                        count +=1
                        

print(count)

Solution (Python):


from collections import Counter
import sys
input = sys.stdin.readline  
N = int(input())
*S, =input().strip()
"""
c =Counter(S)
ans =combinations_count(N, 3) -len(c)
"""
count =0
x100=0
x10=0
x1=0
for i in range(10):
    if str(i) in S:
        x100 =S.index(str(i)) +1
        for j in range(10):
            if str(j) in S[x100:]:
                x10 =S[x100:].index(str(j)) +1
                for k in range(10):
                    if str(k) in S[x100 +x10:]:
                        x1 =S[x100+x10:].index(str(k)) +1
                        count +=1
                        

print(count)

Solution (Python):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))



from collections import Counter
import sys
input = sys.stdin.readline  
N = int(input())
*S, =input().strip()
"""
c =Counter(S)
ans =combinations_count(N, 3) -len(c)
"""
count =0
x100=0
x10=0
x1=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if str(i) in S:
                x100 =S.index(str(i)) +1
                if str(j) in S[x100:]:
                    x10 =S[x100:].index(str(j)) +1
                    if str(k) in S[x100 +x10:]:
                        x1 =S[x100+x10:].index(str(k)) +1
                        count +=1
                        

print(count)

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

def F(S,M): 
    if M ==1:
        ans = 0
        for i in range(10):
            if str(i) in S:
                continue
            else:
                ans +=1
        return ans
    ans = 0
    for i in range(10):
        for j in range(len(S)):
            if i == int(S[j]):
                ans += F(S[j+1:], M-1)
                break
        else:
            ans += 10**(M-1)
    return ans
    
ans = F(S,3)


print(10**3 - ans)

Solution (Python):
N  = int(input())
S = input()
P = 0
count = 0
for j in range(1000):
    V = str(P).zfill(3)
    p1 = False
    p2 = False
    for i in range(N):
        if S[i] == V[0] and not p1:
            p1 = True
            continue
        if S[i] == V[1] and p1 and not p2:
            p2 = True
            continue
        if S[i] == V[2] and p2:
            count += 1
            break
    P += 1
print (count)

Solution (Python):
from collections import Counter
N = int(input())
S = input()
ans = 0
for x in range(10):
    for y in range(10):
        hantei = []
        for i in range(N):
            if x != int(S[i]):
                continue
            for j in range(i+1, N):
                if y != int(S[j]):
                    continue
                for k in range(j+1, N):
                    hantei.append(S[k])
                ans += len(Counter(hantei))
                break
            break

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for x in range(10):
    for y in range(10):
        for z in range(10):
            for i in range(N):
                if x != int(S[i]):
                    continue
                for j in range(i+1, N):
                    if y != int(S[j]):
                        continue
                    for k in range(j+1, N):
                        if z != int(S[k]):
                            continue
                        ans += z == int(S[k])
                        break
                    break
                break
print(ans)

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

result = 0
for i in range(1000):
    i = str(i).zfill(3)
    
    
    index0 = s.find(i[0])
    if -1 < index0:
        index1 = s.find(i[1], index0+1)
        if -1 < index1:
            index2 = s.find(i[2], index1+1)
            if -1 < index2:
                
                result += 1

print(result)

Solution (Python):
N = int(input())
S = input()
R = S[::-1]

count = 0

for v in range(1000):
  V = str(v).zfill(3)
  right = -1
  left = -1
  if V[2] in R:
    r = R.index(V[2]) + 1
    right = N-r
  else:
    continue
  if V[0] in S:
    left = S.index(V[0]) + 1
  else:
    continue
  if V[1] in S[left:right]:
    count += 1

print(count)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1000):
    tmp = str(i).zfill(3)
    number = [tmp[0],tmp[1],tmp[2],"OK"]
    pos = 0
    for ss in s:
        if ss == number[pos] and pos < 3:
            pos += 1
    if number[pos] == "OK":
        ans += 1
print(ans)

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


def main():
    n = int(input())
    S: str = input()
    ans = 0
    for s1 in range(10):
        idx1 = S.find(str(s1))
        if idx1 == -1:
            continue

        for s2 in range(10):
            idx2 = S.find(str(s2), idx1+1)
            if idx2 == -1:
                continue

            for s3 in range(10):
                idx3 = S.find(str(s3), idx2+1)
                if idx3 >= 0:
                    ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = str(input())
R = S[::-1]

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  left = -1
  if z[2] in R:
    r = R.index(z[2]) + 1
    right = N-r
  else:
    continue
  if z[0] in S:
    left = S.index(z[0]) + 1
  else:
    continue
  if z[1] in S[left:right]:
    ans += 1
print(ans)

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

counter = 0
for i in range(10):
    str_i = str(i)
    i_dig = s.find(str_i)
    if i_dig == -1:
        continue

    for j in range(10):
        str_j = str(j)
        j_dig = s.find(str_j, i_dig+1)
        if j_dig == -1:
            continue
        
        for k in range(10):
            str_k = str(k)
            k_dig = s.find(str_k, j_dig+1)
            if k_dig != -1:
                counter += 1

print(counter)

Solution (Python):
n=int(input())
s=list(input())
d={}
ans=0
for x in range(n-2):
  if s[x] not in d:
    d[s[x]]=0
    for y in range(x+1,n-1):
      if (s[x]+s[y]) not in d:
        d[(s[x]+s[y])]=0
        for z in range(y+1,n):
          if (s[x]+s[y]+s[z]) not in d:
            d[(s[x]+s[y]+s[z])]=0
            ans+=1
    
print(ans)

Solution (Python):
from collections import defaultdict
import bisect

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

s2i = defaultdict(list)

for i, si in enumerate(S):
    s2i[si] += [i]

ans = 0

for i in range(1000):
    pin = str(i).zfill(3)
    ii = -1
    flag = True
    for p in pin:
        s2ip = s2i[p]
        if s2ip:
            iii = bisect.bisect_right(s2ip, ii)
            if iii == len(s2ip):
                flag = False
                break
            ii = s2ip[iii]
        else:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    S=list(input())

    ans = 0
    for i in range(1000):
        pin = str(i)
        if len(pin) == 1:
            pin = "00"+pin
        elif len(pin) == 2:
            pin = "0"+pin
        
        waiti = 0
        for j in range(N):
            if S[j] == pin[waiti]:
                waiti += 1
                if waiti == 3:
                    break
                    
        if waiti == 3:
            ans += 1

    print(ans)
            
            





if __name__ == "__main__":
    main()

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

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

ans = 0

numlist = [[] for i in range(10)]
for i in range(len(S)):
  numlist[int(S[i])].append(i)

ans = 0
import bisect
for i in range(1000):
  target = str(i).zfill(3)
  now = 0
  for j in range(len(target)):
    tar = int(target[j])
    pos = bisect.bisect_left(numlist[tar], now)
    if pos >= len(numlist[tar]):
      break
    now = numlist[tar][pos] + 1
  else:
    ans += 1

print(ans)

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

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

ans = 0
for i in range(1000):
  target = str(i).zfill(3)
  ind = 0
  tar_ind = 0
  while ind < N:
    if S[ind] == target[tar_ind]:
      tar_ind += 1
      if tar_ind == 3:
        ans += 1
        break
    ind += 1
  
print(ans)

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

lst = set()
ans = []
for i in range(n):
  pin = ''
  if numbers[i] not in lst:
    pin += numbers[i]
    lst.add(pin)
    lst2 = set()
    for j in range(i+1, n):
      pin += numbers[j]
      if pin[1] not in lst2:
        lst2.add(pin[1])
        lst3 = set()
        for k in range(j+1, n):
          pin += numbers[k]
          if pin[2] not in lst3:
            lst3.add(pin[2])
            ans.append(pin)
          if ('0' in lst3) and ('1' in lst3) and ('2' in lst3) and ('3' in lst3) and ('4' in lst3) and ('5' in lst3) and ('6' in lst3) and ('7' in lst3) and ('8' in lst3) and ('9' in lst3):
            break
          pin = pin[0] + pin[1]
      if ('0' in lst2) and ('1' in lst2) and ('2' in lst2) and ('3' in lst2) and ('4' in lst2) and ('5' in lst2) and ('6' in lst2) and ('7' in lst2) and ('8' in lst2) and ('9' in lst2):
        break
      pin = pin[0]
    if ('0' in lst) and ('1' in lst) and ('2' in lst) and ('3' in lst) and ('4' in lst) and ('5' in lst) and ('6' in lst) and ('7' in lst) and ('8' in lst) and ('9' in lst):
      break
print(len(ans))

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

lst = []
ans = []
for i in range(n):
  pin = ''
  if numbers[i] not in lst:
    pin += numbers[i]
    lst.append(pin)
    lst2 = []
    for j in range(i+1, n):
      pin += numbers[j]
      if pin[1] not in lst2:
        lst2.append(pin[1])
        lst3 = []
        for k in range(j+1, n):
          pin += numbers[k]
          if pin[2] not in lst3:
            lst3.append(pin[2])
            ans.append(pin)
          if ('0' in lst3) and ('1' in lst3) and ('2' in lst3) and ('3' in lst3) and ('4' in lst3) and ('5' in lst3) and ('6' in lst3) and ('7' in lst3) and ('8' in lst3) and ('9' in lst3):
            break
          pin = pin[0] + pin[1]
      if ('0' in lst2) and ('1' in lst2) and ('2' in lst2) and ('3' in lst2) and ('4' in lst2) and ('5' in lst2) and ('6' in lst2) and ('7' in lst2) and ('8' in lst2) and ('9' in lst2):
        break
      pin = pin[0]
    if ('0' in lst) and ('1' in lst) and ('2' in lst) and ('3' in lst) and ('4' in lst) and ('5' in lst) and ('6' in lst) and ('7' in lst) and ('8' in lst) and ('9' in lst):
      break
print(len(ans))

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

lst = [0]*10

dic = {(i,j):set() for i in range(10) for j in range(10)}
a = set()
b = set()

for s_ in S:
  s = int(s_)
  for t in b:
    dic[t].add(s)
  for i in a:
    b.add((i,s))
  a.add(s)

rlt = 0
for c in dic:
  rlt += len(dic[c])
  
print(rlt)

Solution (Python):
_ = input()
s = list(input())
cnt = 0
for i in range(1000):
    a = list(f'{i:03}')
    if a[0] not in s: continue
    s1 = s[s.index(a[0])+1:]
    if a[1] not in s1: continue
    s1 = s1[s1.index(a[1])+1:] 
    if a[2] not in s1: continue
    cnt += 1
print(cnt)

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

ans=0

for i in range (1000):
    tempS=S
    pin=str(i).zfill(3)
    t1=pin[0]
    t2=pin[1]
    t3=pin[2]
    if tempS.count(t1)>=1:
        tempS=tempS[tempS.find(t1)+1:]
    else:
        continue

    if tempS.count(t2)>=1:
        tempS=tempS[tempS.find(t2)+1:]
    else:
        continue

    if tempS.count(t3)>=1:
        ans+=1
    else:
        continue

print(ans)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

from collections import defaultdict
sys.setrecursionlimit(10**7)







def run():
    N = input()
    S = input()
    dp = [0] * 1000
    ans = 0
    for n in S:
        n = int(n)
        
        for i in range(1000):
            if i // 100 == n and dp[i] == 0:
                dp[i] = 1
                
            elif (i // 10) % 10 == n and dp[i] == 1:
                dp[i] = 2
                
            elif i % 10 == n and dp[i] == 2:
                dp[i] = 3
                
                ans += 1
    print(ans)

    
if __name__ == "__main__":
    run()

Solution (Python):
import collections
n = int(input())
s = input()
ans = 0
for i in range(10):
    ind = s.find(str(i))+1
    if ind == 0 or ind == len(s):
        continue
    for j in range(10):

        ind_j = ind + s[ind:].find(str(j))+1
        if ind_j == ind or ind_j == len(s):
            continue
        cnt = collections.Counter(s[ind_j:])
        ans += len(cnt)

print(ans)