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 pprint
import copy
N=int(input())
S=input()
dig=[[] for i in range(10)]
chkigid=[0]*10
ansdigid=[0]*10

cnt=0
for i in range(N):
    dig[int(S[i])].append(i)
    chkigid[int(S[i])]=chkigid[int(S[i])]+1
    
    
    

for i in range(10):
    for j in range(10):
        
        v1 = float("inf")
        if len(dig[i])!=0:
            v1 = dig[i][0]
        v2 = float("inf")
        if len(dig[j])!=0:
            v2= dig[j][len(dig[j])-1]
        if (v1<v2)and(v1!=float("inf"))and(v2!=float("inf")):
            for k in range(10):
                for l in range(len(dig[k])):
                    if v1<dig[k][l]<v2:
                        
                        cnt=cnt+1
                        break
        
        
        
print(cnt)

Solution (Python):
N = int(input())
S = input()
keys = [str(i) for i in range(1000)]
count = 0
for i in range(10):
    keys[i] = '00' + keys[i]
for i in range(10,100):
    keys[i] = '0' + keys[i]
for i in keys:
    temp1 = i
    temp2 = ''
    if temp1[0] in S:
        search = S.find(temp1[0])+1
        if search >= len(S):
            continue
        temp2 = S[search:]
        if temp1[1] in temp2:
            search = temp2.find(temp1[1])+1
            if search >= len(temp2):
                continue
            temp2 = temp2[search:]
            if temp1[2] in temp2:
                count += 1
print(count)

Solution (Python):

def main():
    N = int(input())
    S = input()

    ans = 0
    tmp = list(map(str, range(0,10)))

    def myindex(Stringlist, Checkstr, default = -1):
        if Checkstr in Stringlist:
            return Stringlist.index(Checkstr)
        else:
            return default


    for V1 in tmp:
        C1 = myindex(S[:N-2], V1, default = -1)
        if C1 == -1:
            continue
        for V2 in tmp:
            C2 = myindex(S[C1+1:N-1], V2, default = -1)
            if C2 == -1:
                continue
            for V3 in tmp:
                C3 = myindex(S[C1+C2+2:], V3, default = -1)
                if C3 == -1:
                    continue
                
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1000,2000):
    templ=list(str(i))
    t=templ[1:]
    
    p=0
    for q in range(n):
        if s[q]==t[p]:
            p+=1
        if p>2:
            ans+=1
            break         

print(ans)

Solution (Python):

N = int(input())
S = input()
ans = 0
for v in range(1000):
    v = str(v).zfill(3)
    flag = [False for _ in range(3)]
    for i in range(len(S)):
        if not flag[0] and v[0] == S[i]:
            flag[0] = True
            continue
        if not flag[1] and v[1] == S[i]and flag[0]:
            flag[1] = True
            continue
        if not flag[2] and v[2] == S[i] and flag[1]:
            flag[2] = True
            break
    if sum(flag) == 3:
        ans += 1
print(ans)

Solution (Python):

N = int(input())
S = input()
ans = 0
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    flag = [False for _ in range(3)]
    idx = 0
    for i in range(len(S)):
        if not flag[0] and v[0] == S[i] and not used[i]:
            used[i] = True
            flag[0] = True
            continue
        if not flag[1] and v[1] == S[i] and not used[i] and flag[0]:
            used[i] = True
            flag[1] = True
            continue
        if not flag[2] and v[2] == S[i] and not used[i] and flag[1]:
            used[i] = True
            flag[2] = True
            break
    if sum(flag) == 3:
        ans += 1
print(ans)

Solution (Python):

N = int(input())
S = input()
ans = []
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    idx = 0
    for i in range(len(S)):
        if v[0] == S[i] and not used[i]:
            used[i] = True
            idx = i + 1
            break
    for i in range(idx, len(S)):
        if v[1] == S[i] and not used[i]:
            used[i] = True
            idx = i + 1
            break
    for i in range(idx, len(S)):
        if v[2] == S[i] and not used[i]:
            used[i] = True
            break
    if sum(used) == 3 and v not in ans:
        ans.append(v[:])
print(len(ans))

Solution (Python):

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

ans=0

for i in range(1000):
    Num=list(map(int,str(i).zfill(3)))
    flg=[False for i in range(3)]
    
    for j in range(N):
        if S[j]==Num[0] and not flg[0]:
            flg[0]=True
            continue
        if flg[0] and S[j]==Num[1] and not flg[1]:
            flg[1]=True
            continue
        if flg[1] and S[j]==Num[2]:
            flg[2]=True
            break
    if flg[2]:
        ans+=1

