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()
ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    f = 0
    for j in range(n):
        if(s[j]==t[f]):
            f+=1
            if(f==3):
                break
    if(f==3):
        ans += 1
print(ans)

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.append(s[i] + s[j] + s[k])
print(len(set(a)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tar=str(i)+str(j)+str(k)
            now=0
            for l in range(n):
                
                if tar[0+now]==s[l]:now+=1
                if now==3:
                    ans+=1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
ls = []
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if s[i] + s[j] + s[k] not in ls:
                ls.append(s[i] + s[j] + s[k])
print(len(ls))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num = input()
 
password_list = []
initial_list = []
initial_list2 = []
initial_list3 = []
 
for i in range(len(num)-2):
    if num[i] in initial_list:
        continue
    elif len(initial_list) == 10:
        break
    else:
        initial_list.append(num[i])
        for j in range(i+1,len(num)-1):
            initial_list2 = []
            if num[j] in initial_list2:
                continue
            elif len(initial_list2) == 10:
                break
            else:
                initial_list2.append(num[j])
                for k in range(j+1,len(num)):
                    initial_list3 = []
                    if num[k] in initial_list3:
                        continue
                    elif len(initial_list3) == 10:
                        break
                    else:
                        initial_list3.append(num[k])
                        target = num[i] + num[j] + num[k]
                        if target not in password_list:
                            password_list.append(target)
                else:
                    continue
                break
        else:
            continue
        break
print(len(password_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num = input()
 
password_list = []
initial_list = []
initial_list2 = []
initial_list3 = []
 
for i in range(len(num)-2):
    if num[i] in initial_list:
        continue
    elif len(initial_list) == 10:
        break
    else:
        initial_list.append(num[i])
        for j in range(i+1,len(num)-1):
            initial_list2 = []
            if num[j] in initial_list2:
                continue
            elif len(initial_list2) == 10:
                break
            else:
                initial_list2.append(num[j])
                for k in range(j+1,len(num)):
                    initial_list3 = []
                    if num[k] in initial_list3:
                        continue
                    elif len(initial_list3) == 10:
                        break
                    else:
                        initial_list3.append(num[k])
                        target = num[i] + num[j] + num[k]
                        if target not in password_list:
                            password_list.append(target)
print(len(password_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num = input()
 
password_list = []
initial_list = []
initial_list2 = []
initial_list3 = []
 
for i in range(len(num)-2):
    if num[i] in initial_list:
        continue
    else:
        initial_list.append(num[i])
        for j in range(i+1,len(num)-1):
            initial_list2 = []
            if num[j] in initial_list2:
                continue
            else:
                initial_list2.append(num[j])
                for k in range(j+1,len(num)):
                    initial_list3 = []
                    if num[k] in initial_list3:
                        continue
                    else:
                        initial_list3.append(num[k])
                        target = num[i] + num[j] + num[k]
                        if target not in password_list:
                            password_list.append(target)
print(len(password_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num = input()
 
password_list = []
initial_list = []
 
for i in range(len(num)-2):
    if num[i] in initial_list:
        continue
    else:
        initial_list.append(num[i])
        for j in range(i+1,len(num)-1):
            for k in range(j+1,len(num)):
                target = num[i] + num[j] + num[k]
                if target not in password_list:
                    password_list.append(target)
print(len(password_list))

Submission status: Time Limit Exceeded

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

password_list = []

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            target = num[i] + num[j] + num[k]
            if target not in password_list:
                password_list.append(target)
                

print(len(password_list))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
 
N = int(input())
S = input()
 
ans = 0
for i in range(1000):
    pw = "0"*(3-len(str(i)))+str(i)
 
    w1 = -1
    for j in range(N-2):
        if S[j] == pw[0]:
            w1 = j
            break
    if w1 == -1:
        continue
 
    w2 = -1
    for j in range(w1+1, N-1):
        if S[j] == pw[1]:
            w2 = j
            break
    if w2 == -1:
        continue
 
    w3 = -1
    for j in range(w2+1, N):
        if S[j] == pw[2]:
            w3 = j
            break
    if w3 == -1:
        continue
 
    ans += 1
 
print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(1000):
    pw = "0"*(3-len(str(i)))+str(i)

    w1 = -1
    for j in range(N-2):
        if S[j] == pw[0]:
            w1 = j
            break
    if w1 == -1:
        continue

    w2 = -1
    for j in range(w1+1, N-1):
        if S[j] == pw[1]:
            w2 = j
            break
    if w2 == -1:
        continue

    w3 = -1
    for j in range(w2+1, N):
        if S[j] == pw[2]:
            w3 = j
            break
    if w3 == -1:
        continue

    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(1000):
    pw = list("{0:03d}".format(i))

    w1 = -1
    for j in range(N-2):
        if S[j] == pw[0]:
            w1 = j
            break
    if w1 == -1:
        continue

    w2 = -1
    for j in range(w1+1, N-1):
        if S[j] == pw[1]:
            w2 = j
            break
    if w2 == -1:
        continue

    w3 = -1
    for j in range(w2+1, N):
        if S[j] == pw[2]:
            w3 = j
            break
    if w3 == -1:
        continue

    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

sumtmp = [[0 for i in range(N) ] for j in range(10)]
sumtmp[int(S[0])][0] = 1
for i in range(1, N):
    val = int(S[i])
    for j in range(10):
        sumtmp[j][i] = sumtmp[j][i-1] 
        if j == val:
            sumtmp[j][i] += 1

pw = set()
for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(10):
            if sumtmp[k][N-1] - sumtmp[k][j] > 0:
                w = S[i]+S[j]+str(k) 
                pw.add(w)

print(len(pw))

Submission status: Time Limit Exceeded

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

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

password = set()
for i in range(1, N-1):
    for j in range(i+1, N):
        for k in range(j+1, N+1):
            w = S[i-1] + S[j-1] + S[k-1]
            password.add(w)

print(len(password))

Submission status: Time Limit Exceeded

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

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

password = set()
for i in range(1,N+1):
    for j in range(i+1, N+1):
        for k in range(j+1, N+1):
            w = S[i-1] + S[j-1] + S[k-1]
            password.add(w)

print(len(password))

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1000):
    t = '%03d' % i
    j = 0
    for s in S:
        if s == t[j]:
            j += 1
        if j== 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n = int(input())
    s = tuple(map(int, tuple(input())))
    num_pos = [] # 各数字がｓ中に最後にあらわれる位置。
    for num in range(10):
        if num in s:
            num_pos.append(n - s[::-1].index(num) - 1)
    unique_num = [0] * n # ｓの各桁でその桁以降にある数字の種類。
    for i1 in range(n):
        unique_num[i1] = sum([np >= i1 for np in num_pos])
    d1 = defaultdict(int)
    for keta1 in range(n - 2):
        for keta2 in range(keta1 + 1, n - 1):
            if not d1[(s[keta1], s[keta2])]:
                d1[(s[keta1], s[keta2])] = unique_num[keta2 + 1]
    r = sum(d1.values())
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n = int(input())
    s = tuple(map(int, tuple(input())))
    num_pos = []
    for num in range(10):
        if num in s:
            num_pos.append(n - s[::-1].index(num) - 1)
    unique_num = [0] * n
    for i1 in range(n):
        unique_num[i1] = sum([np >= i1 for np in num_pos])
    d1 = defaultdict(int)
    for keta1 in range(n - 2):
        for keta2 in range(keta1 + 1, n - 1):
            d1[(s[keta1], s[keta2])] = max(d1[(s[keta1], s[keta2])], unique_num[keta2 + 1])
    r = sum(d1.values())
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n = int(input())
    s = tuple(input())

    unique_num = [0] * n
    for i1 in range(n):
        unique_num[i1] = len(set(s[i1:]))
    d1 = defaultdict(int)
    for keta1 in range(n - 2):
        for keta2 in range(keta1 + 1, n - 1):
            d1[(s[keta1], s[keta2])] = max(d1[(s[keta1], s[keta2])], unique_num[keta2 + 1])
    r = sum(d1.values())
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans=0

for i in itertools.product(range(0,10),repeat=3):

    isOK=[False]*3
    
    for x in range(len(S)):
        if isOK[0] and isOK[1]:
            if int(S[x])==i[2]:
                ans+=1
                break
        elif isOK[0]:
            if int(S[x])==i[1]:
                isOK[1]=True
        else:
            if int(S[x])==i[0]:
                isOK[0]=True

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

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = 0
            for l, value in enumerate(S):
                if tmp == 0:
                    if value == str(i):
                        tmp = 1
                elif tmp == 1:
                    if value == str(j):
                        tmp = 2
                elif tmp == 2:
                    if value == str(k):
                        ans += 1
                        break
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):
            flag1 = flag2 = flag3 = False
            for l in range(n):
                if not flag1 and i == int(s[l]):
                    flag1 = True
                    continue
                if flag1 and not flag2 and j == int(s[l]):
                    flag2 = True
                    continue
                if flag1 and flag2 and not flag3 and k == int(s[l]):
                    flag3 = True
            if flag3:
                cnt += 1
print(cnt)

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):
            flag1 = flag2 = flag3 = False
            for l in range(n):
                if not flag1 and str(i) == s[l]:
                    flag1 = True
                    continue
                if flag1 and not flag2 and not flag3 and str(j) == s[l]:
                    flag2 = True
                    continue
                if flag1 and flag2 and not flag3 and str(k) == s[l]:
                    flag3 = True
                    continue
            if flag1 and flag2 and flag3:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
T = tuple(map(int, input()))
ans = 0
for i in range(0, 1000):
    a = i // 100
    b = (i // 10) % 10
    c = i % 10
    flag1 = False
    flag2 = False
    flag3 = False
    for t in T:
        if flag2:
            if t == c:
                flag3 = True
                break
        if flag1:
            if t == b:
                flag2 = True
                continue
        if t == a:
            flag1 = True

    if flag3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# author:  Taichicchi
# created: 17.09.2020 23:46:19


N = int(input())

S = input()

cnt = 0

for i in map(lambda x: str(x).zfill(3), range(1000)):
    f = 0
    for s in S:
        if s == i[f]:
            f += 1
        if f == 3:
            break
    if f == 3:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# author:  Taichicchi
# created: 17.09.2020 23:46:19

import sys

N = int(input())

S = input()

cnt = 0

for i in map(lambda x: str(x).zfill(3), range(1000)):
    f = 0
    for j in range(len(S)):
        if S[j] == i[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()

pin=set()
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            pin.add(s[i]+s[j]+s[k])
print(len(pin))

Submission status: Time Limit Exceeded

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

A = [0]*1000 
ans = 0

for i in range(1000):
  if i < 10:
    s = '00' + str(i)
  elif i < 100:
    s = '0' + str(i)
  else:
    s = str(i)
    
  for j in range(N):
    if S[j] == s[0]:
      for k in range(j+1,N):
        if S[k] == s[1]:
          for l in range(k+1,N):
            if S[l] == s[2]:
              A[i] = 1
              break
          break
      break

print(A.count(1))

Submission status: Time Limit Exceeded

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

A = [0]*1000 
ans = 0

for i in range(1000):
  if i < 10:
    s = '00' + str(i)
  elif i < 100:
    s = '0' + str(i)
  else:
    s = str(i)
    
  for j in range(N):
    if S[j] == s[0]:
      for k in range(j+1,N):
        if S[k] == s[1]:
          for l in range(k+1,N):
            if S[l] == s[2]:
              A[i] = 1
              break
        elif A[i] == 1:
          break
    elif A[i] == 1:
      break

print(A.count(1))

Submission status: Time Limit Exceeded

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

A = [0]*1000 
ans = 0

for i in range(1000):
  if i < 10:
    s = '00' + str(i)
  elif i < 100:
    s = '0' + str(i)
  else:
    s = str(i)
    
  for j in range(N):
    if S[j] == s[0]:
      for k in range(j+1,N):
        if S[k] == s[1]:
          for l in range(k+1,N):
            if S[l] == s[2]:
              A[i] = 1
              break
print(A.count(1))

Submission status: Time Limit Exceeded

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

for i in range(1000): #0~999を全探索
  flg1 = False #1桁目があるか
  flg2 = False #2桁目があるか
  flg3 = False #3桁目があるか
  one = str(i//100) #1桁目
  two = str(i%100//10) #2桁目
  three = str(i%10) #3桁目
  t = 0
  
  for j in range(n-2):
    if s[j] == one:
      flg1 = True
      t = j+1
      break
  for j in range(t,n-1):
    if s[j] == two:
      flg2 = True
      t = j+1
      break
  for j in range(t,n):
    if s[j] == three:
      flg3 = True
      t = j+1
      break
  if flg1 and flg2 and flg3:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
pin = []
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      pin.append(s[i]+s[j]+s[k])
pin = list(set(pin))
print(len(pin))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
m=n-3
passwords=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            passwords.append(s[i]+s[j]+s[k])
print(len(set(passwords)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
cnt = 0
def f(x):
	tgt = [ x[0], x[1], x[2] ]
	now = 0
	global n
	for i in range(n):
		if s[i] == tgt[now]: now += 1
		if now == 3: return True
	return False
for i in range(1000):
	if len(str(i)) == 1: t = "00"+str(i)
	elif len(str(i)) == 2: t = "0"+str(i)
	else: t = str(i)
	if f(t): cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(1000):
    si = str(i).zfill(3)
    k = 0
    for cn in range(n):
        if s[cn] == si[k]:
            if k == 2:
                cnt += 1
                break
            else:
                k += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
  a = [str(i//100), str((i//10)%10), str(i%10)]
  cnt = 0
  for j in range(n):
    if cnt <= 2 and a[cnt] == s[j]: cnt+=1
  if cnt == 3: ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
  a = [i//100, (i//10)%10, i%10]
  cnt = 0
  for j in range(n):
    if cnt <= 2 and a[cnt] == int(s[j]): cnt+=1
  if cnt == 3: ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = input()
s = set()
for i, j, k in itertools.combinations(range(N), 3):
  s.add(S[i]+S[j]+S[k])
print(len(s))

Submission status: Time Limit Exceeded

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

for i in range(1000):
        i = '0' * (3 - len(str(i))) + str(i)
        keep = 0

        for j in range(n):
                if s[j] == i[keep]:
                        keep += 1
                if keep == 3:
                        ans += 1
                        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = input()
ans = set()
for i in range(len(S)-2):
    for j in range(i+1, len(S)-1):
        for k in range(j+1, len(S)):
            s = S[i]+S[j]+S[k]
            if s not in ans:
                ans.add(s)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
# D - Lucky PIN
N = int(input())
S = list(input())
S = [int(s) for s in S]

# dp[i][j][k]: パスワード ijk を作ることができるか
dp = [[[False]*10 for _ in range(10)] for _ in range(10)]

for v in range(N):
    for w in range(v+1,N):
        for x in range(w+1,N):
            tgt = dp[S[v]][S[w]][S[x]]
            if tgt:
                continue
            dp[S[v]][S[w]][S[x]] = True

ans = 0
for i in dp:
    for j in i:
        for k in j:
            if k == True:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

l = []

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            l.append("{0}{1}{2}".format(S[i], S[j], S[k]))
print(len(list(set(l))))

Submission status: Time Limit Exceeded

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

v_lis = []
for i in range(1000):
    if i >= 100:
        v = str(i)
    elif 10 <= i <= 99:
        v = "0" + str(i)
    elif 0 <= i <= 9:
        v = "00" + str(i)
    #print(v)
    tmp_1, tmp_2, tmp_3 = sn + 1, sn + 1, sn + 1
    for j in range(sn):
        if s[j] == v[0] and tmp_1 >= j:
            tmp_1 = j
    if tmp_1 <= sn:
        #print(tmp_1, v)
        for k in range(tmp_1 + 1, sn):
            if s[k] == v[1] and tmp_2 >= k:
                tmp_2 = k
    if tmp_2 <= sn:
            #print(tmp_2, v)
        for l in range(tmp_2 + 1, sn):
            if s[l] == v[2] and tmp_3 >= l:
                tmp_3 = l
                if tmp_3 <= sn:
                    #print(tmp_3, v)
                    v_lis.append(v)

print(len(v_lis))

Submission status: Time Limit Exceeded

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

v_lis = []
for i in range(1000):
    if i >= 100:
        v = str(i)
    elif 10 <= i <= 99:
        v = "0" + str(i)
    elif 0 <= i <= 9:
        v = "00" + str(i)
    #print(v)
    tmp_1 = sn + 1
    for j in range(sn):
        if s[j] == v[0] and tmp_1 >= j:
            tmp_1 = j
    if tmp_1 <= sn:
        #print(tmp_1, v)
        tmp_2 = sn + 1
        for k in range(tmp_1 + 1, sn):
            if s[k] == v[1] and tmp_2 >= k:
                tmp_2 = k
        if tmp_2 <= sn:
            #print(tmp_2, v)
            tmp_3 = sn + 1
            for l in range(tmp_2 + 1, sn):
                if s[l] == v[2] and tmp_3 >= l:
                    tmp_3 = l
                    if tmp_3 <= sn:
                        #print(tmp_3, v)
                        v_lis.append(v)

print(len(v_lis))

Submission status: Time Limit Exceeded

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

v_lis = []
for i in range(1000):
    if i >= 100:
        v = str(i)
    elif 10 <= i <= 99:
        v = "0" + str(i)
    elif 0 <= i <= 9:
        v = "00" + str(i)
    #print(v)
    tmp_1 = sn + 1
    for j in range(sn):
        if s[j] == v[0] and tmp_1 >= j:
            tmp_1 = j
            if tmp_1 <= sn:
                #print(tmp_1, v)
                tmp_2 = sn + 1
                for k in range(tmp_1 + 1, sn):
                    if s[k] == v[1] and tmp_2 >= k:
                        tmp_2 = k
                        if tmp_2 <= sn:
                            #print(tmp_2, v)
                            tmp_3 = sn + 1
                            for l in range(tmp_2 + 1, sn):
                                if s[l] == v[2] and tmp_3 >= l:
                                    tmp_3 = l
                                    if tmp_3 <= sn:
                                        #print(tmp_3, v)
                                        v_lis.append(v)

print(len(v_lis))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

d = defaultdict(list)
for i in range(N):
  d[int(S[i])].append(i)
    
ans = 0
for n1 in range(10):
  if not d[n1]:continue
  for n2 in range(10):
    if not d[n2]:continue
    if min(d[n1])>max(d[n2]): continue
    for n3 in range(10):
      if not d[n3]:continue
      if min(d[n1])>max(d[n3]) or min(d[n2])>max(d[n3]):continue
      for idx in d[n2]:
        if idx>min(d[n1]) and idx<max(d[n3]):
          ans += 1
          break
            
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
tmp = [0 for _ in range(10)]
for i in range(len(S)):
    tmp[int(S[i])] += 1

for i in range(1000):
    flag = True

    if i < 10:
        dic = {"0": 2}
    elif i < 100:
        dic = {"0": 1}
    else:
        dic = {}
    for j in range(len(str(i))):
        if str(i)[j] in dic:
            dic[str(i)[j]] += 1
        else:
            dic[str(i)[j]] = 1

    for k, v in dic.items():
        if dic[k] > tmp[int(k)]:
            flag = False
            break

    if flag:
        if i < 10:
            tmp_i = "00" + str(i)
        elif i < 100:
            tmp_i = "0" + str(i)
        else:
            tmp_i = str(i)
        t = 0
        for j in range(len(S)):
            if tmp_i[t] == S[j]:
                t += 1
            if t == 3:
                ans += 1
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import numpy as np
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n = I()
    s = L()
    cnt = 0
    def f(x):
        tgt = [x[0],x[1],x[2]]
        now = 0
        global n
        for i in range(n):
            if s[i] == tgt[now]:now += 1
            if now == 3:return True
        return False
    for i in range(1000):
        if len(str(i)) == 1:
            t = "00"+str(i)
        elif len(str(i)) == 2:
            t = "0"+str(i)
        else:t = str(i)
        if f(t):cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = list(input())
cnt = 0
Num = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            s = [str(i),str(j),str(k)]
            Num.append(s)

for num in Num:
    flag1 = False
    flag2 = False
    memo1 = 0
    memo2 = 0
    for x in range(n-2):
        if num[0] == lst[x]:
            flag1 = True
            memo1 = x
            break
    if flag1:
        for y in range(memo1+1,n-1):
            if num[1] == lst[y]:
                flag2 = True
                memo2 = y
                break
        if flag2:
            for z in range(memo2+1,n):
                if num[2] == lst[z]:
                    cnt += 1
                    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
S=[]
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            a=[s[i],s[j],s[k]]
            if a not in S:
                S.append(a)
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    ind = 0
    a = 0
    for ij in i:
        while(ind < len(s)):
            if s[ind] == ij:
                a += 1
                ind += 1
                break
            ind += 1
    ans += a == 3
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1000) :
    num_1 = i // 100
    num_2 = (i - num_1*100) // 10
    num_3 = (i - num_1*100 - num_2*10) % 100
    if str(num_1) not in s :
        continue
    if str(num_2) not in s :
        continue
    if str(num_3) not in s :
        continue
    for j in range(n-2) :
        if int(s[j]) == num_1 :
            for k in range(j+1,n-1) :
                if int(s[k]) == num_2 :
                    for l in range(k+1,n) :
                        if int(s[l]) == num_3 :
                            c += 1
                            break
                    break
            break

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
z = input()
ans = 0
cnt=0
for i in range(1000):
    for j in range(n):
        if cnt==0:
            if (str(i).zfill(3))[cnt]==z[j]:
                cnt+=1
        elif cnt==1:
            if (str(i).zfill(3))[cnt]==z[j]:
                cnt+=1
        elif cnt==2:
            if (str(i).zfill(3))[cnt]==z[j]:
                cnt=0
                ans+=1
                break
    cnt=0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def mitsui2019d_lucky_pin():
    import itertools
    n = int(input())
    s = input()
    cnt = 0
    for t in itertools.product(range(0, 10), repeat=3):
        si = ''.join(map(str,t))
        for i in range(n - 2):
            if si[0] != s[i]: continue
            for j in range(i + 1, n - 1):
                if si[1] != s[j]: continue
                if si[2] in s[j + 1:]:
                    cnt += 1
                    break
            break
    print(cnt)


mitsui2019d_lucky_pin()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    S = input()

    ans = 0
    for x in range(0, 1000):
        t = "{:0=3}".format(x)
        j = 0
        for i in range(N):
            if t[j] == S[i]:
                j += 1
            if j == 3:
                ans += 1
                break

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

_ = int(input())
number = input()
#number = list(number)

def comb(list_, num):
    return list(itertools.combinations(list_, num))

numbers = comb(number, 3)
print(len(np.unique(numbers, axis=0)))