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:
import sys
sys.setrecursionlimit(10**6)

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

sum=0

for i in range(10):
    ix = s.find(str(i))
    if ix == -1:
        continue
    six = s[ix+1:]
    for j in range(10):
        iy = six.find(str(j))
        if iy == -1:
            continue
        siy = six[iy+1:]
        for k in range(10):
            iz = siy.find(str(k))
            if iz >= 0:
                sum+=1
print(sum)

Submission status: Accepted

Solution code:
import bisect
N = int(input())
S = input()
X = [[] for i in range(10)]
for i in range(len(S)):
    S_tmp = int(S[i])
    X[S_tmp].append(i)
ans = 0
for i in range(1000):
    i_tmp = i+1000
    p = [0]*3
    for j in range(3):
        p[j] = int(str(i_tmp)[j+1])
    if len(X[p[0]]) != 0:
        x1 = X[p[0]][0]
        if len(X[p[1]]) != 0:
            x2 = bisect.bisect_right(X[p[1]],x1)
            if x2 != len(X[p[1]]):
                x2 = X[p[1]][x2]
                if len(X[p[2]]) != 0:
                    x3 = X[p[2]][-1]
                    if x3 > x2 and x3 > x1:
                        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(10):
    idx1 = s.find(str(i))
    if idx1 == -1:
        pass
    elif idx1 > n-3:
        pass
    else:
        for j in range(10):
            idx2 = s.find(str(j),idx1+1)
            if idx2 == -1:
                pass
            elif idx2 > n-2:
                pass
            else:
                for k in range(10):
                    idx3 = s.find(str(k),idx2+1)
                    if idx3 == -1:
                        pass
                    else:
                        cnt += 1
#    print(i,idx1)
print(cnt)

Submission status: Accepted

Solution code:
# 2019/12/1

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

fst=[]
tmp=set()
for i in range(n):
    tmp.add(s[i])
    fst.append(list(tmp))

trd=[]
tmp=set()
for i in range(n):
    tmp.add(s[n-1-i])
    trd.append(list(tmp))
trd=trd[::-1]
cnt=set()
for i in range(1,n-1):
    for f in fst[i-1]:
        for t in trd[i+1]:
            cnt.add(f+s[i]+t)
print(len(cnt))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
# import numpy as np
# flagbox = np.zeros(1000).reshape(10,10,10)
# flagtable = np.zeros(100).reshape(10,10)
# flaglist = np.zeros(10)
flagbox = [[[0]*10 for _ in range(10)] for _ in range(10)]
flagtable = [[0]*10 for _ in range(10)]
flaglist = [0]*10
for s in S:
    ss = int(s)
    for i in range(10):
        for j in range(10):
            if flagtable[i][j] == 1:
                flagbox[i][j][ss] = 1

    for i in range(10):
        if flaglist[i] == 1:
            flagtable[i][ss] = 1

    if flaglist[ss] == 0:
        flaglist[ss] = 1

# print sum of flagbox
#print(int(np.sum(flagbox)))
ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if flagbox[i][j][k] == 1:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

n = int(input())
s = input()
pass_list = list(map(lambda x: str(x).zfill(3), range(1000)))
res = 0

for p in pass_list:
    
    ptr = 0
    one = False
    two = False
    three = False
    
    for i in range(len(s)):
        if(s[i] == p[0]):
            ptr = i
            one = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[1]):
            ptr = i
            two = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[2]):
            ptr = i
            three = True
            break
    
    if(one and two and three): res += 1

print(res)

Submission status: Accepted

Solution code:
import sys
from itertools import product
from string import digits

def main():
    n, s = sys.stdin.read().split()
    n = int(n)

    cand = list(''.join(p) for p in product(digits, repeat=3))

    res = set()
    for c in cand:
        i = s.find(c[0])
        if i == -1:
            continue
        j = s.find(c[1], i+1)
        if j == -1:
            continue
        k = s.find(c[2], j+1)
        if k == -1:
            continue
        
        res.add(c)
        
    ans = len(res)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

dp = [[0]*10 for _ in range(10)]

count = [0]*10

result = []

for i in range(n-2):
    if count[int(s[i])]==0:
        for j in range(i+1,n-1):
            if dp[int(s[i])][int(s[j])]==0:
                tem = "".join(set(s[j+1:]))
                for k in range(len(tem)):
                    result.append(s[i]+s[j]+tem[k])
                dp[int(s[i])][int(s[j])]=1
        count[int(s[i])]=1

