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 = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([0 for j in range(10)])
l_set=set([])
r_set=set([])
for i,(r,l) in enumerate(zip(S_riv,S)):
  l_lis[i]=l_set.copy()
  r_lis[i]=r_set.copy()
  l_set.add(l)
  r_set.add(r)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  length=len(l_lis[i])
  ans+=(length-mat[s])*len(r_lis[i])
  mat[s]=length
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = "0" * (3 - len(str(i))) + str(i)
    j = 0
    flag = True
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[0]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[1]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[2]:
            j += 1
            break
        j += 1
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

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

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

cnt=0
for n in N:
  n0=s.find(n[0])
  if n0==-1:
    continue
  n1=s.find(n[1],n0+1)
  if n1==-1:
    continue
  n2=s.find(n[2],n1+1)
  if n2!=-1:
    cnt+=1
print(cnt)

Submission status: Accepted

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

def isAvailable(pw):
    for i in range(len(s)):
        if s[i] == pw[0]:
            pw = pw[1:]
            if pw == '':
                break

    if len(pw) == 0:
        return True
    else:
        return False

for i in range(10):
    for j in range(10):
        for k in range(10):
            pw = str(i) + str(j) + str(k)
            if isAvailable(pw):
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([0 for j in range(10)])
l_set=set([])
r_set=set([])
for i,s in enumerate(S):
  l_lis[i]=l_set.copy()
  l_set.add(s)
  
for i,s in enumerate(S_riv):
  r_lis[i]=r_set.copy()
  r_set.add(s)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  length=len(l_lis[i])
  ans+=(length-mat[s])*len(r_lis[i])
  mat[s]=length
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(int,list(input())))
S_riv=S[::-1]
l_lis=[0]*N
r_lis=[0]*N
mat=([set([])for j in range(10)])
l_set=set([])
r_set=set([])
for i,s in enumerate(S):
  l_lis[i]=l_set.copy()
  l_set.add(s)
  
for i,s in enumerate(S_riv):
  r_lis[i]=r_set.copy()
  r_set.add(s)
  
r_lis.reverse()
ans=0
for i,s in enumerate(S):
  ans+=len(l_lis[i]-mat[s])*len(r_lis[i])
  mat[s]=l_lis[i]
  
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(10):
    first = s.find(str(i))
    if first!=-1 and first!=n-1:
        for g in range(10):
            second = s[first+1:].find(str(g))+first+1
            if second!=first and second!=n-1:
                for l in range(10):
                    third = s[second+1:].find(str(l))+second+1
                    if third!=second:
                        ans+=1
print(ans)

Submission status: Accepted

Solution code:
inf = float("inf")

n = int(input())
s = list(map(int, input()))

ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            t = 0
            for l in s:
                if t == 0:
                    if l == i:
                        t += 1
                elif t == 1:
                    if l == j:
                        t += 1
                elif t == 2:
                    if l == k:
                        t += 1
            if t == 3:
                ans += 1

print(ans)

Submission status: Accepted

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

l = [str(i).zfill(3) for i in range(0,1000)]

ct = 0
for i in l:
  n0 = s.find(i[0])
  if n0==-1:
    continue
  n1 = s.find(i[1], n0+1)
  if n1==-1:
    continue
  n2 = s.find(i[2], n1+1)
  if n2!=-1:
    ct += 1
   
print(ct)

Submission status: Accepted

Solution code:
dig = [set() for i in range(3)]
_ = input()
n = input().strip()
for d in list(n):
  for v in dig[1]: dig[2].add(v + d)
  for v in dig[0]: dig[1].add(v + d)
  dig[0].add(d)
print (len(dig[2]))

Submission status: Accepted

