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 copy
def solve(N, S):
    single_ref = [False for _ in range(10)]
    double_ref = [{} for _ in range(N)]

    for i in range(N - 1, -1, -1):
        if i == N - 1:
            single_ref[int(S[i])] = True
            continue
        double_ref[i] = copy.deepcopy(double_ref[i + 1])
        for j in range(10):
            if not single_ref[j]:
                continue
            double_ref[i][S[i] + str(j)] = 1
        single_ref[int(S[i])] = True

    ret = {}
    for i in range(N - 1):
        for k in double_ref[i + 1].keys():
            ret[S[i] + k] = 1
    return len(ret.keys())

if __name__ == "__main__":
    N = int(input())
    S = input()
    print(solve(N, S))

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

s = input()

numlist = [0] * 1000

ans = 0

for i in range(1000):
    nums = []
    top = i // 100
    mid = (i - top * 100) // 10
    bot = i - top * 100 - mid * 10
    nums.append(str(top))
    nums.append(str(mid))
    nums.append(str(bot))
    
    ind = -1
    for j in nums:
        ind = s.find(j, ind+1)
        if ind == -1:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
 
n = int(input())
s = input()
ans = 0
 
pin = [str(i).zfill(3) for i in range(1000)]
 
for i in pin:
    idx = -1
    for j in i:
        idx = s.find(j,idx+1)
        if idx < 0:
            break
    else:
        ans += 1
 
print(ans)

Solution (Python):
n = int(input())
s = input()
cnt = 0
for s1 in range(10):
    s1_ind = s.find(str(s1))
    if s1_ind == -1 or s1_ind >= len(s)-2 : continue
    for s2 in range(10):
        s2_ind = s[s1_ind+1: ].find(str(s2)) + s1_ind + 1
        if s2_ind <= s1_ind or s2_ind >= len(s)-1: continue
        for s3 in range(10):
            s3_ind = s[s2_ind+1: ].find(str(s3)) + s2_ind + 1
            if s3_ind > s2_ind: 
                cnt+=1

print(cnt)

Solution (Python):
n=int(input())
s=input()
cnt=0
for i in range(1000):
  flag=0
  pin=str(i).zfill(3)
  if s.find(pin[0])==-1:
    continue
  s1=s[s.find(pin[0])+1:]
  if s1.find(pin[1])==-1:
    continue
  s2=s1[s1.find(pin[1])+1:]
  if s2.find(pin[2])==-1:
    continue
  cnt+=1
print(cnt)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = read().rstrip().decode()
cnt = 0
for i in range(1000):
    num = str(i).zfill(3)
    idx = -1
    for m in num:
        idx = s.find(m, idx + 1)
        if idx == -1:
            break
    else:
        cnt += 1
print(cnt)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = read().rstrip().decode()
cnt = 0
for i in range(1000):
    num = ''
    if i < 100:
        num += '0'
        if i < 10:
            num += '0'
    num += str(i)
    index = 0
    for ss in s:
        if ss == num[index]:
            index += 1
            if index == 3:
                cnt += 1
                break
print(cnt)

Solution (Python):


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

pin = [str(i).zfill(3) for i in range(1000)]

for i in pin:
    idx = -1
    for j in i:
        idx = s.find(j,idx+1)
        if idx < 0:
            break
    else:
        ans += 1

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for n in range(1000):
    num = "0"*(3-len(str(n))) + str(n)
    index = 0
    can_set = False
    for i in range(N):
        if S[i] == num[index]:
            if index == 2:
                can_set = True
                break
            index += 1
    if can_set:
        ans += 1
print(ans)

Solution (Python):
n = int(input())
s = input()
lst = ["{:03}".format(i) for i in range(1000)]
count = 0
for num in lst:
    pos = 0
    np = num[pos]
    for tmp in s:
        if np == tmp:
            if pos == 2:
                count += 1
                break
            pos += 1
            np = num[pos]
print(count)

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):
            if str(i) in s and str(k) in s:
                start = s.index(str(i))
                goal = n -1 -list(reversed(s)).index(str(k))
                if start+1<goal:
                    if str(j) in s[start+1:goal]:
                        count += 1
print(count)

Solution (Python):
n = int(input())
s = input()
count=0
for pin in range(0, 1000):
    pin = str(pin).zfill(3)

    if s.find(pin[0]) == -1:
        continue
    s1 = s[s.find(pin[0]) + 1:]
    if s1.find(pin[1]) == -1:
        continue
    s2 = s1[s1.find(pin[1]) + 1:]
    if s2.find(pin[2]) == -1:
        continue
    
    count += 1

print(count)

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

pins = [str(i).zfill(3) for i in range(1000)]