print(ans)

Solution (Python):
N=int(input())
S=input()
V=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            s=""
            a=str(i)
            b=str(j)
            c=str(k)
            s=a+b+c
            V.append(s)
ans=0
for i in range(len(V)):
    v=V[i]
    flag1=False
    flag2=False
    flag3=False
    for j in range(N):
        if not flag1:
            if S[j]==v[0]:
                flag1=True
                continue
        if not flag2:
            if flag1:
                if S[j]==v[1]:
                    flag2=True
                    continue
        if flag2:
            if S[j]==v[2]:
                flag3=True
        if flag3:
            ans+=1
            break
print(ans)

Solution (Python):
N=int(input())
S=input()
count=0
for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            look=0
            check=0
            while N-1>=look:
                if check==0:
                    if S[look]==str(i):
                        check=1
                elif check==1:
                    if S[look]==str(j):
                        check=2
                elif check==2:
                    if S[look]==str(k):
                        check=3
                look+=1
            if check==3:
                count+=1

print(count)

Solution (Python):

"""
Created on Tue Mar 31 13:15:15 2020

@author: liang
"""

"""
1.全探索 i,j,kを固定してそれぞれの番号を調べる => O(N^3)
2.全探索3桁の暗証番号000~999が文字列Sにあるか調べる =>O(N)
"""
"""
解1.コード　=> TLE

N = int(input())
S = list(map(int,input().split()))
num_used = [list() for i in range(10)]
numbers = list()
for i in range(N):
    for j in range(i+1, N):
        if S[j] in num_used[S[i]]:
            continue
        else:
            num_used[S[i]].append(S[j])
            for k in range(j+1,N):
                number = str(S[i]) + str(S[j]) + str(S[k])
                if number not in numbers:
                    numbers.append(number)
print(len(numbers))
"""

N = int(input())
S = input()
ans = 0
for i in range(1000):





    t = str(i).zfill(3) 







    a = S.find(t[0])
    b = S.find(t[1],a+1)
    c = S.find(t[2],b+1)
    if a != -1 and b != -1 and c != -1:
        ans += 1
print(ans)

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

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


def canMakeNumber(k, s):
    k = str(k).zfill(3)
    dic = {0: False, 1: False, 2: False}
    for t in s:
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                        return True
                else:
                    return True
    return False


N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    if canMakeNumber(i, str(S)):
        ans += 1
print(ans)

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

N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    k = str(i).zfill(3)
    dic = {0: False, 1: False, 2: False}
    for t in str(S):
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                        ans += 1
                        break
                else:
                    ans += 1
                    break

print(ans)

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

def canMakeNumber(k, s):
    k = str(k).zfill(3)
    dic = {0: False, 1: False, 2: False}
    for t in s:
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                        return True
                else:
                    return True
    return False


N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    if canMakeNumber(i, str(S)):
        ans += 1
print(ans)

Solution (Python):
def canMakeNumber(k, s):
    k = str(k).zfill(3)
    dic = {0: False, 1: False, 2: False}
    rep = False
    for t in s:
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                else:
                    continue
    if dic[0] == dic[1] == dic[2] == True:
        rep = True
    return rep


N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    if canMakeNumber(i, str(S)):
        ans += 1
print(ans)

Solution (Python):
def solve():
    input()
    s = input()
    ans = 0
    for i in range(1000):
        t = str(i)
        while(len(t)<3):
            t = '0'+t
        it = 0
        for i in s:
            if it==3:
                break
            if i==t[it]:
                it+=1
        if it==3:
            ans+=1
    print(ans)
if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
S = input()
ans = 0
for i in range(10):
    if str(i) in S:
        T = S[S.index(str(i)) + 1:]
        for j in range(10):
            if str(j) in T:
                U = T[T.index(str(j)) + 1:]
                for k in range(10):
                    if str(k) in U:
                        ans += 1
print(ans)

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

ret=0

for i in range(1000):
    pin="{:0>3}".format(i)
    
    pos=0
    begin=0
    while pos<3:
        begin=S.find(pin[pos],begin)+1
        if begin==0:
            break

        pos+=1
    else:
        ret+=1

print(ret)

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

Solution (Python):
N=int(input())
S=input()
ans=[set(),set(),set()]
for i in S:
    for j in ans[1]:
        ans[2].add(j+i)
    for j in ans[0]:
        ans[1].add(j+i)
    ans[0].add(i)
