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 = str(input())
ans = 0
for i in range(0, 1000):
    x = str(i).zfill(3)
    try:
        idx1 = S.index(x[0])
        idx2 = S.index(x[1], idx1+1)
        idx3 = S.index(x[2], idx2+1)
        ans += 1
    except ValueError:
        continue
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
re = 0
for i in range(1000):
    ans = [0]*3
    for j in range(3):
        ans[j] = str(i % 10)
        i = i // 10
    ans.reverse()
    flag = False
    idx_left = S.find(ans[0])
    idx_right = S.rfind(ans[2])
    if idx_left != -1 and idx_right != -1 and idx_left < idx_right:
        if ans[1] in S[idx_left+1:idx_right]:
            flag = True
    if flag:
        re += 1
print(re)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = 0
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(len(a_alr) == 10):
        break
    if(s[i] in a_alr):
        continue

    for j in range(i+1,n-1):
        if(len(b_alr[s[i]]) == 10):
            break
        if(s[j] in b_alr[s[i]]):
            continue
        
        ans += len(set(s[j+1:]))
        
        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(ans)

Submission status: Accepted

Solution code:
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():
    n = int(input())
    s = input()
    count = 0
    for i in range(1000):
        key = str(i + 1000)[1:]
        if key[0] in s:
            s2 = s[s.index(key[0]) + 1:]

            if key[1] in s2:
                s3 = s2[s2.index(key[1])+1:]

                if key[2] in s3:
                    count += 1

                else:
                    continue
    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

def dfs(depth, id):
    global ans
    for i in range(10):
        for j in range(id, n):
            if i == s[j]:
                if depth < 2:
                    dfs(depth + 1, j + 1)
                else:
                    ans += 1
                break

dfs(0, 0)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1000):
    if i<10:
        ss="00"+str(i)
    elif i<100:
        ss="0"+str(i)
    else:
        ss=str(i)
    k=0
    for j in range(n):
        if s[j]==ss[k]:
            k+=1
        if k==3:
            break
    if k==3:
        ans+=1
print(ans)

Submission status: Accepted

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

ans = 0
for x in range(0, 1000):
    pin = str(x).zfill(3)

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

print(ans)

Submission status: Accepted

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

count = 0
point_i=0

for s_i in z:
    point = point_i
    point_j = n
    for i in range(point,n):
        if s[i]==s_i:
            point_j = i+1
            break
            
    for s_j in z:
        point = point_j
        point_k = n
        for j in range(point,n):
            if s[j]==s_j:
                point_k = j+1
                break
            
        for s_k in z:
            point = point_k
            #point_l = n
            for k in range(point,n):
                if s[k]==s_k:
                    #point = k+1
                    count +=1
                    break
print(count)

Submission status: Accepted

Solution code:
def func1(i,N,S):
  indexS = 0 #Sの見ている場所
  indexI = 0 #3桁の暗証番号の見ている場所(0~2)
  i2 = str(i).zfill(3) # 0埋めしたi
  
  while indexS < N:
    if indexI > 2:
      break #探索終了
    if i2[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  return 1 if indexI >2 else 0

def main():
  N = int(input())
  S = input()
  print(sum([func1(i,N,S) for i in range(1000)]))

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
	a = '{:0=3}'.format(i)
	b = [False] * 3
	for j in S:
		if j == a[0] and not b[0]:
			b[0] = True
		elif j == a[1] and b[0] and not b[1]:
			b[1] = True
		elif j == a[2] and b[0] and b[1] and not b[2]:
			b[2] = True
	if all(b):
		ans += 1
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):
                if s.find(str(k), b+1) != -1:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    idx1 = S.find(i[0])
    if idx1 < 0:
        continue
    idx2 = S.find(i[1], idx1 + 1)
    if idx2 < 0:
        continue
    idx3 = S.find(i[2], idx2 + 1)
    if idx3 < 0:
        continue
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
#import math
#import bisect
#import numpy as np
import itertools
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')
sys.setrecursionlimit(10**5)

