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:
from collections import defaultdict


def main():
    _ = input()
    S = input()
    S_idx = defaultdict(list)
    num_combs = 0
    for i in range(len(S)):
        S_idx[S[i]].append(i)

    for i in range(10):
        for j in range(10):
            for k in range(10):
                if not ((len(S_idx[str(i)]) == 0) or (len(S_idx[str(j)]) == 0) or (len(S_idx[str(k)]) == 0)):
                    s1_idx = S_idx[str(i)][0]
                    if not s1_idx >= S_idx[str(j)][-1]:
                        s2_idx = binary_search(S_idx[str(j)], s1_idx)
                        if not (s2_idx == -1 or s2_idx >= S_idx[str(k)][-1]):
                            num_combs += 1
    print(num_combs)


def binary_search(A, x):
    ok = len(A)
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if A[mid] > x:
            ok = mid
        else:
            ng = mid
    if ok < len(A):
        return A[ok]
    else:
        return -1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

n = int(input())
s = [int(i) for i in input()]

def myindex(l,x,ind):

    global n
    if ind == n:
        return -1
    for i in range(ind,n):
        if l[i] == x:
            return i
    return -1

c=0

for i in range(10):
    x1 = myindex(s,i,0)
    if x1 != -1:
        for j in range(10):
            x2 = myindex(s,j,x1+1)
            if x2 != -1:
                for k in range(10):
                    x3 = myindex(s,k,x2+1)
                    if x3 != -1:
                        c+=1

print(c)

Submission status: Accepted

Solution code:
import sys
import math

N = int(input())
S = input()
ans = 0

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


print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = [int(x) for x in input()]
all_num = 0

all_dict = {}
for i in range(len(S)-2):
  s_0 = S[i]
  if s_0 in all_dict.keys():
    pass
  else:
    all_dict[s_0] = dict()
    for j in range(i+1, len(S)-1):
      s_1 = S[j]
      if s_1 in all_dict[s_0].keys():
        pass
      else:
        all_dict[s_0][s_1] = len(set(S[j+1:]))
        all_num += len(set(S[j+1:]))
        
print(all_num)

Submission status: Accepted

Solution code:
n = int(input())
s = [int(x) for x in input()]

dp_1 = [False] * 10
dp_2 = [False] * 100
dp_3 = [False] * 1000

for x in s:
    for i in range(100):
        if dp_2[i]:
            dp_3[i * 10 + x] = True
    for i in range(10):
        if dp_1[i]:
            dp_2[i * 10 + x] = True
    dp_1[x] = True

print(sum(dp_3))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
s = ns()

ans = 0

for a in range(10):
    for b in range(10):
        now = 1
        ss = set()
        for i in range(n):
            if now == 1 and s[i] == str(a):
                now = 2
            elif now == 2 and s[i] == str(b):
                now = 3
            elif now == 3:
                ss.add(s[i])
        ans += len(ss)

print(ans)

Submission status: Accepted

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

output = 0
for idx1 in range(10):
    digit1 = s.find(str(idx1))
    if digit1 == -1:
        continue

    for idx2 in range(10):
        digit2 = s.find(str(idx2), digit1 + 1)
        if digit2 == -1:
            continue

        for idx3 in range(10):
            digit3 = s.find(str(idx3), digit2 + 1)
            if digit3 == -1:
                continue
            output += 1
print(output)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
s1 = set()
s2 = set()
s3 = set()

for i in S:
  for j in s2:
    s3.add(j+i)
  for k in s1:
    s2.add(k+i)
  s1.add(i)
print(len(s3))

Submission status: Accepted

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

count = 0
numberlist = [str(i) for i in range(10)]

for a in numberlist:
    idx1 = S.find(a)
    if idx1 == -1 or idx1 >= N - 2:
        continue
    
    for b in numberlist:
        idx2 = S[idx1+1:].find(b)
        if idx2 == -1 or idx2 >= N - 1:
            continue

        count += len(set(S[idx1+idx2+2:]))

print(count)

Submission status: Accepted

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

ans = 0
for i in range(10):
  a = S.find(str(i))
  if a != -1:
    for j in range(10):
      b = S.find(str(j), a+1)
      if b != -1:
        for k in range(10):
          c = S.find(str(k), b+1)
          if c != -1:
            ans += 1
