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



Sample input:
4
0224


Sample output:
3

Submission status: Accepted

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

ans = 0
for d1 in "0123456789":
    p1 = S.find(d1)
    if p1 == -1: continue

    for d2 in "0123456789":
        p2 = S[p1+1:].find(d2)
        if p2 == -1: continue

        for d3 in "0123456789":
            if d3 in S[p1+p2+2:]:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

s_l = list(map(int, s))
# print(s_l)

l = [i for i in range(10)]
ans = 0
for v1, v2, v3 in itertools.product(l, repeat=3):
    # print(f"{v1} {v2} {v3}")

    # print(v1) 
    if not v1 in s_l:
        continue
    else:
        index1 = s_l.index(v1)
    
    # print(f"index1 : {index1}")
    # print(s_l[index1 + 1:])
    
    s_l_1 = s_l[index1 + 1:]
        
    if not v2 in s_l_1:
        continue
    else:
        index2 = s_l_1.index(v2)
        
    s_l_2 = s_l_1[index2 + 1:]
        

    if not v3 in s_l_2:
        continue
    

    # print(f"{v1} {v2} {v3}")
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S =list(str(input()))
a=[]
ans=0
for i in range(10):
    for u in range(10):
        for y in range(10):
            moji=[str(i),str(u),str(y)]
            ti=0
            for t in range(N):
                if S[t]==moji[ti]:
                    ti+=1
                    if ti==3:
                        break
            if ti==3:
                ans+=1
                            
                
print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(1000):
    num = "{:03d}".format(i)
    fst = S.find(num[0])
    if fst == -1:
        continue
    sec = S.find(num[1], fst+1)
    if sec == -1:
        continue
    thr = S.find(num[2], sec+1)
    if thr == -1:
        continue

    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools

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


if __name__ == "__main__":
        
    N = int(input())
    S = [int(c) for c in input()]
    table = list(range(10))

    count = 0
    for p in itertools.product(table, repeat=3): # 重複を許して1~9の数値を３つならべる
        target = list(p)

        s1_index = my_index(S, target[0])
        if s1_index == -1:
            continue
        s1 = S[s1_index+1:]

        s2_index = my_index(s1, target[1])
        if s2_index == -1:
            continue
        s2 = s1[s2_index+1:]
        
        s3_index = my_index(s2, target[2])
        if s3_index == -1:
            continue
        
        count += 1

    print(count)

Submission status: Accepted

Solution code:
def I(): return int(input())
N = I()
S = input()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    if S.find(num[0])==-1:
        continue
    S1 = S[S.find(num[0])+1:]
    if S1.find(num[1])==-1:
        continue
    S2 = S1[S1.find(num[1])+1:]
    if S2.find(num[2])==-1:
        continue
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        ii = S.find(str(i))
        if ii == -1:
            break
        for k in range(10):
            jj = S[ii+1::].find(str(j))
            if jj == -1:
                break
            jj += ii+1
            kk = S[jj+1::].find(str(k))
            if kk != -1:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    N = int(input())
    S = input()

    seen = set()
    ans = 0
    for i in range(N - 2):
        if S[i] in seen:
            continue
        seen.add(S[i])
        for j in range(i + 1, N - 1):
            if S[i] + S[j] in seen:
                continue
            seen.add(S[i] + S[j])
            for k in range(j + 1, N):
                if S[i] + S[j] + S[k] in seen:
                    continue
                seen.add(S[i] + S[j] + S[k])
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

tried_first_digit = {}
tried_second_digit = {}
password = {}

for i in range(N-2):
    if S[i] not in tried_first_digit:
        tried_first_digit[S[i]] = 0
        for j in range(i+1, N-1):
            if S[i]+S[j] not in tried_second_digit:
                tried_second_digit[S[i]+S[j]] = 0
                for k in range(j+1, N):
                    if S[i]+S[j]+S[k] not in password:
                        password[S[i]+S[j]+S[k]] = 0

print(len(password))

Submission status: Accepted

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

seen = {}

for i in range(n):
    if s[i] in seen:
        seen[s[i]].append(i)
    else:
        seen[s[i]] = [i]

cnt = 0

for a, ai in seen.items():
    for b, bi in seen.items():
        if ai[0] >= bi[-1]:
            continue

        lower = ai[0]
        upper = bi[-1]

        for c, ci in seen.items():
            search = ci
            if a == c:
                search = search[1:]
            if b == c:
                search = search[:-1]

            #binary search
            l = 0
            r = len(search)-1
            found = False

            while l <= r:
                mid = (l+r)//2

                if lower < search[mid] < upper:
                    found = True
                    break
                elif search[mid] >= upper:
                    r = mid-1
                else:
                    l = mid+1

            if found:
                cnt += 1

print(cnt)

Submission status: Accepted

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