def main():
    n = int(input())
    s = input()
    ans = 0
    pin = list(itertools.product(range(10), repeat=3))

    for cur in pin:
        a, b, c = map(str,cur)
        if a in s:
            aidx = s.index(a)
            if b in s[aidx+1:]:
                bidx = s[aidx+1:].index(b) + (aidx + 1)
                if c in s[bidx+1:]:
                    ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
d = {str(i):[] for i in range(10)}
for i,x in enumerate(s):
    d[x].append(i)
_sum = 0
for i in range(10):
    if len(d[str(i)]) != 0:
        for j in range(10):
            if len(d[str(j)]) != 0:
                for k in range(10):
                    if len(d[str(k)]) != 0:
                        st = d[str(i)][0]
                        en = d[str(k)][-1]
                        for idx in d[str(j)]:
                            if idx>st and idx<en:
                                _sum+=1
                                break
                            elif idx>=en:
                                break
print(_sum)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
S = input()


# 0〜9までの各数字が左から何桁目に登場するか
d = defaultdict(list)
for i in range(n):
    d[int(S[i])].append(i)

pw = []
for i in d.keys():
    for j in d.keys():
        for k in d.keys():
            first = d[i][0]
            for l in d[j]:
                if l > first:
                    second = l
                    break
            else:
                continue
            for m in d[k]:
                if m > second:
                    third = m
                    break
            else:
                continue
            pw.append(S[first]+S[second]+S[third])
print(len(set(pw)))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
# 暗証番号のパターンは、000, 001, ,,,999の1000パターンしかない。
# このうち作れるモノを、sから探すか。
# その場合、O(1000 * 30000) でまぁ間に合いそう。
patterns = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            patterns.append(str(i) + str(j) + str(k))

ans = 0
for pattern in patterns:
    i = j = 0
    while i < n:
        if s[i] == pattern[j]:
            i += 1
            j += 1
            if j == 3:
                ans += 1
                break
        else:
            i += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for s in range(0, 1000):
    s = str(s).zfill(3)
    i = 0
    for d in s:
        if d in S[i:]:
            i += S[i:].index(d) + 1
        else:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import product

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

cnt = [defaultdict(int) for _ in range(len(N) + 1)]
left = [10 ** 10] * 10
right = [-1] * 10

for i, n in enumerate(N):
    left[n] = min(left[n], i)
    right[n] = max(right[n], i)

    for j in range(10):
        cnt[i + 1][j] = cnt[i][j]
    cnt[i + 1][n] += 1

ans = 0
for l, m, r in product(range(10), repeat=3):
    l = left[l]
    r = right[r]

    if l < r and cnt[r][m] - cnt[l + 1][m] > 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    S = list(input())
    right = [set() for _ in range(N)]
    for i in reversed(range(N - 1)): right[i] = right[i + 1] | {S[i + 1]}
    left = {S[0]}
    PIN = set()
    for i in range(1, N - 1):
        for ln in left:
            for rn in right[i]:
                p = ln + S[i] + rn
                PIN |= {p}
        left |= {S[i]}
    print(len(PIN))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ans = 0
history_i = set()
for i in range(N-2):

    if S[i] in history_i:
        continue

    history_j = set()
    for j in range(i+1, N-1):

        if S[j] in history_j:
            continue

        history_k = set()
        for k in range(j+1, N):

            if S[k] in history_k:
                continue
            history_k.add(S[k])
            ans += 1
            if len(history_k) == 10:
                break
        
        history_j.add(S[j])
        if len(history_j) == 10:
            break

    history_i.add(S[i])
    if len(history_i) == 10:
        break

print(ans)

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

######
# URL: https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
######

