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:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
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
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def main():
    N=int(input())
    S=input()[:-1]
    
    can = set([""]) ## 2文字以下で現在構築可能な文字列(最大10+10*10 = 1010)
    ans = set() ## 3文字で現在構築可能な文字列(最大10*10*10 = 1,000)
    for s in S: 
        for c in deepcopy(can): #途中でcanという集合に追加されるのでcopyする
            res = c+s #2文字以下 + 1文字 で結合する
            if len(res) == 3: #3文字なので暗証番号の候補
                ans.add(res)
            elif len(res) < 3: #2文字以下なのでcanに挿入
                can.add(res)
    print(len(ans))

    """
    copyする回数 = N * len(can) <= 10^3 * N
    for文の走査回数 = N * len(can) <= 10^3 * N
    
    全体で  2 * (10^3 * N)
    N<=3*10^4なので
    2*3* 10^3 * 10^4 = 6 * 10^7 -> 間に合わない？んですか・・・？
    """

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
input1 = int(input())
input2 = input()
kesu = input1 - 1
inputbox = list(input2)
li=[0 for _ in range(1000)]
kazu =""
number = []
i=0
while i < input1-2:
    number.clear()
    number.append(inputbox[i])
    j=0
    while j < input1 - 2 - i:
        number.append(inputbox[j+i+1])
        k=0
        while k < input1 - 2 - i - j:
            number.append(inputbox[k+j+i+2])
            kazu=""
            for n in range(3):
                kazu = kazu+str(number[n])
            kazu1 = int(kazu)
            li[kazu1]=1
            number.pop()
            k=k+1
        j=j+1
        number.pop()
    i=i+1

count = 0
for i in range (1000):
    if li[i] == 1:
        count =count+1

print(count)

Submission status: Time Limit Exceeded

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

