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 = list(input())
ans = 0
snumber = [str(i) for i in range(10)]
for i in snumber:
    for j in snumber:
        for k in snumber:
            n = 0
            code = []
            while i != S[n] and n < N-3:
                n += 1
            if S[n] != i:
                break
            n += 1
            while j != S[n] and n < N-2:
                n += 1
            if S[n] != j:
                break
            n += 1
            while k != S[n] and n < N-1:
                n += 1
            if S[n] == k:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import defaultdict as dict
d = dict(int)
 
N = int(input())
S = [int(_) for _ in input()]
s = list(itertools.combinations(S, 3))
 
for j in range(len(s)):
 
    # カウントアップ
    d[s[j]] += 1
 
print(len(d))

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
                        

                
                        
                
        
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

pl = {}
n = int(input())
s = input()
c = 0

for i in range(n):
    pw = s[:i] + s[i+1:]
    com = list(itertools.combinations(pw,3))
    for j in com:
        st = j[0] + j[1] + j[2]
        if st in pl:
            pass
        else :
            pl[st] = "pw"
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import copy

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

ans = set()
count = 0
for i in itertools.combinations(range(len(S)), len(S)-3):
  count = 0
  tmp = copy.copy(S)
  for j in i:
    tmp.pop(j-count)
    count+=1
  ans.add(str(tmp))
print(len(ans))

Submission status: Time Limit Exceeded

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

ans = 0
done_list = []
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_list:
            continue
        else:
            for factor, num in S_factor_temp.items():
                if num > 0:
                    ans += 1
            done_list.append("{}_{}".format(first_num, second_num))
    S_factor["{}".format(first_num)] -= 1
    S_factor_temp = S_factor.copy()

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
i8 = np.int64
i4 = np.int32


def solve(a, N):
    count = 0
    for x1 in range(10):
        for i1 in range(N):
            if a[i1] == x1:
                for x2 in range(10):
                    for i2 in range(i1 + 1, N):
                        if a[i2] == x2:
                            for x3 in range(10):
                                for i3 in range(i2 + 1, N):
                                    if a[i3] == x3:
                                        count += 1
                                        break
                            break
                break
    return count

def main2():
    stdin = open('/dev/stdin')
    N = int(stdin.readline())
    S = stdin.readline()
    a = np.empty(N, i8)
    for i in range(N):
        a[i] = int(S[i])
    print(solve(a, N))


main2()

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)
    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:
N = int(input())
S = input()
L = []
count = 0
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 L:
        L.append(S[i] + S[j] + S[k])
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ss = set()

for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            ss.add(S[i] + S[j] + S[k])
print(len(ss))

Submission status: Time Limit Exceeded

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

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                count = 0
                for l in s:
                    if l == str(k) and count == 2:
                        count += 1
                    if l == str(j) and count == 1:
                        count += 1
                    if l == str(i) and count == 0:
                        count += 1
                if count == 3:
                    c += 1
print(c)

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):
            for m in range(j+1, N):
                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:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
n = int(input())
s = input()
no_dict = {}
count = 0
suuzi_list = []

for i in range(0, 10):
    if str(i) in s:
        suuzi_list.append(1)
    else:
        suuzi_list.append(0)
