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 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])

        for num in lucky_nums:
            for i in range(10):
                for j in range(10):
                    if array_2d[i][j] == 1:
                        array_3d[i][j][num] = 1

            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:
N = int(input())
L = list(map(int, list(input().strip())))

cnt = 0
for d1 in range(10):
    for d2 in range(10):
        for d3 in range(10):
            find1 = False
            find2 = False
            for i, n in enumerate(L):
                if not find1 and L[i] == d1:
                    find1 = True
                    continue
                if find1 and not find2 and L[i] == d2:
                    find2 = True
                    continue
                if find1 and find2 and L[i] == d3:
                    cnt += 1
                    break
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re
n = int(input())
s = input()
ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    if re.search('{}.*{}.*{}'.format(i[0],i[1],i[2]), s):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import re
n = int(input())
s = input()
ans = 0
for i in itertools.product(range(10),repeat=3):
    if re.search('{}.*{}.*{}'.format(i[0],i[1],i[2]), s):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

answer=0
for i in range(1000):
  i0=i//100
  i1=(i//10)%10
  i2=i%10

  flag_num=0
  for s in S:
    if flag_num==0 and s==str(i0):
      flag_num+=1
    elif flag_num==1 and s==str(i1):
      flag_num+=1
    elif flag_num==2 and s==str(i2):
      answer+=1
      break
      
print(answer)

Submission status: Time Limit Exceeded

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

N = int(input())
S = input().rstrip('\r\n')
ans = 0
for i in range(1000):
    target = str(i).zfill(3)
    indices = [-1] * 3
    for m, c in enumerate(target):
        if m == 0:
            idx = S.find(c)
            if idx == -1:
                break
            indices[0] = idx
            continue
        for n in range(indices[m-1]+1, N):
            if c == S[n]:
                # print(target)
                indices[m] = n
                break
        if indices[0] > -1 and indices[1] > -1 and indices[2] > -1:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n= int(input())
s = input()
S = []
for i in s:
    S.append(i)
import itertools
A = []
for v in itertools.combinations(S, 3):
    a = int("".join(v))
    A.append(a)
print(len(set(A)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
count=0
for i in range(1000):
    if (i<10):
        num="00"+str(i)
    elif (i<100):
        num="0"+str(i)
    else:
        num=str(i)
    k=0
    flag=num[0]
    for j in range(len(s)):
        if (flag==s[j]):
            if (k<2):
                k=k+1
                flag=num[k]
            elif (k==2):
                count+=1
                #print(num)
                break
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp_number=str(i) + str(j) + str(k)
            # print(tmp_number)
            itti_keta = 0
            for n in range(N):
                if S[n]==tmp_number[itti_keta]:
                    itti_keta+=1
                    if itti_keta==3:
                        break
            if itti_keta == 3:
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
numcount = [0] * 10
ans = 0
for i in s:
    numcount[int(i)] += 1
for i in range(10):
    for j in range(10):
        for k in range(10):
            c = 0
            if numcount[i] == 0 or numcount[j] == 0 and numcount[k] == 0:
                continue
            elif ((i == j or i == k) and numcount[i] <= 1) or (j == k and numcount[j] <= 1):
                continue
            elif i == j == k and numcount[i] <= 2:
                continue
            else:
                c, l = 0, 0
                m = [i, j, k]
                while True:
                    if m[l] == int(s[c]):
                        l += 1
                    c += 1
                    if l == 3:
                        ans += 1
                        break
                    if c == n:
                        break
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(10**3):
    mm = 0
    num = str(i).zfill(3)
    for j in range(N):
        if num[mm]==S[j]:
            mm += 1
        if mm==3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
*s, = input()

ans = []
for i in itertools.combinations(s, 3):
    ans.append(i)

print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
# st = set()
# for i in range(n-2):
#     for j in range(i+1, n-1):
#         for k in range(j+1, n):
#             pin = s[i] + s[j] + s[k]
#             st.add(pin)
# print(st)
count = 0
# for i in range(1000):
#     if len(str(i)) == 1:
#         v = "00" + str(i)
#     elif len(str(i)) == 2:
#         v = "0" + str(i)
#     else:
#         v = str(i)
#     k = 0
#     for j in range(len(v)):
#         while k < len(s):
#             if s[k] == v[j]:
#                 k += 1
#                 break
#             k += 1
#         else:
#             break
#     else:
#         count += 1
for i in range(1000):
    v = [i // 100, (i // 10) % 10, i % 10]
    j = 0
    # print(v)
    for k in range(n):
        if s[k] == str(v[j]): j += 1
        if j == 3: break
    if j == 3: count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

print(len(pass_set))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
# st = set()
# for i in range(n-2):
#     for j in range(i+1, n-1):
#         for k in range(j+1, n):
#             pin = s[i] + s[j] + s[k]
#             st.add(pin)
# print(st)
count = 0
for i in range(1000):
    if len(str(i)) == 1:
        v = "00" + str(i)
    elif len(str(i)) == 2:
        v = "0" + str(i)
    else:
        v = str(i)
    k = 0
    for j in range(len(v)):
        while k < len(s):
            if s[k] == v[j]:
                k += 1
                break
            k += 1
        else:
            break
    else:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for i in range(1000):
    i = str(i).zfill(3)
    
    cnt = 0
    for ss in s:
        if cnt == 0:
            if ss==i[0]:
                cnt += 1
                continue
        elif cnt == 1:
            if ss==i[1]:
                cnt += 1
                continue
        else:
            if ss==i[2]:
                ans += 1
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

set_ = set(itertools.combinations(s, 3))

print(len(set_))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
total = 0
for i in range(1000):
  t = list(str(i).zfill(3))
  j = 0
  for c in range(len(s)):
    if (j<=len(t)-1):
      if(s[c] == t[j]):
        j += 1
  if (j == 3):
    total += 1
print(total)

Submission status: Time Limit Exceeded

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

for i in range(1000):
    str_i = '{:03}'.format(i)
    found = 0
    for s in S:
        if(s==str_i[found]):
            found += 1
            if(found == 3):
                cnt += 1
                break
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(1000):
    str_i = '{:03}'.format(i)
    pattern = '.*'+str_i[0]+'.*'+str_i[1]+'.*'+str_i[2]
    if(re.match(pattern, S)!=None):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    tmp = str(i).zfill(3)
    count = 0
    for k in S:
        if k == tmp[count]:
            count += 1
        if 3 == count:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
d=dict()
for i in range(1000):
  num='0'*(3-len(str(i)))+str(i)
  for j in range(n-2):
    if s[j]==num[0]:
      for k in range(j+1,n-1):
        if s[k]==num[1]:
          for l in range(k+1,n):
            if s[l]==num[2]:
              if num not in d:
                ans+=1
                d[num]=0
            if l==n-1:
              break
        if k==n-2:
          break
    if j==n-3:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
d=dict()
for i in range(1000):
  num='0'*(3-len(str(i)))+str(i)
  for j in range(n-2):
    if s[j]==num[0]:
      for k in range(j+1,n-1):
        if s[k]==num[1]:
          for l in range(k+1,n):
            if s[l]==num[2]:
              if num not in d:
                ans+=1
                d[num]=0
            if l==n-1:
              break
        if k==n-2:
          break
    if j==n-3:
      break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(0, 1000):
    num = str(i).zfill(3)
    pos = 0
    for j in range(n):
        if s[j] == num[pos]:
            pos += 1
        
        if pos == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

def judge(S,A): #A:3桁ｎ数字
    dig,pt = 0,0
    while dig < 3 and pt < N:
        if S[pt] == A[dig]:
            dig += 1
            pt += 1
        else:
            pt += 1
        if dig == 3:
            break

    if dig == 3:
        return True
    else:
        return False

count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            if judge(S,[str(a),str(b),str(c)]):
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N, S = int(input()), input()
result = set()
for indexes in combinations(range(N, 0, -1), N - 3):
    tmp = S
    for i in indexes:
        tmp = tmp[:i - 1] + tmp[i:]
    result.add(tmp)
print(len(result))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = range(N)
ans = set()

for comb in itertools.combinations(l, 3):
    x, y, z = comb
    s = S[x] + S[y] + S[z]
    ans .add(s)
    
    if len(ans) >= 10 ** 3:
        break
        
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def password():
    for i in range(10):
        for j in range(10):
            for k in range(10):
                yield [str(i), str(j), str(k)]


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

ans = 0
for perm in password():
    j = 0
    for i in range(n):
        if perm[j] == s[i]:
            j += 1
            if j >= len(perm):
                break
    if j >= len(perm):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def password():
    for i in range(10):
        for j in range(10):
            for k in range(10):
                yield [str(i), str(j), str(k)]


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

ans = 0
for perm in password():
    j = 0
    for i in range(len(s)):
        if perm[j] == s[i]:
            j += 1
            if j >= len(perm):
                break
    if j >= len(perm):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def password():
    for i in range(10):
        for j in range(10):
            for k in range(10):
                yield [str(i), str(j), str(k)]


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

ans = 0
for perm in password():
    j = 0
    for i in range(len(s)):
        if perm[j] == s[i]:
            j += 1
            if j >= len(perm):
                break
    if j >= len(perm):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#三井住友2019_D
n=int(input())
s=input()

cnt=0
for i in range(0,1000):
    t='0'*(3-len(str(i)))+str(i)
    flg1,flg2,flg3=[False]*3
    for j in range(n):
        if flg1:
            if flg2:
                if s[j]==t[2]:
                    flg3=True
                    break
            else:
                if s[j]==t[1]:
                    flg2=True
        else:
            if s[j]==t[0]:
                flg1=True
    cnt+=1 if flg3 else 0
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
A=[int(i) for i in range(10)]
ans=0
import itertools
for a,b,c in itertools.product(A,repeat=3):
  a,b,c=str(a),str(b),str(c)
  chk=0
  for ss in s:
    if chk==0 and ss==a:
      chk=1
    elif chk==1 and ss==b:
      chk=2
    elif chk==2 and ss==c:
      chk=3
  if chk==3:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

import itertools

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

l_pw = []
if N-3 == 1:
    for i in range(N):
        l_S = list(S)
        l_S.pop(i)
        l_pw.append(','.join(l_S))
else:
    combs = list(itertools.combinations(range(N), N-3))
    for comb in combs:
        l_S = list(S)
        for i in sorted(comb, reverse=True):
            l_S.pop(i)
        l_pw.append(','.join(l_S))

print(len(set(l_pw)))

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(10):
    find = 0
    for j in range(n-2):
        if find == 1:
            break
        if s[j] == str(0):
            for k in range(j+1,n-1):
                if find == 1:
                    break
                if s[k] == str(0):
                    for l in range(k+1,n):
                        if s[l] == str(i):
                            find = 1
                            break
    if find == 1:
        cnt += 1

for i in range(10,100):
    find = 0
    for j in range(n-2):
        if find == 1:
            break
        if s[j] == str(0):
            for k in range(j+1,n-1):
                if find == 1:
                    break
                if s[k] == str(i)[0]:
                    for l in range(k+1,n):
                        if s[l] == str(i)[1]:
                            find = 1
                            break
    if find == 1:
        cnt+=1

for i in range(100,1000):
    find = 0
    for j in range(n-2):
        if find == 1:
            break
        if s[j] == str(i)[0]:
            for k in range(j+1,n-1):
                if find==1:
                    break
                if s[k] == str(i)[1]:
                    for l in range(k+1,n):
                        if s[l] == str(i)[2]:
                            find = 1
                            break
    if find == 1:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

password = {}
cnt = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            p = s[i] + s[j] + s[k]
            if not p in password.keys():
                password[p] = 0
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

password = []
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            p = s[i] + s[j] + s[k]
            if not p in password:
                password.append(p)
print(len(password))

Submission status: Time Limit Exceeded

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

temp=[]
for i in range(0,n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            temp.append(int(s[i]+s[j]+s[k]))
            
print(len(list(set(temp))))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
dp = {}
si = set()
for i in range(N-2):
  if i in si:
    continue
  si.add(i)
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set([S[k] for k in range(j+1, N)]))
print(sum(dp.values()))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
dp = {}
for i in range(N-2):
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set([S[k] for k in range(j+1, N)]))
print(sum(dp.values()))

Submission status: Time Limit Exceeded

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

delKeta = N-3
ans = []
for V3 in range(10):
    for i in range(N-2):
        if(V3==int(S[i])):
            p1=i
            for V2 in range(10):
                for j in range(p1+1,N-1):
                    if(V2==int(S[j])):
                        p2=j
                        for V1 in range(10):
                            for k in range(p2+1,N):
                                if(V1==int(S[k])):
                                    ans.append(S[k]+S[p2]+S[p1])
                                    break
                        break
            break
                



print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans=[]
for v in range(1000):
    tmp = ''
    i = 0
    j = 0
    V=[v//100,(v%100)//10,v%10]
    while i < N:
        if(V[j] == int(S[i])):
            tmp+=S[i]
            j += 1
        if(j==3):
            ans.append(tmp)
            break
        i+=1

print(len(set(ans)))

Submission status: Time Limit Exceeded

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

delKeta = N-3
Vall = []
ans=[]
for V3 in range(10):
    for V2 in range(10):
        for V1 in range(10):
            Vall.append([V1, V2, V3])

for V in Vall:
    tmp = ''
    i = 0
    j = 0
    while i < N:
        if(V[j] == int(S[i])):
            tmp+=S[i]
            j += 1
        if(j==3):
            ans.append(tmp)
            break
        i+=1

print(len(set(ans)))

Submission status: Time Limit Exceeded

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

delKeta = N-3
Vall = []
ans=[]
for V3 in range(10):
    for V2 in range(10):
        for V1 in range(10):
            Vall.append([V1, V2, V3])

for V in Vall:
    tmp = ''
    i = 0
    j = 0
    while i < N:
        if(V[j] == int(S[i])):
            tmp+=S[i]
            j += 1
        if(j==3):
            break
        i+=1
    if(len(tmp) == 3):
        ans.append(tmp)

print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
Vall = []
ans=[]

for V3 in range(10):
    for V2 in range(10):
        for V1 in range(10):
            Vall.append([V1, V2, V3])

for V in Vall:
    tmp = ''
    p = 0
    j = 0
    while j < 3:
        for i in range(p, N):
            if(V[j] == int(S[i])):
                p = 1+i
                tmp += S[i]
                j += 1
                break
        else:
            break
    if(len(tmp) == 3):
        ans.append(tmp)

print(len(set(ans)))

Submission status: Time Limit Exceeded

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

delKeta = N-3
ans = []
for V3 in range(10):
    for i in range(N):
        if(V3==int(S[i])):
            p1=i
            for V2 in range(10):
                for j in range(p1+1,N):
                    if(V2==int(S[j])):
                        p2=j
                        for V1 in range(10):
                            for k in range(p2+1,N):
                                if(V1==int(S[k])):
                                    ans.append(S[k]+S[p2]+S[p1])
                                    break
                        break
            break
                



print(len(set(ans)))

Submission status: Time Limit Exceeded

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

delKeta = N-3
ans = []
for V3 in range(10):
    for i in range(N):
        if(V3==int(S[i])):
            p1=i
            for V2 in range(10):
                for j in range(p1+1,N):
                    if(V2==int(S[j])):
                        p2=j
                
                        for V1 in range(10):
                            for k in range(p2+1,N):
                                if(V1==int(S[k])):
                                    ans.append(S[k]+S[p2]+S[p1])
                                    



print(len(set(ans)))

Submission status: Time Limit Exceeded

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

temp=[]
for i in range(0,n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            temp.append(int(s[i]+s[j]+s[k]))
            
temp.sort()

count = 1
cur_num = temp[0]

for i in range(len(temp)-1):
    if temp[i] != temp[i+1]:
        count += 1
        
print(count)

Submission status: Time Limit Exceeded

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

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

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for j in range(n):
        if s[j] == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

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

for i in range(1000):
    cnt = 0
    if i < 100:
        if i < 10:
            match = '00' + str(i)
        else:
            match = '0' + str(i)
    else:
        match = str(i)

    for j in range(len(s)):
        if s[j] == match[cnt]:
            cnt += 1

        if cnt == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

delKeta=N-3
ans=[]


for i in range(N):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            ans.append(int(S[i]+S[j]+S[k]))
    #print(i+1,len(set(ans)))


s=set(ans)
print(len(s))

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 = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            t = str(i) + str(j) + str(k)
            tmp = []
            for z in s:
                if t[len(tmp)] == z:
                    tmp.append(0)
                if len(tmp) == 3:
                    ans += 1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


def c_count(n, r):  # 組み合わせ
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

ans = set()

for i in combinations(s, 3):
    ans.add(i)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

nums = [str(i) for i in range(10)]

ans = 0
for pat in product(nums, repeat=3):
    i = 0
    for e in s:
        if e == pat[i]:
            i += 1

        if i == 3:
            break

    if i == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
ans = set()
for i in range(7, 2**(N-1)+2**(N-2)+2**(N-3)+1):
    tmp = ''
    cnt = 0
    for j in range(0, N):
        if (i >> j) & 1:
            tmp += S[j]
            cnt += 1
        if cnt > 3:
            break
    if cnt == 3:
        ans.add(tmp)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
#000~999からいくつ作れるか試す
num='0123456789'
ans=0
#候補の暗証番号を生成する
for first_num in num:
    for second_num in num:
        for third_num in num:
            temp_lock=first_num+second_num+third_num
            temp_cnt=0
            for i in s:
                if temp_cnt==0 and i==temp_lock[0]:
                    temp_cnt=1
                elif temp_cnt==1 and i==temp_lock[1]:
                    temp_cnt=2
                elif temp_cnt==2 and i==temp_lock[2]:
                    ans+=1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = set()
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(len(a_alr) == 10):
        break
    if(s[i] in a_alr):
        continue

    for j in range(i+1,n-1):
        if(len(b_alr[s[i]]) == 10):
            break
        if(s[j] in b_alr[s[i]]):
            continue
        c_alr = set()
        for k in range(j+1,n):
            c_alr = c_alr | set([s[k]])   
            tmp = s[i]+s[j]+s[k]
            ans = ans | set([tmp])
            if(len(c_alr) == 10):
                break

        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = set()
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(s[i] in a_alr):
        continue
    for j in range(i+1,n-1):
        if(s[j] in b_alr[s[i]]):
            continue
        c_alr = set()
        for k in range(j+1,n):
            c_alr = c_alr | set([s[k]])   
            tmp = s[i]+s[j]+s[k]
            ans = ans | set([tmp])
            if(len(c_alr) == 10):
                break

        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
s = input()

ans = set()
a_alr = []
b_alr = {}

for i in range(10):
    b_alr[str(i)] = []

for i in range(n-2):
    if(s[i] in a_alr):
        continue
    for j in range(i+1,n-1):
        if(s[j] in b_alr[s[i]]):
            continue
        for k in range(j+1,n):
            tmp = s[i]+s[j]+s[k]
            ans = ans | set([tmp])

        b_alr[s[i]].append(s[j])
    a_alr.append(s[i])

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
dp = [[[False] * 30009 for i in range(4)] for j in range(1009)]
dp[0][0][0]=True
cnt=0
for i in range(n):
    for j in range(4):
        for k in range(1000):
            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
for i in range(1000):
    if(dp[n][3][i]==True):
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# resolve after read answer

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

# count = 0
# for i in range(1000):
#     v = str(i).zfill(3)
#     k=0
#     for j in range(n):
#         if v[k] == s[j]:
#             k+=1
#         if k==3:
#             count+=1
#             break

# print(count)

# dp
dp = [[[False] * 30009 for i in range(4)] for j in range(1009)]
dp[0][0][0]=True
cnt=0
for i in range(n):
    for j in range(4):
        for k in range(1000):
            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
    for i in range(1000):
        if(dp[n][3][i]==True):
            cnt+=1
print(cnt)