Problem:


Score: 400 points

Problem Statement

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

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

How many different PIN codes can he set this way?

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

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

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

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

print(len(pl))

Submission status: Time Limit Exceeded

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

L=[0]*1000
D={}

for i in range(N-2):
    for j in range(i+1,N-1):
        s=str(S[i])+str(S[j])
        if(D.get(int(s),None)==None):
            D[int(s)]=1
            for k in range(j+1,N):
                t=str(S[i])+str(S[j])+str(S[k])
                L[int(t)]=1
print(sum(L))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = list(input())
ls = []

for v in itertools.combinations(S, 3):
  ls.append(v)
  
print(len(set(ls)))

Submission status: Time Limit Exceeded

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

n = int(n)

ans = []
counts = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):

        if s[i] + s[j] in ans:
            continue
        else:
            counts += len(set(s[j + 1: n]))
            ans.append(s[i] + s[j])

        # for k in range(j + 1, n):
        #     ans.append(s[i] + s[j] + s[k])

# ans = list(set(ans))
print(counts)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools as it

n = int(input())
d = n - 3
s = input()
s = list(s)

c = list(it.combinations(s, 3))
print(len(set(c)))

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = input()
num_id = [x for x in range(len(s))]
A = list(combinations(num_id, 3))
B = [s[x[0]] + s[x[1]] + s[x[2]] for x in A]
print(len(set(B)))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
# n=19
# s=list(str(3141592653589793238))
a=[0]*1000
s=[int(i) for i in s]
res=[0,0,0]
#print(s)
for i in range(0,n-2):
    b=100*s[i]
    for j in range(i+1,n-1):
        b2=b+10*s[j]
        for k in range(j+1,n):
            b3=b2+s[k]-1
            if a[b3]!=1:
                a[b3]+=1
print(sum(a))

Submission status: Time Limit Exceeded

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

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 = input()
 
ans = set()
 
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            ans.add(S[i] + S[j] + S[k])
 
print(len(ans))

Submission status: Time Limit Exceeded

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

for i in range(2 ** n):#bit全探索
    a=[]
    for j in range(n):
      if i>>j & 1:
        a.append(s[j])
    if len(a)==3:#3桁になっているとき
      l.append(str(a))

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

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(N - 1):
        if (j > i):
            m2 = S[j]
            for k in range(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:
n = int(input())
s = input()
secret = []
for i in range(n-2):
        for j in range(i + 1, n - 1): 
                for k in range(j + 1, n): 
                        secret.append(int(s[i] + s[j] + s[k]))
print(len(set(secret)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

c = set()

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

print(len(c))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = input()
comb = list(itertools.combinations(list(range(N)),3))
ans = []
for i in comb:
    pw = []
    for j in range(len(comb[0])):
        pw.append(S[i[j]])
    pw = "".join(pw)
    if pw not in ans:
        ans.append(pw)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=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]+s[j]+s[k])
print(len(set(ans)))

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 = []
for i in range(N)[::-1]:
  v.append(s[i])
  v = list(set(v))
  a[i] = len(v)

finished = []
t = ""
ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    t = str(s[i]) + str(s[j])
    if t in finished:
      continue
    else:
      ans += a[j + 1]
    finished.append(t)
print(ans)

Submission status: Time Limit Exceeded

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

dic_ = {}

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

ans = [False]*1000

def get_first_pos(i, k):
    if dic_.get(str(i)) is not None:
        for x in dic_[str(i)]:
            if x > k:
                return x
    return None

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

Submission status: Time Limit Exceeded

Solution code:
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():
    n=ii()
    s=input()
    print(len(set(itertools.combinations(s,3))))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

ans=[]

for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      koho=s[i]+s[j]+s[k]
      if not koho in ans:
        ans.append(koho)

print(len(ans))
#print(ans)

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 = input()
cnt = 0
all_set = set()
for i in range(1,N-1):
    before_set = set(S[:i])
    after_set = set(S[i+1:])
    for j in before_set:
        for k in after_set:
            all_set.add(j+S[i]+k)
print(len(all_set))

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):
    for j in range(i+1, len(S)-1):
        se = set(S[j+1:])
        for x in se:
            answer.add((S[i], S[j], x))
        #print(i, j, len(answer))

print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
words = lambda t : list(map(t, input().split()))
n = int(input())
a = input()