def main():
    N = i_inpl()
    base_S = input()
    ans = set()
    for i in range(1000):
        S = copy.deepcopy(base_S)
        find_num = str(i).zfill(3)
        k = S.find(find_num[0])
        if k == -1:
            continue

        S = S[k+1:]
        k = S.find(find_num[1])
        if k == -1:
            continue

        S = S[k+1:]
        k = S.find(find_num[2])
        if k == -1:
            continue

        ans.add(find_num)
    print(len(ans))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

def solve():
  n = int(input())
  s = input()
  dp = [[] for _ in range(4)]

  for i in range(n):
    number = s[i]
    

    for k in dp[2]:
      dp[3].append(k+number)
    for l in dp[1]:
      dp[2].append(l+number)  
    dp[1].append(number)
    
    for i in range(4):
      dp[i] = list(set(dp[i]))
  print(len(dp[3]))
    
      
solve()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
fi=lambda x,y:x.find(str(y))
for i in range(10):
  f1=fi(s,i)
  if f1==-1:
    continue
  s1=s[f1+1:]
  for j in range(10):
    f2=fi(s1,j)
    if f2==-1:
      continue
    s2=s1[f2+1:]
    for k in range(10):
      f3=fi(s2,k)
      if f3>=0:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    idx = 0
    flag = True

    for s in num:
        acc = S[idx:].find(s)
        if acc == -1:
            flag = False
            break
        else:
            idx += acc + 1
    if flag:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy


#X = str(input()).split()
#a = [int(x) for x in input().split()]


N = int(input())
S = str(input())
ii = 0
jj = 0
kk = 0
ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      if(str(i) in S):
        ii = S.index(str(i))
        SS = S[ii+1:]
        if(str(j) in SS):
          jj = SS.index(str(j))
          SS = SS[jj+1:]
          if(str(k) in SS):
            #print(str(i)+str(j)+str(k))
            ans+=1


print(ans)

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N = int(input())
    s = input()
    d1,d2,d3 = defaultdict(int),defaultdict(int),defaultdict(int) 
    
    for moji in s:
        for m2 in d2:
            d3[m2+moji] += 1
        for m1 in d1:
            d2[m1+moji] += 1
        d1[moji] += 1
    
    print(len(d3))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

