Problem:


Score: 400 points

Problem Statement

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

Thus, he can set three different PIN codes: 022, 024, and 224.

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Accepted

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

for N in range(1000):
    tgt = str(N).zfill(3)
    if tgt[0] in s:
        i = s.index(tgt[0])
        if tgt[1] in s[i+1:]:
            j = s[i+1:].index(tgt[1]) + i
            if tgt[2] in s[j+2:]:
                cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
ans=0
for i in range(10):
  for j in range(10):
    for k in range(10):
      x=[str(i),str(j),str(k)]
      cnt=0
      for y in range(len(s)):
        if s[y]==x[cnt]:
          cnt+=1
        if cnt==3:
          ans+=1
          cnt+=1
          break
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(1000):
  l=[]
  for j in range(3):
    l.append(i//10**(2-j)%10)
  k=0
  for j in range(N):
    if int(S[j])==l[k]:
      k+=1
      if k==3:
        ans += 1
        break
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

def kanou(s, i1, i2, i3):
    target = [i1, i2, i3]
    target_iter = target.__iter__()
    now = next(target_iter)
    for c in s:
        if c == now:
            try:
                now = next(target_iter)
            except StopIteration:
                return True
    return False

res = 0
for i in range(0, 1000):
    if i <= 9:
        i1 = "0"
        i2 = "0"
        i3 = str(i)
    elif i <= 99:
        tmp = str(i)
        i1 = "0"
        i2 = tmp[0]
        i3 = tmp[1]
    else:
        tmp = str(i)
        i1 = tmp[0]
        i2 = tmp[1]
        i3 = tmp[2]
    if kanou(S, i1, i2, i3):
        res += 1

print(res)

Submission status: Accepted

Solution code:
cnt = 0
input()
s = input()

for i in range(1000):
    x = str(i).zfill(3)
    a = s[:-1].find(x[0])
    if a != -1:
        b = s[a + 1 : -1].find(x[1])
        if b != -1:
            c = s[a + b + 2 :].find(x[2])
            if c != -1:
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
l=[0]*1000
for _ in range(n):
    i=s[_]
    for j in range(1000):
        k=str(j).zfill(3)
        if k[0]==i and l[j]==2:
            l[j]=3
        if k[1]==i and l[j]==1:
            l[j]=2
        if k[2]==i and l[j]==0:
            l[j]=1
ans=0
for i in l:
    if i==3:
        ans+=1
print(ans)

Submission status: Accepted

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

numlist = [str(i) for i in range(10)]
for a in numlist:
    idx_a = S.find(a)
    if idx_a == -1 or idx_a >= N - 2:
        continue
    
    for b in numlist:
        idx_b = S[idx_a+1:].find(b)
        if idx_b == -1 or idx_a + idx_b + 1 >= N - 1:
            continue
        
        for c in numlist:
            if c in S[idx_a + idx_b + 2:]:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
S = input()
ans = 0
for i in range(1000):
    nya = str(i).zfill(3)
    x = S.find(nya[0])
    y = S.find(nya[1], x+1)
    z = S.find(nya[2], y+1)
    if x != -1 and y != -1 and z != -1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def chk(x):
    cur = 0
    cnt = 0
    while cur<N:
        if S[cur]==str(x[cnt]):
            cnt += 1
            if cnt==3:
                break
        cur += 1
    if cnt==3:
        return 1
    else:
        return 0

N = int(input())
S = input().strip()
cnt = 0
for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            cnt += chk((i,j,k))
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
from bisect import *
def solve():
  ans = 0
  N = int(input())
  S = input()
  d = defaultdict(lambda: [])
  for i,s in enumerate(S):
    d[int(s)].append(i)
  for p in product(range(10),repeat=3):
    if not len(d[p[0]]):
      continue
    ind1 = d[p[0]][0]
    ind2 = bisect_right(d[p[1]],ind1)
    if ind2==len(d[p[1]]):
      continue
    ind2 = d[p[1]][ind2]
    ind3 = bisect_right(d[p[2]],ind2)
    if ind3==len(d[p[2]]):
      continue
    ans += 1
  return ans
print(solve())

Submission status: Accepted

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

cnt = 0
for i in range(1000):
    x = str(i).zfill(3)
    a = s.find(x[0])
    b = s[a+1:].find(x[1])
    c = s[a+b+2:].find(x[2])
    if -1 not in (a,b,c):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 

def main():
    n = getN()
    S = getS()
    dp = [0] * (11*11*11)
    dp[0] = 1
    for c in S:
        tmp = [0] * (11*11*11)
        for i, d in enumerate(dp):
            if d == 1:
                tmp[i] = 1
                tmp[(i%121) * 11 + int(c) + 1] = 1

        dp = tmp
        # print(dp[-999:])
        # print(sum(dp[-999:]))

    print(sum(dp[(11*11):]))


 
if __name__ == "__main__":
    main()

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):
      if s.find(str(k),b+1) != -1:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
