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:
n = int(input())
s = input()
count = 0
for i in range(1000):
    v = str(i).zfill(3)
    k=0
    for j in range(n):
        if v[k] == s[j]:
            k+=1
        if k==3:
            count+=1
            break

print(count)

Submission status: Time Limit Exceeded

Solution code:
def func1(i,N,S):
  indexS = 0
  indexI = 0
  i2 = str(i).zfill(3)
  
  while indexS < N:
    if indexI > 2:
      break
    if i2[indexI] not in S:
      return 0
    if i2[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  return 1 if indexI >2 else 0

def main():
  N = int(input())
  S = input()
  print(sum([func1(i,N,S) for i in range(1000)]))

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
def func1(i,N,S):
  indexS = 0 #Sの見ている場所
  indexI = 0 #3桁の暗証番号の見ている場所(0~2)
  i2 = str(i).zfill(3) # 0埋めしたi
  while indexS < N:
    if indexI > 2:
      break #探索終了
    if i2[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  return 1 if indexI >2 else 0

def main():
  N = int(input())
  S = input()
  print(sum([func1(i,N,S) for i in range(1000)]))

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
  indexS = 0 #Sの見ている場所
  indexI = 0 #3桁の暗証番号の見ている場所(0~2)
  i2 = str(i).zfill(3) # 0埋めしたi
  
  while indexS < N:
    if indexI > 2:
      break #探索終了
    if i2[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  if indexI >2:
    ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
  indexS = 0 #Sの見ている場所
  indexI = 0 #3桁の暗証番号の見ている場所(0~2)
  
  while indexS < len(S):
    if indexI > 2:
      break #探索終了
    if str(str(i).zfill(3))[indexI] == S[indexS]:
      indexI +=1
    indexS +=1
  if indexI >2:
    ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from itertools import product
    n=int(input())
    s=input()
    
    cnt=0
    num='0123456789'
    for pw in product(num,repeat=3):
        j=0
        for i in range(n):
            if pw[j]==s[i]:
                j+=1
                if j==3:
                    cnt+=1
                    break
    
    print(cnt) 
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
key_list = []

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

print(len(key_list))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
S = input()
ansset = set()
counts = np.zeros((N+1, 10))
for i in range(N):
    for j in range(10):
        counts[i+1, j] = counts[i, j] + (j == int(S[i]))
for i in range(1, N-1):
    for j in range(10):
        if counts[i, j] == 0:
            continue

        for k in range(10):
            if counts[N, k] - counts[i+1, k] == 0:
                continue

            ansset.add(100*j + 10*int(S[i]) + k)

print(len(ansset))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
S = input()

# dp = [[[False]*1009 for _ in range(4)] for _ in range(30009)]
dp = np.zeros((N+9, 4, 1009))
# dp[0][0][0] = True
dp[0, 0, 0] = 1

for i in range(N):
    for j in range(4):
        for k in range(1000):
            # jif not dp[i][j][k]:
            if not dp[i, j, k]:
                continue

            dp[i + 1, j, k] = 1
            if j <= 2:
                dp[i+1, j+1, k*10 + int(S[i])] = 1

print(int(np.sum(dp[N, 3, :])))

Submission status: Time Limit Exceeded

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

dp = [[[False]*1009 for _ in range(4)] for _ in range(30009)]
dp[0][0][0] = True

for i in range(N):
    for j in range(4):
        for k in range(1000):
            if not dp[i][j][k]:
                continue

            dp[i + 1][j][k] = True
            if j <= 2:
                dp[i+1][j+1][k*10 + int(S[i])] = True

print(sum(dp[N][3]))

Submission status: Time Limit Exceeded

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

com = combinations(S,3)
print(len(set(com)))

Submission status: Time Limit Exceeded

Solution code:


import math
def solve():
  n = int(input())
  s = input()
  dp = [[] for _ in range(4)]

  for i in range(n):
    number = s[i]
    

    for k in dp[2]:
      dp[3].append(k+number)
    for l in dp[1]:
      dp[2].append(l+number)  
    dp[1].append(number)
    
    for i in range(4):
      dp[i] = list(set(dp[i]))
  print(len(dp[3]))
    
      
solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = readline().decode().rstrip()

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

    for s in S:
        if s == i_[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
S = readline().decode().rstrip()

ans = 0
for i in range(1000):
    i_ = '{:>03}'.format(i)
    idx = 0

    for s in S:
        if s == i_[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(1000):
  tmp = format(i, '03')
  k = 0
  for j in s:
    if j == tmp[k]:
      k+=1
    if k == 3:
      count+=1
      break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
cnt = 0
for l in range(10):
  for m in range(10):
    for r in range(10):
      t = str(l) + str(m) + str(r)
      c = 0
      for i in range(len(S)):
        if t[c] == S[i]:
          c += 1
          if c > 2:
            cnt += 1
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
res = set([])
for l in range(len(S) - 2):
  for m in range(l + 1, len(S) - 1):
    for r in range(m + 1, len(S)):
      res.add(S[l] + S[m] + S[r])
print(len(res))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    t_index = 0
    for s_index in range(N):
        if s[s_index] == t[t_index]:
            t_index += 1
            if t_index == 3:
                break
    if t_index == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

tb = [False]*10**5
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            l = int(''.join(S[i]+S[j]+S[k]))
            tb[l] = True
print(tb.count(True))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = list(input())
se = set(itertools.combinations(S,3))
print(len(se))

Submission status: Time Limit Exceeded

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


ans_L = []
length = len(s)
count = 0

for i in range(1000):
    i = list(str(i).zfill(3))
    idx = 0
    #tmp_L = []
    cnt = 0
    for j in range(3):
        for k in range(idx,length):
            if str(i[j]) == str(s[k]):
                idx = k+1
                #tmp_L.append(str(i[j]))
                cnt += 1
                break

    #if len(tmp_L) == 3:
    #    ans_L.append("".join(tmp_L))
    if cnt == 3:
        count +=1

print(count)
#print(set(ans_L))

Submission status: Time Limit Exceeded

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


ans_L = []
length = len(s)
count = 0

for i in range(1000):
    i = list(str(i).zfill(3))
    idx = 0
    tmp_L = []

    for j in range(3):
        for k in range(idx,length):
            if str(i[j]) == str(s[k]):
                idx = k+1
                tmp_L.append(str(i[j]))
                break

    if len(tmp_L) == 3:
        ans_L.append("".join(tmp_L))

print(len(set(ans_L)))
#print(set(ans_L))

Submission status: Time Limit Exceeded

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

#L = [str(i).zfill(3) for i in range(1000)]
#def find_i(target,L):


ans_L = []
length = len(s)
count = 0

for i in range(1000):
    i = list(str(i).zfill(3))
    #print(i)
    idx = 0
    tmp_L = []

    for j in range(3):
        for k in range(idx,length):
            if str(i[j]) == str(s[k]):
                idx = k+1
                tmp_L.append(str(i[j]))
                break

    if len(tmp_L) == 3:
        ans_L.append("".join(tmp_L))

print(len(set(ans_L)))
#print(set(ans_L))

Submission status: Time Limit Exceeded

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

passwords = []
for i in range(len(S) - 2):
    for j in range(i + 1, len(S) - 1):
        # for k in range(j + 1, len(S)):
        for char in list(set(S[j + 1:])):
            password = S[i] + S[j] + char
            passwords.append(password)


# print(len(passwords))
# print(passwords)
# print(set(passwords))
print(len(list(set(passwords))))

Submission status: Time Limit Exceeded

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

passwords = []
for i in range(len(S) - 2):
    for j in range(i + 1, len(S) - 1):
        for k in range(j + 1, len(S)):
            password = S[i] + S[j] + S[k]
            passwords.append(password)


# print(len(passwords))
# print(passwords)
# print(set(passwords))
print(len(list(set(passwords))))

Submission status: Time Limit Exceeded

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

passwords = []
for i in range(len(S)):
    for j in range(i + 1, len(S)):
        for k in range(j + 1, len(S)):
            password = S[i] + S[j] + S[k]
            passwords.append(password)


# print(len(passwords))
# print(passwords)
# print(set(passwords))
print(len(list(set(passwords))))

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


n = ni()
s = ns()
ans = 0
for num in product(range(0, 10), repeat=3):
    i = 0
    numi = num[0]
    for si in s:
        if int(si) == numi and i == 2:
            ans += 1
            break
        elif int(si) == numi:
            i += 1
            numi = num[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


n = ni()
s = ns()
ans = 0
for num in product(range(0, 10), repeat=3):
    i = 0
    for si in s:
        if int(si) == num[i] and i == 2:
            ans += 1
            break
        elif int(si) == num[i]:
            i += 1
print(ans)

Submission status: Time Limit Exceeded

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

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

    one, two, three = False, False, False
    for j in range(n):
        if one:
            if two:
                if three:
                    break
                else:
                    if s[j] == i[2]:
                        three = True
            else:
                if s[j] == i[1]:
                    two = True
        else:
            if s[j] == i[0]:
                one = True
    if three:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#D - Lucky PIN
n=int(input())
s=list(str(input()))
password_list=[]
password_unique_list = []
for i in range(0,n-2):
    for j in range (i+1, n-1):
        for k in range  (j+1, n):
            password_i = s[i]
            password_j = s[j]
            password_k = s[k]
            password = password_i + password_j + password_k
            password_list.append(password)
password_unique_list = set(password_list)
print(len(password_unique_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x=input()
ans=0
for i in range(0,10):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,100):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
aa=[]
ans=0
for i in range(0,1000):
    chka,chkb,chkc=True,True,True
    i=str(i).zfill(3)
    for a in range(len(s)-2):
        if i[0]==s[a]:
            for b in range(a+1,len(s)-1):
                if i[1]==s[b]:
                    for c in range(b+1,len(s)):
                        if i[2]==s[c]:
                            ans+=1
                            aa.append(i)
                            chka,chkb,chkc=False,False,False
                            break
                        if chkc==False:
                            break
                        if c==len(s)-1 and i[2]!=s[c]:
                            break
                if chkb==False or chkc==False:
                    break
                if b==len(s)-2 and i[1]!=s[b]:
                    break
        if chka==False or chkb==False or chkc==False:
            break
        if a==len(s)-3 and i[0]!=s[a]:
            break


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
aa=[]
ans=0
for i in range(0,1000):
    i=str(i).zfill(3)
    for a in range(len(s)-2):
        if i[0]==s[a]:
            for b in range(a+1,len(s)-1):
                if i[1]==s[b]:
                    for c in range(b+1,len(s)):
                        if i[2]==s[c]:
                            ans+=1
                            aa.append(i)
                            break
                        if c==len(s)-1 and i[2]!=str(c):
                            break
                if b==len(s)-2 and i[1]!=str(b):
                    break
        if a==len(s)-3 and i[0]!=str(a):
            break

print(len(list(set(aa))))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=list(ss())
ans=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            ans.append(s[i]+s[j]+s[k])
            

print(len(list(set(ans))))

Submission status: Time Limit Exceeded

Solution code:
n=input()
s=input()
n=int(n)
ans=0
com=[0 for _ in range(n*(n-1)*(n-2)//6)]
m=0
for i in range(n-2):
  x=int(s[i])
  for j in range(i+1,n-1):
    y=int(s[j])
    for k in range(j+1,n):
      z=int(s[k])
      com[m]=x*100+y*10+z
      m+=1
com=list(set(com))      
ans=len(com)
print(ans)

Submission status: Time Limit Exceeded

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

c = 0
for i in range(1000):
  p = str(i).zfill(3)
  flag = 0
  for s in S:
    if (s == p[0] and flag == 0):
      flag += 1
    elif (s == p[1] and flag == 1):
      flag += 1
    elif (s == p[2] and flag == 2):
      c += 1
      break
print(c)

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):
            key = [i,j,k]
            search = 0
            for n in range(N):
                if int(S[n]) == key[search]:
                    search += 1
                    if search == 3:
                        ans += 1
                        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
dp=[[[0]*1000 for _ in range(4)] for _ in range(n+1)]
dp[0][0][0]=1
for i in range(n):
  n=int(s[i])
  for j in range(3):
    for k in range(100):
      dp[i+1][j+1][k*10+n]=max(dp[i+1][j+1][k*10+n],dp[i][j][k])
  for j in range(4):
    for k in range(1000):
      dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k])
ans=0
for i in range(1000):
  if dp[-1][3][i]==1:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for num in range(1000):
    num_s = str(num).zfill(3)
    f = False
    for i in range(n):
        if f :
            break
        if s[i] == num_s[0]:
            for j in range(i+1,n):
                if s[j] == num_s[1]:
                    for k in range(j+1,n):
                        if s[k] == num_s[2]:
                            f = True
    if f:
        ans +=1
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for num in range(1000):
    num_s = str(num).zfill(3)
    f = False
    for i in range(n):
        if s[i] == num_s[0]:
            for j in range(i+1,n):
                if s[j] == num_s[1]:
                    for k in range(j+1,n):
                        if s[k] == num_s[2]:
                            f = True
    if f:
        ans +=1
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = {}
ii = [0]*10
jj = [0]*100
for i in range(n-2):
  si = int(s[i])
  if sum(ii) == 10:
    break
  elif ii[si] == 1:
    next
  else:
    ii[si] = 1
  for j in range(i+1,n-1):
    sij = 10*si + int(s[j])
    if sum(jj[10*si:10*(si+1)]) == 10:
      break
    elif jj[sij] == 1:
      next
    else:
      jj[sij] = 1
    for k in range(j+1,n):
      a["".join([s[i],s[j],s[k]])] = 1
print(sum(a.values()))

Submission status: Time Limit Exceeded

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

a = {}
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      a["".join([s[i],s[j],s[k]])] = 1

print(sum(a.values()))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
ifChecked = [[False, False, False, False, False, False, False, False, False, False] for i in range(10)]
result = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        i_let = int(s[i])
        j_let = int(s[j])
        if ifChecked[i_let][j_let]:
            continue
        else:
            ifChecked[i_let][j_let] = True
            result += len(set(s[j+1:n]))

print(result)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    p = str(i).zfill(3)
    p_index = 0
    for j in range(n):
        if p[p_index] == s[j]:
            p_index += 1
            if p_index == 3:
                break
    if p_index == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    p = str(i).zfill(3)
    p_index = 0
    for j in range(n):
        if p[p_index] == s[j]:
            p_index += 1
        if p_index == 3:
            break
    if p_index == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

queue = []
for i in range(n-2):
    queue.append(('', i))

ans = 0
nn = n-3
memo = set()
while queue:
    s, pos = queue.pop()
    # print((s,pos))
    for i in range(pos, n):
        t = s + ss[i]
        if len(t) == n - nn:
            memo.add(t)
        else:
            queue.append((t,i+1))
print(len(memo))
# print(memo)

Submission status: Time Limit Exceeded

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

queue = []
for i in range(n-2):
    queue.append(('', i))

ans = 0
nn = n-3
memo = set()
while queue:
    s, pos = queue.pop()
    for i in range(n-2):
        if pos + i >= n:
            continue
        t = s + ss[pos+i]
        if len(t) == n - nn:
            memo.add(t)
        else:
            queue.append((t,pos+i+1))
print(len(memo))
# print(memo)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
from string import digits

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

ret = 0
for perm in product(digits, repeat=3):
    i = 0
    for c in s:
        if c == perm[i]:
            i += 1
            if i == 3:
                break
    if i == 3:
        ret += 1

print(ret)

Submission status: Time Limit Exceeded

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

for i in range(n-2):
    for j in range(i+1, n-1):
        nums = set(s[j+1::])
        for num in nums:
            ans_l.add(s[i] + s[j] + num)

print(len(ans_l))

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    n = int(input())
    s = input()

    ans = 0

    cmb_list = list(itertools.combinations(range(n), 3))
    cmb_len = len(cmb_list)

    output_list = []

    for a, b,c in cmb_list:
        tmp = s[a] + s[b] + s[c]
        output_list.append(tmp)

    print(len(set(output_list)))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = set(itertools.combinations(S, 3))
print(len(ans))

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = set(itertools.combinations(S, 3))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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




num_list = ['1','2','3','4','5','6','7','8','9','0']

ans = 0
for nums in itertools.product(num_list,num_list,num_list):
	j = 0
	for i in range(N):
		if S[i] == nums[j]:
			j+=1
		if j == 3:
			ans += 1
			break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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


def nextpermutation(s,cnt):
	out = 0
	if cnt == 3:
		j = 0
		for i in range(N):
			if S[i] == s[j]:
				j += 1
			if j == 3:
				return 1
		return 0

	for i in range(10):
		s += str(i)
		out += nextpermutation(s,cnt+1)
		s = s[:-1]

	return out

ans = nextpermutation('', 0)

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(0, 1000):
    target = str(i).zfill(3)
    target_idx = 0
    for c in s:
        if c == target[target_idx]:
            target_idx += 1
        if target_idx == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
res = 0
for i in range(1000):
    tmp = str(i).rjust(3, '0')
    state = 0
    for j in range(n):
        if state == 3:
            continue
        elif s[j] == tmp[state]:
            state += 1
    else:
        if state==3:
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

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

from collections import deque

ans = 0

# Rnum: 000 ~ 999
for Rnum in range(0,1000):
    R = deque(str(Rnum).zfill(3))

    for s in S:
        if s == R[0]:
            R.popleft()
        if not R:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

def solve(N: int, S: str):
    answer = 0
    for i in range(1000):
        target = str(i).zfill(3)
        index = 0
        for i in range(N):
            if S[i] == target[index]:
                index += 1
            
            if index == 3:
                answer += 1
                break
    
    print(answer)

    return


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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
n = int(input())
s = input().rstrip()

def solve1(n, s):
    # 全探索
    cnt = 0
    for v in range(0, 1000):
        v = str(v)
        v = "0" * (3 - len(v)) + v
        idx = 0
        for i in range(len(s)):
            if s[i] == v[idx]:
                idx += 1
            if idx == 3:
                cnt += 1
                break
    print(cnt)

def solve2(n, s):
    # DP
    dp = [[[False for _ in range(1000)] for _ in range(4)] for _ in range(n+1)]
    dp[0][0][0] = True

    for i in range(n):
        for j in range(3):
            for k in range(100):
                if dp[i][j][k]:
                    num = k*10 + int(s[i])
                    dp[i+1][j+1][num] = True
        for j in range(4):
            for k in range(1000):
                dp[i+1][j][k] |= dp[i][j][k]

    cnt = 0
    for i in range(1000):
        if dp[n][3][i]:
            cnt += 1
    print(cnt)

solve2(n, s)

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
n = int(input())
s = input().rstrip()

def solve1(n, s):
    # 全探索
    cnt = 0
    for v in range(0, 1000):
        v = str(v)
        v = "0" * (3 - len(v)) + v
        idx = 0
        for i in range(len(s)):
            if s[i] == v[idx]:
                idx += 1
            if idx == 3:
                cnt += 1
                break
    print(cnt)

def solve2(n, s):
    # DP
    dp = [[False for _ in range(1000)] for _ in range(4)]
    dp[0][0] = True

    for i in range(n):
        pre_dp = deepcopy(dp)
        for j in range(3):
            for k in range(100):
                if pre_dp[j][k]:
                    num = k*10+int(s[i])
                    dp[j+1][num] = True
    cnt = 0
    for i in range(1000):
        if dp[3][i]:
            cnt += 1
    print(cnt)
solve2(n, s)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
T = 0
for s in range(1000):
  s = str(s//100) + str(s//10-(s//100)*10) + str(s-(s//10)*10)
  l = 0
  for m in range(N):
    if S[m] == s[l]:
      l += 1
    if l == 3:
      break
  if l >= 3:
    T += 1
print(T)

Submission status: Time Limit Exceeded

Solution code:
def search(a):
    x=0
    a="".join(["0"*(3-len(a)),a])
    for i in range(n):
        if a[x]==s[i]:
            x+=1
            if x==3:
                return True
    return False
n=int(input())
s=input()
ans=0
k=[False]*1000
for i in range(1000):
    k[i]=search(str(i))
for i in k:
    if i:
        ans+=1
print(ans)