Problem:


Score: 400 points

Problem Statement

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

Thus, he can set three different PIN codes: 022, 024, and 224.

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Time Limit Exceeded

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

li=[]
uni_list=[]

for i in range(N-2):
    for j in range(N-1):
        if j>i:
            for k in range(N):
                if k>j:
                    li.append(S[i]+S[j]+S[k])
    

uni_list=list(set(li))

print(len(uni_list))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
data = list(map(int,input()))
result = []
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(data)):
  for j in range(i + 1, len(data)):
    for k in range(j + 1, len(data)):
      result.append([data[i], data[j], data[k]])

print(len(get_unique_list(result)))

Submission status: Time Limit Exceeded

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

L1=[]
ans=[]

for i in range(N-2):
    for j in range(i+1,N-1):
        temp=S[i]+S[j]
        if temp in L1:
            continue
        else:
            L1.append(temp)
        for k in range(j+1,N):
            ans.append(temp+S[k])


print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline
n = int(input())
t = input()
md = defaultdict(int)
s = ""
for i in range(len(t)):
    md[i] += 1
    if md[i] <= 3:
        s += t[i]
m = len(s)-1
d = set()
for i in range(m-2):
    for j in range(i+1,m-1):
        for k in range(j+1,m):
            t = s[i]+s[j]+s[k]
            d.add(t)
print(len(d))

Submission status: Time Limit Exceeded

Solution code:
input()
ns = [n for n in input()]
 
scores = 0
first = []
second = []
third = []
third_nums = None
 
for i in range(len(ns) - 2):
  if i in first:
    continue
  else:
    first.append(i)
  for j in range(i+1, len(ns) - 1):
    if ''.join([ns[i], ns[j]]) in second:
      continue
    else:
      second.append(''.join([ns[i], ns[j]]))
      third_nums = set(ns[j+1:])
      scores += len(third_nums)
      
print(scores)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
input = sys.stdin.readline
N = int(input())
S = input()
d = {}
count = 0
combs = list(itertools.combinations(range(N), 3))
for c in combs:
    if S[c[0]]+S[c[1]]+S[c[2]] not in d:
        d[S[c[0]]+S[c[1]]+S[c[2]]] = 1
        count +=1
    else:
        pass
#print(d)
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
pass_list = list(map(lambda x: str(x).zfill(3), range(1000)))
res = 0

for p in pass_list:
    
    ptr = 0
    one = False
    two = False
    three = False
    
    for i in range(len(s)):
        if(s[i] == p[0]):
            ptr = i
            one = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[1]):
            ptr = i
            two = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[2]):
            ptr = i
            three = True
            break
    
    if(one and two and three): res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
    N = int(input())
    S = input()
    lst = list(S)

    sets = set()
    for i,j,k in itertools.combinations(range(N), 3):
        if i < j < k:
            s = str(lst[i])+str(lst[j])+str(lst[k])
            if s not in sets:
                sets.add(s)
    print(len(sets))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

candidates = set()
for i in range(n-1):
    for j in range(i+1,n):
        candidates = candidates.union([str_s[i] + str_s[j] + k for k in str_s[j+1:]])
print(len(candidates))

Submission status: Time Limit Exceeded

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

ans_list = {}

for i in range(N):
    for j in range(i+1, N):
        if not S[j + 1:N]:
            continue
        elif S[i] + S[j] not in ans_list:
            ans_list[S[i] + S[j]] = S[j + 1:N]
        else:
            ans_list[S[i] + S[j]] += S[j+1:N]
count = 0
# print(ans_list)
ans_len_list = [len(set(value)) for value in ans_list.values()]
print(sum(ans_len_list))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

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

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    S = input()

    num = set()
    for s in combinations(S, 3):
        num.add(s)
    print(len(num))


main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
num = int(input())
arr = input()
 
c = list(itertools.combinations(list(arr), 3))
 
mat = list(set(c))
 
print(len(mat))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
s = list(S)
ret = set()
from itertools import combinations
for i in combinations(s, 3):
    ret.add(i)
print(len(ret))

Submission status: Time Limit Exceeded

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

dp1000 = [False for _ in range(1000)]
dp100 = [False for _ in range(100)]
l = []

ans = 1
dp1000[int(s[:3])] = True
dp100[int(s[:2])] = True
l.append(s[:2])