P, Q = [], [] 
t = 0
for i in range(N-2):
  if S[i] not in P:
    P.append(S[i]) 
    for j in range(i+1, N-1):
      if S[j] not in Q:
        Q.append(S[j])
        t += len(set(S[j+1:]))
    Q.clear()
print(t)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = [False for _ in range(1000)]
for j in range(1000):
  t = str(j).zfill(3)
  if(s.find(t[0:1]) > -1):
    s1 = s[s.find(t[0:1])+1:]
    if(s1.find(t[1:2]) > -1):
      s2 = s1[s1.find(t[1:2])+1:]
      if(s2.find(t[2:3]) > -1):
        a[j] = True
ans = 0
for i in range(1000):
  if(a[i]):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
# D - Lucky PIN
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = 0
            while tmp<N and int(S[tmp])!=i:
                tmp += 1
            if tmp==N:
                continue
            tmp += 1
            while tmp<N and int(S[tmp])!=j:
                tmp += 1
            if tmp==N:
                continue
            tmp += 1
            while tmp<N and int(S[tmp])!=k:
                tmp += 1
            if tmp==N:
                continue
            ans += 1            
print(ans)

Submission status: Accepted

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

ans = 0

# find()は最初に一致した部分のみを返す
# 3桁の番号なので高々1000通り調べれば良いだけ
# N<=30000、N(C)3通り全部調べようとすると10**12個くらい調べることになって死ぬ

# 1桁目
for x in range(10):
    if S.find(str(x)) >= 0:
        temp1 = S[S.find(str(x)) + 1:]

        # 2桁目
        for y in range(10):
            if temp1.find(str(y)) >= 0:
                temp2 = temp1[temp1.find(str(y)) + 1:]

                # 3桁目
                for z in range(10):
                    if temp2.find(str(z)) >= 0:
                        ans += 1

print(ans)

Submission status: Accepted

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

for x in range(10):
    if s.find(str(x)) > -1:
        tmp = s[s.find(str(x)) + 1:]
        for y in range(10):
            if tmp.find(str(y)) > -1:
                tmp2 = tmp[tmp.find(str(y)) + 1:]
                for z in range(10):
                    if tmp2.find(str(z)) > -1:
                        ans += 1

print(ans)

Submission status: Accepted

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

N=int(input())

S=input()


T=[[0] * 10 for _ in range(30000)]
for i in range(N):
    if i!=0:
        T[i]=copy.deepcopy(T[i-1])
    T[i][int(S[i])]+=1
#print(T)

dic={}
flag=[False]*10
for i in range(N-2):
    if flag[int(S[i])]==True:
        continue
    flag[int(S[i])]=True
    for j in range(i+1,N-1):
        tmp2=copy.deepcopy(T[N-1])
        tmp3=copy.deepcopy(T[j])
        tmp4=""
        for k in range(10):
            if tmp2[k]-tmp3[k]!=0:
                tmp4=S[i]+S[j]+str(k)
                #print(tmp4)
                if tmp4 in dic:
                    pass
                else:    
                    dic[tmp4]=1
           
print(len(dic))
#print(dic)

Submission status: Accepted

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

f = [0]*1000

rnum = [0]*10
lnum = [0]*10