ans=0
for i in range(1000):
    cs=str(i).zfill(3)
    p=0
    for c in cs:
        p=s.find(c,p)

        if p==-1:
            break
        p+=1

    else:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product

n = int(input())
s = input()
ans = 0
for a, b, c in product(map(str, range(10)), repeat=3):
    ai = s.find(a)
    bi = s.find(b, ai + 1)
    ci = s.find(c, bi + 1)
    if ai != -1 and bi != -1 and ci != -1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from itertools import product

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

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

use = set((i for i in range(10) if len(A[i]) > 0))
ans = 0
for a, b, c in product(use, repeat=3):
    ai = A[a][0]
    ci = A[c][-1]
    k = bisect_right(A[b], ci - 1) - bisect_left(A[b], ai + 1)
    if k > 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = list(input())
S = list(map(int, S))
first = [-1] * 10
#second = [-1] * 10
#third = [-1] * 10
ans = 0
for i in range(N):
    if first[S[i]] == 1:
        continue
    second = [-1] * 10
    for j in range(i + 1, N):
        if second[S[j]] == 1:
            continue
        third = [-1] * 10
        for k in range(j + 1, N):
            if third[S[k]] == 1:
                continue
            #print(S[i], S[j], S[k])
            ans += 1
            third[S[k]] = 1
        second[S[j]] = 1
    first[S[i]] = 1
print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
S = input()

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

for s in S:
    for ss2 in s2:
        s3.add(ss2+s)
    for ss1 in s1:
        s2.add(ss1+s)
    s1.add(s)

print(len(s3))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input()

    cnt = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                ii = s.find(str(i))
                if ii == -1:
                    continue
                jj = s[ii+1:].find(str(j))
                if jj == -1:
                    continue
                jj += ii+1
                kk = s[jj+1:].find(str(k))
                if kk == -1:
                    continue
                cnt += 1


    print(cnt)


main()

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
S = input()

ans = 0
for a,b,c in itertools.product(map(str,range(10)),repeat=3):
    aa = False
    bb = False
    for s in S:
        if aa == False and s == a:
            aa = True
            continue
        if bb == False and aa == True and s == b:
            bb = True
            continue
        if aa == True and bb == True and s == c:
            ans += 1
            break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
l = len(S)

S += 'eeee'

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            # tmp = str(i)+str(j)+str(k)
            m = 0
            while S[m] != str(i):
                m += 1
                if m >= l:
                    break
            m += 1
            while S[m] != str(j):
                m += 1
                if m >= l:
                    break
            m += 1
            while S[m] != str(k):
                m += 1
                if m >= l:
                    break
            if m < l:
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
def isok(num,val):##適宜変更
    return num<=val
def bisect(ls,val): ##valの関数isok(x,val)がTrueとなる一番右のindex を返す 全部Falseなら-1,Trueならlen(ls)-1
    ok = -1
    ng = len(ls)
    x = (ok+ng)//2
    while ng-ok>1:
        num = ls[x]
        if isok(num,val):
            ok = x
        else:
            ng = x
        x = (ok+ng)//2
    return ok ##一番右のTrueのindex  Trueの個数はok+1こ

n = ni()
s = input()
idxs =[[] for i in range(10)]
for i in range(n):
    num= int(s[i])
    idxs[num].append(i)
ans = 0
for i in range(10):
    if not idxs[i]:
        continue
    i0 = idxs[i][0]
    for j in range(10):
        t1 = bisect(idxs[j],i0)
        if t1==len(idxs[j])-1:
            continue
        i1 = idxs[j][t1+1]
        for k in range(10):
            t2 = bisect(idxs[k],i1)
            if t2==len(idxs[k])-1:
                continue
            else:
                ans+=1
                #print(i,j,k)
print(ans)

Submission status: Accepted

Solution code:
import sys


def main():
    N = int(sys.stdin.readline().rstrip())
    S = sys.stdin.readline().rstrip()

    cnt = 0
    for i in range(10):
        pos_1 = S.find(str(i))
        if pos_1 == -1 or pos_1 > N - 3:
            continue

        for j in range(10):
            pos_2 = S[pos_1 + 1:].find(str(j))
            if pos_2 == -1 or pos_2 > N - 2:
                continue

            for k in range(10):
                pos_3 = S[pos_1 + 1 + pos_2 + 1:].find(str(k))
                if pos_3 != -1:
                    cnt += 1

    print(cnt)


main()

Submission status: Accepted

Solution code:
import copy
N = int(input())
S = input()

cnt = [0]*10
for x in S:
    cnt[int(x)] += 1

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

ans = 0
for tar in tars:
    id = 0
    copy_cnt = copy.copy(cnt)
    if copy_cnt[int(tar[0])] == 0 or copy_cnt[int(tar[1])] == 0 or copy_cnt[int(tar[2])] == 0:
        continue
    while S[id] != tar[0]:
        copy_cnt[int(S[id])] -= 1
        id += 1
    copy_cnt[int(S[id])] -= 1
    id += 1
    if copy_cnt[int(tar[1])] == 0 or copy_cnt[int(tar[2])] == 0:
        continue
    while S[id] != tar[1]:
        copy_cnt[int(S[id])] -= 1
        id += 1
    copy_cnt[int(S[id])] -= 1
    if copy_cnt[int(tar[2])] == 0:
        continue
    else:
        ans += 1