for i in range(3,n):
	count = 0
	for j in range(i-1):
		string = s[j]+s[i-1]
		if not dp100[int(string)]:
			l.append(s[j]+s[i-1])
			dp100[int(string)] = True

	for j in l:
		num = int(j+s[i])
		if not dp1000[num]:
			dp1000[num] = True
			count += 1
	ans += count

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

def get_indexes(num):
  idx = -1
  idxs = []
  while idx != N-1:
    tmp_idx = S[idx+1:].find(str(num))
    if tmp_idx == -1:
      return idxs
    else:
      idx += tmp_idx+1
      idxs.append(idx)
  return idxs
      
N = int(input())
S = input()

ans = 0
S_idxs = []
for i in range(10):
  S_idxs.append(get_indexes(i))

used = set([])
for i in range(10):
  for ii in S_idxs[i]:
    for j in range(10):
      for jj in S_idxs[j]:
        for k in range(10):
          for kk in S_idxs[k]:
            if ii<jj and jj<kk and str(i)+str(j)+str(k) not in used:
              ans += 1
              used.add(str(i)+str(j)+str(k))
              #print(i,j,k,ii,jj,kk)
print(ans)
#print(S_idxs)

#print('*'*20)
#print(get_indexes(1))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
    n=int(input())
    s=list(map(str,input()))
    c = {"-1"}
    c.clear()
    temp={"-1"}
    temp.clear()

  #  print(c)

    for i in range(n):

        for j in c:
            temp.add(j+s[i])
        c = c | temp
        temp.clear()
        c.add(s[i])

#    print(d)
 #   print(c)
 #   print(c)

    for i in c:
        if len(i)<=2 or len(i)>=4:
           temp.add(i)
    for i in temp:
        c.discard(i)

 #   print(c)
#    print(d)
    print(len(c))
            #    print(n,kingaku(a,b,x))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

ans = 0
seta = set()

first = [[False]*10]*n
third = [[False]*10]*n

for i in range(1,n):
  first[i] = first[i-1].copy()
  first[i][int(s[i-1])] = True

for i in range(n-2,-1,-1):
  third[i] = third[i+1].copy()
  third[i][int(s[i+1])] = True
  
for i in range(1,n-1):
  for j in range(10):
    for k in range(10):
      if first[i][j] and third[i][k]:
        seta.add(str(j)+s[i]+str(k))
print(len(seta))

Submission status: Time Limit Exceeded

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

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

    for j in i_set:
        j_ind=s.index(j)
        s_i=s[i+1:]
        j_set=set(s_i[s_i.index(j)+1:])
        [ans.add(s[i]+j+k) for k in j_set]

print(len(ans))

Submission status: Time Limit Exceeded

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

dic = {}
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if not (S[i],S[j],S[k]) in dic:
                dic[(S[i],S[j],S[k])] = 1

print(len(dic))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
def cal(a, b, c):
    x = a[0]
    for bb in b:
        if bb > x:
            y = bb
            for cc in c:
                if cc > y:
                    return 1
    return 0
li = [[] for _ in range(10)]
for i, n in enumerate(S):
    num = int(n)
    li[num].append(i)
cnt = 0
for i in range(10):
    if len(li[i]) > 0:
        for j in range(10):
            if len(li[j]) > 0:
                for k in range(10):
                    if len(li[k]) > 0:
                        cnt += cal(li[i], li[j], li[k])
print(cnt)

Submission status: Time Limit Exceeded

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

L = []
flag1 = [0,1,2,3,4,5,6,7,8,9]
flag2 = [0,1,2,3,4,5,6,7,8,9]
flag3 = [0,1,2,3,4,5,6,7,8,9]

for i in range(N-2):
    x = int(S[i])
    if x in flag1:
        flag1[x] == 99999
    else:
        continue

    for j in range(i+1, N-1):
        y = int(S[j])
        if y in flag2:
            flag2[y] == 99999
        else:
            continue

        for k in range(j+1, N):
            z = int(S[k])
            if z in flag3:
                flag3[z] == 99999
            else:
                continue
            L.append(S[i] + S[j] + S[k])

print(len(set(L)))

Submission status: Time Limit Exceeded