d = {}
for i in range(n-2):
    nums = [0]*10
    for j in range(i+2,n):
        nums[int(a[j-1])] += 1
        #print(i,j, nums)
        for k in range(10):
            if nums[k] > 0:
                d[int(a[i])*100 + k*10 + int(a[j])] = 1
        #print(d)

print(len(d))

Submission status: Time Limit Exceeded

Solution code:
import collections


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

    d = collections.defaultdict(int)
    for a in range(N):
        for b in range(a + 1, N):
            for c in range(b + 1, N):
                k = (S[a], S[b], S[c])
                d[k] += 1

    print(len(d.keys()))

main()

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):
            pin_left = i
            pin_middle = j
            pin_right = k
            index = 0
            flg1 = False
            flg2 = False
            for l in range(len(S)):
                if int(S[l]) == i:
                    index = l+1
                    flg1 = True
                    break
            if flg1 == True:
                for l in range(index,len(S)):
                    if int(S[l]) ==  j:
                        index = l+1
                        flg2 = True
                        break
            if flg2 == True:
                for l in range(index,len(S)):
                    if int(S[l]) ==  k:
                        ans += 1
                        break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

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

    ndelete = N - 3
    ndigits = len(S) - ndelete

    indice = np.array(list(itertools.combinations(np.arange(len(S)),3)))

    S_ary = np.array(list(S) * len(indice))
    #print(np.array(indice))
    #print(S_ary.shape)
    #print(indice.shape)
    indice = S_ary[np.array(indice)]
    #print(indice)
    ans = ["".join(elem) for elem in indice]
    #print(ans)
    ans = len(set(list(ans)))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#D