ans = set(result)
print(len(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
c1 = [False for _ in range(10)]
c2 = [0 for _ in range(1000)]
count = 0
for i in range(n-2):
  si = int(s[i])
  if c1[si] != True:
    c1[si] = True
    c3 = [False for _ in range(10)]
    for j in range(i+1,n-1):
      sj = int(s[j])
      if c3[sj] != True:
        c3[sj] = True
        c4 = [False for _ in range(10)]
        for k in range(j+1,n):
          sk = int(s[k])
          if c4[sk] != True:
            c4[sk] = True
            count += 1
print(count)

Submission status: Accepted

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


for a in range (10):    
    for b in range (10):
        for c in range (10):
            x=S.find(str(a))
            if x != -1 and x<N-2:
                
                y=S.find(str(b),x+1)
                if y!= -1 and y<N-1:
                    z=S.find(str(c),y+1)
                    if z!= -1:ans=ans+1

print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import combinations, product
from string import digits
from collections import Counter

def main():
    n, s = sys.stdin.read().split()
    n = int(n)
    
    # t = [None] * (n+1)
    # c = Counter(s)
    # t[0] = set(s)
    # # for i in range(n):
    # #     c[s[i]] -= 1
    # #     if c[s[i]] == 0:
    # #         t[i+1] = t[i] - set([s[i]])
    # #     else:
    # #         t[i+1] = t[i]
    # # print(t)


    
    cand = list(''.join(p) for p in product(digits, repeat=3))
    # print(cand)
    # for comb in combinations(s, 3):
    #     res.add(comb)
    
    # ans = len(res)
    # print(ans)

    res = set()
    for c in cand:
        i = s.find(c[0])
        if i == -1:
            continue
        j = s.find(c[1], i+1)
        if j == -1:
            continue
        k = s.find(c[2], j+1)
        if k == -1:
            continue
        
        res.add(c)
        
    ans = len(res)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

def get_indexes(num):
  idx = -1
  idxs = []
  while idx != N-1:
    tmp_idx = S[idx+1:].find(str(num))
    if tmp_idx == -1:
      return idxs
    else:
      idx += tmp_idx+1
      idxs.append(idx)
  return idxs

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

ans = 0
S_idxs = []
for i in range(10):
  S_idxs.append(get_indexes(i))

for i in range(10):
  if S_idxs[i] == []:continue
  ii = min(S_idxs[i])
  for j in range(10):
    if S_idxs[j] == []:continue
    jj = max(S_idxs[j])
    for k in range(10):
      for kk in S_idxs[k]:
        if ii<kk and kk<jj:
          ans += 1
          break
          
print(ans)
#print(S_idxs)

#print('*'*20)
#print(get_indexes(1))

Submission status: Accepted

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

L0=[]
L1=[]
ans=[]

for i in range(N-2):
    if S[i] in L0:
        continue
    else:
        L0.append(S[i])
    for j in range(i+1,N-1):
        temp=S[i]+S[j]
        if temp in L1:
            continue
        else:
            L1.append(temp)
        for k in range(j+1,N):
            ans.append(temp+S[k])


print(len(set(ans)))

Submission status: Accepted

Solution code:
import collections as col
n = int(input())
s = list(input())
passwd = set()
pre = col.Counter({'0':0,'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,
                                '7':0,'8':0,'9':0})
post = col.Counter(s[1:])
for i in range(1,n-1):
    pre[s[i-1]] += 1
    post[s[i]] = max(0, post[s[i]]-1) 
    for c0 in pre:
        for c1 in post:
            if pre[c0] != 0 and post[c1] != 0:
                passwd.add(c0+s[i]+c1)
print(len(passwd))

Submission status: Accepted

Solution code:
input()
ns = [n for n in input()]
 
scores = 0
first = []
second = []
third = []
third_nums = None
 
for i in range(len(ns) - 2):
  if ns[i] in first:
    continue
  else:
    first.append(ns[i])
  for j in range(i+1, len(ns) - 1):
    if ''.join([ns[i], ns[j]]) in second:
      continue
    else:
      second.append(''.join([ns[i], ns[j]]))
      third_nums = set(ns[j+1:])
      scores += len(third_nums)
      
print(scores)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input()
    ls_first = [-1 for _ in range(10)]
    ls_last = [-1 for _ in range(10)]


    for i,now in enumerate(s):
        ls_last[int(now)] = i
        if ls_first[int(now)] == -1:
            ls_first[int(now)] = i

    ans = 0
    for i in range(10):
        for j in range(10):
            if ls_first[i]==-1 or ls_last[j]==-1:
                pass
            else:
                now = set([])
                for k in range(ls_first[i]+1,ls_last[j]):
                    now.add(int(s[k]))
                ans += len(now)
    print(ans)    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect

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

C = {0:[],1:[],2:[],3:[],4:[],5:[],6:[],7:[],8:[],9:[]}
for i in range(N):
  C[int(S[i])].append(i)

ans = 0
for i in range(1000):
  a = i//100
  if len(C[a]) == 0:
    continue
  amin = C[a][0]
  b = (i//10)%10
  if len(C[b]) == 0:
    continue
  bi = bisect.bisect_right(C[b], amin)
  if bi == len(C[b]):
    continue
  bmin = C[b][bi]
  c = i%10
  if len(C[c]) == 0:
    continue
  ci = bisect.bisect_right(C[c], bmin)
  if ci < len(C[c]):
    #print(a,b,c)
    ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1000):
    if i <= 9:
        if S.count("0") >= 2:
            first = S.index("0")
            SS = S[first+1:]
            second = SS.index("0")
            SSS = SS[second+1:]
            tmp = str(i)
            if SSS.count(tmp) == 0:
                continue
            ans += 1
            ##print(i)
        else:
            continue
    elif i <= 99:
        if S.count("0") >= 1:
            first = S.index("0")
            SS = S[first+1:]
            tmp = str(i)
            if SS.count(tmp[0]) == 0:
                continue
            second = SS.index(tmp[0])
            SSS = SS[second+1:]
            if SSS.count(tmp[1]) == 0:
                continue
            ans += 1
            ##print(i)
        else:
    
            continue
    else:
        tmp = str(i)
        ##print(tmp)
        if S.count(tmp[0]) == 0:
            continue
        first = S.index(tmp[0])
        SS = S[first+1:]
        if SS.count(tmp[1]) == 0:
            continue
        second = SS.index(tmp[1])
        SSS = SS[second+1:]
        if SSS.count(tmp[2]) == 0:
            continue
        ##print(i)
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
	s = set()
	ss = set()
	sss = set()
	n=int(input())
	ins = input()
	for i in range(n):
		for t in ss:
			sss.add(t+ins[i])
		for t in s:
			ss.add(t+ins[i])
		s.add(ins[i])
	print(len(sss))

main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = list(input())
    sset = set(s)
    d = {}
    for i in sset:
        d[i] = []
    for i in range(n):
        d[s[i]].append(i)
    dk = d.keys()
    ans = 0
    for i in dk:
        for j in dk:
            for k in dk:
                a = d[i][0]
                f = False
                b = ""
                if d[j][-1] > a:
                    for x in d[j]:
                        if x > a:
                            f = True
                            b = x
                            break
                if f:
                    if d[k][-1] > b:
                        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt = 0
S1 = list(set(S[:-2]))
for s1 in S1:
    i1 = S.index(s1)
    SS = S[i1+1:-1:]
    S2 = list(set(SS))
    for s2 in S2:
        i2 = S[i1+1:].index(s2) + i1+1
        SSS = S[i2+1::]
        S3 = set(SSS)
        cnt += len(S3)

print(cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
lists = ['{0:03d}'.format(i) for i in range(1000)]
import re
def check(target, a):
    ans = re.search(a, target)
    if ans == None:
        return None
    else:
        return target[ans.start()+1:]

def print_ans(N, S):
    """Test Case
    >>> print_ans(4, "0224")
    3
    >>> print_ans(6, "123123")
    17
    >>> print_ans(19, "3141592653589793238")
    329
    """
    # s = set()
    # for i in range(N):
    #     for k in range(i+1,N):
    #         for l in range(k+1, N):
    #             s.add(S[i] + S[k] + S[l])
    # print(len(s))
    ans = 0
    for a in lists:
        tmp = S
        for i in range(3):
            tmp = check(tmp, a[i])
            if tmp == None:
                break
        if tmp != None:
            ans += 1
    print(ans)


    # print(check('123','4'))


    
if __name__ == '__main__':
    N = int(input().rstrip())
    S = input().rstrip()
    print_ans(N, S)

Submission status: Accepted

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

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

count = 0

ls_si = []
for i in range(n-2):
    # print("i={}".format(i))
    if s[i] in ls_si:
        pass
    else:
        ls_si.append(s[i])
        ls_sj = []
        for j in range(i+1,n-1):
            if s[j] in ls_sj:
                pass
            else:
                ls_sj.append(s[j])
                # ls = s[j+1:-1]
                # st = set(ls)
                # l = len(st)
                # print(ls)
                # print(st)
                # print(l)
                count += len(set(list(s[j+1:-1])))

# print(ls_si)
# print(ls_sj)
print(count)

Submission status: Accepted

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

def first_idx(s,n):
    for i in range(len(s)):
        if s[i] == n:
            return i
    return -1

ans = 0
for first_pin in range(10):
    tmp = first_idx(S, first_pin)
    if tmp == -1 or tmp >= N-2:
        continue
    tmp_s = S[tmp+1:]
    for second_pin in range(10):
        tmp2 = first_idx(tmp_s, second_pin)
        if tmp2 == -1 or tmp2 == N-1:
            continue
        tmp_s_2 = tmp_s[tmp2+1:]
        ans += len(set(tmp_s_2))

print(ans)

Submission status: Accepted

Solution code:
n= int(input())
s = input()
ans = 0
h = set()
for i in range(n-2):
  ten = set()
  if s[i] not in h:
    h.add(s[i])
    for j in range(i+1,n-1):
      if s[j] not in ten:
        ten.add(s[j])
        ans += len(set(s[j+1:]))
print(ans)

Submission status: Accepted

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

count = 0
for i in range(10):
  idx = S.find(str(i))
  if idx == -1 or idx >= N-2:
    continue
  for j in range(10):
    idx2 = S.find(str(j), idx+1)
    # print(('!', idx, idx2))
    if idx2 == -1 or idx2 >= N-1:
      continue
    set1 = set()
    for k in range(idx2+1, N):
      if S[k] not in set1:
        set1.add(S[k])
        if len(set1) >= 10:
          # print((i, j, 10))
          count += 10
          break
    else:
      # print((i, j, len(set1)))
      count += len(set1)

print(count)

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter
N = int(input())
S = input()
length = len(S)
first = list()
res = 0
for n in range(length-2):
    if S[n] not in first:
        first.append(S[n])
    else:
        continue
    second = list()
    for m in range(n+1, length-1):
        if S[m] not in second:
            second.append(S[m])
        else:
            continue
        third = list()
        for k in range(m+1, length):
            if S[k] not in third:
                third.append(S[k])
            else:
                continue
            res += 1
print(res)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = list(input().strip())
A = [int(S[i]) for i in range(N)]

k1 = [-1]*10
for i in range(N-2):
    if k1[A[i]] == -1:
        k1[A[i]] = i

k2 = [[-1]*10 for i in range(10)]
for i in range(10):
    if k1[i] == -1:
        continue
    else:
        for j in range(k1[i]+1, N-1):
            if k2[i][A[j]] == -1:
                k2[i][A[j]] = j

ans = 0
for i in range(10):
    for j in range(10):
        if k2[i][j] == -1:
            continue
        
        L = [0]*10
        for l in range(k2[i][j]+1 , N):
            if L[A[l]] == 0:
                ans += 1
                L[A[l]] = 1

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

N=int(input())
s=input()


G1 = []
G2 = [[] for i in range(10)]
G3 = [[[] for i in range(10)] for j in range(10)]

def dfs3(x,y,new):
	if new not in G3[x][y]:
		G3[x][y].append(new)


def dfs2(x,new):
	for i in G2[x]:
		dfs3(x,i,new)
	if new not in G2[x]:
		G2[x].append(new)



def dfs1(new):
	for i in G1:
		dfs2(i,new)
	if new not in G1:
		G1.append(new)




for i in s:
	dfs1(int(i))

ans = 0
for i in range(10):
	for j in range(10):
		ans += len(G3[i][j])
print(ans)

Submission status: Accepted

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

def solve(N: int, S: str):
    def nx(S):
        res = [[N+1] * 10 for _ in range(N+1)]
        for i in range(N-1, -1, -1):
            for j in range(10):
                res[i][j] = res[i+1][j]
            res[i][int(S[i])] = i
        return res
    dp = [[0] * 3 for _ in range(N+1)]
    dp[1] = [1, 0, 0]
    res = nx(S)
    for i in range(0, N+1):
        for j in range(10):
            if res[i][j] >= N: continue
            if res[0][j] == res[i][j]:
                dp[res[i][j]+1][0] = 1
            dp[res[i][j]+1][1] += dp[i][0]
            dp[res[i][j]+1][2] += dp[i][1]
    res = 0
    for i in range(N+1):
        res += dp[i][2]
    print(res)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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: int
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import combinations
from collections import Counter


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    N = len(S)
    trees = {}

    trees[S[0]] = {S[1]: set(S[2])}

    prev = S[2]
    prevprev = S[1]
    for i, c in enumerate(S):
        if i <= 2:
            continue

        for first in trees.keys():
            for second in trees[first].keys():
                trees[first][second].add(c)
            if prev not in trees[first]:
                trees[first][prev] = set(c)
        if prevprev not in trees:
            trees[prevprev] = {prev: set(c)}
        prevprev = prev
        prev = c

    count = 0
    for first in trees:
        for second in trees[first]:
            count += len(trees[first][second])
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
S = input()
d = {}
for i in range(N):
  c = S[i]
  if c not in d.keys():
    d[c] = [i]
  else:
    #if len(d[c])>=3:
    #  continue
    #else:
    d[c].append(i)
#print(d)

ans=0
for i in range(1000):
  code = str(i)
  while len(code)<3:
    code = "0" + code
  if code[0] not in d.keys() or code[1] not in d.keys() or code[2] not in d.keys():
    continue
  first = np.array(d[code[0]])
  current = first[0]
  
  second = np.array(d[code[1]])
  if len(second[second>current])==0:
    continue
  current = second[second>current][0]
  
  third = np.array(d[code[2]])
  if len(third[third>current])==0:
    continue
  ans+=1
  
print(ans)

Submission status: Accepted

Solution code:
import re

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

num_list = ['{:0=3}'.format(i) for i in range(1, 1000)]
pattern_list = [j[0]+"[0-9]*?"+j[1]+"[0-9]*?"+j[2] for j in num_list]
#print(pattern_list[0])


count = 0
for i in range(10):
  mi = re.search(str(i), S)
  if mi:
    for j in range(10):
      mj = re.search(str(j), S[mi.start()+1:])
      if mj:
        for k in range(10):
          if re.search(str(k), S[mi.start()+mj.start()+2:]):
            #print(i,j,k)
            count += 1
print(count)

Submission status: Accepted

Solution code:

# -*- coding: utf-8 -*-

def main():
    N = int(input())
    S = input().strip()

    Na = [0] * 10
    NNa = [[0] * 10 for _ in Na]
    NNNa = [[[0] * 10 for _ in Na] for _ in Na]

    for Sc in S:
        Si = int(Sc)

        for i, NNi in enumerate(NNa):
            for j, NNj in enumerate(NNi):
                NNNa[i][j][Si] = NNj

        for j, Nj in enumerate(Na):
            NNa[j][Si] = Nj

        Na[Si] = 1
        

    Count = 0
    for NNi in NNNa:
        for Nj in NNi:
            for Nk in Nj:
                Count += Nk


    print(Count)
        



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    strings = list(input())

    # pins = set()
    ans = 0
    for i in range(1000):
        flag = True
        temp_strings = strings[:]
        for j in range(3):
            i_str = '{:03d}'.format(i)
            number = str(list(i_str)[j])
            if number in temp_strings:
                idx = temp_strings.index(number)
                temp_strings = temp_strings[idx+1:]
            else:
                flag = False
        if flag:
            # print(i_str)
            ans += 1
        else:
            continue

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

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

one = set()
two = set()
three = set()
for s in S:
    for tw in two:
        three.add(tw + s)
    for on in one:
        two.add(on + s)
    one.add(s)
print(len(three))

Submission status: Accepted

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

min_dict = {}
max_dict = {}
for i in range(10):
    for j in range(n):
        if s[j] == str(i):
            min_dict[i] = j
            break
    for j in range(n-1, -1, -1):
        if s[j] == str(i):
            max_dict[i] = j
            break

res = 0
for k1, v1 in min_dict.items():
    for k2, v2 in max_dict.items():
        if v1 >= v2:
            continue
        else:
            res += len(list(set(list(s[v1+1:v2]))))

print(res)

Submission status: Accepted

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

Answer_dict = {}
used_i = list()
used_j = [[] for j in range(10)]

for i in range(N-2):
  if S[i] in used_i:
    continue

  for j in range(i+1,N-1):
    if S[j] in used_j[int(S[i])]:
      continue

    for k in range(j+1,N):
      Answer_dict[S[i]+S[j]+S[k]] = 1

    used_j[int(S[i])].append(S[j])
  used_i.append(S[i])

print(len(Answer_dict))

Submission status: Accepted

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

S = list(S)
#print(S)

number_place_dict={}
for i in range(10):
  number_place_dict[i]=list()

#print(number_place_dict)

for i in range(len(S)):
  #print(int(S[i]))
  number_place_dict[int(S[i])].append(i)

#print(number_place_dict)

ans = 0

for i in range(0,1000):
  i = list(str(i))
  if len(i) == 1:
    i = [0] + [0] + i
  elif len(i) == 2:
    i = [0] + i
  elif len(i) == 0:
    i = [0] + [0] + [0]
  
  #print("i;",i)

  next_place_confition = -1

  for j in range(0,3):
    #print("数字:",int(i[j]),end="")
    place_list = number_place_dict[int(i[j])]
    index = bisect.bisect_right(place_list, next_place_confition)
    if index == len(place_list):
      #print("条件合致無し")
      break
    else:
      next_place_confition = place_list[index]
      #print("……次は→以上のindexが要:",next_place_confition)
  else:
    #print("OK")
    ans += 1

print(ans)

Submission status: Accepted

Solution code:

N=int(input())
S=input()
cnt =0
for i in range(1000):
  s=str(i).zfill(3)

  if s[0] in S:
    s_0_index = S.index(s[0])
    S_0 = S[s_0_index+1:]

    if s[1] in S_0:
      s_1_index = S_0.index(s[1])
      S_1 = S_0[S_0.index(s[1])+1:]
 
      if s[2] in S_1:
        s_2_index = S_1.index(s[2])
        S_2 = S[s_2_index+1:]
        #print(S[s_0_index]+S[s_1_index]+S[s_2_index])
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
tmp = set()
si = set()
for i in range(n-2):
  if s[i] in si:
    continue
  else:
    si.add(s[i])
    sj = set()
    for j in range(i+1,n-1):
      if s[j] in sj:
        continue
      else:
        sj.add(s[j])
        sk = set()
        for k in range(j+1, n):
          if k in sk:
            continue
          else:
            sk.add(s[k])
       	    tmp.add(s[i] + s[j] + s[k])
print(len(tmp))

Submission status: Accepted

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

ss = s[::-1]

ans = 0

for i in range(1000):
    if i < 100:
        a = 0
    else:
        a = i // 100
    if i < 10:
        b = 0
    else:
        b = (i-a*100)//10
    c = i-(a*100+b*10)
    if str(a) in s and str(c) in s:
        k = s.index(str(a))
        l = n-1-ss.index(str(c))
        for j in range(k+1,l):
            if s[j] == str(b):
                ans += 1
                break
            
print(ans)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
s = input()
ans = 0
INDEX = [list() for i in range(10)]
len_index = []
for key,i in enumerate(s):
  i = int(i)
  INDEX[i].append(key)
for i in INDEX:
  len_index.append(len(i))
for first in range(10):
  if len_index[first]:
    f = INDEX[first][0]
    for second in range(10):
      r = bisect.bisect_right(INDEX[second],f)
      if r < len_index[second]:
        s = INDEX[second][r]
        for third in range(10):
          t = bisect.bisect_right(INDEX[third],s)
          if t < len_index[third]:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
count=0
for i in range(10):
  left=s.find('0')
  if left>=0:
    mid=s[left+1:].find('0')
    if mid>=0:
      right=s[left+mid+2:].find(str(i))
      if right>=0:
        count+=1

for i in range(10,100):
  left=s.find('0')
  if left>=0:
    mid=s[left+1:].find(str(i)[0])
    if mid>=0:
      right=s[left+mid+2:].find(str(i)[1])
      if right>=0:
        count+=1

for i in range(100,1000):
  left=s.find(str(i)[0])
  if left>=0:
    mid=s[left+1:].find(str(i)[1])
    if mid>=0:
      right=s[left+mid+2:].find(str(i)[2])
      if right>=0:
        count+=1
print(count)