Solution code:
#D
import itertools
N=int(input())
S=str(input())
S_list=list(S)
password_list=[]
for x in itertools.product(['0','1','2','3','4','5','6','7','8','9'],repeat=3):
  for i in range(N-2):
    if x[0]==S_list[i]:
      for j in range(i+1,N-1):
        if x[1]==S_list[j]:
          for k in range(j+1,N):
            if x[2]==S_list[k]:
              password_list +=[''.join(x)]
              break
answer=len(set(password_list))
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

lis = []

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

lis = set(lis)
print(len(lis))

Submission status: Time Limit Exceeded

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

N = int(input())
S = input()
q = deque([])
q_new = deque([])
d = {}
for i in range(10):
    for j in range(10):
        for k in range(10):
            q.append((i, j, k))
            d[(i, j, k)] = 0

ans = 0
for x in S:
    x = int(x)
    while q:
        (i, j, k) = q.popleft()
        n = d[(i, j, k)]
        if n == 2 and k == x:
            ans += 1
        else:
            if n == 0 and i == x:
                d[(i, j, k)] += 1
            elif n == 1 and j == x:
                d[(i, j, k)] += 1
            q_new.append((i, j, k))
        
    q = q_new
    q_new = deque([])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(i) for i in input()]
c = set()


for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            c.add((s[i], s[j], s[k]))

print(len(c))

Submission status: Time Limit Exceeded

Solution code:
import math

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

num = []
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]
      num.append(tmp)
