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()
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
import bisect

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

L=[[] for index1 in range(10)]
Set=set()
for index in range(N):
    L[int(S[index])].append(index)
    Set.add(int(S[index]))

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i in Set and j in Set and k in Set:
                wi=L[i][0]
                wj_index=bisect.bisect(L[j],wi)
                if wj_index==len(L[j]):
                    continue
                else:
                    wj=L[j][wj_index]
                    wk_index=bisect.bisect(L[k],wj)
                    if wk_index==len(L[k]):
                        continue
                    else:
                        ans+=1

print(ans)

Submission status: Accepted

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

left = [0] * 10
right = [0] * 10
zero = ord("0")

l_set = set([])
r_set = set([])
center = S[0]
for s in S[1:]:
    right[ord(s) - zero] += 1
    r_set.add(s)

res = set([])
for s in S[1:]:
    l_set.add(center)
    left[ord(center)-zero] += 1
    
    center = s
    right[ord(center)-zero] -= 1
    if right[ord(center)-zero] == 0:
        r_set.remove(center)
    
    for r in r_set:
        for l in l_set:
            res.add(r+center+l)
    
    
print(len(res))

Submission status: Accepted

Solution code:
import copy
def solve(N, S):
    single_ref = [False for _ in range(10)]
    double_ref = [{} for _ in range(N)]

    for i in range(N - 1, -1, -1):
        if i == N - 1:
            single_ref[int(S[i])] = True
            continue
        double_ref[i] = copy.deepcopy(double_ref[i + 1])
        for j in range(10):
            if not single_ref[j]:
                continue
            double_ref[i][S[i] + str(j)] = 1
        single_ref[int(S[i])] = True

    ret = {}
    for i in range(N - 1):
        for k in double_ref[i + 1].keys():
            ret[S[i] + k] = 1
    return len(ret.keys())

if __name__ == "__main__":
    N = int(input())
    S = input()
    print(solve(N, S))

Submission status: Accepted

Solution code:
n = int(input())

s = input()

numlist = [0] * 1000

ans = 0

for i in range(1000):
    nums = []
    top = i // 100
    mid = (i - top * 100) // 10
    bot = i - top * 100 - mid * 10
    nums.append(str(top))
    nums.append(str(mid))
    nums.append(str(bot))
    
    ind = -1
    for j in nums:
        ind = s.find(j, ind+1)
        if ind == -1:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
 
n = int(input())
s = input()
ans = 0
 
pin = [str(i).zfill(3) for i in range(1000)]
 
for i in pin:
    idx = -1
    for j in i:
        idx = s.find(j,idx+1)
        if idx < 0:
            break
    else:
        ans += 1
 
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = 0
for s1 in range(10):
    s1_ind = s.find(str(s1))
    if s1_ind == -1 or s1_ind >= len(s)-2 : continue
    for s2 in range(10):
        s2_ind = s[s1_ind+1: ].find(str(s2)) + s1_ind + 1
        if s2_ind <= s1_ind or s2_ind >= len(s)-1: continue
        for s3 in range(10):
            s3_ind = s[s2_ind+1: ].find(str(s3)) + s2_ind + 1
            if s3_ind > s2_ind: 
                cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
cnt=0
for i in range(1000):
  flag=0
  pin=str(i).zfill(3)
  if s.find(pin[0])==-1:
    continue
  s1=s[s.find(pin[0])+1:]
  if s1.find(pin[1])==-1:
    continue
  s2=s1[s1.find(pin[1])+1:]
  if s2.find(pin[2])==-1:
    continue
  cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = read().rstrip().decode()
cnt = 0
for i in range(1000):
    num = str(i).zfill(3)
    idx = -1
    for m in num:
        idx = s.find(m, idx + 1)
        if idx == -1:
            break
    else:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/sumitrust2019/submissions/13016562を見た

n = int(input())
s = input()
ans = 0

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

for i in pin:
    idx = -1
    for j in i:
        idx = s.find(j,idx+1)
        if idx < 0:
            break
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
lst = ["{:03}".format(i) for i in range(1000)]
count = 0
for num in lst:
    pos = 0
    np = num[pos]
    for tmp in s:
        if np == tmp:
            if pos == 2:
                count += 1
                break
            pos += 1
            np = num[pos]
print(count)

Submission status: Accepted

Solution code:
n =int(input())
s = input()
count = 0
for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            if str(i) in s and str(k) in s:
                start = s.index(str(i))
                goal = n -1 -list(reversed(s)).index(str(k))
                if start+1<goal:
                    if str(j) in s[start+1:goal]:
                        count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count=0
for pin in range(0, 1000):
    pin = str(pin).zfill(3)

    if s.find(pin[0]) == -1:
        continue
    s1 = s[s.find(pin[0]) + 1:]
    if s1.find(pin[1]) == -1:
        continue
    s2 = s1[s1.find(pin[1]) + 1:]
    if s2.find(pin[2]) == -1:
        continue
    
    count += 1