def ind(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

cnt = 0
for i in range(1000):
    tmp = S
    t = str(i).zfill(3)

    pos_1 = ind(tmp,t[0])
    if pos_1>=0:
        tmp = tmp[pos_1+1:]
    elif pos_1 == -1:
        continue

    pos_2 = ind(tmp,t[1])
    if pos_2>=0:
        tmp = tmp[pos_2+1:]
    elif pos_2 == -1:
        continue

    pos_3 = ind(tmp,t[2])
    if pos_3>=0:
        tmp = tmp[pos_3+1:]
    elif pos_3 == -1:
        continue
    cnt += 1
print(cnt)

Submission status: Accepted

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

d1 = defaultdict(int)
d2 = defaultdict(int)
d3 = defaultdict(int)

for s in S:
    for x in d2:
        d3[x+s]+=1
    for y in d1:
        d2[y+s]+=1
    d1[s]+=1

print(len(d3))

Submission status: Accepted

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

sum = 0
box = []
for i in range(n-2):
    if s[i] not in box:
        box.append(s[i])
    elif len(box) == 10:
        break
    else:
        continue
    box_1 = []
    for j in range(i+1, n-1):
        if s[j] not in box_1:
            box_1.append(s[j])
        elif len(box_1) == 10:
            break
        else:
            continue
        box_2 = []
        for k in range(j+1, n):
            if s[k] not in box_2:
                box_2.append(s[k])
            elif len(box_2) == 10:
                break
            else:
                continue
        sum += len(box_2)

print(sum)

Submission status: Accepted

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


ans_L = []
length = len(s)
count = 0

for i in range(1000):
    i = list(str(i).zfill(3))
    idx = 0
    cnt = 0
    for j in range(3):
        for k in range(idx,length):
            if str(i[j]) == str(s[k]):
                idx = k+1
                cnt += 1
                break
        if cnt ==0:
            break

    #if len(tmp_L) == 3:
    #    ans_L.append("".join(tmp_L))
    if cnt == 3:
        count +=1

print(count)
#print(set(ans_L))

Submission status: Accepted

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

passwords = []
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            password = str(i) + str(j) + str(k)
            passwords.append(password)

char_hash = {}
for i, char in enumerate(S):
    if char in char_hash.keys():
        char_hash[char].append(i)
    else:
        char_hash[char] = [i]

# print(char_hash

count = 0
for password in passwords:
    exist_keys = char_hash.keys()
    # print(password[0] in char_hash.keys())
    if not(password[0] in exist_keys):
        continue
    if not(password[1] in exist_keys):
        continue
    if not(password[2] in exist_keys):
        continue
    first_index = min(char_hash[password[0]])
    second_indexes = char_hash[password[1]]
    second_index = -1
    for index in second_indexes:
        if index <= first_index:
            continue
        else:
            second_index = index
            break
    third_indexes = char_hash[password[2]]
    third_index = -1
    for index in third_indexes:
        if index <= second_index:
            continue
        else:
            third_index = index
            break
    # print(first_index, second_index, third_index)
    if first_index < second_index and second_index < third_index:
        count += 1

print(count)
# print(len(passwords))
# print(passwords)
# print(set(passwords))
# print(len(list(set(passwords))))

Submission status: Accepted

Solution code:
#python3
def main():
    n = int(input())
    s = input()
    cnt = 0
    for i in range(10):
        ind_i = s.find(str(i))  
        if ind_i == -1:
            continue
        for j in range(10):
            ind_j = s.find(str(j), ind_i+1)
            if ind_j == -1:
                continue
            for k in range(10):
                ind_k = s.find(str(k), ind_j+1)
                if ind_k == -1:
                    continue
                cnt += 1
    print(cnt)
main()

Submission status: Accepted

Solution code:
'''
https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
'''

def main():
    n = int(input())
    s = input()
    ans = 0
    for i in range(1000):
        pas = format(i, '03d')
        k, cnt = 0, 0
        for j in pas:
            if j in s[k:]:
                cnt += 1
                k += s[k:].index(j) + 1
        if cnt == 3:
            ans += 1
    print(ans)


    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    S=input()
    D=[0]*(N+1)
    s=set()
    for i in range(N-1,-1,-1):
        s.add(S[i])
        D[i]=len(s)
    ans=0
    for i in range(10):
        ni=S.find(str(i))
        if ni<0: continue
        for j in range(10):
            nj=S.find(str(j),ni+1)
            if nj>=0:
                ans+=D[nj+1]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#D - Lucky PIN
#000～999までそれぞれ作成できるかをチェックする
n=int(input())
s=str(input())
ans = 0
for i in range (10):
    for j in range (10):
        for k in range (10):
            check_i = (s.find(str(i)))
            check_j = (s.find(str(j),check_i+1))
            check_k = (s.find(str(k),check_j+1))
            if(check_i >= 0 and check_j >= 0 and check_k >= 0):
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=input()
S=input()
ans=0
for i in range(1000):
    n=str(i).zfill(3)
    x=S.find(n[0])
    y=S.find(n[1],x+1)
    z=S.find(n[2],y+1)
    if x!=-1 and y!=-1 and z!=-1:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
brute=[str(i)[1:] for i in range(1000,2000)]
for i in brute:
  flag=0
  for j in s:
    if j==i[0] and flag==0:
      flag+=1
      continue
    if flag==1 and j==i[1]:
      flag+=1
      continue
    if flag==2 and j==i[2]:
      ans+=1
      break
print(ans)

Submission status: Accepted

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

dp1 = [[0 for i in range(10)] for _ in range(n + 1)]
dp2 = [[0 for i in range(100)] for _ in range(n + 1)]
dp3 = [[0 for i in range(1000)] for _ in range(n + 1)]

for i in range(n):
    dp1[i + 1][int(s[i])] = 1
    for j in range(10):
        if dp1[i][j]:
            dp2[i + 1][j * 10 + int(s[i])] = 1
            dp1[i + 1][j] = 1
    for j in range(100):
        if dp2[i][j]:
            dp3[i + 1][j * 10 + int(s[i])] = 1
            dp2[i + 1][j] = 1
    for j in range(1000):
        if dp3[i][j]:
            dp3[i + 1][j] = 1

print(sum(dp3[n]))

Submission status: Accepted

Solution code:
import bisect

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

index_map = {}
for i in range(10):
    index_map[str(i)] = []

for i, c in enumerate(S):
    index_map[c].append(i)

count = 0
for i in range(1000):
    K = "%03d" % i
    index = 0
    for c in K:
        next_index = bisect.bisect_left(index_map[c], index)
        if next_index == len(index_map[c]):
            index = -1
            break
        else:
            index = index_map[c][next_index] + 1
    if index != -1:
        count += 1
print(count)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
d1 = [0] * 10
d2 = [0] * 100
d3 = [0] * 1000
for i in s:
    seq = int(i)
    for j in range(100):
        if d2[j] == 1:
            d3[j * 10 + seq] = 1
    for k in range(10):
        if d1[k] == 1:
            d2[k * 10 + seq] = 1
    d1[seq] = 1
print(sum(d3))

Submission status: Accepted

Solution code:
n=int(input())
S = input()
 
ans = 0
for i in range(1000):
    a, b, c = map(str, list(str(i).zfill(3)))
    mode = 'a'
    for j in S:
        if mode == 'a' and j == a:
            mode = 'b'
        elif mode == 'b' and j == b:
            mode = 'c'
        elif mode == 'c' and j == c:
            ans += 1
            break
print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline())
S = sys.stdin.readline()