t = sum(suuzi_list)
stop_count = t * t * t
for i in range(0, n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            no = ''.join([s[i], s[j], s[k]])
            if no not in no_dict:
                no_dict[no] = 1
                count += 1
                if count == stop_count:
                    print(count)
                    sys.exit()
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
LENG = len(S)
Ans = 0
Hflag = 0
Tflag = 0

for L in range(1000):
  sL = str(L)

  if len(sL) == 3:
    H = sL[0]
    T = sL[1]
    O = sL[2]
  elif len(sL) == 2:
    H = '0'
    T = sL[0]
    O = sL[1]
  else:
    H = '0'
    T = '0'
    O = sL[0]
  
  for i in range(LENG):
    if Hflag == 1 and Tflag == 1 and S[i] == O:
      Ans = Ans + 1
      break
    if Hflag == 1 and S[i] == T:
      Tflag = 1
    if S[i] == H:
      Hflag = 1
  
  Hflag = 0
  Tflag = 0

print(Ans)

Submission status: Time Limit Exceeded

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

perm = combinations([int(i) for i in S], 3)
myset = set(perm)

print(len(myset))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

input = sys.stdin.readline


def main():
    # 種類
    N = int(input())
    S = input().strip()
    print(len(set(combinations(S, 3))))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
d = {}
def subsets(n,s,sc,q):

	if sc == n and len(q)==3:
		print(q)
		s = ''.join(q)
		if s not in d:
			d[s] = 1
		else:
			d[s]+=1
		return 
	if sc>=n:
		return 

	q.append(s[sc])
	subsets(n,s,sc+1,q)

	q.pop()
	subsets(n,s,sc+1,q)

def solve(n,s):
	mp = {}
	for i in range(n-2):
		for j in range(i+1,n-1):
			for k in range(j+1,n):
				temp = s[i]+s[j]+s[k]
				if temp in mp:
					mp[temp]+=1
				else:
					mp[temp]=1
	return len(mp)
n = int(input())
s = input()
# subsets(n,s,0,[])
# for k,v in zip(d.keys(),d.values()):
# 	print(k,v)
print(solve(n,s))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
info=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            info.append(str(i)+str(j)+str(k))
ans=0
kind=0
while kind<=999:
    point=0
    for i in range(n):
        if point==0:  
            if info[kind][0]==s[i]:
                point+=1
                continue
        if point==1:
            if info[kind][1]==s[i]:
                point+=1
                continue
        if point==2:
            if info[kind][2]==s[i]:
                point+=1
                break
    if point==3:
        ans+=1
        #print(info[kind])
    kind+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
input()
S=list(input())
ans=0

for i in range(1000):
    Si=0
    s=list(str(i).zfill(3))
    si=0
    while(Si<len(S)):
        if S[Si] == s[si]:
            si+=1
            if si > 2:
                ans+=1
                break
            Si += 1
            continue
        Si+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = [[set() for j in range(10)] for i in range(10)]
l = set()
for i in range(1, len(s) - 1):
    t = s[i]
    l.add(s[i-1])
    r = set(s[i+1:])
    for j in l:
        a[t][j] |= r

ans = 0
for b in a:
    for c in b:
        ans += len(c)
print(ans)

Submission status: Time Limit Exceeded

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

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 sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

count = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      pas = (str(i),str(j),str(k))
      key = 0
      for c in S:
        if c == pas[key]:
          key += 1
          if key ==3:
            count +=1
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for i in range(n):
    pw = s[:i] + s[i+1:]
    com = list(itertools.combinations(pw,3))
    for j in com:
        st = j[0] + j[1] + j[2]
        if st in pl:
            pass
        else :
            pl.add(st)
            c += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
seq = list(input())
L = list(itertools.combinations(seq,3))
for i in range(len(L)):
  L[i] = ''.join(L[i])
  
print(len(set(L)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
l=[]#要素を入れておくリスト

def next_comb(sub):
  x=sub & -sub
  y=sub + x
  return (((sub & ~y)//x)>>1) | y

bit=(1<<3)-1
while(bit<(1<<n)):#要素数3のもののみ列挙
    a=[]
    for j in range(n):
      if bit>>j & 1:
        a.append(s[j])
    l.append(str(a))
    bit=next_comb(bit)

ll=set(l)#重複要素排除(set化)・リスト化
print(len(ll))

Submission status: Time Limit Exceeded

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

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      num.add(S[i]+S[j]+S[k])

print(len(num))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = 0
number = set(S)
snumber = list(number)
for i in snumber:
    for j in snumber:
        for k in snumber:
            n = 0
            code = []
            while i != S[n] and n < N-3:
                n += 1
            code.append(S[n])
            n += 1
            while j != S[n] and n < N-2:
                n += 1
            code.append(S[n])
            n += 1
            while k != S[n] and n < N-1:
                n += 1
            code.append(S[n])
            if code[0] == i and code[1] == j and code[2] == k:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

keySet = set()

for i in range(N - 2):
    m1 = S[i]
    for j in range(1, N - 1):
        if (j > i):
            m2 = S[j]
            for k in range(2, N):
                if (k > j):
                    m = m1 + m2 + S[k]
                    if (m not in keySet):
                        keySet.add(m)

print(len(keySet))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = input()
c = set()
for n in itertools.combinations(s, 3):
  c.add(n)
print(len(c))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools

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

count = 0
#for v in itertools.permutations(S, 3):
exist = []
for v in itertools.combinations(S, 3):
    if(v in exist):
        continue
    else:
        exist.append(v)
        count +=1


print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

L=list(itertools.combinations(S,3)) #3つ選ぶ組み合わせ列挙


print(len(set(L)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

numbers = set()

def exists(i, j, k, s):
  i_exists = False
  j_exists = False

  for ss in s:
    if i_exists == False and i == ss:
      i_exists = True
    elif j_exists == False and j == ss and i_exists:
      j_exists = True
    elif k == ss and i_exists and j_exists:
      return True
  return False

for i in range(0, 10):
  for j in range(0, 10):
    for k in range(0, 10):
      if exists(i, j, k, s):
        numbers.add(str(i) + str(j) + str(k))

# print(numbers)
print(len(numbers))

Submission status: Time Limit Exceeded

Solution code:

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

tree_1=[]
tree_2=[]
tree_3=[]

for i in range(0,N):
    for e2 in tree_2:
        if len(tree_3)!=0:
            if (e2+S[i] in tree_3)!=True:
                tree_3.append(e2+S[i])
        else:
            tree_3.append(e2+S[i])
    for e1 in tree_1:
        if len(tree_2)!=0:
            if (e1+S[i] in tree_2)!=True:
                tree_2.append(e1+S[i])
        else:
            tree_2.append(e1+S[i])
    if len(tree_1)!=0:
        if (S[i] in tree_1)!=True:
            tree_1.append(S[i])
    else:
        tree_1.append(S[i])
print(len(tree_3))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
PIN=[]
ans=0
#パスコード000~999まで、Sに含まれるか判定
for i in range(N):
    Ein=S[i]
    for j in range(i+1,N):
        Zwei=S[j]
        for k in range(j+1,N):
            Drei=S[k]
            cand=Ein+Zwei+Drei
            if cand in PIN:
                continue
            else:
                PIN.append(cand)
    
print(len(PIN))

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
S = list(map(int, input()))
dic = dict()

ans = 0

for i in range(N - 2):
	for j in range(i + 1, N - 1):
		if not (S[i], S[j]) in dic:
			dic[(S[i], S[j])] = 1
			ans += len(collections.Counter(S[j + 1:]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def main():
  N = int(input())
  S = list(input())
  ls = []
  
  for v in itertools.combinations(S, 3):
    ls.append(v)
  
  print(len(set(ls)))
  
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
S = input()
list = [i for i in S]
anslist = []
for i in range(len(S)):
    s_i = list[i]
    for j in range(i+1,len(S)):
        s_j = list[j]
        for k in range(j+1,len(S)):
            s = s_i + s_j + S[k]
            anslist.append(s)


print(len(set(anslist)))

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
s = input()

l = []
ans=0
for i in itertools.combinations(s,3):
    if not i in l:
        ans+=1
        l.append(i)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import defaultdict as dict
d = dict(int)

N = int(input())
S = [int(_) for _ in input()]
s = list(itertools.combinations(S, 3))

for j in range(len(s)):

    # カウントアップ
    d[s[j]] += 1

print(len(d))

Submission status: Time Limit Exceeded

Solution code:
import sys
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = [i for i in S()]
#print(s)

a = [-1 for i in range(N)]
v = []
n = 0
for i in range(N)[::-1]:
  if s[i] not in v:
    v.append(s[i])
    n += 1
  a[i] = n

finished = [[-1]*10 for i in range(10)]
ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    if finished[int(s[i])][int(s[j])] == True:
      continue
    else:
      ans += a[j + 1]
    finished[int(s[i])][int(s[j])] = True
print(ans)

Submission status: Time Limit Exceeded

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


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

    for k in second:
        ans += len(set(list(S[k+1:])))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = list(input())


al = set()

dp = [[[0 for k in range(10)] for i in range(10)] for j in range(10)]
co = 1
kkk = a[0]+a[1]+a[2]
dp[int(a[0])][int(a[1])][int(a[2])] = 1
al.add(kkk)
for i in range(3,n):
    j = int(a[i])
    ap = []
    for ppp in al:
        aaa = ppp
        m,mm,mmm = int(aaa[0]),int(aaa[1]),int(aaa[2])
        if not dp[m][mm][j]:
            dp[m][mm][j] = 1
            co += 1
            ap.append(str(m)+str(mm)+str(j))
        if not dp[m][mmm][j]:
            dp[m][mmm][j] = 1
            co += 1
            ap.append(str(m)+str(mmm)+str(j))
        if not dp[mm][mmm][j]:
            dp[mm][mmm][j] = 1
            co += 1
            ap.append(str(mm)+str(mmm)+str(j))
            
    for j in ap:
        al.add(j)

print(co)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Answer_dict = {}

for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      Answer_dict[S[i]+S[j]+S[k]] = 1

print(len(Answer_dict))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

set = set()

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

print(len(set))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = input()
len_S = len(S)

key_list = []

for a in range(len_S - 2):
    for b in range(a+1, len_S-1):
        for c in range(b+1, len_S):
            key = S[a] + S[b] + S[c]
            if key not in key_list:
                key_list.append(key)

print(len(key_list))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    s=input()
    S=[int(x) for x in list(s)]
    Pass=[0]*1000
    z=S[0]*100+S[1]*10+S[2]
    Pass[z]=1
    for k in S[3:]:
        s=set()
        for p in range(1000):
            p1,p2,p3=p//100,(p//10)%10,p%10
            if Pass[p]==1:
                s.add(p2*100+p3*10+k)
                s.add(p1*100+p3*10+k)
                s.add(p1*100+p2*10+k)
        for k in s:
            Pass[k]=1
    print(sum(Pass))
    
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(n-2):
    first =  s[i]
    for j in range(i+1,n-1):
        second = s[j]
        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 main():
    N = int(input())
    S = input()

    code_pattern = set()

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

    print(len(code_pattern))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(map(str, input()))
num = [i for i in range(n)]
st = set()
for ll in list(itertools.combinations(s, r=3)):
  nn = ''.join(ll)
  st.add(nn)

print(len(st))

Submission status: Time Limit Exceeded

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

a = [[set() for j in range(10)] for i in range(10)]
for i in range(1, len(s) - 1):
    t = s[i]
    l = set(s[i+1:])
    for j in set(s[:i]):
        a[t][j] |= l

ans = 0
for b in a:
    for c in b:
        ans += len(c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(1000000)

n = input()
s = input()

a = set()

def do(a,s,t):
    if len(t)==0:
        return a
    if len(s) == 2:
        return do(a,s,t[1:]) | {s + t[0]}
    else:
        return do(a,s,t[1:]) | do(a,s+t[0],t[1:])

print(len(do(a,"",s)))

Submission status: Time Limit Exceeded

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

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

# 上限は1000
N = ri()
S = list(rs())
answer = set()

for i in range(len(S)-2):
    se2 = set()
    for j in range(i+1, len(S)-1):
        if j in se2:
            continue
        se2.add(j)
        se = set(S[j+1:])
        x = S[i]
        y = S[j]
        for z in se:
            answer.add((x, y, z))

print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = 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]] = set(S[j + 1:N])
        else:
            ans_list[S[i] + S[j]] | set(S[j+1:N])
count = 0
# print(ans_list)
ans_len_list = [len(value) for value in ans_list.values()]
print(sum(ans_len_list))

Submission status: Time Limit Exceeded

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

def print_ans(N, S):
    """Test Case
    >>> print_ans(4, "0224")
    3
    >>> print_ans(6, "123123")
    17
    >>> print_ans(19, "3141592653589793238")
    329
    """
    s = set()
    for i in range(N):
        for k in range(i+1,N):
            for l in range(k+1, N):
                s.add(S[i] + S[k] + S[l])
    print(len(s))



    
if __name__ == '__main__':
    N = int(input().rstrip())
    S = input().rstrip()
    print_ans(N, S)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
S = input()
if N > 30000 or N < 4:
    exit()
if len(S) > N:
    exit()

intlist = [str(i) for i in str(S)]

perm = combinations([int(i) for i in S], 3)

myset = set()

for i in list(perm):
    myset.add(i)

print(len(myset))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

Li=[]
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      Li+=[s[i]+s[j]+s[k]]

a=[]
for i in Li:
  if i not in a:
    a+=[i]

print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
h = {}
for i in range(n):
    a = s[i]
    for j in range(n):
        if i == j:
            break
        b = s[j]
        for k in range(n):
            if j == k:
                break
            c = s[k]
            h[a + b + c] = 1
print(len(h))

Submission status: Time Limit Exceeded

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

memo = [0]*1000
counter = 0

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

Submission status: Time Limit Exceeded

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

tmp = []
dada = ""
for i in range(N - 2):
    first = S[i]
    # print(i)
    for j in range(i + 1, N - 1):
        second = first + S[j]
        # print("\t" + str(j))
        for k in range(j + 1, N):
            third = second + S[k]
            # print("\t\t" + str(k))
            # print(third)
            if third not in tmp:
                tmp.append(third)
# print(tmp)
print(len(tmp))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    print(len(tmp_set))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    input()
    s=input()
    print(len(set(itertools.combinations(s,3))))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
s = input()
no_dict = {}
count = 0
for i in range(0, n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            no = ''.join([s[i], s[j], s[k]])
            if no not in no_dict:
                no_dict[no] = 1
                count += 1

print(count)