ans = 0
for pin in pins:
    index = -1;
    for c in pin:
      index = s.find(c, index+1);
      if (index < 0):
        break;
    else:
      ans += 1;
      
print(ans)

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

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

pins = [str(i).zfill(3) for i in range(1000)]

ans = 0
for pin in pins:
    index = -1;
    for c in pin:
      index = s.find(c, index+1);
      if (index < 0):
        break;
    if (index > 0):
      ans += 1;
      
print(ans)

Solution (Python):
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

inf = float("inf")


def main():
    N = int(input())
    S = input()
    ret = 0
    for i in range(1000):
        i = str(i).zfill(3)
        cursor = 0
        for s in S:
            if s == i[cursor]:
                cursor += 1
                if cursor == 3:
                    ret += 1
                    break
    print(ret)
        
      
if __name__=='__main__':
    main()

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

pin = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        i = '00' + i
    elif len(i) == 2:
        i = '0' + i
    pin.append(i)

ans = 0
for i in pin:
    c = 0
    for j in s:
        if j == i[c]:
            c += 1
        if c == 3:
            ans += 1
            break
print(ans)

Solution (Python):
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
s=s0()

a=[0]*1000
for i in range(1000):
    num=str(i).zfill(3)
    j=0
    for x in s:
        if x==num[j]:
            j+=1
        if j==3:
            a[i]=1
            break
print(sum(a))

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

used = [0]*1000

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

print(sum(used))

Solution (Python):
def main():
    from sys import stdin
    n = int(stdin.readline().rstrip())
    s = list(map(int,list(stdin.readline().rstrip())))
    ans=0
    g = set(list(range(10))) - set(s)
    for i in range(1000):
        tap = (i//100,(i//10)%10,i%10)
        if set(tap) & g == set({}):
            flag = 0
            for p in s:
                if flag == 0:
                    if p==tap[0]:
                        flag = 1
                elif flag == 1:
                    if p==tap[1]:
                        flag = 2
                elif flag == 2:
                    if p==tap[2]:
                        flag = 0
                        ans+=1
                        break
        else:
            continue

    
    print(ans)
main()

Solution (Python):
n = int(input())
s = input()
target = [str(i) for i in range(10)]
count = 0
for x in target:
    a = s.find(x)
    if a == -1:
        continue
    for y in target:
        b = s.find(y,a+1)
        if b == -1:
            continue
        for z in target:
            c = s.find(z,b+1)
            if c != -1:
                count +=1
print(count)

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

codes = set()

S1 = S[:N-2]
for i in set(S1):
  idx1 = S1.index(i)
  S2 = S1[idx1+1:] + S[N-2]
  for j in set(S2):
    idx2 = S2.index(j)
    S3 = S2[idx2+1:] + S[N-1]
    for k in set(S3):
      pin = i + j + k
      codes.add(pin)
      
print(len(codes))

Solution (Python):
def solution1():

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

if __name__ == "__main__":
    solution1()

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

s = input()

ans = set()
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.add(str(i)+str(j)+str(k))
print(len(ans))

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

s = input()

ans = set()
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.add(str(i)+str(j)+str(k))
print(len(ans))

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(10):
    for  j in range(10):
        for k in range(10):
            i_index = s.find(str(i))
            if i_index > - 1:
                j_index = s.find(str(j), i_index + 1)
                if j_index > -1:
                    k_index = s.find(str(k), j_index + 1)
                    if k_index > -1:
                        ans += 1
print(ans)

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

S = input()

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

print(ans)

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

Solution (Python):
from collections import deque,defaultdict
def solve():
    N = int(input())
    S = list(input())
    dic = defaultdict(lambda: False)
    ans = 0
    d = deque()
    for s in S:
        for _ in range(len(d)):
            t = d.popleft()
            d.append(t)
            if len(t)==1:
                u = t+s
                if dic[u]==False:
                    dic[u] = True
                    d.append(u)
            if len(t)==2:
                u = t+s
                if dic[u]==False:
                    dic[u] = True
                    ans += 1
        if dic[s]==False:
            dic[s] = True
            d.append(s)
    return ans
print(solve())

Solution (Python):
from collections import deque,defaultdict
def solve():
    N = int(input())
    S = list(input())
    dic = defaultdict(lambda: False)
    ans = 0
    d = deque()
    for s in S:
        for _ in range(len(d)):
            t = d.popleft()
            d.append(t)
            if len(t)==1:
                u = t+s
                if dic[u]==False:
                    dic[u] = True
                    d.append(u)
            if len(t)==2:
                u = t+s
                if dic[u]==False:
                    dic[u] = True
                    ans += 1
        if dic[s]==False:
            dic[s] = True
            d.append(s)
    return ans
print(solve())

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

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

for i, s in enumerate(S):
    pos[int(s)].append(i)

res = set()


def calc(i, pin):
    if len(pin) == 3:
        res.add(pin)
        return

    for num in range(10):
        tmp = list(filter(lambda x: x > i, pos[num]))
        if len(tmp) == 0:
            continue
        calc(tmp[0], pin + str(num))


calc(-1, '')
print(len(res))

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

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

for i, s in enumerate(S):
    pos[int(s)].append(i)

res = set()

for i in range(10):
    if len(pos[i]) == 0:
        continue
    p = pos[i][0]
    for j in range(10):
        tmp = list(filter(lambda x: x > p, pos[j]))
        if len(tmp) == 0:
            continue
        q = tmp[0]
        for k in range(10):
            tmp = list(filter(lambda x: x > q, pos[k]))
            if len(tmp) == 0:
                continue
            r = tmp[0]

            res.add(str(p) + str(q) + str(r))

print(len(res))

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


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



ans = 0
for x in range(0,1000):
    x = str(x)
    if len(x) == 1:
        x = "00" + x
    elif len(x) == 2 :
        x = "0" + x
    index = 0
    for s in S:
        if x[index] == s:
            index += 1
        if index == 3:
            ans += 1
            break

print(ans)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True




def warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)






