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)
  
  if si[0] in S and si[1] in S and si[2] in S :
    pattern = "^.*"+ si[0] + ".*" + si[1] + ".*" + si[2] + ".*$"
    if re.match(pattern, S) :
      cnt += 1

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)
  pattern = "^.*"+ si[0] + ".*" + si[1] + ".*" + si[2] + ".*$"
  
  if re.search(pattern, S) :
    cnt += 1

print (cnt)

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 S[j] == str(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 = [i // 100, (i // 10) % 10, i % 10]
  f = 0
  for j in range(N):
    if S[j] == str(c[f]):
      f += 1
    if f == 3:
      break
  if f == 3:
    cnt += 1
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)
  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()

def judge(n):
    j = 0
    for i in range(N):
        if S[i] == n[j]:
            j += 1
        if j == 3:
            return True
    return False

ans = 0

for num in range(1000):
    num = str(num)
    num = "0" * (3-len(num)) + num
    if judge(num):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = input()
s = list(S)

a = list(itertools.combinations(s, 3))
A = []

for i in range(len(a)):
  if a[i] not in A:
    A.append(a[i])
else:
  print(len(A))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
#i番目の数とそれ以降の数の二個の組み合わせの個数
ct=[0]*n
for i in range(n):
  count=0
  a=set()
  for j in range(i+1,n):
    new=s[i]+s[j]
    if not new in a:
      a.add(new)
      count+=1
  a.clear()
  ct[i]=count
lis=list(range(10))
ans=0
for i in range(n-1):
  a=int(s[i])
  if a in lis:
    lis.remove(a)
    b=list(range(10))
    for j in range(i+1,n):
      count=0
      a=set()
      c=int(s[j])
      if c in b:
        ans+=ct[j]
        b.remove(c)
        for j in range(i+1,n):
          new=s[i]+s[j]
          if not new in a:
            a.add(new)
            count+=1
        a.clear()


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
b=[]
for i in range(1000):
	while len(str(i))<3:
		i="0"+str(i)
	for j in range(n):
		if str(i)[0]==s[j]:
			for k in range(j+1,n):
				if str(i)[1]==s[k]:
					for l in range(k+1,n):
						if str(i)[2]==s[l]:
							b.append(i)
							break
					break
			break
print(len(set(b)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
b=[]
for i in range(1000):
	while len(str(i))<3:
		i="0"+str(i)
	for j in range(n):
		if str(i)[0]==s[j]:
			for k in range(j+1,n):
				if str(i)[1]==s[k]:
					for l in range(k+1,n):
						if str(i)[2]==s[l]:
							b.append(i)	
print(len(set(b)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
#i番目の数とそれ以降の数の二個の組み合わせの個数
ct=[0]*n
for i in range(n):
  count=0
  a=set()
  for j in range(i+1,n):
    new=s[i]+s[j]
    if not new in a:
      a.add(new)
      count+=1
  a.clear()
  ct[i]=count
lis=list(range(10))
ans=0
for i in range(n-1):
  a=int(s[i])
  if a in lis:
    lis.remove(a)
    b=list(range(10))
    for j in range(i+1,n):
      c=int(s[j])
      if c in b:
        ans+=ct[j]
        b.remove(c)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
d=[]
for i in range (n):
	for j in range(n):
		for k in range(n):
			if (k>j) and (j>i):
				d.append(s[i]+s[j]+s[k])
d.sort()
i=1
for j in range(1,len(d)):
	if d[j] != d[j-1]:
		i+=1
print(i)

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
already=[0]*1000
code=str(input())
count=0
for i in range(num):
  for j in range(i,num):
    for k in range(j,num):
      if i<j and i<k and j<k:
      	string=code[i]+code[j]+code[k]
      	intString=int(string)
      	if already[intString]==0:
          already[intString]=1
          count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
already=[0]*1000
code=str(input())
count=0
for i in range(num):
  for j in range(i,num):
    for k in range(j,num):
      if i!=j and j!=k and i!=k and i<j and i<k and j<k:
      	string=code[i]+code[j]+code[k]
      	intString=int(string)
      	if already[intString]==0:
          already[intString]=1
          count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
num=int(input())
already=[0]*1000
code=str(input())
count=0
for i in range(num):
  for j in range(num):
    for k in range(num):
      if i!=j and j!=k and i!=k and i<j and i<k and j<k:
      	string=code[i]+code[j]+code[k]
      	intString=int(string)
      	if already[intString]==0:
          already[intString]=1
          count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=str(input())
X=[0]*1000
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      X[int(S[i])*100+int(S[j])*10+int(S[k])]=1
print(sum(X))

Submission status: Time Limit Exceeded

Solution code:
input()
S = [int(i) for i in input()]
cnt = 0
for i in range(0, 1000):
  c = (i//100, (i//10)%10, i%10)
  f = 0
  for s in S:
    if 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:
n = int(input())
s = str(input())
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    cursor = 0
    for j in range(n):
        if s[j] == i[cursor]:
            cursor += 1
            if cursor == 3:
                ans += 1
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
res = 0
a = [i for i in range(10)]
for num in itertools.product(a, repeat=3):
    p = 0
    for i,j in enumerate(s):
        if int(j) == num[p]:
            p += 1
            if p == 3:
                res += 1
                break
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
res = 0
for num in itertools.product(range(10), repeat=3):
    p = 0
    for i,j in enumerate(s):
        if int(j) == num[p]:
            p += 1
            if p == 3:
                res += 1
                break
print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
a=[0]*3
f=0

for a[0] in range(10):
    for a[1] in range(10):
        for a[2] in range(10):
            #print("pass=",a[0],a[1],a[2])
            f=0
            for ss in s:
                #print(ss,a[f],f)
                if ss == str(a[f]):
                    f+=1
                    if f==3:
                        ans+=1
                        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import re


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()

    list_ = []
    sum_ = 0

    for x in range(10):
        for y in range(10):
            for z in range(10):
                list_.append(str(x)+str(y)+str(z))

    for A in list_:
        x, y, z = A
        patarn = "{}(\\d)*?{}(\\d)*?{}".format(x, y, z)
        search_result = re.search(patarn, S)
        if search_result:
            sum_ += 1

    print(sum_)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
a=[0]*3
f=0

for a[0] in range(10):
    for a[1] in range(10):
        for a[2] in range(10):
            #print("pass=",a[0],a[1],a[2])
            f=0
            for ss in s:
                #print(ss,a[f],f)
                if int(ss) == a[f]:
                    f+=1
                    if f==3:
                        ans+=1
                        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import re


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()

    list_ = []
    sum_ = 0

    for x in range(10):
        for y in range(10):
            for z in range(10):
                list_.append(str(x)+str(y)+str(z))

    for A in list_:
        x, y, z = A
        patarn = "{}(\\d)*{}(\\d)*{}".format(x, y, z)
        search_result = re.search(patarn, S)
        if search_result:
            sum_ += 1

    print(sum_)


if __name__ == "__main__":
    main()

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):
            f1 = False
            f2 = False
            p1 = 0
            p2 = 0
            for i in range(0, n-2):
                if int(s[i]) == a:
                    f1 = True
                    p1 = i
                    break
            if f1:
                for j in range(p1+1, n-1):
                    if int(s[j]) == b:
                        f2 = True
                        p2 = j
                        break
            if f2:
                for k in range(p2+1, n):
                    if int(s[k]) == c:
                        count += 1
                        break
            if not f1 or not f2:
                break
        if not f1:
            break
print(count)

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):
            f1 = False
            f2 = False
            p1 = 0
            p2 = 0
            for i in range(0, n-2):
                if int(s[i]) == a:
                    f1 = True
                    p1 = i
                    break
            if f1:
                for j in range(p1+1, n-1):
                    if int(s[j]) == b:
                        f2 = True
                        p2 = j
                        break
            if f2:
                for k in range(p2+1, n):
                    if int(s[k]) == c:
                        count += 1
                        break
print(count)

Submission status: Time Limit Exceeded

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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    for j in range(N):
        if key[i][0] == int(S[j]):
            flag1 = 1
            break
            
    if flag1 == 0:
        continue
            
    for k in range(j+1,N):
        if key[i][1] == int(S[k]):
            flag2 = 1
            break
            
    if flag2 == 0:
        continue
                
    for l in range(k+1,N):
        if key[i][2] == int(S[l]):
            flag3 = 1
            break
                            
    if flag1 == 1 and flag2 == 1 and flag3 == 1:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
S = (stdin.readline().rstrip())
ans = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            i_a = 0
            i_b = 0
            i_c = 0
            for s in S:
                s = int(s)
                if s == a and (not i_a):
                    i_a = 1
                    continue
          
                if i_a and (s == b) and (not i_b):
                    i_b = 1
                    continue

                if i_a and i_b and (s == c):
                    ans += 1
                    break
            
print(ans)

Submission status: Time Limit Exceeded

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

key = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            key.append([i,j,k])
            
flag1 = 0
flag2 = 0
flag3 = 0
ans = 0



for i in range(len(key)):
    flag1 = 0
    flag2 = 0
    flag3 = 0
    
    for j in range(N):
        if key[i][0] == int(S[j]):
            flag1 = 1
            break
            
    for k in range(j+1,N):
        if key[i][1] == int(S[k]):
            flag2 = 1
            break
                
    for l in range(k+1,N):
        if key[i][2] == int(S[l]):
            flag3 = 1
            break
                            
    if flag1 == 1 and flag2 == 1 and flag3 == 1:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
n=int(input())
s=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p=re.compile(r'.*'+str(i)+r'.*'+str(j)+r'.*'+str(k)+r'.*')
            x=p.match(s)
            if x:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
n=int(input())
s=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p=r'.*'+str(i)+r'.*'+str(j)+r'.*'+str(k)+r'.*'
            x=re.match(p, s)
            if x:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
n=int(input())
s=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            p=r'.*'+str(i)+r'.*'+str(j)+r'.*'+str(k)+r'.*'
            x=re.search(p, s)
            if x:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#encoding: utf-8
import sys

input = sys.stdin.readline
def MAP(): return [int(s) for s in input().split()]

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

# 入力の網羅は 30,000C3 の組み合わせとなり全探索は不可能
# 出力は000〜999までの10**3であり、3*10**4とのかけあわせで
# O(10**7)であれば、制限時間内に計算が可能（出力全探索による貪欲法）

# PIN[0]に該当する文字が入力Sから見つかった場合、
# そのSを利用するのが最も効果的であるので貪欲法が利用できる
# (最初に見つかったものを使うとのちのちの制約に引っかかる、というような場合はDPなどを考慮)

# s in S に対し、PIN[0]に該当するsがあれば PIN[1]に該当するsを探索、、という繰り返しで3桁分見つかればans+=1

ans = 0
for i in range(1000):
	pin = str(i).zfill(3)
	cnt = 0 # 該当するsのカウント
	idx = 0 # 探索するPINのインデックス
	for s in S:
		if s==pin[idx]:
			cnt += 1 # カウントアップ
			idx += 1 # インデックスをPINの次の文字へ送る
			if idx == 3:
				break
	if cnt == 3:
		#print(pin)
		ans += 1
				
print(ans)

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

print (len(M))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(str(input()))
x = []
cnt = 0

for i in range(1000):
    x.append(list(str(i).zfill(3)+'x'))
    k = 0
    for j in range(n):
        if x[i][k] == s[j]:
            k += 1
    if k == 3:
            cnt += 1
 
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(str(input()))
cnt = 0
x = [list(str(i).zfill(3)+'x') for i in range(1000)]


for i in range(1000):
    k = 0
    for j in range(n):
        if x[i][k] == s[j]:
            k += 1
    if k == 3:
            cnt += 1
 
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(str(input()))
cnt = 0
x = [list(str(i).zfill(3)) for i in range(1000)]


for i in range(1000):
    k = 0
    for j in range(n):
        try:
            if x[i][k] == s[j]:
                k += 1
        except IndexError:
            pass
    if k == 3:
            cnt += 1
 
print(cnt)

Submission status: Time Limit Exceeded

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

N = int(input())
S = input().rstrip()

ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    ti = 0
    for j in range(N):
        if S[j] == t[ti]:
            ti += 1
        if ti == 3:
            break
    if ti == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1000):
    bl = [False,False,False]
    num = str(i).zfill(3)
    k = 0 
    for j in range (3):
        while k < n:
            if s[k] == num[j]:
                bl[j] = True
                k += 1
                break
            k += 1
    if bl[0] and bl[1] and bl[2]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
res = 0
for num in itertools.product(range(10), repeat=3):
    p = 0
    for i in range(n):
        if int(s[i]) == num[p]:
            p += 1
            if p == 3:
                res += 1
                break
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline

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

    tmp=[0,0,0]
    cnt=0
    for i in range(0,1000):
        if i < 10:
            tmp[0]=0
            tmp[1]=0
            tmp[2]=i
        elif i < 100:
            tmp[0]=0
            tmp[1]=i//10
            tmp[2]=i-tmp[1]*10
        else:
            tmp[0]=i//100
            tmp[1]=(i-tmp[0]*100)//10
            tmp[2]=i-tmp[0]*100-tmp[1]*10
        ketaflg=0
        for j in s :
            if j == '\n':
                break
            if tmp[0]==int(j) and ketaflg==0:
                ketaflg=1
            elif tmp[1]==int(j) and ketaflg==1:
                ketaflg=2
            elif tmp[2]==int(j) and ketaflg==2:
                ketaflg=3
                cnt+=1
                break
    print(cnt)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    input = sys.stdin.readline

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

    tmp=[0,0,0]
    cnt=0
    for i in range(0,1000):
        if i < 10:
            tmp[0]=0
            tmp[1]=0
            tmp[2]=i
        elif i < 100:
            tmp[0]=0
            tmp[1]=i//10
            tmp[2]=i-tmp[1]*10
        else:
            tmp[0]=i//100
            tmp[1]=(i-tmp[0]*100)//10
            tmp[2]=i-tmp[0]*100-tmp[1]*10
        ketaflg=0
        for j in range(0,n):
            if tmp[0]==int(s[j]) and ketaflg==0:
                ketaflg=1
            elif tmp[1]==int(s[j]) and ketaflg==1:
                ketaflg=2
            elif tmp[2]==int(s[j]) and ketaflg==2:
                ketaflg=3
                break
        if ketaflg==3:
            cnt+=1
    print(cnt)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

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

    tmp=[0,0,0]
    cnt=0
    for i in range(0,1000):
        if i < 10:
            tmp[0]=0
            tmp[1]=0
            tmp[2]=i
        elif i < 100:
            tmp[0]=0
            tmp[1]=i//10
            tmp[2]=i-tmp[1]*10
        else:
            tmp[0]=i//100
            tmp[1]=(i-tmp[0]*100)//10
            tmp[2]=i-tmp[0]*100-tmp[1]*10
        ketaflg=0
        for j in range(0,n):
            if tmp[0]==int(s[j]) and ketaflg==0:
                ketaflg=1
            elif tmp[1]==int(s[j]) and ketaflg==1:
                ketaflg=2
            elif tmp[2]==int(s[j]) and ketaflg==2:
                ketaflg=3
                break
        if ketaflg==3:
            cnt+=1
    print(cnt)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

    tmp=[0,0,0]
    cnt=0
    for i in range(0,1000):
        if i < 10:
            tmp[0]=0
            tmp[1]=0
            tmp[2]=i
        elif i < 100:
            tmp[0]=0
            tmp[1]=i//10
            tmp[2]=i-tmp[1]*10
        else:
            tmp[0]=i//100
            tmp[1]=(i-tmp[0]*100)//10
            tmp[2]=i-tmp[0]*100-tmp[1]*10
        ketaflg=0
        for j in range(0,n):
            if tmp[0]==int(s[j]) and ketaflg==0:
                ketaflg=1
            elif tmp[1]==int(s[j]) and ketaflg==1:
                ketaflg=2
            elif tmp[2]==int(s[j]) and ketaflg==2:
                ketaflg=3
                break
        if ketaflg==3:
            cnt+=1
    print(cnt)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

dp = np.zeros((30009, 4, 1009), dtype=np.bool)

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

for i in range(n):  # i: どの桁にいるか
    for j in range(4):  # j: 何文字残すか
        for k in range(1000):  # k: 残すと決まった数字
            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]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
S = input()

ans = 0
pos = 0

for i in range(1000):
    pos = 0
    number = str(i).zfill(3)
    for s in S:
        if number[pos] == s:
            pos += 1

        if pos == 3: break
        
    if pos == 3:
        ans += 1


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
S = input()

ans = 0
flag = [1,1,1]
flag_number = [1,0,0]
li = []

for i in range(1000):
    number = str(i).zfill(3)
    for s in range(len(S)):
        if flag[0] and (S[s] == number[0]):
            flag_number[0] = s
            flag[0]  = 0
            flag[1] = 1
            continue
        if flag[1] and (S[s] == number[1]):
            flag_number[1] = s
            flag[1] = 0
            flag[2] = 1
            continue
        if  flag[2] and (S[s] == number[2]):
            flag_number[2] = s
            flag[2] = 0
            continue
    if flag_number[2] != 0:
        ans += 1
    flag_number = [0,0,0]
    flag = [1,0,0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
S = input()

ans = 0
flag = [1,1,1]
flag_number = [1,0,0]
li = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            number = [i,j,k]
            for s in range(len(S)):
                if flag[0] and (int(S[s]) == number[0]):
                    flag_number[0] = s
                    flag[0]  = 0
                    flag[1] = 1
                    continue
                if flag[1] and (int(S[s]) == number[1]):
                    flag_number[1] = s
                    flag[1] = 0
                    flag[2] = 1
                    continue
                if  flag[2] and (int(S[s]) == number[2]):
                    flag_number[2] = s
                    flag[2] = 0
                    continue
            if flag_number[2] != 0:
                ans += 1
            flag_number = [0,0,0]
            flag = [1,0,0]

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for x in range(1000):
  x=str(x).zfill(3)
  idx=0
  for j in range(n):
    if S[j]==x[idx]:
      idx+=1
    if idx>=3:
      ans+=1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
S = [i for i in input()]

ans = 0
flag = [1,1,1]
flag_number = [0,0,0]
li = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            number = [i,j,k]
            for s in S:
                if flag[0] and flag[1] and flag[2] and (int(s) == int(number[0])):
                    flag_number[0] = s
                    flag[0]  = 0
                    continue
                if (not flag[0]) and flag[1] and flag[2] and (int(s) == int(number[1])):
                    flag_number[1] = s
                    flag[1] = 0
                    continue
                if (not flag[0]) and (not flag[1]) and flag[2] and (int(s) == int(number[2])):
                    flag_number[2] = s
                    flag[2] = 0
                    continue
            if flag_number[2] != 0:
                ans += 1
            flag_number = [0,0,0]
            flag = [1,1,1]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
S = [i for i in input()]

ans = 0
flag = [1,1,1]
flag_number = [0,0,0]
li = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            number = [i,j,k]
            for num,s in enumerate(S):
                if flag[0] and flag[1] and flag[2] and (int(s) == int(number[0])):
                    flag_number[0] = num
                    flag[0]  = 0
                    continue
                if (not flag[0]) and flag[1] and flag[2] and (int(s) == int(number[1])):
                    flag_number[1] = num
                    flag[1] = 0
                    continue
                if (not flag[0]) and (not flag[1]) and flag[2] and (int(s) == int(number[2])):
                    flag_number[2] = num
                    flag[2] = 0
                    continue
            if flag_number[2] != 0:
                ans += 1
            flag_number = [0,0,0]
            flag = [1,1,1]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(1000):
    str_i = str(i).zfill(3)
    i_ptr = 0
    s_ptr = 0
    
    while True:
        if i_ptr >= len(str_i):
            cnt += 1
            break

        while s_ptr <= len(s) - 1 and s[s_ptr] != str_i[i_ptr]:
            s_ptr += 1
        if s_ptr >= len(s):
            break
        i_ptr += 1
        s_ptr += 1
print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
for p in range(1000):
    v = format(p, '03')
    found = False
    for i in range(N):
        if S[i] == v[0]:
            p1 = i
            found = True
            break
    if not found:
        continue
    found = False
    for i in range(p1 + 1, N):
        if S[i] == v[1]:
            p2 = i
            found = True
            break
    if not found:
        continue
    found = False
    for i in range(p2 + 1, N):
        if S[i] == v[2]:
            p3 = i
            found = True
            break
    if not found:
        continue
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数
 
for a in range(10): #1文字目
  for b in range(10): #2文字目
    for c in range(10): #3文字目
      flg = False
      for i in range(n-2):
        if str(a) == s[i]:
          tmp_i = i + 1
          for j in range(tmp_i,n-1):
            if str(b) == s[j]:
              tmp_i = j + 1
              for k in range(tmp_i,n):
                if str(c) == s[k]:
                  cnt = cnt + 1
                  flg = True
                  break
              else:
                flg = True
            if flg:
              break
          else:
            flg = True
        if flg:
          break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cnt = 0
flag = False

for x in range(10):
	for y in range(10):
		for z in range(10):
			for i in range(n-2):
				if int(s[i]) == x:
					for j in range(i+1, n-1):
						if int(s[j]) == y:
							for k in range(j+1, n):
								if int(s[k]) == z:
									flag = True
									cnt += 1
									break
							if flag:
								break
					if flag:
						break
			
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

for ii in range(1000):
    v = str(ii).zfill(3)
    #print(v[0])
    #s2=s
    #print("s=",v)
    start=0
    for j in range(3):
        f=0
        for i in range(start,n):
            if s[i] == v[j]:
                start=i+1
                f=1
                #print("aa",s2)
                break

        if f == 0 :
            break

    if f == 1:
        ans += 1
        #print(v)

print(ans)