for i in s:
    rnum[i] += 1

rnum[s[0]] -= 1
lnum[s[0]] += 1

for i in range(1, n-1):
    rnum[s[i]] -= 1
    for j in range(10):
        for k in range(10):
            if lnum[j] >= 1 and rnum[k] >= 1:
                f[j*100+s[i]*10+k] = 1
    lnum[s[i]] += 1

cnt = 0
for i in f:
    if i == 1:
        cnt += 1
    
print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(10):
    if str(i) in s:
        index_i = s.index(str(i))
        for j in range(10):
            if str(j) in s[index_i + 1:]:
                index_j = s[index_i + 1:].index(str(j)) + index_i + 1
                for k in range(10):
                    if str(k) in s[index_j + 1:]:
                        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

counter = 0
for a,b,c in itertools.product(range(10), repeat=3):
  
  a_ind = S.find(str(a))
  if a_ind==-1:
    continue
  else:
    b_ind = S[a_ind+1:].find(str(b))
    if b_ind==-1:
      continue
    else:
      c_ind = S[a_ind+1+b_ind+1:].find(str(c))
      if c_ind==-1:
        continue
      else:
        counter += 1
        # print(a_ind,b_ind,c_ind)
        
print(counter)

Submission status: Accepted

Solution code:
def find(fr, target):
    for i in range(fr, len(S)):
        if S[i] == target:
            return i
    return -1

N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            now = find(0, str(i))
            if now == -1: continue
            now = find(now+1, str(j))
            if now == -1: continue
            now = find(now+1, str(k))
            if now == -1: continue
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 0
for i in range(0,1000):
    tmp = 0
    for nun,j in enumerate(list(str(i).zfill(3))):
        pretmp = tmp
        tmp = s[tmp:].find(j)
        if tmp < 0:
            break
        if nun == 2 and tmp >= 0:
            count +=1
        tmp = tmp + pretmp + 1
print(count)

Submission status: Accepted

Solution code:
import copy

N = input()
S = list(map(int, input()[:]))
left = [False for i in range(10)]
right = [0 for i in range(10)]

for n in S[1:]:
    right[n] += 1
left[S[0]] = True
flag = [[[False for i in range(10)] for j in range(10)] for k in range(10)]
for n in S[1:-1]:
    right[n] -= 1
    for i, l in enumerate(left):
        if l:
            for j, r in enumerate(right):
                if r > 0:
                    flag[n][i][j] = True
    left[n] = True
count = 0
for i in flag:
    for j in i:
        for k in j:
            if k:
                count += 1
print(count)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    S = input().strip("\n")
    Left = [set() for _ in range(N)]
    Right = [set() for _ in range(N)]
    Left[0] |= {S[0]}
    Right[N-1] |= {S[N-1]}
    for i in range(1, N):
        Left[i] = Left[i-1] | {S[i]}
        Right[N-i-1] = Right[N-i] | {S[N-i-1]}
    used = set()
    for i in range(1, N - 1):
        mid = S[i]
        for l in Left[i-1]:
            for r in Right[i+1]:
                used |= {l + mid + r}
    print(len(used))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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


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

one = set()
two = set()
thi = set()
for s in S:
    for t in two:
        thi.add(t+s)
    for o in one:
        two.add(o+s)
    one.add(s)

print(len(thi))

Submission status: Accepted

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

ans = 0
for i in range(1000):
    judge = False
    p = 0
    if i >= 0 and i < 10:
        number = "00" + str(i)
    elif i >= 10 and i < 100:
        number = '0' + str(i)
    else:
        number = str(i)
    
    for j in range(N):
        if number[p] == S[j]:
            p += 1
            if p == 3:
                ans += 1
                break
            

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
S = input()[:-1]
ans = 0

for i in range(1000):
    s = '0'*(3-len(str(i)))+str(i)
    now = 0
    
    for j in range(N):
        if S[j]==s[now]:
            now += 1
    
            if now==3:
                break
    
    if now==3:
        ans += 1

print(ans)

Submission status: Accepted

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

s = set()
L = [[set() for i in range(2)] for j in range(N+1)]