print(len(ans[2]))

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

for i in range(10):
    first = False
    second = False
    for j in range(N):
        if not first:
            if S[j] == 0:
                first = True
                continue
        elif not second:
            if S[j] == 0:
                second = True
                continue
        else:
            if S[j] == i:
                ans += 1
                break

for i in range(10, 100):
    first = False
    second = False
    second_v = i // 10
    third_v = i % 10
    for j in range(N):
        if not first:
            if S[j] == 0:
                first = True
                continue
        elif not second:
            if S[j] == second_v:
                second = True
                continue
        else:
            if S[j] == third_v:
                ans += 1
                break

for i in range(100, 1000):
    first = False
    second = False
    first_v = i // 100
    second_v = i // 10 % 10
    third_v = i % 10
    for j in range(N):
        if not first:
            if S[j] == first_v:
                first = True
                continue
        elif not second:
            if S[j] == second_v:
                second = True
                continue
        else:
            if S[j] == third_v:
                ans += 1
                break

print(ans)

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

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

    ans = 0
    for i in range(1000):
        s = str(i).zfill(3)
        i0 = S.find(s[0])
        if i0 != -1:
            i1 = S[i0+1:].find(s[1])
            if i1 != -1:
                i2 = S[i0+i1+2:].find(s[2])
                if i2 != -1:
                    ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()

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

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

    ans = 0
    for i in range(1000):
        s = str(i).zfill(3)
        j = 0
        flg0 = False
        flg1 = False
        flg2 = False
        for j in S:
            if not flg0 and j==s[0]:
                flg0 = True
            elif flg0 and not flg1 and j==s[1]:
                flg1 = True
            elif flg0 and flg1 and not flg2 and j==s[2]:
                flg2 = True
        if flg0 and flg1 and flg2:
            ans +=1

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
s = input()
cnt = 0
for i in range(10):
    if str(i) in s:
        idx_i = s.index(str(i)) + 1
        t = s[idx_i:]
        
        for j in range(10):
            if str(j) in t:
                idx_j = t.index(str(j)) + 1
                u = t[idx_j:]
                
                for k in range(10):
                    if str(k) in u:
                        cnt += 1
print(cnt)

Solution (Python):
N = input()
S = input()
all = "0123456789"
result = 0
for i in all:
    Si = S.find(i)
    if Si != -1:
        for j in all:
            Sj = S[Si+1:].find(j)
            if Sj != -1:
                for k in all:
                    Sk = S[Si+Sj+2:].find(k)
                    if Sk != -1:
                        result += 1

print(result)

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions

from functools import reduce

import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)







def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList




N = int(input())
s = input()

items_list = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = [str(i), str(j), str(k)]
            items_list.append(tmp)

ans = 0
for pin in items_list:
    cnt = 0
    for i in range(0, len(s), 1):
        if s[i] == pin[cnt]:
            cnt += 1
            if cnt == 3:
                ans += 1
                break

print(ans)

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions

from functools import reduce

import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)







def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList




N = int(input())
s = input()

items_list = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = [str(i), str(j), str(k)]
            items_list.append(tmp)

ans = 0
for pin in items_list:
    cnt = 0
    for i in range(len(s)):
        if s[i] == pin[cnt]:
            cnt += 1
            if cnt == 3:
                ans += 1
                break

print(ans)

Solution (Python):


import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
s = ns()

def ok(p):
    k = 0
    for i in range(n):
        if s[i] == p[k]:
            k += 1
        if k == 3:
            return True
    return False

ans = 0
for i in range(1000):
    p = "{:0>3}".format(i)
    if ok(p):
        ans += 1

print(ans)

Solution (Python):
import bisect
n=int(input())
s=list(str(input()))
cnt=0
index={}
for i in range(n):
  v=s[i]
  if v not in index.keys():
    index[v]=[]
  index[v].append(i)
for i in range(1000):
  i_str='0'*(3-len(str(i)))+str(i)
  x,y,z=i_str[0],i_str[1],i_str[2]
  if x in index.keys() and y in index.keys() and z in index.keys():
    a=index[x][0]
    v=bisect.bisect_left(index[y],a+1)
    if v<len(index[y]):
      b=index[y][v]
      if b<=a or b>=n:
        pass
      else:
        v=bisect.bisect_left(index[z],b+1)
        if v<len(index[z]):
          c=index[z][v]
          if c<=b or c>=n:
            pass
          else:
            cnt+=1
print(cnt)

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