ans = 0
for i in range(1000):
    password = str(i).zfill(3)
    p_i = 0
    s_i = 0
    while s_i < len(S) and p_i < 3:
        # print(p_i, s_i)
        if S[s_i] == password[p_i]:
            p_i += 1
        s_i += 1
    if p_i == 3:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input().strip()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag = 0
            for n in range(N):
                if flag==0 and S[n]==str(i):
                    flag = 1
                elif flag==1 and S[n]==str(j):
                    flag = 2
                elif flag==2 and S[n]==str(k):
                    flag = 3
                    break
            if flag==3:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import bisect

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

X = []
for i in range(10):
    X.append([])
for i in range(N):
    X[int(S[i])].append(i)

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if len(X[i]) > 0:
                ind = bisect.bisect_left(X[j],X[i][0] + 1)
                if ind < len(X[j]):
                    ind = X[j][ind] + 1
                    ind = bisect.bisect_left(X[k],ind)
                    if ind < len(X[k]):
                        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import bisect

n=int(input())
s=input()
fpos=[-1]*10
npos=[[-1] for _ in range(10)]
for i in range(n):
  if fpos[int(s[i])]==-1:
    fpos[int(s[i])]=i
  npos[int(s[i])].append(i)
lpos=[len(npos[i]) for i in range(10)]
ans=0
for i in range(10):
  if fpos[i]==-1:
    continue
  for j in range(10):
    spos=bisect.bisect_right(npos[j],fpos[i])
    if spos>=lpos[j]:
      continue
    spos=npos[j][spos]
    for k in range(10):
      tpos=bisect.bisect_right(npos[k],spos)
      if tpos>=lpos[k]:
        continue
      ans+=1
print(ans)

Submission status: Accepted

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