print(ans)

Submission status: Accepted

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

top_used = set()
used = set()
ans = 0
for i in range(n - 1):
    if int(s[i]) in top_used:
        continue
    top_used.add(int(s[i]))
    for j in range(i + 1, n):
        top = s[i] + s[j]
        if top not in used:
            ans += len(set(s[j + 1:]))
            used.add(top)


print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()[::-1]
    digits_1 = [0] * 10
    digits_2 = [[0 for _ in range(10)] for _ in range(10)]
    digits_3 = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(10)]
    for i, d in enumerate(S):
        d = int(d)
        for d1 in range(10):
            for d2 in range(10):
                if digits_2[d2][d1] == 1:
                    digits_3[d][d2][d1] = 1
        for d1 in range(10):
            if digits_1[d1] == 1:
                digits_2[d][d1] = 1
        digits_1[d] = 1
    ans = 0
    for d3 in range(10):
        for d2 in range(10):
            for d1 in range(10):
                ans += digits_3[d3][d2][d1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# smbc2019 d
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
0224"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """6
123123"""
        output = """17"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """19
3141592653589793238"""
        output = """329"""
        self.assertIO(input, output)


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

    ans = 0
    o = []
    for i in range(10):
        ip = S.find(str(i))
        if ip >= N-2 or ip == -1:
            continue
        for j in range(10):
            jp = S[ip+1:].find(str(j))
            if jp == -1:
                continue
            if ip + 1 + jp >= N-1:
                continue
            jp += ip+1
            for k in range(10):
                kp = S[jp+1:].find(str(k))
                if kp == -1:
                    continue
                t = str(i)+str(j)+str(k)
                if t not in o:
                    ans += 1
                    o.append(t)
    print(ans)


if __name__ == "__main__":
     # unittest.main()
     resolve()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
numlst = []
ans = 0

for i in range(1000):
  if i//10 == 0:
    numlst.append("00"+str(i))
  elif i//100 == 0:
    numlst.append("0"+str(i))
  else:
    numlst.append(str(i))

for i in range(1000):
  judge = False
  a, b, c = numlst[i][0], numlst[i][1], numlst[i][2]
  
  for j in range(n-2):
    if s[j] == a:
      for k in range(j+1, n-1):
        if s[k] == b:
          for l in range(k+1, n):
            if s[l] == c:
              judge = True
          break
      break
      
  if judge:
    ans += 1
     
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

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

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
x=list(map(str,list(range(10))))
cnt=0
for i in x:
  if i in S:
    p=S.index(i)
    S1=S[p+1:]
    for j in x:
      if j in S1:
        q=S1.index(j)
        S2=S1[q+1:]
        for k in x:
          if k in S2:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    sys.setrecursionlimit(10**5)
    n = I()
    s = S()
    global cnt
    cnt = 0
    def tansaku(st,depth):
        global cnt
        for i in range(10):
            index = st.find(str(i))
            if index != -1:
                if depth == 0:
                    cnt += 1
                    # print(i)
                # print(st,i,index,depth)
                else:
                    tansaku(st[index+1:],depth-1)
    tansaku(s,2)

    print(cnt)

main()

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

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

print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

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

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


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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

                if cnt == 3:
                    ans += 1

print(ans)

Submission status: Accepted

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

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

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

        if cnt == 3:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

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

    if f3:
        ans += 1
print(ans)

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(10):
  for j in range(10):
    for k in range(10):
      p,q,r=str(i),str(j),str(k)
      if p in S:
        x=S.index(p)
        S_=S[x+1:]
        if q in S_:
          y=S_.index(q)
          S__=S_[y+1:]
          if r in S__:
            ans+=1
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
#a, b, c, x, y = map(int, input().split())
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]
s = list(input())
ans = 0


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 0

    for i in range(10):
        for j in range(10):
            for k in range(10):
                i_index = S.find(str(i))
                if i_index == -1:
                    continue

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 0
    # password = set()

    # for i in range(N - 2):
    #     for j in range(i + 1, N - 1):
    #         for k in range(10):
    #             if str(k) in S[j + 1:]:
    #                 password.add(S[i] + S[j] + str(k))

    for i in range(10):
        for j in range(10):
            for k in range(10):
                i_index = S.find(str(i))
                j_index = S.find(str(j), i_index + 1)
                k_index = S.find(str(k), j_index + 1)
                if i_index != -1 and j_index != -1 and k_index != -1:
                    ans += 1

    print(ans)


if __name__ == "__main__":
    main()