print(len(set(num)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from collections import Counter
n=int(input())
s=input()
a=list(s)
c=list(combinations(a,3))

num=len(Counter(c))
print(num)

Submission status: Time Limit Exceeded

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

ans = set()
for i in range(1, len(S) - 1):
    # print(i)
    left_set = set(S[:i])
    right_set = set(S[i + 1:])
    for j in left_set:
        for k in right_set:
            # print((j, S[i], k))
            ans.add((j, S[i], k))

print(len(ans))

Submission status: Time Limit Exceeded

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

resset = set()

def set_range(start,end):
    return set(i for i in range(start, end))

range1 = set(i for i in range(0,N))

for i in range1:
    range2 = set(i for i in range(i+1,N))
    for j in range2:
        range3 = set(i for i in range(j+1,N))
        for k in range3:
            temp = S[i] + S[j] + S[k]
            resset.add(temp)

print(len(resset))

Submission status: Time Limit Exceeded

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

n = int(n)

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


checked_i = []
for i in range(n - 2):
    if i in checked_i:
        continue
    else:
        checked_i.append(i)
    
    checked_j = []
    for j in range(i + 1, n - 1):
        if j in checked_j:
            continue
        else:
            checked_j.append(j)
        # checked_j.append(j)

        num = int(s[i]) * 100 + int(s[j]) * 10

        if num in ans:
            continue
        else:
            ans.append(num)

            saigo_cnt = len(set([int(s[k]) for k in range(j + 1, n)]))
            counts += saigo_cnt

print(counts)

Submission status: Time Limit Exceeded

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

S10 = [0 for i in range(10)]
S100 = [list(S10) for i in range(10)]
S1000 =[list([list(S10) for i in range(10)]) for i in range(10)]

for n in S:
    for i in range(10):
        for j in range(10):
            if list(S100)[i][j] == 1:
                S1000[i][j][int(n)] = 1
        if list(S10)[i] == 1:
            S100[i][int(n)] = 1
    S10[int(n)] = 1
    


ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if S1000[i][j][k] == 1:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections
N = int(input())
S = str(input())
S = list(S)
print(len(collections.Counter(list(itertools.combinations(S,3)))))

Submission status: Time Limit Exceeded

Solution code:
import itertools
a=input()
b=input()
c=list(itertools.combinations(b,3))
d=list(set(c))
print(len(d))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

s_list = list(itertools.combinations(s, 3))

print(len(set(s_list)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
dicts=[]
ans=0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            s2=int(S[i]+S[j])
            if s2 in dicts:
                break
            else:
                dicts.append(s2)
                ans+=len(set(S[k:]))
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
kinds = [set() for _ in range(N + 1)]
history = set()

for i in range(N - 1, -1, -1):
    kinds[i] = kinds[i + 1].union(S[i])

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if not (S[i], S[j],) in history:
            ans += len(kinds[j+1])
            history.add((S[i], S[j],))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
lis = tuple(input())

ans = tuple(itertools.combinations(lis, 3))

result = []
for line in ans:
    if line not in result:
        result.append(line)
print(len(result))

Submission status: Time Limit Exceeded

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

l = len(s)
lst = []
count = 0
for i in range(l - 2):
    for j in range(i + 1, l - 1):
        for k in range(j + 1, l):
            pin = s[i] + s[j] + s[k]
            if pin not in lst:
                lst.append(pin)
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
p = [set() for _ in range(100)]
sp = [set() for _ in range(n)]
k = int(s[-1])
sp[-1].add(k)
for j in range(n-2,1,-1):
    tmp = set(sp[j+1])
    tmp.add(int(s[j]))
    sp[j] = tmp
for x in range(n-2):
    for y in range(x,n-1):
        if x < y:
            tstr = str(s[x])+str(s[y])
            b2 = int(tstr)
            if len(p[b2]) == 9:
                pass
            else:
                p[b2] |= sp[y+1]
g =0
for c in p:
    g += len(c)
print(g)

Submission status: Time Limit Exceeded

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

ans_list = {}

for i in range(N):
    for j in range(i+1, N):
        if not S[j + 1:N]:
            continue
        elif S[i] + S[j] not in ans_list:
            ans_list[S[i] + S[j]] = S[j + 1:N]
        else:
            ans_list[S[i] + S[j]].extend(S[j+1:N])
count = 0
# print(ans_list)
ans_len_list = [len(set(value)) for value in ans_list.values()]
print(sum(ans_len_list))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
res = []
for el1 in range(0, n - 2):
    for el2 in range(el1 + 1, n - 1):
        for el3 in range(el2 + 1, n):
            st = s[el1] + s[el2] + s[el3]
            res.append(st)
res = list(set(res))
print(len(res))

Submission status: Time Limit Exceeded

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

n = int(n)

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



for i in range(n - 2):
    checked_j = []
    for j in range(i + 1, n - 1):
        if j in checked_j:
            continue
        else:
            checked_j.append(j)
        # checked_j.append(j)

        num = int(s[i]) * 100 + int(s[j]) * 10

        if num in ans:
            continue
        else:
            ans.append(num)

            saigo_cnt = len(set([int(s[k]) for k in range(j + 1, n)]))
            counts += saigo_cnt

print(counts)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
S = list(map(int, list(input())))

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

Submission status: Time Limit Exceeded

Solution code:

from itertools import product, permutations,combinations
N = int(input())
S = str(input())

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

Submission status: Time Limit Exceeded

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

c = 0

flag0 = False
flag1 = False
flag2 = False

for i in range(1000):
    for n in reversed(S):
        if c == 1000:
            break
        if flag0 and flag1:
            if len(str(i)) >= 3:
                if int(str(i)[-3]) == int(n):
                    flag2 = True
            else:
                if 0 == int(n):
                    flag2 = True

        if flag0:
            if len(str(i)) >= 2:
                if int(str(i)[-2]) == int(n):
                    flag1 = True
            else:
                if 0 == int(n):
                    flag1 = True

        if int(str(i)[-1]) == int(n):
            flag0 = True

        if flag0 and flag1 and flag2:
            c += 1
            flag0 = False
            flag1 = False
            flag2 = False
            break

    flag0 = False
    flag1 = False
    flag2 = False

print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = [int(i) for i in input()]
a = {i for i in itertools.combinations(s, 3)}

print(len(a))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
n = int(input())
s = input()
count = 0
suuzi_list = []

for i in range(0, 10):
    if str(i) in s:
        suuzi_list.append(i)
for no_100 in suuzi_list:
    no_100 = str(no_100)
    for no_10 in suuzi_list:
        no_10 = str(no_10)
        for no_1 in suuzi_list:
            no_1 = str(no_1)
            repatter = re.compile(no_100 + '\d*?' + no_10 + '\d*?' + no_1)
            result = repatter.search(s)
            if result:
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def main():
    sc = Scan()
    N = sc.intarr()[0]
    S = sc.strarr()[0]

    array = []
    for i in range(N):
        for j in range(i+1, N):
            Marray = []
            for m in range(j+1, N):
                Marray.append(S[m])
                Marray = list(set(Marray))
                if len(Marray) == 10:
                    break
                num = S[i] + S[j] + S[m]
                array.append(num)
    array = set(array)
    print(len(array))


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = str(input())
l = [int(x) for x in list(S)]
lst = list(itertools.combinations(l, 3))
print(len(set(lst)))

Submission status: Time Limit Exceeded

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

D=[0]*100
C=0
W=[0]*10
R=len(set(S))**3

for i in range(N-2):
    if(C==R):
        break
    if(W[int(S[i])]<10):
        for j in range(i+1,N-1):
            s=str(S[i])+str(S[j])
            if(D[int(s)]==0):
                D[int(s)]=1
                W[int(S[i])]+=1
                C+=len(set(S[j+1:N]))
print(C)

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
input_line1=int(input())
input_line2=list(input())
 
password_length=input_line1-(input_line1-3)
list=[]
for subset in itertools.combinations(input_line2, password_length):
    if subset in list:
        pass
    else:
        list.append(subset)
print (len(list))

Submission status: Time Limit Exceeded

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

t = []
for i in range(d-2):
  for j in range(i+1,d-1):
    for k in range(j+1,d):
      t.append(n[i] + n[j] + n[k])
print(len(set(t)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
l=[]
for i in range(n):
  for j in range(i+1,n):
    if not s[i]+s[j] in l:
      l.append(s[i]+s[j])
      ans+=len(set(s[j+1:]))
print(ans)

Submission status: Time Limit Exceeded

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

firsts = []
firsts_seconds = [[]*10 for _ in range(10)]

for i in range(n-2):
    if len(firsts) == 10:
        break
    first =  s[i]
    if first in firsts:
        continue
    firsts.append(first)
    for j in range(i+1,n-1):
        if len(firsts_seconds[int(first)]) == 10:
            break
        second = s[j]
        first_second = first + second
        if first_second in firsts_seconds[int(first)]:
            continue
        firsts_seconds[int(first)].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:
def judge(candidate,S):
    for i in range(0,len(S)):
        if(S[i]==candidate[0]):
            for j in range(i+1,len(S)):
                if(S[j]==candidate[1]):
                    for k in range(j+1,len(S)):
                        if(S[k]==candidate[2]):
                            return 1
                        elif(S[k]==S[j]):
                            j=k
                elif(S[j]==S[i]):
                    i=j  
    return 0
def main():
    count=0
    N=int(input())
    S=input()
    number=[]
    for i in S:
     if int(i) not in number:
        number.append(int(i))
    number_list=[]
    max_number=max(number)
    for i in number:
        for j in number:
            for k in number:
                number_list.append(str(i)+str(j)+str(k))

    for i in number_list:
        count+=judge(i,S)
    print(count)

main()

Submission status: Time Limit Exceeded

Solution code:
input()
ns = [n for n in input()]
 
answers = []
first = []
second = []
third = []
third_nums = None
 
for i in range(len(ns) - 2):
  if i in first:
    continue
  else:
    first.append(i)
  for j in range(i+1, len(ns) - 1):
    if ''.join([ns[i], ns[j]]) in second:
      continue
    else:
      second.append(''.join([ns[i], ns[j]]))
      third_nums = set(ns[j+1:])
      for k in third_nums:
        answers.append(''.join([ns[i], ns[j], k]))
print(len(set(answers)))

Submission status: Time Limit Exceeded

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

comb_list = []
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            comb_list.append('{}{}{}'.format(S[i], S[j], S[k]))

comb_list = set(comb_list)
print(len(comb_list))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
dicts=[]
ans=0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            s2=int(S[i]+S[j])
            if s2 in dicts:
                continue
            else:
                dicts.append(s2)
                ans+=len(set(S[k:]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
import numpy as np
flagbox = np.zeros(1000).reshape(10,10,10)
flagtable = np.zeros(100).reshape(10,10)
flaglist = np.zeros(10)
# flagbox = [[[0]*10 for _ in range(10)] for _ in range(10)]
# flagtable = [[0]*10 for _ in range(10)]
# flaglist = [0]*10
for s in S:
    ss = int(s)
    for i in range(10):
        for j in range(10):
            if flagtable[i][j] == 1:
                flagbox[i][j][ss] = 1

    for i in range(10):
        if flaglist[i] == 1:
            flagtable[i][ss] = 1

    if flaglist[ss] == 0:
        flaglist[ss] = 1

# print sum of flagbox
print(int(np.sum(flagbox)))