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 itertools

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

for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            flag1 = 0
            flag2 = 0
            flag3 = 0
            for m in range(n):
                if flag1 == 0:
                    if int(s[m]) == i:
                        flag1 = 1
                elif flag2 == 0:
                    if int(s[m]) == j:
                        flag2 = 1
                elif flag3 == 0:
                    if int(s[m]) == k:
                        flag3 = 1
                        ans += 1
                        break
                    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env/ python3
N = int(input())
S = input()
#A, B, C = input().split()
#A, B, C, X, Y = map(int, input().split())

#N = int(input())
#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(A[0][0])

ans = 0
for tmp_num in range(1000):
    tmp = str(tmp_num).zfill(3)
    digit = 0
    for i in range(N):
        if S[i] == tmp[digit]: digit += 1
        if digit == 3: break
    if digit == 3: ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env/ python3
N = int(input())
S = input()
#A, B, C = input().split()
#A, B, C, X, Y = map(int, input().split())

#N = int(input())
#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(A[0][0])

ans = 0
tmp = []
#first = []
#second = []
#third = []
for tmp_num in range(1000):
    flag = False
    tmp = str(tmp_num).zfill(3)
    for i in range(N-2):
        if S[i] == tmp[0]:
            for j in range(i+1, N-1):
                if S[j] == tmp[1]:
                    for k in range(j+1, N):
                        if S[k] == tmp[2]:
                            ans += 1
                            flag = True
                        if flag: break
                if flag: break
        if flag: break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env/ python3
N = int(input())
S = input()
#A, B, C = input().split()
#A, B, C, X, Y = map(int, input().split())

#N = int(input())
#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(A[0][0])

ans = 0
tmp = []
#first = []
#second = []
#third = []
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 tmp):
                ans += 1
                tmp.append([S[i], S[j], S[k]])
            #if (S[i] not in first) or (S[j] not in second) or (S[k] not in third): ans += 1
            #if i not in first: first.append(S[i])
            #if j not in second: second.append(S[j])
            #if k not in third: third.append(S[k])                        
print(ans)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(1000):
    password = str(i).zfill(3)
    j = 0
    for s in S:
        if s == password[j]:
            j += 1
            if j == 3:
                count += 1
                break
print(count)

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(10):
    x = 0
    while S[x] != str(i) and x != (len(S)-3):
        x += 1
    if S[x] == str(i):
        for j in range(10):
            y = x + 1
            while S[y] != str(j) and y != (len(S)-2):
                y += 1
            if S[y] == str(j):
                for k in range(10):
                    z = y + 1
                    while S[z] != str(k) and z != (len(S)-1):
                        z +=1
                    if S[z] == str(k):
                        cnt +=1

print(cnt)

Submission status: Time Limit Exceeded

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

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()


N = i_i()
S = i_s()

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

Submission status: Time Limit Exceeded

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