def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



n = int(input())
s = input()
ans = 0
for i in range(0, 1000):
    
    num = str(i).zfill(3)

    
    ok_a = False
    ok_b = False
    ok_c = False
    a, b, c = num[0], num[1], num[2]
    for j in s:
        if not ok_a:
            if j == a:
                ok_a = True
        elif not ok_b:
            if j == b:
                ok_b = True
        elif not ok_c:
            if j == c:
                ok_c = True
                break
    if ok_c:
        ans += 1

print(ans)

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

print(ans)

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




import re
s = re.sub('[0]{4,}','000',s)
s = re.sub('[1]{4,}','111',s)
s = re.sub('[2]{4,}','222',s)
s = re.sub('[3]{4,}','333',s)
s = re.sub('[4]{4,}','444',s)
s = re.sub('[5]{4,}','555',s)
s = re.sub('[6]{4,}','666',s)
s = re.sub('[7]{4,}','777',s)
s = re.sub('[8]{4,}','888',s)
s = re.sub('[9]{4,}','999',s)

n = len(s)
ans = 0
target = [0] * 10
for i in s:
  target[int(i)] = 1

for xxx in range(1000):
  x = str(xxx).zfill(3)
  if(not (target[int(x[0])] and target[int(x[1])] and target[int(x[2])])):
    continue

  ck1,ck2,ck3 = 0,0,0
  start = 0
  for i in range(start,n):
    if(s[i] == x[0]):
      ck1 = 1
      start = i+1
      break
  if(ck1):
    for i in range(start,n):
     if(s[i] == x[1]):
       ck2 = 1
       start = i+1
       break
  if(ck1 and ck2):
    for i in range(start,n):
     if(s[i] == x[2]):
       ans += 1
       break

print(ans)

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

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

ans =0
for a in range(10):
  index_a = my_index(s, str(a))
  if index_a == -1:
    continue
  
  for b in range(10):
    index_b = my_index(s[index_a+1:], str(b))
    if index_b == -1:
      continue
      
    for c in range(10):
      index_c = my_index(s[index_a+1+index_b+1:], str(c))
      if index_c !=-1:
        ans += 1
print(ans)

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

Solution (Python):
def sumitb19_d():
    _ = int(input().strip())  
    S = str(input().strip())  
    ans = 0

    
    for i in range(10):
        d1 = S.find(str(i), 0)  
        if d1 == -1: continue
        for j in range(10):
            d2 = S.find(str(j), d1+1)
            if d2 == -1: continue
            for k in range(10):
                d3 = S.find(str(k), d2+1)
                if d3 > -1: ans += 1

    print(ans)

sumitb19_d()

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

Solution (Python):
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    qi = q[0]
    i = 0
    for s in S:
        if s==qi:
            if i==2:
                ans += 1
                break
            else:
                i+=1
                qi = q[i]
print (ans)

Solution (Python):
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Solution (Python):


import sys

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

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            if S.find(str(k), code2 + 1) != -1:
                ans += 1

print(ans)

Solution (Python):


import sys

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

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            if S.find(str(k), code2 + 1) != -1:
                ans += 1

print(ans)

Solution (Python):


import sys

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

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)

Solution (Python):

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

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)

Solution (Python):


import sys

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

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)

Solution (Python):