print(count)

Submission status: Accepted

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

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

ans = 0
for pin in pins:
    index = -1;
    for c in pin:
      index = s.find(c, index+1);
      if (index < 0):
        break;
    else:
      ans += 1;
      
print(ans)

Submission status: Accepted

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

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

ans = 0
for pin in pins:
    index = -1;
    for c in pin:
      index = s.find(c, index+1);
      if (index < 0):
        break;
    if (index > 0):
      ans += 1;
      
print(ans)

Submission status: Accepted

Solution code:
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

inf = float("inf")


def main():
    N = int(input())
    S = input()
    ret = 0
    for i in range(1000):
        i = str(i).zfill(3)
        cursor = 0
        for s in S:
            if s == i[cursor]:
                cursor += 1
                if cursor == 3:
                    ret += 1
                    break
    print(ret)
        
      
if __name__=='__main__':
    main()

Submission status: Accepted

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

used = [0]*1000

for i in range(1000):
  stri = str(i)
  if len(stri) == 2:
    stri = "0"+stri
  elif len(stri) == 1:
    stri = "00"+stri
  count = 0
  for j in range(N):
    if S[j] == stri[count]:
      count += 1
    if count == 3:
      used[i] = 1
      break

print(sum(used))

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    n = int(stdin.readline().rstrip())
    s = list(map(int,list(stdin.readline().rstrip())))
    ans=0
    g = set(list(range(10))) - set(s)
    for i in range(1000):
        tap = (i//100,(i//10)%10,i%10)
        if set(tap) & g == set({}):
            flag = 0
            for p in s:
                if flag == 0:
                    if p==tap[0]:
                        flag = 1
                elif flag == 1:
                    if p==tap[1]:
                        flag = 2
                elif flag == 2:
                    if p==tap[2]:
                        flag = 0
                        ans+=1
                        break
        else:
            continue

    
    print(ans)
main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
target = [str(i) for i in range(10)]
count = 0
for x in target:
    a = s.find(x)
    if a == -1:
        continue
    for y in target:
        b = s.find(y,a+1)
        if b == -1:
            continue
        for z in target:
            c = s.find(z,b+1)
            if c != -1:
                count +=1
print(count)

Submission status: Accepted

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

codes = set()

S1 = S[:N-2]
for i in set(S1):
  idx1 = S1.index(i)
  S2 = S1[idx1+1:] + S[N-2]
  for j in set(S2):
    idx2 = S2.index(j)
    S3 = S2[idx2+1:] + S[N-1]
    for k in set(S3):
      pin = i + j + k
      codes.add(pin)
      
print(len(codes))

Submission status: Accepted

Solution code:
def solution1():

    # 入力
    n = int(input())
    s = [int(i) for i in input()]
    cnt = 0
    for c in range(1000):
        # 100の桁、１０の桁、１の桁に分解
        candidate = [c//100, (c//10)%10, c%10]
        f = -1
        for j in range(n):
            if s[j] == candidate[f]:
                f += 1
            if f == 2:
                break
        if f == 2:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    solution1()

Submission status: Accepted

Solution code:
n = int(input())

s = input()

ans = set()
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.add(str(i)+str(j)+str(k))
print(len(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(10):
    for  j in range(10):
        for k in range(10):
            i_index = s.find(str(i))
            if i_index > - 1:
                j_index = s.find(str(j), i_index + 1)
                if j_index > -1:
                    k_index = s.find(str(k), j_index + 1)
                    if k_index > -1:
                        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input()) #桁数を指定

S = input()

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
 
for i in range(10):
    x=s.find(str(i))
    if x!=-1:
        for j in range(10):
            y=s.find(str(j),x+1)
            if y!=-1:
                for k in range(10):
                    z=s.find(str(k),y+1)
                    if z!=-1:
                        ans+=1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque,defaultdict
def solve():
    N = int(input())
    S = list(input())
    dic = defaultdict(lambda: False)
    ans = 0
    d = deque()
    for s in S:
        for _ in range(len(d)):
            t = d.popleft()
            d.append(t)
            if len(t)==1:
                u = t+s
                if dic[u]==False:
                    dic[u] = True
                    d.append(u)
            if len(t)==2:
                u = t+s
                if dic[u]==False:
                    dic[u] = True
                    ans += 1
        if dic[s]==False:
            dic[s] = True
            d.append(s)
    return ans
print(solve())

Submission status: Accepted

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

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

for i, s in enumerate(S):
    pos[int(s)].append(i)

res = set()


def calc(i, pin):
    if len(pin) == 3:
        res.add(pin)
        return

    for num in range(10):
        tmp = list(filter(lambda x: x > i, pos[num]))
        if len(tmp) == 0:
            continue
        calc(tmp[0], pin + str(num))


calc(-1, '')
print(len(res))

Submission status: Accepted

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

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

for i, s in enumerate(S):
    pos[int(s)].append(i)

res = set()

for i in range(10):
    if len(pos[i]) == 0:
        continue
    p = pos[i][0]
    for j in range(10):
        tmp = list(filter(lambda x: x > p, pos[j]))
        if len(tmp) == 0:
            continue
        q = tmp[0]
        for k in range(10):
            tmp = list(filter(lambda x: x > q, pos[k]))
            if len(tmp) == 0:
                continue
            r = tmp[0]

            res.add(str(p) + str(q) + str(r))

print(len(res))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
# intin = map( int, readline().rstrip().split() )

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

# 10^4 * 10^3 * 3 = 3* (10 ^7)

ans = 0
for x in range(0,1000):
    x = str(x)
    if len(x) == 1:
        x = "00" + x
    elif len(x) == 2 :
        x = "0" + x
    index = 0
    for s in S:
        if x[index] == s:
            index += 1
        if index == 3:
            ans += 1
            break

print(ans)

Submission status: Accepted

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

#n = 10000
#s = '8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888818888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888388888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888828888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888885888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888898888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888388888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888488888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888788888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888898888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888788888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888868888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888688888888888888888888888888888888888888888888888808888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888'

import re
s = re.sub('[0]{4,}','000',s)
s = re.sub('[1]{4,}','111',s)
s = re.sub('[2]{4,}','222',s)
s = re.sub('[3]{4,}','333',s)
s = re.sub('[4]{4,}','444',s)
s = re.sub('[5]{4,}','555',s)
s = re.sub('[6]{4,}','666',s)
s = re.sub('[7]{4,}','777',s)
s = re.sub('[8]{4,}','888',s)
s = re.sub('[9]{4,}','999',s)

n = len(s)
ans = 0
target = [0] * 10
for i in s:
  target[int(i)] = 1

for xxx in range(1000):
  x = str(xxx).zfill(3)
  if(not (target[int(x[0])] and target[int(x[1])] and target[int(x[2])])):
    continue

  ck1,ck2,ck3 = 0,0,0
  start = 0
  for i in range(start,n):
    if(s[i] == x[0]):
      ck1 = 1
      start = i+1
      break
  if(ck1):
    for i in range(start,n):
     if(s[i] == x[1]):
       ck2 = 1
       start = i+1
       break
  if(ck1 and ck2):
    for i in range(start,n):
     if(s[i] == x[2]):
       ans += 1
       break

print(ans)

Submission status: Accepted

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

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

ans =0
for a in range(10):
  index_a = my_index(s, str(a))
  if index_a == -1:
    continue
  
  for b in range(10):
    index_b = my_index(s[index_a+1:], str(b))
    if index_b == -1:
      continue
      
    for c in range(10):
      index_c = my_index(s[index_a+1+index_b+1:], str(c))
      if index_c !=-1:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def sumitb19_d():
    _ = int(input().strip())  # 文字列Sの長さ
    S = str(input().strip())  # 半角数字0-9
    ans = 0

    # 3桁すべて 000 -> 999 を調べる、文字列S内にその順で出現するか
    for i in range(10):
        d1 = S.find(str(i), 0)  # 引数2は開始位置
        if d1 == -1: continue
        for j in range(10):
            d2 = S.find(str(j), d1+1)
            if d2 == -1: continue
            for k in range(10):
                d3 = S.find(str(k), d2+1)
                if d3 > -1: ans += 1

    print(ans)

sumitb19_d()

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    qi = q[0]
    i = 0
    for s in S:
        if s==qi:
            if i==2:
                ans += 1
                break
            else:
                i+=1
                qi = q[i]
print (ans)

Submission status: Accepted

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

import sys

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

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

print(ans)

Submission status: Accepted

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

import sys

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

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN
N = int(input())
S = str(input())

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)

Submission status: Accepted

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

import sys

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

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)

Submission status: Accepted

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

import sys


def main():
    N = int(input())  # 桁数
    S = str(input())

    ans = set()

    digit1 = set()

    for i in range(0, N - 2):
        if S[i] in digit1:
            continue
        digit1.add(S[i])
        digit2 = set()

        for j in range(i + 1, N - 1):
            if S[j] in digit2:
                continue
            digit2.add(S[j])
            digit3 = set()
            for k in range(j + 1, N):
                if len(digit3) == 10:
                    break
                code = S[i] + S[j] + S[k]
                ans.add(code)

    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

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

X = [[str(a),str(b),str(c)] for a,b,c in product(range(10), repeat=3)]
s_index = {s_i:[] for s_i in s}

for i, s_i in enumerate(s):
  s_index[s_i].append(i)

counter = 0
  
for x in X:
  ind_pos = -1
  check = True
  for x_i in x:
    if x_i not in s_index.keys():
      check = False
      break
    else:
      ind_list = [i for i in s_index[x_i] if i>ind_pos]
      if ind_list:
        ind_pos = min(ind_list)
      else:
        check = False
        break
  if check: counter += 1
    
print(counter)