print(ans)

Submission status: Accepted

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

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

for i in S:
  for j in s2:
    s3.add(j+i)
  for k in s1:
    s2.add(k+i)
  s1.add(i)

print(len(s3))

Submission status: Accepted

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

ans = 0

for i in range(10):
  a = S.find(str(i))
  if a == -1:
    continue
  for j in range(10):
    b = S.find(str(j), a+1)
    if b == -1:
      continue
    for k in range(10):
      c = S.find(str(k), b+1)
      if c != -1:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
for i in range(n):
    s[i]=int(s[i])

def idx(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

lst=[idx(s,j) for j in range(10)]
len_lst=[len(lst[i]) for i in range(10)]

ans=0
switch=0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if len_lst[i]>=1:
                place_num1=lst[i][0]
                for l in lst[j]:
                    if l>place_num1:
                        place_num2=l
                        switch=1
                        break
                if switch==1:
                    switch=0
                    for m in lst[k]:
                        if m>place_num2:
                            ans+=1
                            break

print(ans)

Submission status: Accepted

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

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            i_ok = False
            j_ok = False
            k_ok = False
            check = str(i)
            for l in range(N):
                if S[l] == check:
                    if not i_ok:
                        i_ok = True
                        check = str(j)
                    elif not j_ok:
                        j_ok = True
                        check = str(k)
                    elif not k_ok:
                        k_ok = True
                        break
    
            if i_ok and j_ok and k_ok:
                res += 1

print(res)

Submission status: Accepted

Solution code:
import sys

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


def resolve():
    n = int(input())
    s = input()
    num = list(set(s))
    res = 0
    for i in num:
        for j in num:
            for k in num:
                ss = i + j + k
                pos = 0
                for l in range(len(s)):
                    if ss[pos] == s[l]:
                        pos += 1
                        if pos == 3:
                            res += 1
                            break
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)

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

ans = 0

for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
S = input()
res = 0
for pair in product(range(10), repeat=3):
  s = S[::]
  found = True
  for i,num in enumerate(pair):
    idx = s.find(str(num))
    if idx == -1:
      found = False
      break
    else:
      if idx+1 == N:
        if i != len(pair)-1:
          found = False
        break
      s = s[idx+1:]

  if found:
    res += 1

print(res)

Submission status: Accepted

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