N=int(input())
S=str(input())
password_list=[]
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      password_list += [S[i]+S[j]+S[k]]
answer=len(list(set(password_list)))
print(answer)

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
    """
    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:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = count = 0; pro = 1

n=int(input())
s=list(map(int,input()))
S=set()
checked=[0]*10
# print(s)
# print(checked)
for i in range(n):
    # print(s,3456)
    # print(s[i])
    # print(checked[0])
    if not checked[s[i]]:

        C=[[0]*10 for h in range(10)]
        past=[0]*10
        for j in range(i+1,n):

            for k in range(10):
                if past[k] and C[k][s[j]]==0:
                    C[k][s[j]]+=1
            past[s[j]]=1
        for l in range(10):
            for t in range(10):
                if C[l][t]:
                    S.add(str(s[i])+str(l)+str(t))
        # for r in C:
        #     print(r)
# print(S)
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
p = {s}
for i in range(len(s)-3):
    np = set()
    for x in p:
        for j in range(len(x)):
            np.add(x[:j] + x[j+1:])
    p = np
print(len(p))

Submission status: Time Limit Exceeded

Solution code:
input()
ns = [n for n in input()]

answers = []

for i in range(len(ns) - 2):
  for j in range(i+1, len(ns) - 1):
    for k in range(j+1, len(ns)):
      answers.append(''.join([ns[i], ns[j], ns[k]]))
print(len(set(answers)))

Submission status: Time Limit Exceeded

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

Set=[]

for i in range(2 ** n):
    select = []
    total = 0
    for j in range(n): 
        if ((i >> j) & 1): 
            select.append(S[j])  # フラグが立っていたらselect
            total += 1 
    if (total == 3):
        Set.append(''.join(select))

print(len(set(Set)))

Submission status: Time Limit Exceeded

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

s = []
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            c = S[i] + S[j] + S[k]
            if c in s:
                continue
            else:
                s.append(c)

print(len(s))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
S = input()
length = len(S)
l = list()
for n in range(length-2):
    for m in range(n+1,length):
        for k in range(m+1, length):
            s = S[n]+S[m]+S[k]
            l.append(s)
print(len(np.unique(l)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
ans=[]
for i in range(len(S)):
  for j in range(i+1,len(S)):
    for k in range(j+1,len(S)):
      #print(i,j,k)
      ans.append(S[i]+S[j]+S[k])
     # if not S[i]+S[j]+S[k] in ans.keys():
        #ans[S[i]+S[j]+S[k]]=1
#print(len(ans.keys()))
print(len(set(ans)))
#print(set(ans))

Submission status: Time Limit Exceeded

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

memo = [False for _ in range(100)]
ans = 0
f = False
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    if memo[int(S[i]) * 10 + int(S[j])]:
      continue
    ans += len(set(S[j + 1 :]))
    memo[int(S[i]) * 10 + int(S[j])] = True
    if ans == 999:
      f = True
      break
  if f:
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
list1 = []
cnt = 0
for x in range(len(S)):
  for y in range(x+1, len(S)):
    for z in range(y+1, len(S)):
      if (S[x]+S[y]+S[z] in list1) == False:
        cnt += 1
        list1.append(S[x]+S[y]+S[z])
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0
for a in range(10):
    ai = 0
    while ai < n:
        if s[ai] == str(a):
            break
        else:
            ai += 1
    if ai == n:
        continue
    for b in range(10):
        bi = ai + 1
        while bi < n:
            if s[bi] == str(b):
                break
            else:
                bi += 1
        if bi == n:
            continue
        for c in range(10):
            ci = bi + 1
            while ci < n:
                if s[ci] == str(c):
                    break
                else:
                    ci += 1
            if ci == n:
                continue
            else:
                ans += 1

print(ans)
exit(0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

keys = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
a = 0
for key in keys:
  s = 0
  for st in luk:
    if st == key[s]:
      s += 1
    if s == 3:
      a += 1
      s = 0
      break
print(a)

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
for i in range(10):
  for j in range(10):
    for k in range(10):
      s = en[i] + en[j] + en[k]
      l = 0
      for m in range(len(S)):
        if S[m] == s[l]:
          l += 1
        if l == 3:
          break
      if l >= 3:
        T += 1
print(T)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"

inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N=I()
    X=S()
    OUT=np.array([[[0]*10]*10]*10)
    for i in range(10):
        for j in range(10):
            for k in range(10):
                target=[i,j,k]
                idx=0
                for x in X:
                    if x==str(target[idx]):
                        idx+=1
                    if idx==3:
                        OUT[i][j][k]=1
                        break
    print(OUT.sum())

if __name__ == "__main__":
    main()

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]] = list(S[j + 1:N])
        else:
            ans_list[S[i] + S[j]].extend(list(S[j+1:N]))
count = 0
# print(ans_list)
for v in ans_list.values():
    # print(v)
    count += len(set(v))
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
S=input()
kes=N-3
pass_set=set([])
for thing in itertools.combinations(range(0,N),3):
    t=sorted(thing)
    pswd=S[t[0]]+S[t[1]]+S[t[2]]
    pass_set.add(pswd)
print(len(pass_set))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
S=list(input())

number=list(itertools.combinations(S,3))
print(len(set(number)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = 0
table = [[0 for i in range(10)] for j in range(10)]
for i in range(N - 2):
    for j in range(i+1, N-1):
        if(table[int(S[i])][int(S[j])] != 1):
            table[int(S[i])][int(S[j])] = 1
            ans += len(set(S[j+1:]))

print(ans)

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):
        list.append(subset)
print (len(set(list)))

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 = input()
s = input()

n = int(n)

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]+s[j]+s[k])
            # print(s[i]+s[j]+s[k])

ans = list(set(ans))
print(len(ans))

Submission status: Time Limit Exceeded

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

l = [0] * 1000 # 000 to 999
for i in range(n - 2): # i桁目 を残す
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):
      password = s[i] + s[j] + s[k]
      l[int(password)] = 1

print(l.count(1))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
cnt=0
for i in range(1000):
    t=list(str(i))
    flag0=False
    flag1=False
    flag2=False
    flag3=False
    if(len(t)==1):
        t.insert(0,'0')
        t.insert(0,'0')
    if(len(t)==2):
        t.insert(0,'0')
    #print(t)
    for j in range (len(s)):
        if(s[j]==t[0] and flag0==False):
            flag1=True
            flag0=True
            continue
        if(s[j]==t[1] and flag1==True):
            flag2=True
            flag1=False
            continue
        if(s[j]==t[2] and flag2==True and flag1==False):
            flag3=True
            flag2=flag1=False
            continue
   # if(t==['2','2','4']):
    #    print(flag1,flag2,flag3)
    if(flag3):
        cnt+=1
      #  print(t)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
set_n_3=set()
for i0 in range(n):
    for i1 in range(i0+1,n):
        for i2 in range(i1+1,n):
            set_n_3.add(s[i0]+s[i1]+s[i2])
print(len(set_n_3))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = set(combinations(s, 3))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
length = len(S)
l = list()
for n in range(length-2):
    for m in range(n+1,length):
        for k in range(m+1, length):
            s = S[n]+S[m]+S[k]
            if s not in l:
                l.append(s)
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=str(input())
ans=0
counter=0
#000~999までを検索する
for x in range(0,1000):
    counter=0
    c=x%10
    b=(x//10)%10
    a=(x//100)
    for i in range(0,N):
        if(counter==0):
            if(int(S[i])==a):
                counter+=1
        elif(counter==1):
            if(int(S[i])==b):
                counter+=1
        elif(counter==2):
            if(int(S[i])==c):
                ans+=1
                counter=0
                break
print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int,input()))
ans =[]
for i in range(n):
    for j in range(i+1,n):
        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:
n = int(input())
s = list(str(input()))

from itertools import combinations

ans = {s[x[0]]+s[x[1]]+s[x[2]] for x in combinations(range(n), 3)}
print(len(ans))

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():
    n=ii()
    s=list(input())
    print(len(set(itertools.combinations(s,3))))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
s = set()
for a in range(0, N - 2):
  for b in range(a + 1, N - 1):
    for c in range(b + 1, N):
      s.add(S[a] + S[b] + S[c])
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
s=input()
d=dict()
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      d[s[i]+s[j]+s[k]]=0
print(len(d))

Submission status: Time Limit Exceeded

Solution code:
def f():
    n = int(input())
    s0 = input()
    poss = []
    for i in range(1000):
        char = str(i)
        poss.append('0'*(3-len(char)) + char)

    def exit(s):
        i = 0
        j = 0
        while i < n:
            if s0[i] == s[j]:
                i += 1
                j += 1
                if j == 3:
                    return True
            else:
                i += 1
        return False

    ans = 0
    for s in poss:
        if exit(s):
            ans += 1
    print(ans)



f()

Submission status: Time Limit Exceeded

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

a = 0
b = 0
c = 0
cnt = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      b = 0
      a = 0
      for x in range(n):
        if a == 0:
          if int(s[x]) == i:
            a = 1
        elif b == 0:
          if int(s[x]) == j:
            b = 1
        elif c == 0:
          if int(s[x]) == k:
            cnt += 1
            break    
        

print(cnt)

Submission status: Time Limit Exceeded

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

pins=list()

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = input()
S = input()

com = list(set([c[0]+c[1]+c[2] for c in itertools.combinations(S,3)]))
#com = list(set([c[0]+c[1]+c[2] for c in itertools.combinations(N,3)]))
print(len(com))

Submission status: Time Limit Exceeded

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

n=int(input())
s=list(input())
a=[0 for i in range(1000)]
res=[0,0,0]
#cnt=0
def abc(i,cnt):
    global s,a,res
    if i==3:
        b=100*int(res[0])+10*int(res[1])+int(res[2])
        if a[b]!=1:
            a[b]+=1
    elif cnt>=n:
        pass
    else:
        if res[0]==0:
            res[0]=s[cnt]
            abc(i+1,cnt+1)
            res[0]=0
            abc(i,cnt+1)
        elif res[1]==0:
            res[1]=s[cnt]
            abc(i+1,cnt+1)
            res[1]=0
            abc(i,cnt+1)
        else:
            res[2]=s[cnt]
            abc(i+1,cnt+1)
            res[2]=0
            abc(i,cnt+1)
abc(0,0)
print(sum(a))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np

N=int(input())
S=list(input())
C=np.asarray(list(map(str,list(combinations(S,3)))))
U=np.unique(C)

print(len(np.unique(C)))

Submission status: Time Limit Exceeded

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

ans = set()
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      a, b, c = int(s[i]), int(s[j]), int(s[k])
      ans.add(100*a+10*b+c)
print(len(ans))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    A = i // 100
    B = i // 10 % 10
    C = i % 10
    a = False
    b = False
    for j in S:
        if a:
            if b:
                if j == C:
                    ans += 1
                    break
            elif j == B:
                b = True
        elif j == A:
            a = True

print(ans)

Submission status: Time Limit Exceeded

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

ans = []
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            key = S[i] + S[j] + S[k]
            if key not in ans:
                ans.append(key)
print(len(ans))

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 not in list:
        list.append(subset)
print (len(list))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

comb = combinations(s, 3)
set_ = set()

for x in comb:
    set_.add(x)

print(len(set_))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    X = II()
    S = input()
    l = len(S)
    memo = {}
    for i in range(l):
        for j in range(i+1,l):
            for k in range(j+1,l):
                memo[S[i]+S[j]+S[k]] = True
    print(len(memo.keys()))



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for num in itertools.combinations(s, 3):
    nums.add(num)

print(len(nums))