dp = [[[False] * 1000 for _ in range(4)] for _ 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 not dp[i][j][k]:
                continue
                
            # Not choose S[i]
            dp[i + 1][j][k] = True
            
            # Choose S[i]
            if j < 3:
                dp[i + 1][j + 1][k * 10 + int(S[i])] = True
            
print(sum(dp[-1][-1]))

Submission status: Time Limit Exceeded

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

    count = 0
    for i in range(1000):
        v = '{:0=3}'.format(i)
        c = False
        j = 0
        for k in range(n):
            if s[k] == v[j]:
                j += 1
                if j == 3:
                    c = True
                    break
        
        count += c
    return count

if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
N = int(input())
S = [int(c) for c in input()]
 
a = [b for b in itertools.combinations(S, 3)]
 
print(len(set(a)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  1 21:29:17 2019

@author: Shunya
"""

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

kesu = input1 - 1
inputbox = list(input2)
li=[0 for _ in range(1000)]
kazu =""
number = []
number1 = []
number2 = []
i=0


while i < input1-2:
    number.clear()
    number.append(inputbox[i])
    j=0
    while j < input1 - 2 - i:
        number1 = number
        number1.append(inputbox[j+i+1])
        k=0
        while k < input1 - 2 - i - j:
            number2 =number1
            number2.append(inputbox[k+j+i+2])
            kazu=""
            for n in range(3):
                kazu = kazu+str(number[n])
            kazu1 = int(kazu)
            li[kazu1]=1
            number2.pop()
            k=k+1
        j=j+1
        number1.pop()
    i=i+1

count = 0
for i in range (1000):
    if li[i] == 1:
        count =count+1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=str(input())
ans=0
for i in range(0,1000):
  if i<10:
    n='0'+'0'+str(i)
  elif i<100:
    n='0'+str(i)
  else:
    n=str(i)
  v1,v2,v3=n[0],n[1],n[2]
  j=0
  while j+1<=N-2 and a[j]!=v1:
    j+=1
  if j>N-2:
    break
  k=j+1
  while k+1<=N-1 and a[k]!=v2:
    k+=1
  if k>N-1:
    break
  l=k+1
  while l+1<=N and a[l]!=v3:
    l+=1
  if l<=N-1:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
tmp=[0]*3
for i in range(0,1000):
    tmp[0]=i/100
    tmp[1]=(i/10)%10
    tmp[2]=i%10
    cnt = 0
    for j in range(0,len(s)):
        if int(s[j])==int(tmp[cnt]):
            cnt+=1
        if cnt==3:
            break
    if cnt==3:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from bisect import bisect_left

def index(a, x):
    'Find leftmost index of item greater than or equal to x'
    i = bisect_left(a, x)
    if i != len(a):
        return i
    return False

def main():
    N = int(input())
    S = input()
    lst = list(S)

    a = []
    for i,j,k in itertools.combinations(range(N), 3):
        if i < j < k:
            s = int(str(lst[i])+str(lst[j])+str(lst[k]))

            idx = bisect_left(a, s)

            if idx == len(a):
                a.append(s)
            
            elif a[idx] != s:
                a.insert(idx, s)
            
            if len(a) == 1000:
                break
    print(len(a))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
 
cnt = []
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            s = S[i] + S[j] + S[k]
            cnt.append(s)

print(len(set(cnt)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from bisect import bisect_left

def index(a, x):
    'Find leftmost index of item greater than or equal to x'
    i = bisect_left(a, x)
    if i != len(a):
        return i
    return False

def main():
    N = int(input())
    S = input()
    lst = list(S)

    a = []
    for i,j,k in itertools.combinations(range(N), 3):
        if i < j < k:
            s = int(str(lst[i])+str(lst[j])+str(lst[k]))

            idx = bisect_left(a, s)

            if idx == len(a):
                a.append(s)
            
            elif a[idx] != s:
                a.insert(idx, s)

    print(len(a))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
 
cnt = []
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            S = ''.join([s[i], s[j], s[k]])
            cnt.append(S)

print(len(set(cnt)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
 
cnt = [0] * 1000
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            S = ''.join([s[i], s[j], s[k]])
            cnt[int(S)] += 1
 
ans = 0
for i in range(len(cnt)):
    if cnt[i] > 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

dp = tuple([0] * 1000 for _ in range(4))
dp[0][0] = 1
# dp[x][int(str)]:=x文字のstrは構成可能か？0/1

for x in s:
    for k in range(2, -1, -1):
        for incomplete_key in range(100):
            dp[k + 1][incomplete_key * 10 + x] |= dp[k][incomplete_key]

print(sum(dp[3]))

# dp

Submission status: Time Limit Exceeded

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

se = set()
for num in range(1000):
    if len(str(num))==1:
        check = '00'+str(num)
    elif len(str(num))==2:
        check = '0'+str(num)
    else:
        check = str(num)
    for i in range(n-2):
        if s[i] == check[0]:
            for j in range(i+1,n-1):
                if s[j] == check[1]:
                    for k in range(j+1,n):
                        if s[k] == check[2]:
                            se.add((s[i],s[j],s[k]))
            
print(len(se))

Submission status: Time Limit Exceeded

Solution code:
input()
S = input()
cnt = 0
for i in range(0, 1000):
  c = (i//100, (i//10)%10, i%10)
  f = 0
  for s in S:
    if int(s) == 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 = str(input())
V = []
f=0
s=set()
for i in range(10):
    for j in range(10):
        for k in range(10):
            V.append(str(i)+str(j)+str(k))

for v in V:
    for a in range(N):
        if S[a]==v[0]:
            for b in range(a+1, N):
                if S[b]==v[1]:
                    for c in range(b+1, N):
                        if S[c]==v[2]:
                            s.add(v)
print(len(s))

Submission status: Time Limit Exceeded

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

    count = 0
    for i in range(1000):
        v = '{:0=3}'.format(i)
        p = 0
        c = 1
        for j in range(3):
            tmp = p
            for k in range(p, n):
                if s[k] == v[j]:
                    p = k+1
                    break
            if tmp == p:
                c = 0
                break
        
        count += c
    return count

if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
n0=input()
s=input()
ans=0

for i in range(1000):
    n = str(i).zfill(3)
#    print(n[0])
    p = ".*"+ n[0] + ".*" + n[1] + ".*" + n[2] +".*"
    if re.match(p,s):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = 0
for i in range(0, 1000):
  c = [i//100, (i//10)%10, i%10]
  f = 0
  for j in range(len(S)):
    if int(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 = list(input())

cnt = 0
for i in range(1000):
    c = [str(int(i/100)), str(int((i/10)%10)), str(int(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 = list(str(input()))
cnt = 0

for i in range(1000):
    f = 0
    for j in range(3):
        x = list(str(i).zfill(3))
        for k in range(f,n):
            if x[j] == s[k]:
                f = k+1
                break
        else:
            break
    else:
        if f:
            cnt += 1

print(cnt)

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):
            val = [i,j,k]
            idx = 0
            for s in S:
                if int(s)==val[idx]:idx+=1
                if idx>2:
                    ans += 1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    cnt = 0
    n = str(i).zfill(3)
    for c in S:
        if c == n[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(1000):
    c = list(str(i).zfill(3).strip())
    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 = list(input())
s = [int(s[i]) for i in range(n)]

cnt = 0
for i in range(1000):
    c = [int(i/100), int((i/10)%10), int(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()
seq = list(set(list(s)))
genkai_list = []
for i in range(0,1000):
    if 0 <= i <= 9:
        ap = "00" + str(i)
        genkai_list.append(ap)
    elif 10 <= i <= 99:
        ap = "0" + str(i)
        genkai_list.append(ap)
    else:
        genkai_list.append(str(i))
ans = []
for a in range(len(genkai_list)):
    for i in range(len(s)):
        if s[i] == genkai_list[a][0]:
            for j in range(i + 1, len(s)):
                if s[j] == genkai_list[a][1]:
                    for k in range(j + 1, len(s)):
                        if s[k] == genkai_list[a][2]:
                            ans.append(a)
                            break # break1
                    else:  # break1されなかった場合
                        continue
            else:
                continue # jのループが全部回った（2文字目で一致しなかった）ら、iを次の文字に
            break
    else:
        continue # iのループが全部回った（1文字目で一致しなかった）ら、aを次の文字に
    break
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
p = [set() for _ in range(100)]
sp = [set() for _ in range(n)]
k = int(s[-1])
sp[-1].add(k)
ful = False
for j in range(n-2,1,-1):
    if ful:
        sp[j] = {0,1,2,3,4,5,6,7,8,9}
    tmp = set(sp[j+1])
    if len(tmp) == 10:
        ful = True
    tmp.add(int(s[j]))
    sp[j] = tmp
co = 0
for x in range(n-2):
    if co == 100:
        break
    for y in range(x,n-1):
        if x < y:
            tstr = str(s[x])+str(s[y])
            b2 = int(tstr)
            if len(p[b2]) > 0:
                pass
            else:
                p[b2] |= sp[y+1]
                co += 1
            if co == 100:
                break
g =0
for c in p:
    g += len(c)
print(g)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
X = ["{:03d}".format(i) for i in range(1000)]
# print(X)
ans = 0
for x in X:
    now = 0
    for s in S:
        if s == x[now]:
            now += 1
        if now == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
p = [set() for _ in range(100)]
sp = [set() for _ in range(n)]
k = int(s[-1])
sp[-1].add(k)
for j in range(n-2,1,-1):
    tmp = set(sp[j+1])
    tmp.add(int(s[j]))
    sp[j] = tmp
for x in range(n-2):
    for y in range(x,n-1):
        if x < y:
            tstr = str(s[x])+str(s[y])
            b2 = int(tstr)
            if len(p[b2]) > 0:
                pass
            else:
                p[b2] |= sp[y+1]
g =0
for c in p:
    g += len(c)
print(g)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    c = [i // 100, (i // 10) % 10, i % 10]
    digit = 0
    for j in s:
        if c[digit] == int(j):
            digit+=1
        if digit == 3:
            break
    if digit == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1000):
    if len(str(i))==1:
        i=str(0)+str(0)+str(i)
    elif len(str(i))==2:
        i=str(0)+str(i)
    else:
        i=str(i)
    x=0
    for j in range(n):
        if s[j]==i[x]:
            x+=1
            if x==3:
                count+=1
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(input())
ans=0
for i in range(10):
  for j in range(10):
    for k in range(10):
      now=str(i)
      count=0
      b=True
      f=1
      while count<n and b:
        if l[count]==now:
          if f==1:
            now=str(j)
            f+=1
          elif f==2:
            now=str(k)
            f+=1
          else:
            b=False
            ans+=1
        count+=1
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            pin = [i, j, k]
            x = 0

            for l in range(N):
                if int(S[l]) == pin[x]:
                    x += 1
                    if x == 3:
                        cnt += 1
                        break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    c = [i // 100, (i // 10) % 10, i % 10]
    digit = 0
    for j in range(len(s)):
        if c[digit] == int(s[j]):
            digit+=1
        if digit == 3:
            break
    if digit == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = 0
for i in range(1000):
  hy = i//100
  zyu = (i-hy*100)//10
  ichi = i%10
  cnt_hy = float('inf')
  cnt_zyu = float('inf')
  cnt_ichi = float('inf')
  t = 0
  for j in range(n):
    if t == 0:
      if int(S[j]) == hy:
        cnt_hy = j
        t += 1
    elif t == 1:
      if int(S[j]) == zyu:
        cnt_zyu = j
        t += 1
    elif t == 2:
      if int(S[j]) == ichi:
        cnt_ichi = j
        cnt += 1
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
seq = list(set(list(s)))
genkai_list = []
for i in range(0,1000):
    if 0 <= i <= 9:
        ap = "00" + str(i)
        genkai_list.append(ap)
    elif 10 <= i <= 99:
        ap = "0" + str(i)
        genkai_list.append(ap)
    else:
        genkai_list.append(str(i))
ans = []
for a in range(len(genkai_list)):
    for i in range(len(s)):
        if s[i] == genkai_list[a][0]:
            for j in range(i + 1, len(s)):
                if s[j] == genkai_list[a][1]:
                    for k in range(j + 1, len(s)):
                        if s[k] == genkai_list[a][2]:
                            ans.append(a)
                            break # break1
                    else:  # break1されなかった場合
                        continue
            else:
                continue # jのループが全部回った（2文字目で一致しなかった）ら、iを次の文字に
    else:
        continue # iのループが全部回った（1文字目で一致しなかった）ら、aを次の文字に
                
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
L = [str(i).zfill(3) for i in range(1000)]


def contain(l):
    phase = 0
    for c in S:
        if phase == 0 and c == l[0]:
            phase = 1
            continue
        if phase == 1 and c == l[1]:
            phase = 2
            continue
        if phase == 2 and c == l[2]:
            return 1
    return 0


print(sum(list(map(contain, L))))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = 0
for i in range(1000):
  hy = i//100
  zyu = (i-hy*100)//10
  ichi = i%10
  cnt_hy = float('inf')
  cnt_zyu = float('inf')
  cnt_ichi = float('inf')
  t = 0
  for j in range(n):
    if t == 0:
      if int(S[j]) == hy:
        cnt_hy = j
        t += 1
    elif t == 1:
      if int(S[j]) == zyu:
        cnt_zyu = j
        t += 1
    elif t == 2:
      if int(S[j]) == ichi:
        cnt_ichi = j
        break
  if cnt_hy < cnt_zyu < cnt_ichi <= n-1:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

def isThere(suji):
    flag1=False
    flag2=False
    flag3=False
    for i in s:
        if flag2==True and suji[2]==i:
            flag3=True
            break
        if flag1==True and suji[1]==i:
            flag2=True
        if suji[0]==i:
            flag1=True
    return flag3 

candidate=list(range(1000))
candidate=['0'+'0'+str(candidate[i]) if candidate[i]<10 else ('0'+str(candidate[i]) if 9<candidate[i]<100 else str(candidate[i])) for i in range(1000)]
ans=0
for suji in candidate:
    if isThere(suji):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            pin = [i, j, k]
            x = 0

            for a in S:
                if a == pin[x]:
                    x += 1
                    if x == 3:
                        cnt += 1
                        break

print(cnt)

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):
            n = 0
            while str(i) != S[n] and n < N-3:
                n += 1
            if S[n] != str(i):
                break
            n += 1
            while str(j) != S[n] and n < N-2:
                n += 1
            if S[n] != str(j):
                break
            n += 1
            while str(k) != S[n] and n < N-1:
                n += 1
            if S[n] == str(k):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = 0
for i in range(1000):
  hy = i//100
  zyu = (i-hy*100)//10
  ichi = i%10
  cnt_hy = float('inf')
  cnt_zyu = float('inf')
  cnt_ichi = float('inf')
  t = 0
  for j in range(n):
    if int(S[j]) == hy and t == 0:
      cnt_hy = j
      t += 1
    elif int(S[j]) == zyu and t == 1:
      cnt_zyu = j
      t += 1
    elif int(S[j]) == ichi and t == 2:
      cnt_ichi = j
  if cnt_hy < cnt_zyu < cnt_ichi <= n-1:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve(s1, s2, s3, S):
	key = 0
	L = [s1, s2, s3]
	for i in range(len(S)):
		if S[i] == L[key]:
			key += 1
			if key == 3:
				return True
	return False


if __name__ == "__main__":
	N = int(input())
	S = input()
	ans = 0
	for s1 in range(0, 10):
		for s2 in range(0, 10):
			for s3 in range(0, 10):
				if solve(str(s1), str(s2), str(s3), S):
					# print(str(s1) + str(s2) + str(s3))
					ans += 1
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
def int2str(i):
  t=str(i)
  if i <10:
    a="0"
    b="0"
    c=t[-1]
  elif i <100:
    a="0"
    b=t[-2]
    c=t[-1]
  else:
    a=t[-3]
    b=t[-2]
    c=t[-1]
  return a,b,c

N=int(input())
S=input()
ans=0
for i in range(1000):
  S1=[]
  S2=[]
  a,b,c=int2str(i)
  flag=0
  for j in  range(len(S)):
    if S[j] ==a:
      S1=S[j+1:]
      break
  if S1==[]:
    continue
  for j in  range(len(S1)):
    if S1[j] ==b:
      S2=S1[j+1:]
      break
  if S2==[]:
    continue
  for j in  range(len(S2)):
    if S2[j] ==c:
      ans+=1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1000):
	i=str(i)
	i=(3-len(i))*"0"+i
	r=0
	for j in range(n):
		if s[j]==i[r]:
			r+=1
		if r==3:
			break
	if r==3:
		ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = True
            flag2 = True

            for a in S:
                if flag1:
                    if a == i:
                        flag1 = False
                elif flag2:
                    if a == j:
                        flag2 = False
                elif a == k:
                    cnt += 1
                    break

print(cnt)

Submission status: Time Limit Exceeded

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

ans=0
for v in range(1000):
  v=str(v).zfill(3)
  idx,cnt=0,0
  for i in range(n):
    if S[i]==v[idx]:
      idx+=1
    else:
      cnt+=1
    if idx>=3:
      ans+=1
      break
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

list=list(S)

kei=[]
for a in range(N-2):
    for b in range(a+1,N-1):
        if b<=a:
            break
        for c in range(b+1,N):
            if c<=b:
                break
            #print(a,b,c)
            retsu=''
            retsu=retsu+list[a]+list[b]+list[c]
            kei.append(retsu)
last=set(kei)
print(len(last))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
for A in range(1000):
    x = str(A).zfill(3)[0]
    y = str(A).zfill(3)[1]
    z = str(A).zfill(3)[2]
    phase = 0
    for c in S:
        if phase == 0 and c == str(x):
            phase = 1
            continue
        if phase == 1 and c == str(y):
            phase = 2
            continue
        if phase == 2 and c == str(z):
            count += 1
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
 
ans = set()
 
for i in range(n-2):
    for j in range(i+1, n-1):
        for l in range(j+1, n):
            ans.add(s[i] + s[j] + s[l])

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import math
N = int(input())
S = input()

ans = 0

for z in range(10):
    for y in range(10):
        for x in range(10):
            s = str(z) + str(y) + str(x)

            z_exist = False
            y_exist = False

            key = ""

            for i in range(N):

                if str(x) == S[i] and z_exist and y_exist:
                    ans += 1
                    break
                elif str(y) == S[i] and z_exist and not y_exist:
                    y_exist = True
                    continue
                elif str(z) == S[i] and not z_exist and not y_exist:
                    z_exist = True
                    continue

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
for i_1 in range(0,10):
    for i_2 in range(0,10):
        for i_3 in range(0,10):
            for j_1 in range(0,N-2):
                if S[j_1] == str(i_1):            
                    for j_2 in range(j_1+1,N-1):
                        if S[j_2] == str(i_2):
                            for j_3 in range(j_2+1,N):
                                if S[j_3] == str(i_3):
                                    count += 1
                                    break
                            break
                    break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = 0
snumber = [str(i) for i in range(10)]
for i in snumber:
    for j in snumber:
        for k in snumber:
            n = 0
            while i != S[n] and n < N-3:
                n += 1
            if S[n] != i:
                break
            n += 1
            while j != S[n] and n < N-2:
                n += 1
            if S[n] != j:
                break
            n += 1
            while k != S[n] and n < N-1:
                n += 1
            if S[n] == k:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    # input
    n = int(input())
    s = input()

    ans = 0
    for i in range(0, 1000):
        num = str(i).rjust(3, '0')
        index = 0
        for i in s:
            if index == 3:
                ans += 1
                break
            elif num[index]==i:
                index += 1
        else:
            if index == 3:
                ans += 1

    print(ans)

    # calc


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=input()
count=0
for i in range(1000):
    flag=False
    for j in range(a):
        if b[j]==str(i).zfill(3)[0]:
            x=j
            flag=True
            break
    if flag:
        flag=False
    else:
        continue
    for k in range(x+1,a):
        if b[k]==str(i).zfill(3)[1]:
            y=k
            flag=True
            break
    if flag:
        flag=False
    else:
        continue
    for l in range(y+1,a):
        if b[l]==str(i).zfill(3)[2]:
            count+=1
            break
print(count)

Submission status: Time Limit Exceeded

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

ans=0
for v in range(1000):
  v=str(v).zfill(3)
  idx,cnt=0,0
  for i in range(n):
    if S[i]==v[idx]:
      idx+=1
    else:
      cnt+=1
    if cnt>n-3 or idx>=3:
      break
  if idx>=3:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

dp = [[[0 for _ in range(1000)] for _ in range(4)] for _ in range(n+1)]
dp[0][0][0] = 1
ans = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
new_s = input()
# new_s = ""
# for i in range(len(s)):
#    if i<3:
#        new_s+=s[i]
#     else:
#         if s[i-1] == s[i] and s[i-2] == s[i]:
#             pass
#         else:
#             new_s+=s[i]
pas = -1
ans = 0
lens = len(new_s)
for i in range(1000):
    ott = 0
    pas = int(pas)+1
    if pas < 10:
        pas = "00"+str(pas)
    elif pas < 100:
        pas = "0"+str(pas)
    pas = str(pas)
    idx = -1
    while idx < lens-1:
        idx += 1
        if ott == 0:
            if pas[0] == new_s[idx]:
                ott += 1
        elif ott == 1:
            if pas[1] == new_s[idx]:
                ott += 1
        elif ott == 2:
            if pas[2] == new_s[idx]:
                ott += 1
                ans += 1
        if ott == 3:
            break
print(ans)