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: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import re
 
# 入力
N = int(input())
S = str(input())
#M1, D1 = map(int, input().split())
 
si = ""
cnt = 0
for i in range(1000) :
  
  si = str(i).zfill(3)
  pattern = "^.*"+ si[0] + ".*" + si[1] + ".*" + si[2] + ".*$"
  
  if re.match(pattern, S) :
    cnt += 1

print (cnt)

Submission status: Time Limit Exceeded

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

selected = set()
for i in range(n-2): # O(n^3) but it can be run with O(n^2) in many time
    for j in range(i+1, n-1):
        if any([sel.startswith(s[i]+s[j]) for sel in selected]):
            continue
        for k in range(j+1, n):
            selected.add(s[i]+s[j]+s[k])

print(len(selected))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

def count(poi):
    point = 0
    for i in range(poi):
        bango = str(i).zfill(3)
        count = 0
        for j in range(n):
            if s[j] == bango[count]:
                count += 1
            if count == 3:
                point += 1
                break
    return point

print(count(1000))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
point = 0
for i in range(1000):
    bango = str(i).zfill(3)
    count = 0
    for j in range(n):
        if s[j] == bango[count]:
            count += 1
        if count == 3:
            point += 1
            break
print(point)

Submission status: Time Limit Exceeded

Solution code:
from re import match
N = int(input())
S = input()

cnt = 0
for i in range(1000):
    s = '{:03}'.format(i)
    if match('.*' + s[0] + '.*' + s[1] +'.*' + s[2], S):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re

n = int(input())
s = input()
print(len([r for r in [re.match(".*{}.*{}.*{}.*".format(i,j,k),s) for i in range(10) for j in range(10) for k in range(10)] if r is not None]))

Submission status: Time Limit Exceeded

Solution code:
import re

n = int(input())
s = input()
cnt = 0
for i in range(0,1000):
  f = "{0:0>3}".format(i)
  if re.match(".*{}.*{}.*{}.*".format(f[0],f[1],f[2]), s):
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

i = 0
j = 0
k = 0
N_1 = int(N) - 2
N_2 = N_1 + 1
N_3 = N_2 + 1
count = 0
for a in range(10):
    for i in range(N_1):
        if str(a) == S[i]:
            for b in range(10):
                for j in range(i+1, N_2):
                    if str(b) == S[j]:
                        for c in range(10):
                            for k in range(j+1,N_3):
                                if str(c) == S[k]:
                                    count += 1
                                    break
                        break
            break
print(count)

Submission status: Time Limit Exceeded

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

i = 0
j = 0
k = 0
N = int(N)
count = 0
for a in range(10):
    for i in range(N-2):
        if str(a) == S[i]:
            for b in range(10):
                for j in range(i+1, N-1):
                    if str(b) == S[j]:
                        for c in range(10):
                            for k in range(j+1,N):
                                if str(c) == S[k]:
                                    count += 1
                                    break
                        break
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = input()
S = list(S)
i = 0
j = 0
k = 0
N = int(N)
count = 0
for a in range(10):
    for i in range(N-2):
        if str(a) == S[i]:
            for b in range(10):
                for j in range(i+1, N-1):
                    if str(b) == S[j]:
                        for c in range(10):
                            for k in range(j+1,N):
                                if str(c) == S[k]:
                                    count += 1
                                    break
                        break
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = input()
S = list(S)
i = 0
j = 0
k = 0
count = 0
for a in range(10):
    for i in range(len(S)-2):
        if str(a) == S[i]:
            for b in range(9,-1,-1):
                for j in range(i+1, len(S)-1):
                    if str(b) == S[j]:
                        for c in range(9,-1,-1):
                            for k in range(j+1,len(S)):
                                if str(c) == S[k]:
                                    count += 1
                                    break
                        break
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = input()
S = list(S)
i = 0
j = 0
k = 0
count = 0
for a in range(10):
    for i in range(len(S)-2):
        if str(a) == S[i]:
            for b in range(10):
                for j in range(i+1, len(S)-1):
                    if str(b) == S[j]:
                        for c in range(10):
                            for k in range(j+1,len(S)):
                                if str(c) == S[k]:
                                    count += 1
                                    break
                        break
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = input()
S = list(S)
i = 0
j = 0
k = 0
count = 0
for a in range(10):
    for b in range(10):
        for i in range(len(S)-2):
            if str(a) == S[i]:
                for j in range(i+1, len(S)-1):
                    if str(b) == S[j]:
                        for c in range(10):
                            for k in range(j+1,len(S)):
                                if str(c) == S[k]:
                                    count += 1
                                    break
                        break
                break
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = input()
S = list(S)
i = 0
j = 0
k = 0
count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            for i in range(len(S)-2):
                if str(a) == S[i]:
                    for j in range(i+1, len(S)-1):
                        if str(b) == S[j]:
                            for k in range(j+1,len(S)):
                                if str(c) == S[k]:
                                    count += 1
                                    break
                            break
                    break
    if count == 1000:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = input()
