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 = input()
seq = list(set(list(s)))
avcodelist = list(itertools.product(seq, repeat=3))
ans = []
for a in range(len(avcodelist)):
    for i in range(len(s)):
        if s[i] == avcodelist[a][0]:
            for j in range(i + 1, len(s)):
                if s[j] == avcodelist[a][1]:
                    for k in range(j + 1, len(s)):
                        if s[k] == avcodelist[a][2]:
                            ans.append((avcodelist[a][0], avcodelist[a][1], avcodelist[a][2]))
print(len(set(ans)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
c = 0
for i in range(1000):
    s = "0"*(3-len(str(i)))+str(i)
    #print(s)
    k = 0
    for j in S:
        if j == s[k]:
            k += 1
            if k == 3:
                c += 1
                #print(s)
                break
        #print("j={},k={}".format(j,k))
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)


def solve(c, idx, N, S, ans):
    if len(c)==3:
        ans.add(c)
        return
    if idx >= len(S):
        return
    solve(c+S[idx], idx+1, N, S, ans)
    solve(c, idx+1, N, S, ans)

if __name__ == "__main__":
    N = int(input())
    S = input()
    ans = set()
    solve("", 0, N, S, ans)
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
se = set()
check = set()
for first in range(10):
    temp = ''
    for i in range(n):
        if s[i] in check:
            continue
        if int(s[i])==first:
            temp+=s[i]
            check.add(s[i])
            for second in range(10):
                for j in range(i+1,n):
                    if (s[i],s[j]) in check:
                        continue
                    if int(s[j])==second:
                        temp+=s[j]
                        check.add((s[i],s[j]))
                        for third in range(10):
                            for k in range(j+1,n):
                                if (s[i],s[j],s[k]) in check:
                                    continue
                                if int(s[k])==third:
                                    temp+=s[k]
                                    check.add((s[i],s[j],s[k]))
                                    if len(temp)==3:
                                        se.add(temp)
                                    temp=temp[:-1]
                        temp=s[i]
print(len(se))

Submission status: Time Limit Exceeded

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

n = int(n)

allnum = set(range(0, 1000))
ans = []

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            num = int(s[i]) * 100 + int(s[j]) * 10 + int(s[k])

            if num in allnum and num not in ans:
                ans.append(num)

print(len(ans))

Submission status: Time Limit Exceeded

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

ans=[]
for i in range(n-1):
    i_set=set(s[i+1:])

    for j in i_set:
        j_ind=s.index(j)
        s_j=s[i+1:]
        j_set=set(s_j[s_j.index(j)+1:])
        # print(s_j)

        for k in j_set:
            k_ind=s.index(k)
            ans.append(s[i]+s[j_ind]+s[k_ind])
            # print(s[i]+s[j_ind]+s[k_ind])

print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
def num():
    return int(input())

def nums():
    return list(map(int,input().split()))

def delete_str(str_,index):
    str_ = str_[:index]+str_[index+1:]
    return str_

#A
"""
M1,D1 = nums()
M2,D2 = nums()
print(int(M1 != M2))
"""
#B
"""
import math
N = num()
without_tax = N / 1.08
if int(int(without_tax) * 1.08) == N:
    print(int(without_tax))
elif int(math.ceil(without_tax) * 1.08) == N:
    print(math.ceil(without_tax))
else:
    print(":(")
"""
#C
"""
X = num()
amari = X % 100
kinds = {}
for i in reversed(range(1,6)):
    kinds[i] = int(amari / i)
    print(amari)
    amari %= i
print(amari,kinds)
"""
#D
import math
import itertools

N = num()
S = list(input())
cand = set()
for place in itertools.combinations(range(N),N-3):
    pin = S.copy()
    pre = 0
    for index in place:
        pin.pop(index-pre)
        pre += 1
    cand.add("".join(pin))
print(len(cand))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
x=[]
y=[]
z=[]
count=0

for i in range(n-2):
    y=[]
    if x.count(s[i])!=0:
        continue
    else:
        x.append(s[i])
        for j in range(i+1,n-1):
                for k in range(j+1,n):
                    v=s[j]+s[k]
                    if y.count(v)!=0:
                        continue
                    else:
                        y.append(v)
                        count+=1
                        if count==1000:
                            print(1000)
                            exit()
                        
                
        
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(input())
q = list(itertools.combinations(range(n), 3))
r = []

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

for i in range(len(q)):
  a = s[q[i][0]]
  b = s[q[i][1]]
  c = s[q[i][2]]
  r.append([a,b,c])


print(len(get_unique_list(r)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
b=input()
a=input()
print(len(list(set(list(combinations(a,3))))))

Submission status: Time Limit Exceeded

Solution code:
import sys, math
from collections import defaultdict
from copy import deepcopy
import itertools
# 文字列の場合は普通のinput()を使うか下を使う
# input = sys.stdin.readline().rstrip()

N = int(input())
S = input()
d = {}
key = set([])
for i in range(10):
    for j in range(10):
        for k in range(10):
            d[(i, j, k)] = 0
            key.add((i, j, k))

ans = 0
for x in S:
    x = int(x)
    for key_num in key:
        i, j, k = key_num
        n = d[key_num]
        if n == 0 and i == x:
            d[key_num] += 1
        elif n == 1 and j == x:
            d[key_num] += 1
        elif n == 2 and k == x:
            d[key_num] += 1
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 2019/12/01
# 三井住友信託銀行プログラミングコンテスト2019 - D

import re

# Input
n = int(input())
s = input()

ans = 0

# Search
for i1 in range(10):
    for i2 in range(10):
        for i3 in range(10):
            pt = str(i1) + "+" + "[0-9]*" + str(i2) + "+" + "[0-9]*" + str(i3) + "+" + "[0-9]*"
            res = re.search(pt, s)
            if res != None:
                ans = ans + 1

# Output
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

def solve():
  N = int(input())
  S = input()
  aa = map(lambda x:"".join(x),combinations(S,N-(N-3)))
  print(len(set(aa)))

if __name__ == '__main__':
  solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
S = input()
data = np.zeros((10, 10, 10))
data[int(S[0]), int(S[1]), int(S[2])] = 1
for i in range(3, N):
    where = np.where(data == 1)
    data[where[0], where[2], int(S[i])] = 1
    data[where[1], where[2], int(S[i])] = 1
    data[where[0], where[1], int(S[i])] = 1
print(int(np.sum(data)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = input()
S = list(S)
L = set()
for i, j, k in itertools.combinations(S,3):
  L.add(i + j + k)
#print(L)
print(len(L))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
anslist = []
_ = input()
S = input()
l = [i for i in S]
for c  in itertools.combinations(l, 3):
    
    anslist.append(c)

print(len(set(anslist)))

Submission status: Time Limit Exceeded

Solution code:
import bisect
import numpy as np
N = int(input())
S = input()

dic_ = {}

for i in range(N):
    dic_[S[i]] = dic_.get(S[i], []) + [i]

ans = [False]*1000

def get_first_pos(i, k):
    if dic_.get(str(i)) is not None:
        ind = bisect.bisect_right(dic_[str(i)], k)
        if ind != len(dic_[str(i)]):
            return dic_[str(i)][ind]
    return None

        
for i in range(10):
    x1 = get_first_pos(i, -1)
    if x1 is None:
        continue
    for j in range(10):
        x2 = get_first_pos(j, x1)
        if x2 is None:       
            continue
        for k in range(10):
            x3 = get_first_pos(k, x2)
            if x3 is None:       
                continue
            ans[int(str(i)+str(j)+str(k))] = True
print(np.count_nonzero(ans))

Submission status: Time Limit Exceeded

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

memo = [0]*100
counter = 0

for i in range(n):
    for j in range(i+1,n):
            if memo[int(s[i])*10+int(s[j])] == 0:
                memo[int(s[i])*10+int(s[j])] = 1
                counter += len(set(s[j+1:]))
        
print(counter)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import itertools

    n = int(input())
    s = input()
    print(len(set(itertools.combinations(s, 3))))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

print(len(set(list(itertools.combinations(s,3)))))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

slen = list(itertools.combinations(S, N - (N - 3)))
setlen = set(slen)

print(len(setlen))

Submission status: Time Limit Exceeded

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

dp = [False for _ in range(1000)]
#dp[i][j] = 左からi桁目までで暗証番号がjになるものがあるかどうか

ans = 1
dp[int(s[:3])] = True
for i in range(3,n):
	count = 0
	for j in range(i):
		for k in range(j+1,i):
			num = int(s[j]+s[k]+s[i])
			if not dp[num]:
				dp[num] = True
				count += 1
	ans += count

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
passwd = set()
for i in range(1,n-1):
    pre = set(s[:i])
    post = set(s[i+1:])
    for c0 in pre:
        for c1 in post:
            passwd.add(c0+s[i]+c1)
print(len(passwd))

Submission status: Time Limit Exceeded

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


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


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = True
show_flg = False


def main():
    N = int(input())
    S = input()
    pos = [[] for i in range(10)]
    ans = 0

    for i in range(len(S)):
        pos[int(S[i])].append(i)

    show(pos)

    NUM = 10
    for i in range(NUM):
        for j in range(NUM):
            for k in range(NUM):
                cur = -1
                # print(pos[k])
                pos_i = [m for m in pos[i]]

                pos_j = [m for m in pos[j]]
                if j == i and len(pos_j) > 1:
                    pos_j.pop(0)

                pos_k = [m for m in pos[k]]
                if k == i and len(pos_k) > 1:
                    pos_k.pop(0)
                if k == j and len(pos_k) > 1:
                    pos_k.pop(0)

                if len(pos_i) == 0:
                    show('len(pos_i) == 0:')
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                cur = pos_i.pop(0)

                #################################

                if len(pos_j) == 0:
                    show('len(pos_j) == 0:')
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                prev_cur = cur
                while len(pos_j) > 0:
                    tmp = pos_j.pop(0)
                    if tmp > cur:
                        cur = tmp
                        break

                if prev_cur == cur:
                    show('pos_j', tmp, cur)
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                #################################

                if len(pos_k) == 0:
                    show('len(pos_k) == 0:')
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                prev_cur = cur
                while len(pos_k) > 0:
                    tmp = pos_k.pop(0)
                    if tmp > cur:
                        cur = tmp
                        break

                if prev_cur == cur:
                    show('pos_k', tmp, cur)
                    show(i, j, k, pos[i], pos[j], pos[k])
                    continue

                # show(i, j, k)
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

_n = int(input())
_s = input()[:-1]


def chker(n, s):
    flg = [0] * 1000
    for i in range(1000):
        password = str(i).zfill(3)
        digit = 0
        for num in s:
            if password[digit] == num:
                digit += 1

            if digit == 3:
                flg[i] = 1
                break

    print(sum(flg))


chker(_n, _s)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
se = set()
 
for first in range(10):
    temp = ''
    for i in range(n):
        if int(s[i])==first:
            temp+=s[i]
            for second in range(10):
                for j in range(i+1,n):
                    if int(s[j])==second:
                        temp+=s[j]
                        for third in range(10):
                            for k in range(j+1,n):
                                if int(s[k])==third:
                                    temp+=s[k]
                                    if len(temp)==3:
                                        se.add(temp)
                                    temp=temp[:-1]
                        temp=s[i]
print(len(se))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
#print(N,S)

count=0

for n1 in range(10):
 for n2 in range(10):
  string=''
  for i in range(N-2):
    if n1==int(S[i]):
       for j in range(i+1,N-1):
         if n2==int(S[j]):
          #print(n1,n2,S[j+1:])
          string +=S[j+1:]           
  count+=len(set(string))
     
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
def main():
    _ = input()
    s = list(input())
    sset = set(s)
    l = []
    for i in sset:
        for j in sset:
            for k in sset:
                l.append(str(i)+str(j)+str(k))
    ans = 0
    for i in s:
        l_ = []
        while l:
            x = l.pop(-1)
            if x[0] == i:
                if len(x) == 1:
                    ans += 1
                else:
                    l_.append(x[1:])
            else:
                l_.append(x)
        l = copy.deepcopy(l_)
    print(ans)
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

L=[0]*9
D=[0]*100
C=0
for i in range(N-2):
    for j in range(i+1,N-1):
        s=str(S[i])+str(S[j])
        if(D[int(s)]==0):
            D[int(s)]=1
            C+=len(set(S[j+1:N]))
print(C)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
S=input()
seq=range(N)
pick=list(itertools.combinations(seq,3))
ans=[]
for p in pick:
    #print(p[0],p[1],p[2])
    #print(N-1-p[0],N-1-p[1],N-1-p[2])
    y=""+S[N-1-p[0]]+S[N-1-p[1]]+S[N-1-p[2]]
    ans.append(y)
print(len(set(ans)))

Submission status: Time Limit Exceeded

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

dp = [[0]*10 for _ in range(10)]

result = []
for i in range(n-2):
    for j in range(i+1,n-1):
        if dp[int(s[i])][int(s[j])]==0:
            tem = "".join(set(s[j+1:]))
            for k in range(len(tem)):
                result.append(s[i]+s[j]+tem[k])
            dp[int(s[i])][int(s[j])]=1

ans = set(result)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N= int(input())
S=input()
pointer = 0
counter = 0
def search(point,string, num):
    l_point = point
    for i in range(len(string)-point):
        if int(string[l_point])==num:
            return l_point
        l_point = l_point+1
    return -1
for i in range(0,10):
    pointer = 0
    pointer = search(pointer,S, i)
    #print("pointer = ",pointer)
    if pointer ==-1:
        pointer = 0
        continue;
    else:
        for j in range(0,10):
            pointer_1 = search(pointer+1,S,j)
            if pointer_1 == -1:
                pointer_1 = 0
                continue;
            else:
                for k in range(0,10):
                    pointer_2 = search(pointer_1+1,S,k)  
                    if pointer_2 == -1:
                        pointer_2 = 0
                        continue;
                    else:
                        #print(i,j,k)
                        counter = counter+1
print(counter)

Submission status: Time Limit Exceeded

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

from itertools import permutations, combinations,combinations_with_replacement,product
L = list(combinations(range(N), 3))   #nCr
A=[]
for i in L:
  X = S[i[0]]+S[i[1]]+S[i[2]]
  if X not in A:
    A.append(X)
print(len(A))

Submission status: Time Limit Exceeded

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

ans = 0
done_dic = {}
S_factor = collections.Counter(list(S))
S_factor_temp = S_factor.copy()
for i in range(N - 2):
    first_num = S[i]
    S_factor_temp["{}".format(first_num)] -= 1
    for j in range(i + 1, N - 1):
        second_num = S[j]
        S_factor_temp["{}".format(second_num)] -= 1
        if "{}_{}".format(first_num, second_num) in done_dic:
            continue
        else:
            for factor, num in S_factor_temp.items():
                if num > 0:
                    ans += 1
            done_dic["{}_{}".format(first_num, second_num)] = 0
    S_factor["{}".format(first_num)] -= 1
    S_factor_temp = S_factor.copy()

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
number=[]
for i in S:
    number.append(i)

numberlist=[]
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            candidate=number[i]+number[j]+number[k]
            if candidate not in numberlist:
                numberlist.append(candidate)

print(len(numberlist))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=str(input())
point=0
a=[]
coo=[]
for i in range(0,len(S)-2):
  if S[i] in a:
    pass
  else:
    a.append(int(S[i]))
    for j in range(i+1,len(S)-1):
        for k in range(j+1,len(S)):
          coo.append(int(S[i]+S[j]+S[k]))
          
print(len(set(coo)))

Submission status: Time Limit Exceeded

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

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

ls_password = []

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            pw = s[i] + s[j] + s[k]
            ls_password.append(pw)

# print(ls_password)

print(len(set(ls_password)))

Submission status: Time Limit Exceeded

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

for i in range(N-2):
  x = S[i]
  for j in range(i+1,N-1):
    y = S[j]
    for k in range(j+1,N):
      z = S[k]
      data.add(x+y+z)
print(len(data))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
passwd = set()
for i in range(1,n-1):
    pre = set(s[:i])
    post = (s[i+1:])
    for c0 in pre:
        for c1 in post:
            passwd.add(c0+s[i]+c1)
print(len(passwd))

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from itertools import combinations
    
    N = int(input())
    S = input()
    
    passcode = set((''.join(t) for t in combinations(S, 3)))
    print(len(passcode))

solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [int(s) for s in list(input())]

r_and_l = [set([]) for i in range(10)]
for i in range(1, N-1):
  right = set(S[:i])
  left = set(S[i+1:])
  for num_r in right:
    for num_l in left:
      r_and_l[S[i]] = r_and_l[S[i]] | set([str(num_r)+str(num_l)])
count = 0
for i in range(10):
  count += len(r_and_l[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(input())
x = list(itertools.combinations(range(n), 3))
ans = 0
p = []
for i in range(len(x)):
  l = ""
  for j in x[i]:
    l+=s[j]
  p.append(l)
print(len(set(p)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
S = input()
ans_list = []
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            tmp = S[i] + S[j] + S[k]
            ans_list.append(tmp)

ans = len(set(ans_list))

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(1000):
	sec = str('%03d' % i)
	nex = 0
	for j in range(n):
		if nex == 0 and s[j] == sec[0]:
			nex += 1
		elif nex == 1 and s[j] == sec[1]:
			nex += 1
		elif nex == 2 and s[j] == sec[2]:
			cnt += 1
			break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

candidate = set()

def dfs(num,pw):
    global s
    global n
    global candidate
    if len(pw) == 3:
        candidate.add(pw)
        return
    elif num == n:
        return
    else:
        dfs(num+1,pw)
        pw+=s[num]
        dfs(num+1,pw)

dfs(0,"")

print(len(candidate))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
keys=set()
keys.add(s[0:3])
for i in range(3,n):
	adkeys=set()
	for key in keys:
		adkeys.add(key[0]+key[1]+s[i])
		adkeys.add(key[0]+key[2]+s[i])
		adkeys.add(key[1]+key[2]+s[i])
	keys=keys|adkeys
print(len(keys))

Submission status: Time Limit Exceeded

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

L=[0]*9
D={}
C=0
for i in range(N-2):
    for j in range(i+1,N-1):
        s=str(S[i])+str(S[j])
        if(D.get(s,None)==None):
            D[s]=1
            C+=len(set(S[j+1:N]))
print(C)

Submission status: Time Limit Exceeded

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

n = int(n)

allnum = list(range(0, 1000))

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            num = int(s[i]) * 100 + int(s[j]) * 10 + int(s[k])
            # print(num)

            try:
                allnum.remove(num)
            except:
                pass

print(1000 - len(allnum))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
N = int(input())
S = input()

ans = set()

def solve(c, idx):
    if len(c)==3:
        ans.add(c)
        return
    if idx >= len(S):
        return
    solve(c+S[idx], idx+1)
    solve(c, idx+1)

if __name__ == "__main__":
    solve("", 0)
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def num():
    return int(input())

def nums():
    return list(map(int,input().split()))

def delete_str(str_,index):
    str_ = str_[:index]+str_[index+1:]
    return str_

#A
"""
M1,D1 = nums()
M2,D2 = nums()
print(int(M1 != M2))
"""
#B
"""
import math
N = num()
without_tax = N / 1.08
if int(int(without_tax) * 1.08) == N:
    print(int(without_tax))
elif int(math.ceil(without_tax) * 1.08) == N:
    print(math.ceil(without_tax))
else:
    print(":(")
"""
#C
"""
X = num()
amari = X % 100
kinds = {}
for i in reversed(range(1,6)):
    kinds[i] = int(amari / i)
    print(amari)
    amari %= i
print(amari,kinds)
"""
#D
import math
import itertools

N = num()
S = input()
cand = set()
for place in itertools.combinations(range(N),N-3):
    pin = S
    pre = 0
    for index in place:
        pin = delete_str(pin,index-pre)
        pre += 1
    cand.add(pin)
print(len(cand))

Submission status: Time Limit Exceeded

Solution code:
import re

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

pins = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      pins.append(str(i) + str(j) + str(k))

ans = 0
for p in pins:
  repatter = re.compile("\d*{}\d*{}\d*{}\d*".format(p[0], p[1], p[2]))
  if repatter.match(S):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
passwords = []

firsts = []
firsts_seconds = []

for i in range(n-2):
    first =  s[i]
    if first in firsts:
        continue
    firsts.append(first)
    for j in range(i+1,n-1):
        second = s[j]
        first_second = first + second
        if first_second in firsts_seconds:
            continue
        firsts_seconds.append(first_second)
        for k in range(j+1, n):
            password = first_second + s[k]
            if password not in passwords:
                passwords.append(password)

print(len(passwords))

Submission status: Time Limit Exceeded

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

from itertools import permutations, combinations,combinations_with_replacement,product
L = list(combinations(range(N), 3))   #nCr
A=[]
for i in L:
  A.append(S[i[0]]+S[i[1]]+S[i[2]])
print(len(set(A)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
A = []
B = {}

#for i in range(N):
#  t=int(S[i])
#  if t not in B:
#    B[t]=1
#    A.append(t)
#  elif B[t]<3:
#    B[t]+=1
#    A.append(t)
#  else:
#    pass

for i in range(N):
  A.append(S[i])
C=len(A)
D=set()

for i in range(0,C-2):
  for j in range(i+1,C-1):
    for k in range(j+1,C):
      strg=str(A[i])+str(A[j])+str(A[k])
      D.add(strg)
                 
#print(D)
print(len(D))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=input()
l=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        m=0
        for k in range(j+1,n):
            if S[i]+S[j]+S[k] not in l:
                l.append(S[i]+S[j]+S[k])
                m=m+1
                if m==10:
                    break
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from math import factorial
from itertools import combinations

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
s = [int(i) for i in s]

lin = list(combinations(s, 3))

lin = list(set(lin))

print(len(lin))

Submission status: Time Limit Exceeded

Solution code:
def check(first, second, third, num_list):
    first_flag = False
    second_flag = False
    third_flag = False
    for num in num_list:
        if first_flag:
            if second_flag:
                if third_flag:
                    return True
                else:
                    if str(num) == third:
                        third_flag = True
            else:
                if str(num) == second:
                    second_flag = True
        else:
            if str(num) == first:
                first_flag = True
        if first_flag and second_flag and third_flag:
            return True
    return False

n = int(input())
s = input()
sl = list(s)

ans = 0

for i in range(1000):
    if i < 10:
        flag = check('0', '0', str(i), sl)
    elif i < 100:
        flag = check('0', str(i//10), str(i%10), sl)
    else:
        flag = check(str(i//100), str((i%100)//10), str(i%10), sl)
        
    if flag:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = input()
passwords = set(itertools.combinations(S,3))
print(len(passwords))

Submission status: Time Limit Exceeded

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

di=[0]*1000
for i in range(N):
  ii=int(s[i])
  for j in range(i+1,N):
    jj=int(s[j])
    for k in range(j+1,N):
      kk=int(s[k])
      di[ii*100+jj*10+kk]=1
      
print(sum(di))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
cnt=0
for i in range(1000):
  con=0
  if i<10:
    a="00"+str(i)
  elif i<100:
    a="0"+str(i)
  else:
    a=str(i)
  for j in range(N):
    if S[j]==a[con]:
      con+=1
      if con==3:
        cnt+=1
        break
print(cnt)