ans = 0
pins = [0] * 3
for pin in range(1000):
    pins[0] = pin // 100
    pins[1] = (pin % 100) // 10
    pins[2] = pin % 10
    x = 0
    for c in S:
        if c == pins[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for pin in ("%03d" % x for x in range(10 ** 3)):
    x = 0
    for c in S:
        if c == pin[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = set()
c0done = set()
for i0 in range(N - 2):
    c0 = S[i0]
    if c0 in c0done:
        continue
    c0done.add(c0)
    for i1 in range(i0 + 1, N - 1):
        c1 = S[i1]
        for c2 in set(S[i1+1:]):
            ans.add(c0 + c1 + c2)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = set()
for i0 in range(N - 2):
    for i1 in range(i0 + 1, N - 1):
        for i2 in range(i1 + 1, N):
            ans.add(int(S[i0] + S[i1] + S[i2]))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


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

    res = 0
    for i in range(1000):
        t = str(i).zfill(3)
        pos = 0
        for j in s:
            if t[pos] == j:
                pos += 1
            if pos == 3:
                res += 1
                break
    print(res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

res = 0
for i in range(1000):
    t = str(i).zfill(3)
    pos = 0
    for j in s:
        if t[pos] == j:
            pos += 1
        if pos == 3:
            res += 1
            break

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(input())
print(len(set(itertools.combinations(s, 3))))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans = set()
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      ans.add("".join(map(str, s[i]+s[j]+s[k])))
  
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1000,2000):
    templ=list(str(i))
    t=templ[1:]
    #print(t)
    p=0
    for q in range(n):
        if s[q]==t[p]:
            p+=1
        if p>2:
            ans+=1
            break         

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    N=int(input())
    s = str(input())


    l=['%03d'%(p) for p in range(0,10**3)]
    ans=[]
    for i in l:
        for j in range(N):
            if s[j]==i[0]:
                for k in range(j+1,N):
                    if s[k]==i[1]:
                        for m in range(k+1,N):
                            if s[m]==i[2]:
                                ans.append(i)

    print(len(set(ans)))


resolve()

Submission status: Time Limit Exceeded

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

numbers = set()

for i in range(0, len(S), 1):
    for j in range(i+1, len(S), 1):
        for k in range(j+1, len(S), 1):
            number = (S[i],S[j],S[k])
            numbers.add(number)
print(len(numbers))

Submission status: Time Limit Exceeded

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

numbers = []
cnt = 0

for i in range(0, len(S), 1):
    for j in range(i+1, len(S), 1):
        for k in range(j+1, len(S), 1):
            number = [S[i],S[j],S[k]]
            numbers.append(number)

for x in range(10):
    for y in range(10):
        for z in range(10):
            lucky_number = [str(x), str(y), str(z)]
            if lucky_number in numbers:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

numbers = []
cnt = 0

for i in range(0, len(S), 1):
    for j in range(i+1, len(S), 1):
        for k in range(j+1, len(S), 1):
            number = [S[i],S[j],S[k]]
            numbers.append(number)

for x in range(10):
    for y in range(10):
        for z in range(10):
            lucky_number = [str(x), str(y), str(z)]
            for num in numbers:
                if num == lucky_number:
                    cnt += 1
                    break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
a=[0 for _ in range(n*(n-1)*(n-2)//6)]
ind=0
for i in range(n-2):
  p=s[i]
  #q
  for j in range(i+1,n-1):
    r=p
    r+=s[j]
    for k in range(j+1,n):
      t=r
      t+=s[k]
      a[ind]=t
      ind+=1
#print(a)
a=list(set(a))
#print(a)
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n,s=int(input()),input()

cnt=0
flag1=[]
ans=[]
for i in range(n-2):
    flag2=[]
    if s[i] in flag1:continue
    flag1.append(s[i])
    for j in range(i+1,n-1):
        if s[i]!=s[j] and s[j] in flag2:continue
        flag2.append(s[j])
        for k in range(j+1,n):
            ans.append(s[i]+s[j]+s[k])
#print(ans,flag1,flag2)
print(len(set(ans)))

Submission status: Time Limit Exceeded

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

cnt=0
flag1=[]
ans=[]
for i in range(n-2):
    flag2=[]
    if s[i] in flag1:continue
    flag1.append(s[i])
    for j in range(i+1,n-1):
        if s[i]!=s[j] and s[j] in flag2:continue
        flag2.append(s[j])
        for k in range(j+1,n):
            ans.append(s[i]+s[j]+s[k])
#print(ans,flag1,flag2)
print(len(set(ans)))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    target = str(i).zfill(3)
    char_idx = 0
    for c in S:
        if c == target[char_idx]:
            char_idx += 1

        if char_idx == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

patterns = set(map(lambda c: ''.join(c), combinations(S, 3)))
print(len(patterns))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

patterns = set([])
for c in combinations(S, 3):
    password = int(''.join(c))
    patterns.add(password)
print(len(patterns))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
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:
import itertools
n = int(input())
s = input()
ans = set()
for x in itertools.combinations(s,3):
    ans.add(x)
print(len(ans))

Submission status: Time Limit Exceeded

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


def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

# mod=10**9+7
# rstrip().decode('utf-8')

import re

def main():
	n=II()
	s=input()
	ans=0
	for i in range(1000):
		j=str(i).zfill(3)
		now=0
		for k in s:
			if j[now]==k:
				now+=1
			if now==3:
				ans+=1
				break



	print(ans)



















if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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


def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

# mod=10**9+7
# rstrip().decode('utf-8')

import re

def main():
	n=II()
	s=input()
	ans=0
	for i in range(1000):
		a,b,c=str(i).zfill(3)
		m=re.search(r'%s.*%s.*%s'%(a,b,c),s)
		if m!=None:
			ans+=1
	print(ans)



















if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
import re

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

res = 0
fmt = "[0-9]*{}[0-9]*{}[0-9]*{}[0-9]*"
for i in range(1000):
  s = "{:03}".format(i)
  if re.search(fmt.format(s[0], s[1], s[2]), S):
    res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())[::-1]
result = 0
for i in range(1000):
    x = format(i, "03")
    j = 0
    p = 0
    while p < n:
        if s[p]==x[j]:
            j += 1
            if j == 3:
                result += 1
                break
        p += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())[::-1]
result = 0
for i in range(1000):
    x = format(i, "03")
    j = 0
    p = 0
    while j < 3 and p < n:
        if s[p]==x[j]:
            j += 1
        p += 1
    if j==3:
        result += 1
print(result)

Submission status: Time Limit Exceeded

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

ans = set()

for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            iss = s[i : i + 1]
            js = s[j : j + 1]
            ks = s[k : k + 1]
            ans.add(iss + js + ks)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
anss = []
for i in range(1000):
    str_i = str(i).zfill(3)
    idx = 0
    ans = ""
    for j in range(N):
        if S[j] == str_i[idx]:
            if idx == 2:
                ans += str_i[idx]
                anss.append(ans)
                break
            else:
                ans += str_i[idx]
                idx += 1
print(len(set(anss)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
S = np.array(list(str(input())))
x = '000'
ans = 0
while int(x) < 1000:
  st = 0
  cnt = 0
  if x[0] in S:
    for i in range(N):
      if x[0] == S[i]:
        st = i+1
        cnt += 1
        break
  if x[1] in S[st:]:
    for j in range(st, N):
      if x[1] == S[j]:
        st = j+1
        cnt += 1
        break
  if x[2] in S[st:]:
    for k in range(st, N):
      if x[2] == S[k]:
        st = k+1
        cnt += 1
        break
                
  if cnt == 3:
    ans += 1
  x = '{:03d}'.format(int(x)+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
x = '000'
ans = 0
while int(x) < 1000:
  st = 0
  cnt = 0
  if x[0] in S:
    for i in range(N):
      if x[0] == S[i]:
        st = i+1
        cnt += 1
        break
  if x[1] in S[st:]:
    for j in range(st, N):
      if x[1] == S[j]:
        st = j+1
        cnt += 1
        break
  if x[2] in S[st:]:
    for k in range(st, N):
      if x[2] == S[k]:
        st = k+1
        cnt += 1
        break
                
  if cnt == 3:
    ans += 1
  x = '{:03d}'.format(int(x)+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
b=0
for i in range(1000):
 i1=int(i/100)
 i2=int((i-i1*100)/10)
 i3=i%10
 a=0
 for j in range(N):
  if a==0:
   if int(S[j])==i1:
    a+=1
  elif a==1:
   if int(S[j])==i2:
    a+=1
  else:
   if int(S[j])==i3:
    b+=1
    break
print(b)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
b=0
for i in range(1000):
 i1=int(i/100)
 i2=int((i-i1*100)/10)
 i3=i%10
 a=0
 for j in range(N):
  if a==0:
   if int(S[j])==i1:
    a+=1
  elif a==1:
   if int(S[j])==i2:
    a+=1
  elif a==2:
   if int(S[j])==i3:
    a+=1
  else:
   continue
 if a==3:
  b+=1
print(b)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
a=0
for i in range(1000):
 i1=int(i/100)
 i2=int((i-i1*100)/10)
 i3=i%10
 for j in range(N-2):
  if int(S[j])==i1:
   for k in range(j+1,N-1):
    if int(S[k])==i2:
     for l in range(k+1,N):
      if int(S[l])==i3:
       a+=1
       break
     else:
      continue
     break
   else:
    continue
   break
print(a)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
b=0
for i in range(1000):
 a=0
 i1=int(i/100)
 i2=int((i-i1*100)/10)
 i3=i%10
 for j in range(N-2):
  if int(S[j])==i1:
   for k in range(j+1,N-1):
    if int(S[k])==i2:
     for l in range(k+1,N):
      if int(S[l])==i3:
       a+=1
       break
     else:
      continue
     break
   else:
    continue
   break
 if a>0:
  b+=1
print(b)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
b=0
for i in range(1000):
 a=0
 i1=int(i/100)
 i2=int((i-i1*100)/10)
 i3=i%10
 for j in range(N-2):
  if int(S[j])==i1:
   for k in range(j+1,N-1):
    if int(S[k])==i2:
     for l in range(k+1,N):
      if int(S[l])==i3:
       a+=1
     break
 if a>0:
  b+=1
print(b)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
b=0
for i in range(1000):
 a=0
 i1=int(i/100)
 i2=int((i-i1*100)/10)
 i3=i%10
 for j in range(N-2):
  if int(S[j])==i1:
   for k in range(j+1,N-1):
    if int(S[k])==i2:
     for l in range(k+1,N):
      if int(S[l])==i3:
       a+=1
 if a>0:
  b+=1
print(b)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
# sys.setrecursionlimit(10000000)
# INF = 1<<32s


def solve(N: int, S: str):
    ans = 0
    for i in range(1000):
        si = format(i, '03')

        idx = 0
        for j in range(len(S)):
            if idx >= len(si):
                break
            elif si[idx] == S[j]:
                idx += 1

        if idx == len(si):
            ans += 1

    print(ans)
    
    return



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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, S: str):
    ans = 0
    for i in range(1000):
        si = format(i, '03')

        idx = 0
        for j in range(len(S)):
            if idx < len(si) and si[idx] == S[j]:
                idx += 1

        if idx == len(si):
            ans += 1

    print(ans)
    
    return



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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    if i<10: i = "00"+str(i)
    elif i<100: i = "0"+str(i)
    else: i = str(i)
    for j in range(n-2):
        if s[j] == i[0]:
            for k in range(j+1, n-1):
                if s[k] == i[1]:
                    for l in range(k+1, n):
                        if s[l] == i[2]:
                            ans += 1
                            break
                    break
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
s = input()
ct = 0
for p in range(1000):
    step = 0
    p = str(p).zfill(3)
    for i in range(n):
        if s[i] == p[0]:
            step += 1
            idx = i
            break
    if step == 1:
        for i in range(idx+1, n):
            if s[i] == p[1]:
                step += 1
                idx = i
                break
    if step == 2:
        for i in range(idx+1, n):
            if s[i] == p[2]:
                #print(p)
                ct += 1
                break
print(ct)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

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

a = list(itertools.combinations(S, 3))
c = collections.Counter(a)
print(len(c))

Submission status: Time Limit Exceeded

Solution code:
import re

def solve():
    N = int(input())
    S = input()
    searched = [False]*999
    
    # 愚直にやると↓だが、まあ間に合わないだろう
    # ret = len(set(for s in combination(S, 3)))
    ret = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                regex = '.*{0}.*{1}.*{2}.*'.format(i,j,k)
                if re.search(regex,S):
                    ret += 1
                    
    print(ret)
    
solve()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

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

s = set()
a = list(itertools.combinations(S, len(S) - (N - 3)))
c = collections.Counter(a)
print(len(c))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

print(len(set(S[i] + S[j] + S[k] for i, j, k in combinations(range(N), 3))))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

s = set()
for v in itertools.combinations(S, len(S) - (N - 3)):
    s.add(v)
    
print(len(s))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    flag = [False, False, False]
    st = str(i).zfill(3)
    for j in range(len(s)):
        if st[0] == s[j] and not flag[0] and not flag[1]:
            flag[0] = True
        elif st[1] == s[j] and flag[0] and not flag[1]:
            flag[1] = True
        elif st[2] == s[j] and flag[0] and flag[1]:
            flag[2] = True
        if all(flag):
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

cnt = [0]*11
i = 0
T = ''
for s in S:
  cnt[int(s)]+=1
  if min(cnt)<=3:
    T += s
#print(T)
ans = 0
P = []
for a in range(10):
  A = str(a)
  k = 0
  ind1 = -1
  while k < len(T)-2:
    t = T[k]
    if A == t:
      ind1 = k
      break
    k += 1
  if ind1 == -1:
    continue
  for b in range(10):
    B = str(b)
    l = ind1+1
    ind2 = -1
    while l < len(T)-1:
      t = T[l]
      if B == t:
        ind2 = l
        break
      l += 1
    #print(a,b,ind1,ind2)
    if ind2 == -1:
      continue
    for c in range(10):
      C = str(c)
      m = ind2+1
      while m < len(T):
        t = T[m]
        if C == t:
          ans += 1
          break
        m += 1
print(ans)

#print(*ans, sep='/n')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
P = []
for a in range(10):
  A = str(a)
  k = 0
  ind1 = -1
  while k < len(S)-2:
    s = S[k]
    if A == s:
      ind1 = k
      break
    k += 1
  if ind1 == -1:
    continue
  for b in range(10):
    B = str(b)
    l = ind1+1
    ind2 = -1
    while l < len(S)-1:
      s = S[l]
      if B == s:
        ind2 = l
        break
      l += 1
    #print(a,b,ind1,ind2)
    if ind2 == -1:
      continue
    for c in range(10):
      C = str(c)
      m = ind2+1
      while m < len(S):
        s = S[m]
        if C == s:
          ans += 1
          break
        m += 1
print(ans)

#print(*ans, sep='/n')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
P = []
for a in range(10):
  for b in range(10):
    #if a == 1:
      #print(P, ans)
    for c in range(10):
      P = []
      P.append(str(a))
      P.append(str(b))
      P.append(str(c))
      j = 0
      k = 0
      while j < len(P) and k < len(S):
        p = P[j]
        s = S[k]
        if p == s:
          j += 1
        k += 1
      if j == len(P):
        ans += 1
print(ans)

#print(*ans, sep='/n')

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
s = list(map(int, input()))
cnt = 0
for i1 in range(10):
    for i2 in range(10):
        for i3 in range(10):
            for i in range(n):
                if s[i]==i1: 
                    for j in range(i+1, n):
                        if s[j]==i2:
                            for k in range(j+1, n):
                                if s[k]==i3:
                                    cnt += 1
                                    #print(i1, i2, i3)
                                    break
                            break
                    break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import glob
import numpy as np
import sys


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'smbc2019\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        N = int(self.input_data())
        S = self.input_data()
        lucky_nums = [int(s) for s in S]

        array_1d = np.zeros([10])
        array_2d = np.zeros([10,10])
        array_3d = np.zeros([10,10,10])

        array_fin_1d = [False for i in range(10)]
        array_fin_2d = [[False for i in range(10)] for j in range(10)]

        for num in lucky_nums:

            if array_fin_1d[num]:
                continue
            fin_count_i = 0
            for i in range(10):
                if array_1d[i] == 0:
                    continue
                if array_fin_1d[i]:
                    fin_count_i += 1
                    continue

                if array_fin_2d[i][num]:
                    continue

                fin_count_j = 0
                for j in range(10):
                    if array_2d[i][j] == 1:
                        array_3d[i][j][num] = 1
                        fin_count_j += 1
                if fin_count_j == 10:
                    array_fin_2d[i][num] = True

            if fin_count_i == 10:
                array_fin_1d[num] = True

            for i in range(10):
                if array_1d[i] == 1:
                    array_2d[i][num] = 1

            array_1d[num] = 1

        result = array_3d.sum()

        print(str(int(result)))


solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Time Limit Exceeded

Solution code:
import glob
import numpy as np
import sys


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'smbc2019\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        N = int(self.input_data())
        S = self.input_data()
        lucky_nums = [int(s) for s in S]

        array_1d = np.zeros([10])
        array_2d = np.zeros([10,10])
        array_3d = np.zeros([10,10,10])

        array_fin_1d = [False for i in range(10)]
        array_fin_2d = [[False for i in range(10)] for j in range(10)]

        for num in lucky_nums:

            if array_fin_1d[num]:
                continue
            fin_count_i = 0
            for i in range(10):
                if array_fin_1d[i]:
                    fin_count_i += 1
                    continue

                if array_fin_2d[i][num]:
                    continue

                fin_count_j = 0
                for j in range(10):
                    if array_2d[i][j] == 1:
                        array_3d[i][j][num] = 1
                        fin_count_j += 1
                if fin_count_j == 10:
                    array_fin_2d[i][num] = True

            if fin_count_i == 10:
                array_fin_1d[num] = True

            for i in range(10):
                if array_1d[i] == 1:
                    array_2d[i][num] = 1

            array_1d[num] = 1

        result = array_3d.sum()

        print(str(int(result)))


solver = Solver(REL_PATH)
solver.exec_resolve()