Solution code:
import sys
#input = sys.stdin.readline
def solve():
  n = int(input())
  s = input()
  ans = 0
  for i in range(0,1000):
    t1,t2,t3 = 0,0,0
    c3 = str(i%10)
    c2 = str((i//10)%10)
    c1 = str(i//100)
    for t in range(n):
      if not t1:
        if s[t] == c1:
          t1 = 1
      elif not t2:
        if s[t] == c2:
          t2 = 1
      elif not t3:
        if s[t] == c3:
          t3 = 1
      
    
      if t1 and t2 and t3: 
        ans += 1
        break
  print(ans)
solve()

Submission status: Accepted

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

ones = set()
twos = set()
threes = set()

for a in s:
    for item in twos:
        threes.add(item+a)
    for item in ones:
        twos.add(item+a)
    ones.add(a)

print(len(threes))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
visited = {}

count = 0

for i, s in enumerate(S):
    if s in visited:
        continue
    visited[s] = []
    for j, s2 in enumerate(S[i+1:N-1]):
        # print(s, s2, S[i + j + 2:N])
        if s2 in visited[s]:
            continue
        count += len(set(S[i + j + 2:N]))
        visited[s].append(s2)
        # print(s, s2, set(S[j + 1:N]))
print(count)

Submission status: Accepted

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

def nc(n,s,i,j,k):
    c1 = -1
    for l in range(n):
        if s[l] == i:
            c1 = l
            break
    if c1 == -1:
        return 0
    c2 = -1
    for l in range(c1+1,n):
        if s[l] == j:
            c2 = l
            break
    if c2 == -1:
        return 0
    c3 = -1
    for l in range(c2+1,n):
        if s[l] == k:
            c3 = l
            break
    if c3 == -1:
        return 0
    return 1

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                c += nc(n,s,i,j,k)



print(c)

Submission status: Accepted

Solution code:

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

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

for i in range(n):
    c = int(s[i])
    lst[c].append(i)

done = []
cnt = 0
for x in range(0,1000):
    tmp = str(x).rjust(3,'0')
    c1,c2,c3 = int(tmp[0]),int(tmp[1]),int(tmp[2])
    
    mi = -1
    mx = -1
    if len(lst[c1]) != 0:
        mi = lst[c1][0]
    if len(lst[c3]) != 0:
        mx = lst[c3][-1]
    
    if mi >= 0 and mx >= 0:
        for y in lst[c2]:
            if mi < y < mx:
                done.append(tmp)
    else:
        continue
        

print(len(set(done)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter
from math import factorial

def main():
    n = int(input().strip())
    s = input().strip()
    s += 'E'
    ans = 0
    for i in range(1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
        k = s.find(str(a))
        l = s.find(str(b), k+1)
        m = s.find(str(c), l+1)
        if k != -1 and l != -1 and m != -1:
            # print(a, b, c)
            ans += 1
    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(1000):
  num = '{:03}'.format(i)
  t=0
  for j in range(n):
    if s[j] == num[t]:
      t += 1
      if t > 2:
        cnt += 1
        break
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
nums = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            nums.append(str(i) + str(j) + str(k))

cnt = 0
for num in nums:
    j = 0
    for i in range(N):
        if S[i] == num[j]:
            j += 1
        if j > 2:
            cnt += 1
            break

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
cnt = 0

for i in range(1000):
    j = 0
    flag1 = False
    flag2 = False
    flag3 = False
    istr = str(i)
    istr = istr.rjust(3, '0')
    #print(istr)
    while j < N:
        if not flag1 and S[j] == istr[0]:
            flag1 = True
        elif flag1 and (not flag2) and S[j] == istr[1]:
            flag2 = True
        elif flag1 and flag2 and S[j] == istr[2]:
            flag3 = True
            #print(istr)
            break
        j += 1
    if flag1 and flag2 and flag3:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
s=list(map(lambda c:ord(c)-48,input()))
cnt=0
for x in range(10):
    idx=0
    while idx<N and s[idx]!=x:
        idx+=1
    if idx==N:continue
    for y in range(10):
        idy=idx+1
        while idy<N and s[idy]!=y:
            idy+=1
        if idy==N:continue
        for z in range(10):
            idz=idy+1
            while idz<N and s[idz]!=z:
                idz+=1
            if idz<N:cnt+=1
print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    n = "{:03}".format(i)
    index = 0
    c = 0
    for k in n:
        for j in range(index, N):
            if S[j] == k:
                index = j+1
                c+=1
                break
    if c == 3:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                a = 0
                password = str(i) + str(j) + str(k)
                for s in S:
                    if s == password[a]:
                        a += 1
                    if a == 3:
                        ans += 1
                        break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1000):
        password = str(i).zfill(3)
        j = 0
        for s in S:
            if s == password[j]:
                j += 1
            if j == 3:
                ans += 1
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
input()
a, b, c = set(), set(), set()
for x in input():
  c.update(y + x for y in b)
  b.update(y + x for y in a)
  a.add(x)
print(len(c))

Submission status: Accepted

Solution code:
input()
a = set(), set(), set(), ('',)
for x in input():
  for s, t in zip(a, a[1:]):
    s.update(y + x for y in t)
print(len(a[0]))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
L=[[0 for j in range(10)]for i in range(N+1)]
R=[[0 for j in range(10)]for i in range(N+1)]
for i in range(N):
    for j in range(10):
        L[i+1][j]=L[i][j]
    L[i+1][int(S[i])]=1
for i in range(N-1,-1,-1):
    for j in range(10):
        R[i][j]=R[i+1][j]
    R[i][int(S[i])]=1
ans=[[[0 for k in range(10)]for j in range(10)] for i in range(10)]
num=[0 for k in range(10)]
for t in range(N):
    X=[]
    Y=[]
    k=int(S[t])
    for x in range(10):
        if L[t][x]==1:
            X.append(x)
    for y in range(10):
        if R[t+1][y]==1:
            Y.append(y)
    for i in X:
        for j in Y:
            if ans[i][j][k]==0:
                ans[i][j][k]=1
                num[k]+=1
print(sum(num))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
L=[[0 for j in range(10)]for i in range(N+1)]
R=[[0 for j in range(10)]for i in range(N+1)]
for i in range(N):
    for j in range(10):
        L[i+1][j]=L[i][j]
    L[i+1][int(S[i])]=1
for i in range(N-1,-1,-1):
    for j in range(10):
        R[i][j]=R[i+1][j]
    R[i][int(S[i])]=1
ans=[[[0 for k in range(10)]for j in range(10)] for i in range(10)]
num=[0 for k in range(10)]
for t in range(N):
    X=[]
    Y=[]
    k=int(S[t])
    if num[k]==100:
        continue
    for x in range(10):
        if L[t][x]==1:
            X.append(x)
    for y in range(10):
        if R[t+1][y]==1:
            Y.append(y)
    for i in X:
        for j in Y:
            if ans[i][j][k]==0:
                ans[i][j][k]=1
                num[k]+=1
print(sum(num))

Submission status: Accepted

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

first_num_list  = []
second_num_list = []
third_num_list  = []

count = 0

for s_first in range(len(S)):
  second_num_list = []
  if S[s_first] not in first_num_list:
    first_num_list.append(S[s_first])
    for s_second in range(s_first+1,len(S)):
      third_num_list = []
      if S[s_second] not in second_num_list:
        second_num_list.append(S[s_second])
        for s_third in range(s_second+1,len(S)):
          if S[s_third] not in third_num_list:
            third_num_list.append(S[s_third])
            count += 1

print(count)

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):
            a = s.find(str(i))
            if a < 0:
                continue
            b = s.find(str(j), a + 1)
            if b < 0:
                continue
            c = s.find(str(k), b + 1)
            if c > -1:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
#print(N,S)

count=0


for n1 in range(10):
 cond=0
 for i in range(N-2):
   if n1==int(S[i]):
      p1=i
      cond=1
      break
 if cond==1:
  for n2 in range(10):
    for j in range(p1+1,N-1):
      if n2==int(S[j]):
        p2=j
        cond=2
        break
    if cond==2:
     for n3 in range(10):
       #print(n3,S[p2+1:],str(n3) in S[p2+1:] )
       if str(n3) in S[p2+1:]:
        #print(n1,n2,n3)
        count+=1
        cond=0
      
              
print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    S=input()
    ans=0

    for p in range(1000):
        p=str(p).zfill(3)
        now=0
        for i,d in enumerate(p):
            while(now<n and S[now]!=d):
                now+=1
            if(i<=1):
                now+=1
        ans+=(now<n)
    print(ans)
resolve()

Submission status: Accepted

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

v1 = [100]*10
v2 = [0]*10
v3 = [0]*10

out = 0

for i in range(len(s)):
  idx = int(s[i])
  if v3[idx] > 0:
    out += v3[idx]
    v3[idx] = 0
  if v2[idx] > 0:
    for j in range(len(v2)):
      v3[j] += v2[idx]//10
    v2[idx] = 0
  if v1[idx] > 0:
    for j in range(len(v2)):
      v2[j] += v1[idx]//10
    v1[idx] = 0

print(out)

Submission status: Accepted

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

count = 0

for i in range(10):
    if i in S[:N-2]:
        a = S.index(i)
        for j in range(10):
            if j in S[a+1:N-1]:
                b = S[a+1:N-1].index(j) +a+1
                for k in range(10):
                    if k in S[b+1:]:
                        count +=1
print(count)

Submission status: Accepted

Solution code:
_,s=open(0)
x,y,z=eval('set(),'*3)
for c in s[:-1]:
  z|={t+c for t in y}
  y|={t+c for t in x}
  x|={c}
print(len(z))

Submission status: Accepted

Solution code:
_,s=open(0)
x,y,z=eval('set(),'*3)
for c in s[:-1]:
  for t in y:z.add(t+c)
  for t in x:y.add(t+c)
  x.add(c)
print(len(z))

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
S = input()

def check(x):
    i = 0
    for a in S:
        if a == x[i]:
            i += 1
            if i == 3:
                return True
    return False

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x = str(i)+str(j)+str(k)
            if check(x):
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def d():
	from bisect import bisect_left
	N = int(input())
	S = input()
	chars_at = {}
	for i in range(N):
		try:
			chars_at[S[i]].append(i)
		except KeyError:
			chars_at[S[i]] = [i]
	ans = 0
	for i in range(1000):
		s = str(i).zfill(3)
		cur = -1
		for j in range(3):
			try:
				p = bisect_left(chars_at[s[j]],cur)
			except KeyError:
				break

			if p < len(chars_at[s[j]]):
				cur = chars_at[s[j]][p] + 1
			else:
				break
		else:
			ans += 1
	print(ans)
d()

Submission status: Accepted

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

    # 暗証番号を全探索 (PyPy で 400ms 程度)
    ans = 0
    for v in range(1000):
        pin = '{0:03}'.format(v)
        current_index = 0
        current_searching = pin[current_index]

        for ch in S:
            if ch == current_searching:
                current_index += 1
                if current_index == 3:
                    ans += 1
                    break
                current_searching = pin[current_index]
    return ans

print(d_lucky_pin())

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def main():
    N=int(input())
    S=input()[:-1]
    
    can = set([""]) ## 2文字以下で現在構築可能な文字列(最大10+10*10 = 1010)
    ans = set() ## 3文字で現在構築可能な文字列(最大10*10*10 = 1,000)
    for s in S: 
        for c in can.copy(): #途中でcanという集合に追加されるのでcopyする
            res = c+s #2文字以下 + 1文字 で結合する
            if len(res) == 3: #3文字なので暗証番号の候補
                ans.add(res)
            elif len(res) < 3: #2文字以下なのでcanに挿入
                can.add(res)
    print(len(ans))

    """
    copyする回数 = N * len(can) <= 10^3 * N
    for文の走査回数 = N * len(can) <= 10^3 * N
    
    全体で  2 * (10^3 * N)
    N<=3*10^4なので
    2*3* 10^3 * 10^4 = 6 * 10^7 -> 間に合わない？んですか・・・？
    """

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_right
n=int(input())
s=input()
ind=[[] for i in range(10)]
i=0
for c in s:
    ind[ord(c)-48].append(i)
    i+=1
cnt=0
for i in range(1000):
    j=i//100
    k=i//10-j*10
    l=i%10
    if len(ind[j])*len(ind[k])*len(ind[l])==0:
        continue
    if ind[j][0]<ind[k][-1]:
        if ind[k][bisect_right(ind[k],ind[j][0])]<ind[l][-1]:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
p = [set() for _ in range(100)]
sp = [set() for _ in range(n)]
k = int(s[-1])
sp[-1].add(k)
ful = False
for j in range(n-2,1,-1):
    if ful:
        sp[j] = {0,1,2,3,4,5,6,7,8,9}
    tmp = set(sp[j+1])
    if len(tmp) == 10:
        ful = True
    tmp.add(int(s[j]))
    sp[j] = tmp

s10 = [[99999 for _ in range(2)] for _ in range(10)]
for i,d in enumerate(s):
    c = int(d)
    if s10[c][0] == 99999:
        s10[c][0] = i
    elif s10[c][1] == 99999:
        s10[c][1] = i
g = 0
for i in range(10):
    for j in range(10):
        ans = 0
        nexid = min(s10[i])
        if nexid != 99999:
            for r in range(nexid+1,n-1):
                if int(s[r]) == j:
                    ans = len(sp[r+1])
                    break
            g += ans
print(g)

Submission status: Accepted

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

ans=0
for i in range(1000):
    j="0"*(3-len(str(i)))+str(i)
    flag1=False
    flag2=False
    flag3=False
    for i in range(n):
        if not flag1 and S[i]==j[0]:
            flag1=True
            continue
        if flag1 and not flag2:
            if S[i]==j[1]:
                flag2=True
                continue
        if flag2 and not flag3:
            if S[i]==j[2]:
                flag3=True
                break
    if flag3:
        ans+=1
print(ans)

Submission status: Accepted

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

def solve(N: int, S: str):
    answer = 0
    for i in range(0,1000):
        i = str(i).zfill(3)
        x = S.find(i[0])
        if x == -1:
            continue

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

        z = S.find(i[2],y+1)
        if z == -1:
            continue
        
        answer +=1
    print(answer)
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
PIN = []
b1 = []
for i in range(N-2):
    b2 = []
    if S[i] in b1:
        continue
    else:
        b1.append(S[i])
    for j in range(i+1, N-1):
        b3 = []
        if S[j] in b2:
            continue
        else:
            b2.append(S[j])
        for k in range(j+1, N):
            if S[k] in b3:
                continue
            else:
                b3.append(S[k])
            cand = S[i] + S[j] + S[k]
            PIN.append(cand)

print(len(set(PIN)))

Submission status: Accepted

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

ctr = [0] * 1000
ans = 0
for i in range(1000):
    v1 = i // 100
    v2 = i // 10 - v1 * 10
    v3 = i - v1 * 100 - v2 * 10
    
    p1 = S.find(str(v1))
    if p1 < 0:
        continue
        
    p2 = S[p1+1:].find(str(v2))
    if p2 < 0:
        continue
        
    p3 = S[p1+p2+2:].find(str(v3))
    ans += int(p3 >= 0)
    
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
 
N = int(input())
S = input()
 
cnt = 0
for i, j, k in product("0123456789", repeat=3):
    try:
        x = S.index(i)
        y = S.index(j, x + 1)
        z = S.index(k, y + 1)
    except:
        continue
    cnt += 1
 
print(cnt)

Submission status: Accepted

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

nsl=['{:03}'.format(i) for i in range(1000)]

res=0
for ns in nsl:
  idx=0
  for char in s:
    if char == ns[idx]:
      idx+=1
      if idx == 3:
        res+=1
        break
print(res)

Submission status: Accepted

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

def my_index(LIST, VALUE,START):
    if VALUE in LIST[START:]:
        return LIST.index(VALUE,START)
    else:
        return float("inf")

answer = 0
# 暗証番号がiとなるか判定
for i in range(1000):
    PIN = str(i).rjust(3,"0")
    if PIN[0] in S:
        one_digit = S.index(PIN[0])
    else:
        continue
    if PIN[1] in S:
        two_digit = my_index(S,PIN[1],one_digit+1)
        if two_digit == float("inf"):
            continue
    else:
        continue
    if PIN[2] in S:
        three_digit = my_index(S,PIN[2],two_digit+1)
        if three_digit == float("inf"):
            continue
    else:
        continue
    answer += 1

print(answer)

Submission status: Accepted

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

dp = tuple([0] * 1000 for _ in range(4))
dp[0][0] = 1
# dp[x][int(str)]:=x文字のstrは構成可能か？0/1

for x in s:
    for incomplete_key in range(100):
        dp[3][incomplete_key * 10 + x] |= dp[2][incomplete_key]
    for incomplete_key in range(10):
        dp[2][incomplete_key * 10 + x] |= dp[1][incomplete_key]
    dp[1][x] = 1

print(sum(dp[3]))

# dp

Submission status: Accepted

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

count = 0 
for i in range(1000):
        key = str(i)
        if len(key) == 1:
                key = '00' + key 
        elif len(key) == 2:
                key = '0' + key 
        position_first = s.find(key[0]) 
        if position_first != -1 and position_first < n - 2:
                position_first += 1
                position_second = s[position_first:].find(key[1])
                if position_second != -1 and position_second + position_first < n - 1:
                        position_second += 1
                        position_third = s[position_first + position_second:].find(key[2])
                        if position_third != -1: 
                                count += 1
print(count)

Submission status: Accepted

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

total = 0

for i in range(1000):
    query = str(i)
    query = "0"*(3-len(query)) + query

    current_query = query[0]
    current_query_index = 0
    for s in S:
        if s == current_query:
            current_query_index += 1
            if current_query_index == 3:
                break
            current_query = query[current_query_index]
    if current_query_index == 3:
        total += 1

print(total)

Submission status: Accepted

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

dp = tuple(set() for _ in range(4))
dp[0].add('')
# dp[x]:=x文字の構成可能なset

for c in s:
    for k in range(2, -1, -1):
        for incomplete_key in dp[k]:
            dp[k + 1].add(incomplete_key + c)

print(len(dp[3]))

# dp

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
V = []
f=0
s=set()
for i in range(10):
    for j in range(10):
        for k in range(10):
            V.append(str(i)+str(j)+str(k))

for v in V:
    for a in range(N):
        if S[a]==v[0]:
            for b in range(a+1, N):
                if S[b]==v[1]:
                    for c in range(b+1, N):
                        if S[c]==v[2]:
                            s.add(v)
                            break
                    break
            break
print(len(s))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
S_uniquie = ''.join(set(S))
answer = 0
for left_s in S_uniquie:
    for i in range(N):
        if S[i] == left_s:
            left_pos = i
            break
    for right_s in S_uniquie:
        for i in range(N - 1, -1, -1):
            if S[i] == right_s:
                right_pos = i
                if left_pos + 2 <= right_pos:
                    answer += len(''.join(set(S[left_pos + 1:right_pos])))
                break

print(answer)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1000):
  v=str(i)
  v=v.zfill(3)
  ss=s
  if not v[0] in ss:
    continue  
  ss=ss[ss.index(v[0])+1:]
  if not v[1] in ss:
    continue
  ss=ss[ss.index(v[1])+1:]
  if not v[2] in ss:
    continue
  ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s= input()
ans=0
for x in range(1000):
    num=str("{0:03d}".format(x))
    s1=s.find(num[0])
    if(s1!=-1):
        s2=s.find(num[1],s1+1)
        if(s2!=-1):
            s3=s.find(num[2],s2+1)
            if(s3!=-1):
                ans+=1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
from string import digits


def is_producible(s, digit3):
    curr = 0
    for c in s:
        if c == digit3[curr]:
            curr += 1
            if curr == 3:
                return True
    return False


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

ret = 0
for digit3 in product(digits, repeat=3):
    if is_producible(s, digit3):
        ret += 1
print(ret)

# 問題を分割する
# この番号は作れるのか？

Submission status: Accepted

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

Submission status: Accepted

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


N = 0
number1 = list(range(10))


for i in range(0,n-2):
    if int(s[i]) in number1:
        number1.remove(int(s[i]))
        number2 = list(range(10))
        for j in range(i + 1,n - 1):
            
            if int(s[j]) in number2:
                number2.remove(int(s[j]))
                number3 = list(range(10))
                for k in range(j + 1,n):
                    if int(s[k]) in number3:
                        number3.remove(int(s[k]))
                        N += 1
                        if N == 1000:
                            break
"""
                        print(s[i]+s[j]+s[k])
                        print("{}{}{}".format(i,j,k))
"""
                        

print(N)

Submission status: Accepted

Solution code:
def main():
    import itertools
    import re

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

    cnt = 0
    for key in itertools.product('0123456789', repeat=3):
        key1, key2, key3 = map(str, key)
        if key1 in s:
            key1_idx = s.find(key1)
            if key2 in s[key1_idx+1:]:
                key2_idx = key1_idx + s[key1_idx+1:].find(key2) + 1
                if key3 in s[key2_idx+1:]:
                    cnt += 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
s = input()
ans = 0
for i in range(1000):
  code = str(i).zfill(3)
  f = 0
  for j in range(len(s)):
    if (s[j] == code[f]):
      f += 1
    if (f == 3):
      break
  if (f == 3):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
input()
S=list(input())
ans=0
 
def index(x,l):
    if x in l:
        return l.index(x)
    else:
        return -1
 
for i in range(1000):
    s=list(str(i).zfill(3))
    if index(s[0],S) != -1:
        if index(s[1],S[S.index(s[0])+1:]) != -1:
            if index(s[2],S[S.index(s[0])+1:][S[S.index(s[0])+1:].index(s[1])+1:]) != -1:
                ans += 1
print(ans)