import sys


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

    ans = set()

    digit1 = set()

    for i in range(0, N - 2):
        if S[i] in digit1:
            continue
        digit1.add(S[i])
        digit2 = set()

        for j in range(i + 1, N - 1):
            if S[j] in digit2:
                continue
            digit2.add(S[j])
            digit3 = set()
            for k in range(j + 1, N):
                if len(digit3) == 10:
                    break
                code = S[i] + S[j] + S[k]
                ans.add(code)

    print(len(ans))


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import product

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

X = [[str(a),str(b),str(c)] for a,b,c in product(range(10), repeat=3)]
s_index = {s_i:[] for s_i in s}

for i, s_i in enumerate(s):
  s_index[s_i].append(i)

counter = 0
  
for x in X:
  ind_pos = -1
  check = True
  for x_i in x:
    if x_i not in s_index.keys():
      check = False
      break
    else:
      ind_list = [i for i in s_index[x_i] if i>ind_pos]
      if ind_list:
        ind_pos = min(ind_list)
      else:
        check = False
        break
  if check: counter += 1
    
print(counter)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]

from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left



def main():
    n = II()
    s = IS()
    c = [str(i).zfill(3) for i in range(1000)]
    cnt = 0
    for ci in c:
        id_1 = s.find(ci[0])
        if id_1 == -1: continue
        id_2 = s.find(ci[1], id_1+1)
        if id_2 == -1: continue
        id_3 = s.find(ci[2], id_2+1)
        if id_3 == -1: continue
        cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=[int(c) for c in input()]
count=0
for p in range(10):
        if p in s[:n-2]:
            inp=s.index(p)
            for q in range(10):
                if q in s[inp+1:n-1]:
                    inq=s[inp+1:n-1].index(q)+inp+1
                    for r in range(10):
                        if r in s[inq+1:]:
                            count+=1
print(count)

Solution (Python):
n=int(input())
s=[int(c) for c in input()]
count=0
for p in range(10):
    for q in range(10):
        for r in range(10):
            if p in s[:n-2]:
                inp=s.index(p)
                if q in s[inp+1:n-1]:
                    inq=s[inp+1:n-1].index(q)+inp+1
                    if r in s[inq+1:]:
                        count+=1
print(count)

Solution (Python):
N = int(input())
S = [int(c) for c in input()]

count = 0

for x100 in range(10):
    if x100 in S[:N-2]:
        ind_100 = S.index(x100)
        
        for x10 in range(10):
            if x10 in S[ind_100+1:N-1]:
                ind_10 = S[ind_100+1:N-1].index(x10) + ind_100 + 1
                
                for x1 in range(10):
                    if x1 in S[ind_10 + 1:]:
                        count += 1
print(count)

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

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

yn=""
icnt=0
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    stri=list(map(int,stri))
    if len(m[stri[0]])>0:
        m01=m[stri[0]][0]
    else:
        continue

    for ii in m[stri[1]]:
        if m01<ii:
            m02=ii
            yn="yes2"
            break
    if yn!="yes2":
        continue

    for ii in m[stri[2]]:
        if m02<ii:
            icnt+=1
            break

print(icnt)

Solution (Python):

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

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

yn=""
icnt=0
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    stri=list(map(int,stri))
    if len(m[stri[0]])>0:
        m01=m[stri[0]][0]
    else:
        continue

    if len(m[stri[1]])>0:
        for ii in m[stri[1]]:
            if m01<ii:
                m02=ii
                yn="yes2"
                break
    if yn!="yes2":
        continue

    if len(m[stri[2]])>0:
        for ii in m[stri[2]]:
            if m02<ii:
                yn="yes3"
                break
    if yn!="yes3":
        continue
    else:
        icnt+=1

print(icnt)

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

pin=set()

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

    yn=""
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    mo=[0]*10
    if len(m[int(stri[0])])>0:
        m01=m[int(stri[0])][0]
    else:
        continue
    if len(m[int(stri[1])])>0:
        for ii in range(len(m[int(stri[1])])):
            if m01<m[int(stri[1])][ii]:
                m02=m[int(stri[1])][ii]
                yn="yes2"
                break
    if yn!="yes2":
        continue

    if len(m[int(stri[2])])>0:
        for ii in range(len(m[int(stri[2])])):
            if m02<m[int(stri[2])][ii]:
                m03=m[int(stri[2])][ii]
                yn="yes3"
                break
    if yn!="yes3":
        continue
    else:
        pin.add(stri)

print(len(pin))

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

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

for s in S[::-1]:
  for _s in s2:
    s3.add(s+_s)
  for _s in s1:
    s2.add(s+_s)
  s1.add(s)

print(len(s3))