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

D=[0]*100
C=0
W=[0]*10
R=len(set(S))**3
u=0
for i in range(N-2):
    if(C==R):
        break
    if(W[int(S[i])]<10):
        u=len(set(S[i+1:N]))
        for j in range(i+1,N-1):
            if(W[int(S[i])]==u):
                break
            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:
N = int(input())
S = input()

L = []
flag1 = [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):
        for k in range(j+1, N):
            L.append(S[i] + S[j] + S[k])

print(len(set(L)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
a = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
cnt = 0
tmp_i = -1
tmp_j = -1
for num in a:
    for i in range(N):
        if S[i]==num[0]:
            tmp_i = i
            break
    if tmp_i == -1:
        continue
    for j in range(N-1,-1,-1):
        if S[j]==num[2]:
            tmp_j = j
            break
    if tmp_j == -1:
        tmp_i = -1
        continue
    if tmp_i+1<tmp_j:
        if num[1] in S[tmp_i+1:tmp_j]:
            cnt+=1
    tmp_i = -1
    tmp_j = -1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import copy

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

group = set()
for balls in itertools.combinations(list(range(n)), n-3):
    # print(balls)
    tmp = copy.copy(s)
    for i in balls:
        # print(i)
        tmp[i] = None
    tmp = [x for x in tmp if x]
    tmp = ''.join(tmp)
    group.add(tmp)


print(len(group))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input()
anslist = []
for i in range(n-2):
  for j in range(n-1):
    for k in range(n):
      if not i<j<k:
        continue
      if not a[i]+a[j]+a[k] in anslist:
        anslist.append(a[i]+a[j]+a[k])
print(len(anslist))

Submission status: Time Limit Exceeded

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

List = []
List.append(S[0:3])
for i in range(3,N):
    cnt = 0
    List0 = copy.copy(List)
    for s in List0:
        for j in range(len(s)):
            if s[0:j]+s[j+1:N]+S[i] not in List:
                List.append(s[0:j]+s[j+1:N]+S[i])

print(len(List))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
i = 1
cnt = 0
while i < len(S):
    if S[i-1] == S[i]:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 4:
        S.pop(i)
    else:
        i += 1
#print(S)
pin = [0] * 1000
for i in range(len(S) - 2):
    for j in range(i + 1 , len(S) - 1):
        for k in range(j + 1 , len(S)):
            now = S[i] + S[j] + S[k]
            pin[int(now)] = 1
            if all(pin):
                print(sum(pin))
                exit()
print(sum(pin))

Submission status: Time Limit Exceeded

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

# 集合を使う
shugo = set()
for i in range(N - 2):
    for j in range(i+1, N -1):
        for k in range(j + 1, N):
            shugo.add(S[i] + S[j] + S[k])
print(len(shugo))

Submission status: Time Limit Exceeded

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

set_ = set()

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

print(len(set_))

Submission status: Time Limit Exceeded

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

import itertools as it
import numpy as np
x = list(it.combinations(list(S), 3))
y = ["".join(i) for i in x]
z = len(np.unique(y))
print(z)

Submission status: Time Limit Exceeded

Solution code:

from collections import defaultdict

answers = defaultdict(set)

n = int(input())
str_s = input()

candidates = set()

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


print(sum(list(map(len, answers.values()))))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

S = list(S)

ans = 0
S12 = []
for i in range(n-2):
    for j in range(i+1, n-1):
        if len(S12) == 100:
            break
        if S[i]+S[j] not in S12:
            S12.append(S[i]+S[j])
            ans += len(set(S[j+1:]))

print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
S = input().rstrip()

s = set()

a = set()
b = set()
c = set()

for i in range(0, N-2):
    if i in a:
        continue
    a.add(i)
    for j in range(i+1, N-1):
        # if j in b:
        #     continue
        # b.add(j)
        for k in range(j+1, N):
            # if k in c:
            #     continue
            # c.add(k)
            s.add(S[i]+S[j]+S[k])

print(len(s))

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):
  for n3 in range(10):
   cond=0 
   for i in range(N-2):
     if cond==1:
      break
     if n1==int(S[i]):
       for j in range(i+1,N-1):
         if cond==1:
          break
         if n2==int(S[j]):
          for k in range(j+1,N):
           if n3==int(S[k]):
             count+=1
             cond=1
             break
              
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = tuple(map(int, input()))
a = tuple(set(itertools.combinations(s, 3)))
ans = len(a)
print(ans)

Submission status: Time Limit Exceeded

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

seen = [False] * 10

ans = 0
for i in range(n - 2):
    if seen[int(s[i])]:
        continue

    tmp = set()
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            tmp.add(s[j] + s[k])
    ans += len(tmp)
    seen[int(s[i])] = True

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(raw_input())
S = raw_input()

ans_list = [" "]

for num in range(1000):
    cha3 = str(num%10)
    cha2 = str((num%100 - num%10)/10)
    cha1 = str(num/100)


    for i in range(N):
        if S[i] == cha1:
            for j in range(i+1, N):
                if S[j] == cha2:
                    for k in range(j+1,N):
                        if S[k] == cha3:
                            string = cha1+cha2+cha3
                            ans_list.append(string)
                            break

print len(collections.Counter(ans_list))-1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans_li = []
for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            ans_li.append(s[i]+s[j]+s[k])

ans = len(set(ans_li))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
input = sys.stdin.readline
N = int(input())
S = input()
A = []
for i in range(10):
    A.append(str(i))

X = []
for i in itertools.product(A, repeat=3):
    X.append("".join(i))

cnt = 0
t = 0
for x in X:
    for i in range(N):
        if t == 3:
            cnt += 1
            t = 0
            break
        elif x[t] == S[i]:
            t += 1
    else:
        if t == 3:
            cnt += 1
        t = 0

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

res = {
    '0': [],
    '1': [],
    '2': [],
    '3': [],
    '4': [],
    '5': [],
    '6': [],
    '7': [],
    '8': [],
    '9': [],
}

for i in range(0, N - 2):
    c = S[i]
    cmb = list(combinations(S[i+1:], 2))
    res[c].extend(cmb)

ans = 0
for c in ['0','1','2','3','4','5','6','7','8','9']:
    ans += len(set(res[c]))

print(ans)

Submission status: Time Limit Exceeded

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

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

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 history.get((S[i], S[j],)):
            ans += len(kinds[j+1])
            history[(S[i], S[j],)] = 1

print(ans)

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(''.join([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 = input()

result = set()

for i1 in range(N):
    for i2 in range(i1+1, N):
        for i3 in range(i2+1, N):
            result.add(S[i1] + S[i2] + S[i3])
            if len(result) >= 10**3:
                print(10**3)

print(len(result))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import itertools


def solve(*args: str) -> str:
    n = int(args[0])
    s = args[1]
    ret = len(set(''.join(c) for c in itertools.combinations(s, 3)))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
seq = list(input())
# print(seq)

import itertools
combination = list(itertools.combinations(seq, 3))

print(len(set(combination)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import copy

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

group = []
for balls in itertools.combinations(list(range(n)), n-3):
    # print(balls)
    tmp = copy.copy(s)
    for i in balls:
        # print(i)
        tmp[i] = None
    tmp = [x for x in tmp if x]
    tmp = ''.join(tmp)
    group.append(tmp)


print(len(set(group)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections
import copy
def a_index(a,b):
  if b in a:
    return a.index(b)
  else:
    return -1
m=0
n=int(input())
s=list(input())
s=list(map(int,s))
c=collections.Counter(s)
for i in range(10):
  ss=copy.deepcopy(s)
  if a_index(s,i)!=-1:
    del ss[:a_index(s,i)+1]
    for k in range(10):
      sss=copy.deepcopy(ss)
      if a_index(ss,k)!=-1:
        del sss[:a_index(sss,k)+1]
        m=m+len(list(set(sss)))
print(m)

Submission status: Time Limit Exceeded

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

ans = []
a = ['{:0=3}'.format(i) for i in range(1000)]

for key in a:
    a_loc = 0
    for i in range(N):
        if key[a_loc] == S[i]:
            if a_loc == 2:
                ans.append(key)
                break
            else:
                a_loc += 1
                
print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
l = []
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            l.append(S[i]+S[j]+S[k])
l = list(set(l))
print(len(l))

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):
            if(W[int(S[i])]==10):
                break
            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:
N = int(input())
S = input()
total = 0

count = [0]*10
for i in range(N):
    count[int(S[i])] += 1

for i in range(1000):
    first = i//100
    second = (i-first*100)//10
    third = i-first*100-second*10
    count_i = [0]*10
    count_i[first] += 1
    count_i[second] += 1
    count_i[third] += 1
    if count_i[first] > count[first] or count_i[second] > count[second] or count_i[third] > count[third]:
        continue
    d_f = str(first)
    d_s = str(second)
    d_t = str(third)
    flag=0
    for j in range(N):
        if flag==0:
            if S[j]==d_f:
                flag=1
        elif flag==1:
            if S[j]==d_s:
                flag=2
        else:
            if S[j]==d_t:
                total += 1
                break
    if total==1000:
        break
print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
en = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
T = 0
U = [[] for i in range(10)]
for i in range(1, N - 1):
  for j in range(10):
    if S[i] == en[j]:
      U[j].append(i)
k1, k2 = 0, 0
for k in range(10):
  for l in range(len(U[k])):
    p, q = [0 for i in range(10)], [0 for i in range(10)]
    for m in range(U[k][l]):
      for z in range(10):
        if S[m] == en[z]:
          p[z] = 1
    k1 = sum(p)
    for m in range(U[k][l] + 1, N):
      for z in range(10):
        if S[m] == en[z]:
          q[z] = 1
    l1 = sum(q)
    T += ((k1 - k2) * l1)
    k2 = k1
  k1, k2 = 0, 0
print(T)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans_list = {}

for i in range(N):
    for j in range(i+1, N):
        if not S[j + 1:N] or S[i] + S[j] in S_set:
            continue
        ans_list[S[i] + S[j]] = S[j + 1:N]
        S_set.add(S[i] + S[j])
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()
a=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if s[i]+s[j]+s[k] not in a:
                a.append(s[i]+s[j]+s[k])

print(len(a))

Submission status: Time Limit Exceeded

Solution code:
# your code goes here
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:
import itertools
import copy

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

group = []
for balls in itertools.combinations(list(range(n)), n-3):
    # print(balls)
    tmp = copy.copy(s)
    for i in balls:
        # print(i)
        tmp[i] = None
    tmp = [x for x in tmp if x]
    if tmp not in group:
        group.append(tmp)

print(len(group))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
A=[]
for i in range(1,N-1):
  a=list(set(S[0:i]))
  b=len(a)
  c=list(set(S[i+1:N]))
  d=len(c)
  for j in range(b):
    for k in range(d):
      A.append(a[j]+S[i]+c[k])
print(len(set(A)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
S=str(s)
A = set([])
ans = 0
for i in range(n-2):
  for j in range(i+1, n-1):

    x = int(S[i])
    y = int(S[j])

    if not((10*x+y) in A):
      A.add(10*x+y)
      ans += len(set(list(S[j+1::])))
print(ans)

Submission status: Time Limit Exceeded

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

hoge = []
for i, v in enumerate(s):
    for j , v2 in enumerate(s):
        for k , v3 in enumerate(s):
            if i < j and j < k:
                hoge.append(str(v) + str(v2) + str(v3))

hoge2 = list(set(hoge))
print(len(hoge2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

result = set()

for i1 in range(N):
    for i2 in range(i1+1, N):
        for i3 in range(i2+1, N):
            result.add(S[i1] + S[i2] + S[i3])

print(len(result))

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):
    s1 = str(i1) + "+[0-9]*"
    for i2 in range(10):
        s2 = str(i2) + "+[0-9]*" 
        for i3 in range(10):
            pt = s1 + s2 + 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:
import math

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

ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            index_i = [l for l, x in enumerate(S) if x == str(i)]
            index_j = [l for l, x in enumerate(S) if x == str(j)]
            index_k = [l for l, x in enumerate(S) if x == str(k)]
            k_list = []

            if len(index_i) != 0:
                j_list = [m for m in index_j if m > index_i[0]]

                if len(j_list) != 0:
                    k_list = [m for m in index_k if m > j_list[0]]

                if len(k_list) != 0: ans += 1


            

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy as cp
N = int(input())
S = input()
total = 0

feasible = {int(S[:3])}
for j in range(3,N):
    new_feasible = cp.copy(feasible)
    for elem in feasible:
        d1 = elem//100
        d2 = (elem-d1*100)//10
        d3 = elem-d1*100-d2*10
        
        k = d1*100+d2*10+int(S[j])
        new_feasible.add(k)
        
        k = d1*100+d3*10+int(S[j])
        new_feasible.add(k)
        
        k = d2*100+d3*10+int(S[j])
        new_feasible.add(k)

    feasible = new_feasible

print(len(feasible))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
l = [int(x) for x in list(S)]
result = []
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        for k in range(j + 1, len(l)):
            if [l[i], l[j], l[k]] in result:
                pass
            else:
                result.append([l[i], l[j], l[k]])
print(len(result))

Submission status: Time Limit Exceeded

Solution code:
import itertools
num = int(input())
num_list = [int(item) for item in input()]

res_list = itertools.combinations(num_list,3)

print(len((set(res_list))))

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

Submission status: Time Limit Exceeded

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

a = N - 3

s = set()
for i in range(0, N - 2):
    s1 = S[i]
    for j in range(i + 1, N - 1):
        s2 = s1 + S[j]
        for k in range(j + 1, N):
            s3 = s2+S[k]
            s.add(s3)

print(len(s))

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:
from collections import defaultdict

N = int(input())
S = [int(i) for i in list(input())]

answer = defaultdict(int)

for a in range(N-2):
    for b in range(a+1,N-1):
        for c in range(b+1,N):
            num = S[a]*100 + S[b]*10 + S[c]
            answer[num] += 1

print(len(answer))

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

#入力
N=int(input())
A = [int(x) for x in list(input())]
dict = {}

for i,j,k in itertools.combinations(A, 3):
    if(not((i,j,k) in dict)):
        dict[i,j,k]=1
#print(dict)
print(len(dict))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
l = set()
table = [[0 for i in range(10)] for i in range(2)]
for i in range(N-2):
    if table[0][int(S[i])] == 0:
        for j in range(i+1,N-1):
            if table[1][int(S[j])] == 1 and table[0][int(S[i])] == 1:
                continue
            else:
                table[1][int(S[j])] = 1   
                for k in range(j+1,N):
                    l.add(S[i]+S[j]+S[k])
        table[0][int(S[i])] = 1

print(len(l))

Submission status: Time Limit Exceeded

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

resset = set()

for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            temp = ''.join([S[i],S[j],S[k]])
            resset.add(temp)

print(len(resset))

Submission status: Time Limit Exceeded

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

N = int(input())
S = input().rstrip()

s = set()


for i in range(0, N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            s.add(S[i]+S[j]+S[k])

print(len(s))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
seq = list(set(list(s)))
genkai_list = []
for i in range(0,1000):
    if 0 <= i <= 9:
        ap = "00" + str(i)
        genkai_list.append(ap)
    elif 10 <= i <= 99:
        ap = "0" + str(i)
        genkai_list.append(ap)
    else:
        genkai_list.append(str(i))
avcodelist = genkai_list
ans = []
for a in range(len(genkai_list)):
    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:
import itertools
N = int(input()) - 3
S = input()

nums = [i for i in range(len(S))]
comb = list(itertools.combinations(nums, N))
#print(comb)
answers = []
for i in range(len(comb)):
  tmp = list(S)
  comb[i] = sorted(list(comb[i]), reverse=True)
  for j in range(N):
    #print(j, end = " ")
    #print(int(comb[i][j]), end=" ")
    #print(tmp, end=" ")
    tmp.pop(int(comb[i][j]))
    #print(tmp)
  if answers.count(tmp) == 0:
    answers.append(tmp)

print(len(answers))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=str(input())
counter=0
for i in range(1000):
  I=str(i)
  n=len(I)
  if n!=3:
    I=str(0)*(3-n)+I
  p=0
  t=-1
  ANS=1
  k=0
  for j in range(3):
    p=t+1
    while p<N:
      if S[p]==I[j]:
        t=p
        k=k+1
        break
      if p==N-1:
        ANS=0
        break
      p=p+1
    if ANS==0:
      break
    
  if ANS!=0 and k==3:
      counter+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
MAX_N = 30000
n = int(input())
s = [ x for x in list(input())]

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

Submission status: Time Limit Exceeded

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

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:
n= int(input())
s=input()
a=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a.append(s[i]+s[j]+s[k])

print(len(set(a)))

Submission status: Time Limit Exceeded

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

for i in range(n-2):
    y=[]
    if x.count(s[i])!=0:
        if len(x)==10:
            break
        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
                        

                
                        
                
        
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n = int(input())
s = input()
c = set()

for sc in combinations(map(int, list(s)), 3):
    c.add(sc)

print(len(c))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list( input("") )
A = list(set(S))
result = []
for i in A:
    for j in range(S.index(i)+1 , N):
        for k in range(j+1, N):
            result.append(i + S[j] + S[k])
c = list(set(result))
print(len(c))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input())
    S = input().rstrip()
    u = len(set(list(S)))
    tmp = set()
    ans = 0
    for index, i in enumerate(range(N - 2)):
        second = set()
        for j in range(index + 1, N - 1):
            if j in second:
                continue
            if S[i] + S[j] not in tmp:
                second.add(j)
                tmp.add(S[i] + S[j])
                ans += len(set(list(S[j + 1:])))
                if len(tmp) == u ** 2:
                    print(ans)
                    quit()
            if len(second) == u:
                break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
s_lis = []
for i in range(len(s)):
    if s[i] not in s_lis:
        s_lis.append(s[i])
s_lis_len = len(s_lis)
del_n = n - 3
ch_n = len(s) - del_n
import itertools
lis = []
cnt = 0
for i in itertools.combinations(s, ch_n):
    if cnt >= s_lis_len ** 3:
        break
    tmp_ch = ''.join(i)
    if tmp_ch not in lis:
        lis.append(tmp_ch)
        cnt += 1
print(len(lis))

Submission status: Time Limit Exceeded

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

cand = []
for i in range(0,N-2,1):
  for j in range(i+1,N-1,1):
    for k in range(j+1,N,1):
      #print(i,j,k)
      num = S[i]+S[j]+S[k]
      #print(num)
      if num not in cand:
        cand.append(num)

print(len(cand))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
import itertools
rows = []
for i in itertools.combinations(S, r=3):
  if i not in rows:
    rows.append(i)
print(len(rows))

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)
                if len(array) >= 1000:
                    array = list(set(array))
                    if len(array) == 999:
                        print("999")
                        return
    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()