def solve(s):
    s = str(s)
    c = 0
    for i in range(1000):
        v = [i//100, i//10%10, i%10]
        f = 0
        for j in range(len(s)):
            if int(s[j]) == v[f]:
                f += 1
            if f == 3:
                break
        if f == 3:
            c += 1
    return c

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
m = n - 3
l = []

for i in num:
    for j in num:
        for k in num:
            if i in s:
                a = s.index(i)
                if j in s[a+1:]:
                    b = s[a+1:].index(j)
                    if k in s[a+1:][b+1:]:
                        l.append(i+j+k)

print(len(set(l)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
pins = ['0' * (3-len(str(i))) + str(i) for i in range(1000)]
ans = 0
for p in pins:
    a, b, c, = p
    if a not in s:
        continue
    p1 = s.index(a)
    if b not in s[p1+1:]:
        continue
    p2 = s[p1+1:].index(b) + len(s[:p1+1])
    if c not in s[p2+1:]:
        continue
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  divisors.sort()
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = S()

dic = DD(list)
for i in range(N):
  a = int(A[i])
  dic[a].append(i)
  
ans = 0
for i in range(10):
  if dic[i]:
    x = dic[i][0]
    for j in range(10):
      if dic[j]:
        p = bisect.bisect(dic[j],x)
        if p < len(dic[j]):
          y = dic[j][p]
          for k in range(10):
            p = bisect.bisect(dic[k],y)
            if p < len(dic[k]):
              ans += 1
print(ans)

Submission status: Accepted

Solution code:
import bisect
from collections import defaultdict
n = int(input())
s = input()

cnt = defaultdict(list)
for i, c in enumerate(s):
    cnt[c].append(i)


def is_Lucky(x):
    x = '{:03d}'.format(x)
    if not cnt[x[0]]:
        return False
    idx = cnt[x[0]][0]
    for c in x[1:]:
        i = bisect.bisect_right(cnt[c], idx)
        if len(cnt[c]) == i:
            return False
        idx = cnt[c][i]
    else:
        return True


ans = 0
for i in range(1000):
    if is_Lucky(i):
        ans += 1
print(ans)

Submission status: Accepted

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


def is_Lucky(x):
    x = tuple(map(int, '{:03d}'.format(x)))
    idx = 0
    for c in s:
        if x[idx] == c:
            idx += 1
            if idx == 3:
                return True
    else:
        return False


ans = 0
for i in range(1000):
    if is_Lucky(i):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    n=int(input())
    s=list(input())
    chk1=[0]*10
    chk2=[0]*100
    l=[]
    ans=0
    for i in range(n-2):
        if chk1[int(s[i])]==0:
            chk1[int(s[i])]=1
            for j in range(i+1,n-1):
                x=s[i]+s[j]
                if chk2[int(x)]==0:
                    chk2[int(x)]=1
                    if x in l:
                        continue
                    else:
                        l.append(x)
                        ans+=len(set(s[j+1:]))
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
cnt = 0
for i in range(10):
  if str(i) not in s[:-2]: continue
  i1 = s[:-2].index(str(i))
  for j in range(10):
    if str(j) not in s[i1+1:-1]: continue
    j1 = s[i1+1:-1].index(str(j))
    for k in range(10):
      if str(k) not in s[i1+1+j1+1:]: continue
      k1 = s[i1+1+j1+1:].index(str(k))
      #print(s[i1],s[i1+j1+1],s[i1+j1+k1+2])
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
for i in range(1000):
    secret = ('0' * 2 + str(i))[-3:]
    j = 0
    for c in S:
        if c == secret[j]:
            j += 1
        if j >= 3:
            ans += 1
            break
print(ans)

Submission status: Accepted

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

    ans = 0

    for i in range(10):
        a = s.find(str(i))
        if a == -1:
            continue
        for j in range(10):
            b = s.find(str(j), a + 1)
            if b == -1:
                continue
            for k in range(10):
                c = s.find(str(k), b + 1)
                if c == -1:
                    continue
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    ans = 0

    for i in range(10):
        a = s.find(str(i))
        if a == -1:
            continue
        for j in range(10):
            b = s.find(str(j), a + 1)
            if b == -1:
                continue
            for k in range(10):
                c = s.find(str(k), b + 1)
                if c == -1:
                    continue
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
p = 0
for i in range(10):
    pi = s.find(str(i))
    if pi == -1:
        continue
    for j in range(10):
        pj = s.find(str(j), pi + 1)
        if pj == -1:
            continue
        for k in range(10):
            pk = s.find(str(k), pj + 1)
            if pk == -1:
                continue
            p = p + 1
print(p)

Submission status: Accepted

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

ans = 0

for i in range(10):
    a = s.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = s.find(str(j), a + 1)
        if b == -1:
            continue
        for k in range(10):
            c = s.find(str(k), b + 1)
            if c == -1:
                continue
            ans += 1
print(ans)

Submission status: Accepted

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

ans = []

for i in range(10):
    if i in s:
        a = s.index(i)
        for j in range(10):
            if j in s[a + 1 :]:
                b = a + s[a + 1 :].index(j) + 1
                for k in range(10):
                    if k in s[b + 1 :]:
                        ans.append(f"{i}{j}{k}")
print(len(ans))

Submission status: Accepted

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

ans = []

for i in range(10):
    if i in s:
        a = s.index(i)
        for j in range(10):
            if j in s[a + 1 :]:
                b = [x for x, y in enumerate(s) if x > a and y == j][0]
                for k in range(10):
                    if k in s[b + 1 :]:
                        ans.append(f"{i}{j}{k}")
print(len(ans))

Submission status: Accepted

Solution code:
##
#<6>wa
n = int(input())
s = list(input())
st = [set() for i in range(3)]
for a in s:
    for pre in st[1]:
        st[2].add(pre + a)#3桁目
    for pre in st[0]:
        st[1].add(pre + a)#2桁目
    st[0].add(a)#1桁目

print(len(st[2]))

Submission status: Accepted

Solution code:
import sys
from collections import deque
from itertools import *


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())


n = I()
s = S()

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

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
ans=0
for _ in range(1000):
  t=str(_).zfill(3)
  #print(t)
  if s.find(t[0])==-1:
    continue
  check=s[s.find(t[0])+1:]
  if check.find(t[1])==-1:
    continue
  fin=check[check.find(t[1])+1:]
  if fin.find(t[2])==-1:
    continue
  ans+=1
print(ans)

Submission status: Accepted

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

    c = 0
    l1 = set()
    for i in range(n)[:-2]:
        if s[i] in l1:
            continue
        l1.add(s[i])
        l2 = set()
        for j in range(n)[i + 1:-1]:
            if s[j] in l2:
                continue
            l2.add(s[j])
            c += len(set(list(s[j + 1:])))

    print(c)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = set()
a1 = []
for i in range(n-2):
  if s[i] in a1:
    continue
  a1.append(s[i])
  a2 = []
  for j in range(i+1,n-1):
    if s[j] in a2:
      continue
    a2.append(s[j])
    a = a|set([s[i]+s[j]+k for k in set(list(s[j+1:]))])
print(len(a))

Submission status: Accepted

Solution code:
# 6
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN

import itertools
import copy
from collections import deque

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

ans = 0
iter = itertools.product("0123456789", repeat=3)

for it in iter:
    _s = copy.deepcopy(s)
    for i in it:
        try:
            _idx = _s.index(i)
            _s = _s[_idx+1:]
        except:
            break
    else:
        ans += 1
    
print(ans)

Submission status: Accepted

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

# 100の位
for i in range(10):
    # Sのn-2番目までにiがあるか
    str_i = str(i)
    for a in range(n-2):
        if s[a] == str_i:
            now_i = a
            break
    # 作れなかった場合打ち切り
    else:
        continue
    # 10の位
    for j in range(10):
        str_j = str(j)
        for b in range(now_i+1,n-1):
            if s[b] == str_j:
                now_j = b
                break
        else:
            continue
        # 1の位
        for k in range(10):
            str_k = str(k)
            for c in range(now_j+1,n):
                # 暗証番号がそろった
                if s[c] == str_k:
                    point += 1
                    break

print(point)

Submission status: Accepted

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

# 100の位
for i in range(10):
    # Sのn-2番目までにiがあるか
    now_i = -1
    str_i = str(i)
    for a in range(n-2):
        if s[a] == str_i:
            now_i = a
            break
    # 作れない場合以降の探索は打ち切り
    if now_i == -1:
        continue
    # 10の位
    for j in range(10):
        now_j = -1
        str_j = str(j)
        for b in range(now_i+1,n-1):
            if s[b] == str_j:
                now_j = b
                break
        if now_j == -1:
            continue
        # 1の位
        for k in range(10):
            str_k = str(k)
            for c in range(now_j+1,n):
                # 暗証番号がそろった
                if s[c] == str_k:
                    point += 1
                    break

print(point)

Submission status: Accepted

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

# 暗証番号を全探索する
for i in range(1000):
    t = str(i).zfill(3)
    now = 0
    # sで暗証番号が作れるかを検証
    for j in s:
        if j == t[now]:
            now += 1
        if now == 3:
            point += 1
            break

print(point)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    t = key[k]
    for s in s_list:
        if t == s:
            k += 1
            if k == 3:
                ans += 1
                break
            t = key[k]
print(ans)

Submission status: Accepted

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

for i in range(10):
    first = 0
    while S[first] != str(i) and first < N-1:
        first += 1
    if first > N-3:
        continue
    for j in range(10):
        second = first+1
        while S[second] != str(j) and second < N-1:
            second += 1
        if second > N-2:
            continue
        #print(i,first,j,second)
        ans += len(set(S[second+1:]))
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
re_list=[]
ele = list(map(str, S))
v_list=[]
vi_list=[]
flag = 0
count = 0
for i in range(1000):
    if i < 10:
        v_list.append("00"+str(i))
    elif i < 100:
        v_list.append("0" + str(i))
    else:
        v_list.append(str(i))

for i in range(1000):
    for j in range(N):
        if ele[j] == v_list[i][0] and flag == 0:
            flag = 1
            continue
        if ele[j] == v_list[i][1] and flag == 1:
            flag = 2
            continue
        if ele[j] == v_list[i][2] and flag == 2:
            count += 1
            break
    flag = 0
print(count)

Submission status: Accepted

Solution code:
import string
N = int(input())
S = input()
L = []
for i in string.digits:
    for j in string.digits:
        for k in string.digits:
            L.append((i,j,k))
count = 0
for l in L:
    if l[0] not in S:
        continue
    S2 = S[S.index(l[0])+1:]
    if l[1] not in S2:
        continue
    S3 = S2[S2.index(l[1])+1:]
    if l[2] not in S3:
        continue
    count += 1
print(count)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

kk=0
for i in range(1000):
  if i<10:
    p=['0','0',str(i)]
  elif i<100:
    p=['0',str(i)[0],str(i)[1]]
  else:
    p=list(str(i))
    
  flag=0
  for w in k:
    if w==p[flag]:
      flag+=1
    if flag==3:
      break
  
  if flag==3:
    #print(i)
    kk+=1
  else:pass

print(kk)

Submission status: Accepted

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

cnt = 0
for x in range(10):
    x_ = str(x)
    for i in range(n-2):
        if s[i] == x_:
            break
    else:
        continue
    for y in range(10):
        y_ = str(y)
        for j in range(i+1, n-1):
            if s[j] == y_:
                break
        else:
            continue
        for z in range(10):
            z_ = str(z)
            for k in range(j+1, n):
                if s[k] == z_:
                    cnt += 1
                    break

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    idx = 0
    target = key[idx]
    for ii in s:
        if target == ii:
            idx += 1
            if idx > 2:
                ans += 1
                break
            target = key[idx]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
d = [set() for _ in range(3)]
for i in range(N - 2):
    if S[i] in d[0]:
        continue
    d[0].add(S[i])
    for j in range(i + 1, N - 1):
        if S[i] + S[j] in d[1]:
            continue
        d[1].add(S[i] + S[j])
        for k in range(j + 1, N):
            if S[i] + S[j] + S[k] in d[2]:
                continue
            d[2].add(S[i] + S[j] + S[k])
print(len(d[2]))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
d = [set() for _ in range(3)]
for i in range(N - 2):
    if S[i] in d[0]:
        continue
    d[0].add(S[i])
    for j in range(i + 1, N - 1):
        if S[i] + S[j] in d[1]:
            continue
        d[1].add(S[i] + S[j])
        for k in range(j + 1, N):
            if S[i] + S[j] + S[k] in d[2]:
                continue
            d[2].add(S[i] + S[j] + S[k])
            ans += 1
print(ans)

Submission status: Accepted

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

num1, num2, num3 = set([]), set([]), set([])

#new for num3 <=> new password

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

print(len(num3))

Submission status: Accepted

Solution code:
from itertools import combinations

def readinput():
    n=int(input())
    s=input()

    return n,s

def main(n,s):
    count=0
    s1=s[:]
    for i in range(10):
        index1=s1.find(str(i))
        if index1 == -1:
            continue
        s2=s1[index1+1:]
        if(len(s2)<2):
            continue
        #print('s2: {}'.format(s2))
        for j in range(10):
            index2=s2.find(str(j))
            if index2 == -1:
                continue
            s3=s2[index2+1:]
            if(len(s3)<1):
                continue
            #print('s3: {}'.format(s3))
            for k in range(10):
                #print(s[index1+index2+1:])
                index3=s3.find(str(k))
                if index3 == -1:
                    continue
                count+=1
                #print(i,j,k)
    return count

if __name__=='__main__':
    n,s=readinput()
    ans=main(n,s)
    print(ans)

Submission status: Accepted

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

ans = 0

for i in range(10):
    a = S.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = S.find(str(j),a+1)
        for k in range(10):
            if b == -1:
                continue
            c = S.find(str(k),b+1)
            if c > b :
                ans +=1
print(ans)