ans = set()

for i in range(N):
    L[i+1][0].add(S[i])
    for k in L[i][0]:
        L[i+1][0].add(k)
        L[i+1][1].add(k + S[i])
    for k in L[i][1]:
        L[i+1][1].add(k)
        ans.add(k + S[i])

print(len(ans))

Submission status: Accepted

Solution code:
import sys
import math
n=int(input())
s=str(input())
ans_lis=[]
ans=0
for i in range(1000):
    tmp=[str(i//100),str((i%100)//10),str((i%100)%10)]
    f=0
    for j in range(n):
        if s[j]==tmp[f]:f+=1
        if f==3:
            ans+=1
            break
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
cnt=0
for m in range(1000):
  m=str(m).zfill(3)
  j=0
  for i in m:
    if i not in s[j:]:break
    j+=s[j:].index(i)+1
  else:cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
a=list(input())
a=list(map(int,a))
ans=0
for i in range(10):
    s=set(a)
    if i in s:
        p=a.index(i)
        for j in range(10):
            s=set(a[p+1:])
            if j in s:
                q=a[p+1:].index(j)+p+1
                for k in range(10):
                    s=set(a[q+1:])
                    if k in s:
                        ans+=1
print(ans)

Submission status: Accepted

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

len1 = set()
len2 = set()
len3 = set()

for d in S:
    for l2 in len2:
        len3.add(l2+d)
    for l1 in len1:
        len2.add(l1+d)
    len1.add(d)
print(len(len3))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()
c = 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:
                c += len(set(s[b + 1:]))
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()
c = 0
for i in range(10):
    for j in range(10):
        a = s.find(str(i))
        if a > -1:
            b = s.find(str(j), a + 1)
            if b > -1:
                c += len(set(s[b + 1:]))
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()
s = [int(i) for i in s]
c = 0
for i in range(10):
    for j in range(10):
        if i in s:
            t = s[s.index(i) + 1:]
            if j in t:
                c += len(set(t[t.index(j) + 1:]))
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()

c = 0

for i in range(10):
    i = str(i)
    for j in range(10):
        j = str(j)
        for k in range(10):
            k = str(k)
            if i in s:
                t = s[s.index(i)+1:]
                if j in t:
                    u = t[t.index(j)+1:]
                    if k in u:
                        c+=1
print(c)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
s = S
count = 0
for i in range(10):
  i = str(i)
  for j in range(10):
    j = str(j)
    for k in range(10):
      k = str(k)
      if i in s:
        s=s[s.index(i)+1:]
        if j in s:
          s=s[s.index(j)+1:]
          if k in s:
            count += 1
      s = S
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0
for i in range(10):
    #print(S.find(str(i)),i)
    if S.find(str(i)) == -1:
        #print(S.find(str(i)),i)
        continue
    for j in range(10):
        if S.find(str(j),S.find(str(i))+1) == -1:
            #print(S.find(str(j)),j)
            continue
        for k in range(10):
            if S.find(str(k),S.find(str(j),S.find(str(i))+1)+1) != -1:
                #print(S.find(str(k)),k)
                count += 1
print(count)

Submission status: Accepted

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

cnt = 0

for a in range(10):
    s_index = s.find(str(a)) 
    if s_index == -1:
        continue##この先はやらない
    for b in range(10):
        t_index = s.find(str(b),s_index+1)
        if t_index==-1:
            continue
        for c in range(10):
            u_index = s.find(str(c),t_index+1)
            if u_index != -1:
                cnt+=1
                    
               
        
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for p in range(10):
    s = S.find(str(p))
    if s == -1:
        continue
    for q in range(10):
        t = S.find(str(q), s + 1)
        if t == -1:
            continue
        for r in range(10):
            u = S.find(str(r), t + 1)
            if u != -1:
                count += 1
print(count)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
#print(S)
SETF=[set() for i in range(N)]
SETE=[0 for i in range(N)]
ANSSET=set()
SETF[0]=set()
SETF[0].add(S[0])
#print(SETF)
#print(type(SETF[1]))
import copy
for i in range(1,N):
    SETF[i]=copy.deepcopy(SETF[i-1])
    SETF[i].add(S[i])
#print(SETF)

SETE[0]=set()
SETE[0].add(S[-1])
#print(SETE)
for i in range(1,N):
    SETE[i]=copy.deepcopy(SETE[i-1])
    SETE[i].add(S[N-1-i])
SETE=SETE[::-1]

for i in range(1,N-1):
    for f in SETF[i-1]:
        for e in SETE[i+1]:
            ANSSET.add(f+S[i]+e)
print(len(ANSSET))
#print(SETE)

Submission status: Accepted

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

count=0
for p in range(10):
    s=S.find(str(p))
    if s==-1:
        continue
    for q in range(10):
        t=S.find(str(q),s+1)
        if t==-1:
            continue
        for r in range(10):
            u=S.find(str(r),t+1)
            if u!=-1:
                count+=1
print(count)

Submission status: Accepted

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

def is_include(t: str, S: str) -> bool:
    tlis = list(t)
    slis = list(S)
    pointer = 0
    len_t = len(tlis)
    for s in slis:
        if s == tlis[pointer]:
            pointer += 1
        if pointer == len_t:
            return True
    return False

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            t = str(i)+str(j)+str(k)
            if is_include(t, S):
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n, s = open(0).read().split()

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

from itertools import product,repeat

ans = 0
for a,b,c in product(range(10), range(10), range(10)):
    abc = [a,b,c]
    tmp = 0
    for dig in s:
        if dig == abc[tmp]:
            tmp += 1
            if tmp == 3:
                ans += 1
                break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
NUMS = list(map(int, S))
ans = 0
for i in range(10):
    for j in range(10):
        iok = False
        jok = False
        k = set()
        for num in NUMS:
            if jok:
                k.add(num)
            elif iok:
                if num == j:
                    jok = True
            else:
                if num == i:
                    iok = True
        ans += len(k)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import bisect
from itertools import product

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

# {文字:その文字の出現位置}の辞書を構築
d = defaultdict(list)
for i in range(n):
    d[s[i]].append(i)

def canCreate(x,y,z):
    pos = 0
    for c in map(str, [x,y,z]):
        pos = bisect.bisect_left(d[c], pos)
        if pos == len(d[c]):
            return False
        pos = d[c][pos] + 1
    return True

ans = sum([canCreate(x, y, z) for x,y,z in product(range(10), repeat=3)])

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
cnt=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:
                cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
c=0
for i in range(10):
  a=s.find(str(i))
  if -1<a<n-2:
    
    for j in range(10):
      b=s[a+1:].find(str(j))
      if -1<b<len(s[a+1:])-1:
    
        for k in range(10):
          if s[a+b+2:].find(str(k))>-1:
            c+=1
print(c)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
I = []
for i in range(n-2):
    if s[i] not in I:
        I.append(s[i])
    else:
        continue
    J = []
    for j in range(i+1, n-1):
        if s[j] not in J:
            J.append(s[j])
        else:
            continue
        K = []
        for k in range(j+1, n):
            if s[k] not in K:
                K.append(s[k])
                ans += 1
print(ans)

Submission status: Accepted

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

ok = [0,0,0,0,0,0,0,0,0,0]
ans = 0

for i in range(n):
    if sum(ok) == 10:
        break
    if ok[int(s[i])] == 1:
        continue
    ok[int(s[i])] = 1
    nd = [0,0,0,0,0,0,0,0,0,0]
    for j in range(i+1,n):
        if sum(nd) == 10:
            break
        if nd[int(s[j])] == 1:
            continue
        nd[int(s[j])] = 1
        rd = [0,0,0,0,0,0,0,0,0,0]
        for k in range(j+1, n):
            if sum(rd) == 10:
                break
            if rd[int(s[k])] == 1:
                continue
            rd[int(s[k])] = 1
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
ans = 0
def ok(i):
    pin = '{:0=3}'.format(i)
    j = 0
    for s in S:
        if s == pin[j]:
            j += 1
            if j == 3:
                return True
    else:
        return False

for i in range(1000):
    ans += ok(i)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    tmp = s
    if v[0] in tmp:
        tmp = tmp[tmp.index(v[0])+1:]
    else:
        continue
    if v[1] in tmp:
        tmp = tmp[tmp.index(v[1])+1:]
    else:
        continue
    if v[2] in tmp:
        res += 1
print(res)

Submission status: Accepted

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

search = [("00"+str(s))[-3:] for s in range(0,1000)]
ans = []
for num in search:
    tmp_S = S
    if num[0] in tmp_S:
        tmp_S = tmp_S[tmp_S.index(num[0])+1:] 
    else:
        continue
    if num[1] in tmp_S:
        tmp_S = tmp_S[tmp_S.index(num[1])+1:] 
    else:
        continue
    if num[2] in tmp_S:
        ans.append(num)

print(len(ans))

Submission status: Accepted

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

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    S = input()

    return N, S


def main(N: int, S: str) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 桁数
        S (str): ラッキーナンバー
    """
    # 求解処理
    ans = 0
    x_bit = [False for n in range(10)]
    for x in range(N):
        S_x = int(S[x])
        if x_bit[S_x]:
            continue
        x_bit[S_x] = True
        y_bit = [False for n in range(10)]
        for y in range(x + 1, N):
            S_y = int(S[y])
            if y_bit[S_y]:
                continue
            y_bit[S_y] = True
            z_bit = [False for n in range(10)]
            for z in range(y + 1, N):
                S_z = int(S[z])
                if z_bit[S_z]:
                    continue
                z_bit[S_z] = True
                ans += 1

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, S = get_input()

    # メイン処理
    main(N, S)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力を取得
N = int(input())
S = input()

# 求解処理
ans = 0
x_bit = [False for n in range(10)]
for x in range(N):
    S_x = int(S[x])
    if x_bit[S_x]:
        continue
    x_bit[S_x] = True
    y_bit = [False for n in range(10)]
    for y in range(x + 1, N):
        S_y = int(S[y])
        if y_bit[S_y]:
            continue
        y_bit[S_y] = True
        z_bit = [False for n in range(10)]
        for z in range(y + 1, N):
            S_z = int(S[z])
            if z_bit[S_z]:
                continue
            z_bit[S_z] = True
            ans += 1

# 結果出力
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    S = input()

    cnt = 0
    for i in range(1000):
        words = '{:0>3}'.format(i)
        k = 0
        for item in S:
            if item == words[k]:
                # print(item, words[k])
                k += 1

            if k == 3:
                cnt +=1
                break

    print(cnt)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
""" tutorial06
    https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d
"""
import sys
import math
from functools import reduce

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def main(N, S):
    """ main
    """
    count = 0
    skip1 = []
    skip2 = []
    skip3 = []

    for i in range(0, N):
        if S[i] in skip1:
            continue
        skip1.append(S[i])
        for j in range(i+1, N):
            if S[j] in skip2:
                continue
            skip2.append(S[j])
            for k in range(j+1, N):
                if S[k] in skip3:
                    continue
                skip3.append(S[k])
                count += 1
            skip3 = []
        skip2 = []

    return count

if __name__ == "__main__":
    _N = readInteger()
    _S = readString()

    print(main(_N, _S))

Submission status: Accepted

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

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    # N = II()
    # S = input()

    # ans = []
    # for i in range(2**N, 2**(N+1)):
    #     if bin(i)[3:].count('1') == N - 3:
    #         t = ''
    #         for s, b in zip(S, bin(i)[3:]):
    #             if b != '1':
    #                 t += s
    #         ans.append(t)
        
    # print(len(set(ans)))

    N = II()
    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)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
S=input()
count=0
I=[]
for i in range(N-2):
    if S[i] not in I:
        I.append(S[i])
    else:
        continue
    J=[]
    for j in range(i+1,N-1):
        if S[j] not in J:
            J.append(S[j])
        else:
            continue
        K=[]
        for k in range(j+1,N):
            if S[k] not in K:
                K.append(S[k])
                count+=1
print(count)

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)