S = list(S)
i = 0
j = 0
k = 0
count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            for i in range(len(S)-2):
                if str(a) == S[i]:
                    for j in range(i+1, len(S)-1):
                        if str(b) == S[j]:
                            for k in range(j+1,len(S)):
                                if str(c) == S[k]:
                                    count += 1
                                    break
                            break
                    break
print(count)

Submission status: Time Limit Exceeded

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

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

    ind = 0
    for s in S:
        if pin[ind] == s:
            ind += 1
        if ind >= 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

S_set = {S[0:3]}
cnst = 0
for i in range(3,N):
    S_0_set = S_set.copy()
    for s_0 in S_0_set:
        for j in range(len(s_0)):
            if s_0[0:j]+s_0[j+1:3]+S[i] not in S_set:
                S_set.add(s_0[0:j]+s_0[j+1:3]+S[i])
    if len(S_set) == 1000:
        print(1000)
        cnst = 1
        break
if cnst == 0:
    print(len(S_set))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = flag2 = False
            for s in S:
                if flag1 and flag2 and int(s) == k:
                    count += 1
                    break
                elif flag1 and int(s) == j:
                    flag2 = True
                elif int(s) == i:
                    flag1 = True

print(count)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(1000):
  c = str(i).zfill(3)
  f = 0
  for j in range(N):
    if S[j] == c[f]:
      f += 1
    if f == 3:
      break
  if f == 3:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(1000):
  c = [str(i // 100), str((i // 10) % 10), str(i % 10)]
  f = 0
  for j in range(N):
    if S[j] == c[f]:
      f += 1
    if f == 3:
      break
  if f == 3:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
count = 0
for i in range(1000):
    x= i%10
    z= i//100
    y= (i-x-(z*100))//10
    
    p=0
    for j in range(N):
        if S[j]!=str(z):
            p = p+1
        else:
            break
    
    q=p+1
    for k in range(p+1,N):
        if S[k]!=str(y):
            q = q+1
        else:
            break
            
    r=q+1
    for l in range(q+1,N):
        if S[l]!=str(x):
            r = r+1
        else:
            break
            
    if r < N:
        count = count + 1
    else:
        count = count
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
_ = input()
s = input()

new_s = []
count = 0
prev = ""
for i in s:
  if i == prev:
    count = count + 1
    if count >= 3:
      continue
  else:
    count = 0
  new_s.append(i)
  prev = i

# print(len(set(list(itertools.combinations(new_s, 3)))))

result = []
for i in itertools.combinations(new_s, 3):
  result.append(int("".join(str(x) for x in i)))
print(len(set(result)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
_ = input()
s = input()

new_s = []
count = 0
prev = ""
for i in s:
  if i == prev:
    count = count + 1
    if count >= 3:
      continue
  else:
    count = 0
  new_s.append(i)
  prev = i

print(len(set(list(itertools.combinations(new_s, 3)))))

Submission status: Time Limit Exceeded

Solution code:
import itertools
_ = input()
s = input()

print(len(set(list(itertools.combinations(s, 3)))))

Submission status: Time Limit Exceeded

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

dp1 = [set() for i in range(4)]
dp2 = [set() for i in range(4)]
dp1[0].add('')
for i, S_i in enumerate(S):
    for j, dp1_j in enumerate(dp1):
        for s in dp1_j:
            dp2[j].add(s)
            if j <= 2:
                dp2[j + 1].add(s + S_i)
    dp1 = dp2
    dp2 = [set() for i in range(4)]

print(len(dp1[-1]))

Submission status: Time Limit Exceeded

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

dp = [[dict() for i in range(4)] for i in range(N + 1)]
dp[0][0][''] = True
for i in range(N):
    for j in range(4):
        for k, v in dp[i][j].items():
            dp[i+1][j][k] = True
            if j <= 2:
                dp[i+1][j+1][k+S[i]] = True

print(len(dp[-1][-1]))

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1000):
    ss = str(i).zfill(3)
    idx = 0
    for j in range(len(s)):
        if (s[j] == ss[idx]):
            idx += 1
            if (idx == 3):
                break
    if (idx == 3):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

S_set = {S[0:3]}
cnst = 0
for i in range(3,N):
    S_0_set = set()
    for s_0 in S_set:
        for j in range(len(s_0)):
            if s_0[0:j]+s_0[j+1:3]+S[i] not in S_set:
                S_0_set.add(s_0[0:j]+s_0[j+1:3]+S[i])
    S_set = S_set.union(S_0_set)
    if len(S_set) == 1000:
        print(1000)
        cnst = 1
        break
if cnst == 0:
    print(len(S_set))

Submission status: Time Limit Exceeded

Solution code:
import itertools

_ = input()
S = input().strip()

pass_set = set()
for ci in range(1,len(S)-1):
  for l, r in itertools.product(set(S[:ci]), set(S[ci+1:])):
    pass_set.add(l+S[ci]+r)

print(len(pass_set))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = set()
S = input()
res = 0
for i in range(n-2) :
    for j in range(i+1,n-1) :
        for k in range(j+1,n) :
            t = S[i]+S[j]+S[k]
            if t not in A :
                A.add(t)
                res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = input()
S = input()
l = []
l = [i for i in S]

answer = []

answer = [i for i in itertools.combinations(l,3)]

answer = set(answer)
print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
# N桁のSからN-3桁の数字を削除して(N<30000)３桁の数字を残す．残った数字の組み合わせて押してありえるのは何通りか？
# 実際に10^4通りから３通り選ぶのは 10^4C3通りくらい計算量的には計算できる?
# 更にあり得る組み合わせの上限==1000通りを終えた時点で終了すれば更に早い？
# 右の数字から数えていって1を取れるかみたいにしていけば最大１０００のループで終わる？
# 0001がNの中から取れるかの判定まず最初の0について左側からとっていって，0があれば存在すればとり，そこのindexを記録，．次に1として次のindexから検索していく

#for n in N_str:
#なぜ224とかの時に上手く行かないのだ?
#0224
count=0
NUM = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
for i in NUM:
    i_3d = i
    index_num = 0
    for j,i_s in enumerate(i_3d): # 1,2
        S_mid = S[index_num:]
        for s_s in S_mid: # 2 ひょっとして個々がコストが高い??もしかするとここで配列を取り出して新たな配列オブジェクトに入れてみたいな糞めんどくさいことをしてるのかも？？？
            index_num+= 1 #3
            if s_s == i_s: #2 == 2
                if j == len(i_3d)-1:  # 最後の文字がマッチングした
                    count+=1
                break
        # i_sについて探索しても何も見つからなかった場合,最後まで探索したとき，次のindexがあふれる時には停止する
        if index_num == len(S): # 3==4:False
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
# N桁のSからN-3桁の数字を削除して(N<30000)３桁の数字を残す．残った数字の組み合わせて押してありえるのは何通りか？
# 実際に10^4通りから３通り選ぶのは 10^4C3通りくらい計算量的には計算できる?
# 更にあり得る組み合わせの上限==1000通りを終えた時点で終了すれば更に早い？
# 右の数字から数えていって1を取れるかみたいにしていけば最大１０００のループで終わる？
# 0001がNの中から取れるかの判定まず最初の0について左側からとっていって，0があれば存在すればとり，そこのindexを記録，．次に1として次のindexから検索していく

#for n in N_str:
#なぜ224とかの時に上手く行かないのだ?
#0224
count=0
NUM = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
for i in NUM:
    i_3d = i
    index_num = 0
    for j,i_s in enumerate(i_3d): # 1,2
        for s_s in S[index_num:]: # 2
            index_num+= 1 #3
            if s_s == i_s: #2 == 2
                if j == len(i_3d)-1:  # 最後の文字がマッチングした
                    count+=1
                break
        # i_sについて探索しても何も見つからなかった場合,最後まで探索したとき，次のindexがあふれる時には停止する
        if index_num == len(S): # 3==4:False
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = input()
l = []

for i in S:
    l.append(i)

answer = []

for i in itertools.combinations(l,3):
    answer.append(i)
answer = set(answer)

print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
lst = []
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if S[i]+S[j]+S[k] in lst:
                continue
            else:
                lst.append(S[i]+S[j]+S[k])
            if len(lst) == 999:
                print(len(lst))
                quit()
print(len(lst))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
lst = []
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if S[i]+S[j]+S[k] in lst:
                continue
            else:
                lst.append(S[i]+S[j]+S[k])
print(len(lst))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
lst = []
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            lst.append(S[i]+S[j]+S[k])
print(len(set(lst)))

Submission status: Time Limit Exceeded

Solution code:
N = input()

S = input()
len_S = len(S)

key_list = range(0, 1000)

key_list = tuple(map(lambda key: '0' * (3 - len(str(key))) + str(key), key_list))

ans_list = []

for key in key_list:
    target_num = 0
    for s in S:
        if key[target_num] == s:
            target_num += 1
        if target_num == 3:
            ans_list.append(key)
            break

print(len(ans_list))

Submission status: Time Limit Exceeded

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

S_set = {S[0:3]}
for i in range(3,N):
    S_0_set = set()
    for s_0 in S_set:
        for j in range(len(s_0)):
            S_0_set.add(s_0[0:j]+s_0[j+1:3]+S[i])
    S_set = S_set.union(S_0_set)

print(len(S_set))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = input()
M = { X[0:3]:1 }
result = {}

for i in range(3, N) :
	i = X[i]
	keys = M.keys()
	for j in tuple(keys) :
		if (j, i) in result :
			continue
		M[j[0] + j[1] + i] = 1
		M[j[0] + j[2] + i] = 1
		M[j[1] + j[2] + i] = 1
		result[(j, i)] = True
	if len(M) == 1000:
		break

print(len(M))

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
from itertools import combinations as cmb
n=int(input())
s=list(input())
s.remove("\n")
combiset=set(cmb(s,3))
print(len(combiset))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as cmb
n=int(input())
s=input()
sss=[]
for i in range(len(s)):
    sss.append(s[i])
combiset=set(cmb(sss,3))
print(len(combiset))

Submission status: Time Limit Exceeded

Solution code:
# 動的計画法
import sys
input=sys.stdin.readline

n=int(input())
s=input()
dp=[[[False]*1000 for j in range(4)] for i in range(n+1)]

dp[0][0][0]=True

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==False:continue
            dp[i+1][j][k]=True
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=True
cnt=0
for i in range(1000):
    if dp[n][3][i]==1:cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

n=int(input())
s=input()
dp=[[[False]*1000 for j in range(4)] for i in range(n+1)]

dp[0][0][0]=True

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==False:continue
            dp[i+1][j][k]=True
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=True
cnt=0
for i in range(1000):
    if dp[n][3][i]==1:cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

n=int(input())
s=input()
dp=[[[False for k in range(1000)] for j in range(4)] for i in range(n+1)]

dp[0][0][0]=True

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==False:continue
            dp[i+1][j][k]=True
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=True
cnt=0
for i in range(1000):
    if dp[n][3][i]==1:cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# 動的計画法

n=int(input())
s=input()
dp=[[[0 for k in range(1000)] for j in range(4)] for i in range(n+1)]

dp[0][0][0]=1

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==0:continue
            dp[i+1][j][k]=1
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=1
cnt=0
for i in range(1000):
    if dp[n][3][i]==1:cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# 動的計画法

n=int(input())
s=input()
dp=[[[False for k in range(1000)] for j in range(4)] for i in range(n+1)]

dp[0][0][0]=True

for i in range(n):
    for j in range(4):
        for k in range(1000):
            if dp[i][j][k]==False:continue
            dp[i+1][j][k]=True
            if j<=2:
                dp[i+1][j+1][k*10+int(s[i])]=True
cnt=0
for i in range(1000):
    if dp[n][3][i]==True:cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0

for n in range(1000):
    pin = str(n).zfill(3)
    head = 0
    for c in S:
        if c == pin[head]:
            head += 1
        if head == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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):
            head = 0
            pin = [i, j, k]
            for c in S:
                if c == str(pin[head]):
                    head += 1
                if head == 3:
                    ans += 1
                    break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
S = str(input())

cand = []

for i, j, k in combinations(range(N), 3):
  cand.append(int(S[i])*100 + int(S[j])*10 + int(S[k]))

print(len(set(cand)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count = 0
num_list = [str(i).zfill(3) for i in range(1000)]
for i in range(len(num_list)):
    a = b = -1
    i100 = num_list[i][0]
    i10 = num_list[i][1]
    i1 = num_list[i][2]
    for j in range(len(s)-2):
        if s[j] == i100:
            a = j
            break
    if a != -1:
        for j in range(a+1,len(s)-1):
            if s[j] == i10:
                b = j
                break
    if b != -1:
        for j in range(b+1,len(s)):
            if s[j] == i1:
                count += 1
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count = 0
num_list = [str(i).zfill(3) for i in range(1000)]
for i in range(len(num_list)):
    a = b = -1
    for j in range(len(s)):
        if s[j] == num_list[i][0]:
            a = j
            break
    if a != -1:
        for j in range(a+1,len(s)):
            if s[j] == num_list[i][1]:
                b = j
                break
    if b != -1:
        for j in range(b+1,len(s)):
            if s[j] == num_list[i][2]:
                count += 1
                break
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sl = list(input())
ans = 0
for i in range(1000):
    try:
        i_zero = str(i)
        i_zero = i_zero.zfill(3)
        for j1,s in  enumerate (sl):
            if s == i_zero[0]:
                for j2,s in enumerate(sl[j1+1:],j1+1):
                    if s == i_zero[1]:
                        for j3,s in enumerate(sl[j2+1:],j2+1):
                            if s == i_zero[2]:
                                ans += 1
                                break
                        break
                break
    except:
        pass
print(ans)

Submission status: Time Limit Exceeded

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

S_set = {S[0:3]}
for i in range(3,N):
    S_0_set = S_set.copy()
    for s_0 in S_0_set:
        for j in range(len(s_0)):
            if s_0[0:j]+s_0[j+1:3]+S[i] not in S_set:
                S_set.add(s_0[0:j]+s_0[j+1:3]+S[i])

print(len(S_set))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    tmp = 0
    v = '{:03}'.format(i)
    for j in range(N):
        if v[tmp] == S[j]: tmp += 1
        if tmp == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

from itertools import product
pro = product(cs, repeat=3)

ans = 0
for c in pro:
    tmp = 0
    for i in range(N):
        if c[tmp] == S[i]: tmp += 1
        if tmp == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

dp = [set(), set()]

dp[0].add("")
for i in range(n):
    dp[(i + 1) % 2] = dp[i % 2].copy()
    i1 = (i + 1) % 2
    i0 = (i + 0) % 2
    for j in dp[i0]:
        if len(j) < 3:
            dp[i1].add(j + s[i])

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

dp = [defaultdict(int), defaultdict(int)]

dp[0][""] = 1
for i in range(n):
    dp[(i + 1) % 2] = dp[i % 2].copy()
    i1 = (i + 1) % 2
    i0 = (i + 0) % 2
    for j in dp[i0]:
        if len(j) < 3:
            dp[i1][j + s[i]] += dp[i0][j]

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

dp = [defaultdict(int), defaultdict(int)]

dp[0][""] = 1
for i in range(n):
    dp[(i + 1) % 2] = dp[i % 2].copy()
    for j in dp[i % 2]:
        # dp[(i + 1) % 2][j] = dp[i % 2][j]
        if len(j) < 3:
            dp[(i + 1) % 2][j + s[i]] += dp[i % 2][j]

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

dp = [defaultdict(int), defaultdict(int)]

dp[0][""] = 1
for i in range(n):
    dp[(i + 1) % 2] = defaultdict(int)
    for j in dp[i % 2]:
        dp[(i + 1) % 2][j] = dp[i % 2][j]
        if len(j) < 3:
            dp[(i + 1) % 2][j + s[i]] += dp[i % 2][j]

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

dp = [defaultdict(int), defaultdict(int)]

dp[0][""] = 1
for i in range(n):
    for j in dp[i % 2]:
        dp[(i + 1) % 2][j] = dp[i % 2][j]

    for j in dp[i % 2]:
        if len(j) < 3:
            dp[(i + 1) % 2][j + s[i]] += dp[i % 2][j]

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ans=[]
for i in range(1000):
    key=str(i).zfill(3)
    if key[0] in S:
        idx1=S.index(key[0])
    else:
        continue
    for j in range(idx1+1,L-1):
        if S[j]==key[1]:
            idx2=j
            for k in range(idx2+1,L):
                if S[k]==key[2]:
                    ans.append(key)
                    break
               

print(len(set(ans)))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    ii = i
    key = ii%10
    count = 0
    for j in range(N):
        if key == S[j]:
            count += 1
            if count == 3:
                ans += 1
                break
            ii //= 10
            key = ii%10

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def search(string,n):
    cnt=0
    for i in range(1000):
        s=str(i)
        if len(s)==1:
            s='00'+s
        elif len(s)==2:
            s='0'+s
        k=0
        for j in range(n):
            if k==2 and s[k]==string[j]:
                cnt+=1
                #print(l[i])
                break
            if s[k]==string[j]:
               k+=1
    
    return cnt
    
    

n=int(input())
s=input()
l=search(s,n)
print(l)

Submission status: Time Limit Exceeded

Solution code:
def search(string,n):
    l=[]
    for i in range(1000):
        s=str(i)
        if len(s)==1:
            s='00'+s
        elif len(s)==2:
            s='0'+s
        l.append(s)
    cnt=0
    for i in range(1000):
        k=0
        for j in range(n):
            if k==2 and l[i][k]==string[j]:
                cnt+=1
                #print(l[i])
                break
            if l[i][k]==string[j]:
               k+=1
    
    return cnt
    
    

n=int(input())
s=input()
l=search(s,n)
print(l)

Submission status: Time Limit Exceeded

Solution code:

input1 = int(input())
input2 = input()

inputbox = list(input2)
i=0
count = 0
for i in range(1000):
        c = [int(i/100),int(i/10)%10,i%10]
        f = 0
        for j in inputbox:
            if int(j)==c[f]:
                f=f+1
            if f==3:
                break
        if f==3:
            count = count + 1
            
print(count)

Submission status: Time Limit Exceeded

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

import math
import itertools
import re

# 入力
N = int(input())
S = str(input())
#M1, D1 = map(int, input().split())

si = ""
cnt = 0
for i in range(1000) :
  
  si = str(i).zfill(3)
  
  c = 0
  for x in range(N) :
    if S[x] == si[c] :
      c += 1
      if c == 3 :
        cnt += 1
        break    

print (cnt)

Submission status: Time Limit Exceeded

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

import math
import itertools
import re

# 入力
N = int(input())
S = str(input())
#M1, D1 = map(int, input().split())

si = ""
cnt = 0
for i in range(1000) :
  
  si = str(i).zfill(3)
  flag = 0

  for x in range(N) :
    if S[x] == si[0] :
      S1 = S[(x+1):]
      #print (si + ":" + S1)
      for y in range(len(S1)) :
        if S1[y] == si[1] :
          S2 = S1[(y+1):]
          for z in range(len(S2)) :
            if S2[z] == si[2] :
              cnt += 1
              flag = 1
              break
        if flag == 1 :
          break
    if flag == 1 :
      break


print (cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
  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 = str(i) + str(j) + str(k)
        cur = 0
        for x in range(N):
          if t[cur] == str(S[x]):
            cur += 1
            if cur == 3:
              ans += 1
              break
  print(ans)
main()

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(1000):
  c = [i // 100, (i // 10) % 10, i % 10]
  f = 0
  for j in range(N):
    if int(S[j]) == c[f]:
      f += 1
    if f == 3:
      break
  if f == 3:
    cnt += 1
print(cnt)