ans = 0
for num in range(1000):
    num_s = str(num).zfill(3)
    
    s_index_0 = s.find(num_s[0])
    if s_index_0 == -1 :
        continue
    s_index_1 = s.find(num_s[1],s_index_0+1)
    if s_index_1 == -1 :
        continue

    s_index_2 = s.find(num_s[2],s_index_1+1)
    if s_index_2 == -1:
        continue

    ans +=1 

        
    
print(ans)

Submission status: Accepted

Solution code:
def ABC106_B():
    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
    N = I()
    ans = 0
    for i in range((N+1)//2):
        cur = i*2+1
        if len(make_divisors(cur))==8:
            ans += 1
    print(ans)
    return

def ABC122_B():
    S = SI()
    ans = 0
    cur = 0
    d = {"A","C","G","T"}
    for s in S:
        if s in d:
            cur += 1
        else:
            ans = max(ans,cur)
            cur = 0
    ans = max(ans,cur)
    print(ans)
    return

def paken2019_C():
    N, M = LI()
    A = [LI()for _ in range(N)]
    T = [i for i in range(M)]
    ans = 0
    for t1,t2 in itertools.permutations(T,2):
        cur = 0
        for i in range(N):
            cur += max(A[i][t1],A[i][t2])
        ans = max(ans,cur)
    print(ans)
    return

def ABC95_C():
    A, B, C, X, Y = LI()
    if A+B<=C*2:
        ans = A*X+B*Y
    else:
        if X>Y:
            ans = Y*C*2 + min(A,C*2)*(X-Y)
        else:
            ans = X*C*2 + min(B,C*2)*(Y-X)
    print(ans)
    return

def SMTB_D():
    def flag(n,s):
        for l in range(n,N):
            if S[l]==str(s):
                return l
        return N
    N = I()
    S = SI()
    ans = 0
    for i in range(10):
        L1 = flag(0,i)
        for j in range(10):
            L2 = flag(L1+1,j)
            for k in range(10):
                L3 = flag(L2+1,k)
                if L3<N:
                    ans += 1
                    #print(i,j,k)
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    SMTB_D()

"""

"""

Submission status: Accepted

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

a = 0
ii = [0]*10
for i in range(n-2):
  si = int(s[i])
  if sum(ii) == 10:
    break
  elif ii[si] == 1:
    continue
  else:
    ii[si] = 1
  jj = [0]*10
  for j in range(i+1,n-1):
    sj = int(s[j])
    if sum(jj) == 10:
      break
    elif jj[sj] == 1:
      continue
    else:
      jj[sj] = 1
    kk = [0]*10
    for k in range(j+1,n):
      sk = int(s[k])
      if sum(kk) == 10:
        break
      else:
        kk[sk] = 1
    a += sum(kk)
print(a)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x = S.find(str(i))
            if x >=0 and x < len(S) - 2:
                y = S[x+1:].find(str(j))
                if y >= 0 and x+y < len(S) -1:
                    z = S[x+y+2:].find(str(k))
                    if z >= 0:
                        cnt += 1
print (cnt)

Submission status: Accepted

Solution code:
import itertools

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

    ans = 0
    output_list = []

    for i in range(1000):
        if len(str(i)) == 1:
            a = 0
            b = 0
            c = i
        elif len(str(i)) == 2:
            a = 0
            b = i // 10
            c = i - b * 10
        else:
            a = i // 100
            b = (i - a * 100) // 10
            c = i - a * 100 - b * 10
        tmp = str(a) + str(b) + str(c)
        output_list.append(tmp)
    
    for i in range(1000):
        a = output_list[i][0]
        b = output_list[i][1]
        c = output_list[i][2]
        first_flag = False
        second_flag = False
        for j in range(n):
            if not first_flag and s[j] == a:
                first_flag = True
                continue
            if first_flag and not second_flag and s[j] == b:
                second_flag = True
                continue
            if first_flag and second_flag and s[j] == c:
                ans += 1
                break

    print(ans)

if __name__ == '__main__':
    main()