ans = 0
for n in range(1000):
    c = [n // 100, (n // 10) % 10, n % 10]
    f = 0
    for i in range(N):
        if S[i] == str(c[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(1000) :
    code = str(i).zfill(3)
    j = 0
    for s in S :
        if j == 3 :
            ans += 1
            break
        if s == code[j] :
            j += 1

print(ans)

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

ans = 0
for x, y, z in product(range(10), repeat=3):
    index_1 = s.find(str(x))
    index_2 = s.find(str(y), index_1+1)
    index_3 = s.find(str(z), index_2+1)
    if index_1 != -1 and index_2 != -1 and index_3 != -1:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()
li = []
b_li1 = []
b_li2 = []
for i in range(0, n-2):
    if s[i] in b_li1:
        continue
    b_li1.append(s[i])
    for j in range(i+1, n-1):
        if s[i]+s[j] in b_li2:
            continue
        b_li2.append(s[i]+s[j])
        for k in range(j+1, n):
            li.append(s[i]+s[j]+s[k])
print(len(set(li)))

Solution (Python):
import itertools

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

li = [[] for _ in range(10)]
for i in range(n):
    t = int(s[i])
    li[t].append(i)
    

for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            a = 0
            b = 0
            
            if len(li[i]) > 0:
                a = li[i][0]
                
                for d in li[j]:
                    if d > a:
                        b = d
                        break
                else:
                    break
                
                for e in li[k]:
                    if e > b:
                        ans += 1
                        break
                    
print(ans)

Solution (Python):

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








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

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

count = 0
for i in range(1000):
    password = str(i).zfill(3)
    j = 0
    for s in S:
        if s == password[j]:
            j += 1
            if j == 3:
                count += 1
                break
print(count)

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

cnt = 0

for i in range(10):
    x = 0
    while S[x] != str(i) and x != (len(S)-3):
        x += 1
    if S[x] == str(i):
        for j in range(10):
            y = x + 1
            while S[y] != str(j) and y != (len(S)-2):
                y += 1
            if S[y] == str(j):
                for k in range(10):
                    z = y + 1
                    while S[z] != str(k) and z != (len(S)-1):
                        z +=1
                    if S[z] == str(k):
                        cnt +=1

print(cnt)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()


N = i_i()
S = i_s()

ans = 0
for i in range(1000):
    s = str(i).zfill(3)
    
    i = S.find(s[0])
    if i == -1:
        continue

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

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

    ans += 1

print(ans)

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

ans = 0
pins = [0] * 3
for pin in range(1000):
    pins[0] = pin // 100
    pins[1] = (pin % 100) // 10
    pins[2] = pin % 10
    x = 0
    for c in S:
        if c == pins[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

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

def is_pin(pp):
    idx = 0
    for p in pp:
        find_idx = s[idx:].find(p)
        nxt = idx + find_idx
        if find_idx == -1:
            return False
        else:
            idx = nxt+1
    return True
        
count = 0
for pin_n in range(1000):
    pin = str(pin_n).zfill(3)
    if is_pin(pin):
        count += 1
print(count)

Solution (Python):
def main():
    n = int(input())
    s = str(input())
    
    res = 0
    for i in range(1000):
        t = str(i).zfill(3)
        pos = 0
        for j in s:
            if t[pos] == j:
                pos += 1
            if pos == 3:
                res += 1
                break
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
if __name__ == "__main__":
    N = int(input())
    S = input()

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

        cur = 0
        for c in S:
            if password[cur] == c:
                cur += 1
            if cur == 3:
                result += 1
                break

    print(result)

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


ans = 0
for i in range(1000):
  num = str(i).zfill(3)
  pos = 0
  for j in range(n):
    if num[pos] == s[j]:
      pos += 1
      if pos == 3: 
        ans += 1
        break
print(ans)

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

for i in range(1000):
    t = str(i).zfill(3)
    isExists = [False]*3
    pos = 0
    for (p,j) in enumerate(t):
        while pos<n:
            if s[pos]==j:
                pos += 1
                isExists[p] = True
                break
            pos += 1
    if all(isExists):
        ans += 1

print(ans)

Solution (Python):

def resolve():

    N=int(input())
    s = str(input())


    l=['%03d'%(p) for p in range(0,10**3)]
    ans=[]
    for i in l:
        if i[0] in s:
            s0=s.index(i[0])
            if i[1] in s[s0+1:]:
                s1=s[s0+1:].index(i[1])
                if i[2] in s[s0+1:][s1+1:]:
                    ans.append(i)



    print(len(set(ans)))


resolve()

Solution (Python):

def resolve():

    N=int(input())
    s = str(input())


    l=['%03d'%(p) for p in range(0,10**3)]
    ans=[]
    for i in l:
        if i[0] in s:
            s0=s.index(i[0])
            if i[1] in s[s0+1:]:
                s1=s[s0+1:].index(i[1])
                if i[2] in s[s0+1:][s1+1:]:
                    ans.append(i)



    print(len(set(ans)))


resolve()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
mod = 10**9+7

N = int(input())
S = [int(x) for x in input()[:-1]]
left = defaultdict(lambda : [10**9]*10)
right = defaultdict(lambda : [-10**9]*10)
cnt = [0]*10
flg = [0]*10
for i, x in enumerate(S):
    if flg[x] == 0:
        flg[x] = 1
        left[x] = cnt[:]
    right[x] = cnt[:]
    cnt[x] += 1
ans = 0
for i in range(1000):
    a, b, c = i%1000//100, i%100//10, i%10
    if a == b:
        if right[c][b]-left[a][b] > 1:
            ans += 1
    elif right[c][b]-left[a][b] > 0:
        ans += 1
print(ans)

Solution (Python):
n=int(input())
s=input()
list=["" for _ in range(1000)]
ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    

  









print(ans)

Solution (Python):
n=int(input())
s=input()
list=["" for _ in range(1000)]
ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    

  









print(ans)

Solution (Python):
n=int(input())
s=input()
list=["" for _ in range(1000)]
ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    

  









print(ans)

Solution (Python):
N=int(input())
S=input()
r=[[] for i in range(10)]
for i in range(N):
    r[int(S[i])].append(i)

ans=0
import bisect
for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            
            if (len(r[i])*len(r[j])*len(r[k]))>0:
                le=bisect.bisect_right(r[j],r[i][0])
                ri=bisect.bisect_left(r[j],r[k][-1])
                if le<ri:
                    ans+=1
                    
print(ans)

Solution (Python):

import sys


def solve(N: int, S: str):
    counter = 0
    for i in range(1000):
        c = i % 10
        b = (i // 10) % 10
        a = (i // 100) % 10
        aa = S.find(str(a))
        if aa != -1 and aa < N - 2:
            bb = S[aa+1:].find(str(b))
            if bb != -1 and bb < N - 1:
                cc = S[aa+bb+2:].find(str(c))
                if cc != -1:
                    counter += 1
    print(counter)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = next(tokens)  
    solve(N, S)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline
n,s=int(input()),input()

cnt=0
flag1=[]
ans=[]
for i in range(n-2):
    flag2=[]
    if s[i] in flag1:continue
    flag1.append(s[i])
    for j in range(i+1,n-1):
        if s[j] in flag2:continue
        flag2.append(s[j])
        for k in range(j+1,n):
            ans.append(s[i]+s[j]+s[k])

print(len(set(ans)))

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

    ans = 0
    for i in range(10):
        idx = S.find(str(i))
        if idx != -1:
            for j in range(10):
                idx2 = S.find(str(j), idx+1)
                if idx2 != -1:
                    for k in range(10):
                        idx3 = S.find(str(k), idx2+1)
                        if idx3 != -1:
                            ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()

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

ans = 0
for i in range(1000):
    target = str(i).zfill(3)
    char_idx = 0
    for c in S:
        if c == target[char_idx]:
            char_idx += 1

        if char_idx == 3:
            ans += 1
            break

print(ans)

Solution (Python):
n = int(input())
s = input()
mya = [0]*3
       
ans = 0
for i in range(1000):
    q = '{:0=3}'.format(i)

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

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

    for i in range(10):
        idx1 = S.find(str(i))
        if idx1 < 0:
            continue
        for j in range(0, 10):
            idx2 = S.find(str(j), idx1+1)
            if idx2 < 0:
                continue
            for k in range(0, 10):
                idx3 = S.find(str(k), idx2+1)
                if idx3 < 0:
                    continue
                ans += 1
    print(ans)

if __name__ == '__main__':
    resolve()

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

Solution (Python):
from collections import Counter


def inpl():
    return list(map(int, input().split()))


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

cS = Counter(S)

for i in range(10):
    cS[str(i)] = cS.get(str(i), 0)

ans_1 = {}
ans_2 = {}
ans_3 = {}
for s in S:
    for v in ans_2.keys():
        ans_3[v + s] = True
    for v in ans_1.keys():
        ans_2[v + s] = True
    ans_1[s] = True

print(len(ans_3))