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

n = int(n)

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

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

        #
        # saigo = set([int(k) for k in s[j + 1:n]])
        # saigo_cnt = len(saigo)

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

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

print(counts)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

l = collections.Counter(s[:1])
r = collections.Counter(s[2:])
key = set()
for i in range(n-2):
    for j in range(10):
        for k in range(10):
            if l[str(j)] > 0 and r[str(k)] > 0:
                key.add('{}{}{}'.format(j,s[i+1],k))
    l[str(s[i+1])] += 1
    r[str(s[i+2])] -= 1
print(len(key))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

Solution code:
import re

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

numbers = set()

def exists(i, j, k, s):
  pattern = '.*' + str(i) + '.*' + str(j) + '.*' + str(k) + '.*'
  result = re.match(pattern, s)
  return result is not None

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 = list(input())
S = [int(S[i]) for i in range(N)]
count = 0
for i in range(10):
    for l in range(10):
        for q in range(10):
            t = 0
            for s in range(N):
                if t == 1:
                    break
                if S[s] == i:
                    p = s
                    for r in range(p + 1, N):
                        if t == 1:
                            break
                        if S[r] == l:
                            p = r
                            for b in range(p + 1, N):
                                if t == 1:
                                    break
                                if S[b] == q:
                                    count += 1
                                    t = 1
                                    break
                                elif b == N - 1:
                                    t = 1
                        elif r == N-1:
                            t = 1
                elif s == N - 1:
                    t = 1
print(count)

Submission status: Time Limit Exceeded

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

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

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


print(sum(history.values()))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(input())
tmp = n - 3

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

local = ''
result = []
for i in range(len(s_list)):
    result.append(''.join(s_list[i]))
    local = ''

print(len(set(result)))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

num = []
for i in range(n-2):
  for j in range(i + 1, n-1):
    for k in range(j + 1, n):
      tmp = s[i] + s[j] + s[k]
      if tmp not in num:
      	num.append(tmp)
print(len(num))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s = input()
nm = [i for i in range(n)]
sl = itertools.combinations(nm, 3)
ans = []

for v in sl:
    a, b, c = v[0], v[1], v[2]
    p = str(s[a]) + str(s[b]) + str(s[c])
    ans.append(p)
    ans_s = set(ans)
    
print(len(ans_s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

keySet = set()


for i in range(N - 2):
    m1 = S[i]
    for j in range(i + 1, N - 1):
        m2 = m1 + S[j]
        for k in range(j + 1, N):
            m = 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=list(input())

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

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)
    for i2 in range(10):
        s2 = str(i2)
        for i3 in range(10):
            pt = s1 + "+[0-9]*" + s2 + "+[0-9]*" + str(i3) + "+[0-9]*"
            res = re.search(pt, s)
            if res != None:
                ans = ans + 1

# Output
print(ans)

Submission status: Time Limit Exceeded

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

memo = [set()]*4
def dp(n):
  for i in range(4, n+1):
    if i == 4:
      t = {S[:j]+S[j+1:i] for j in range(i)}
      memo.append(t)
    else:
      t = {a[:-1]+S[i-1] for a in memo[i-1]}
      u = {a[0]+a[2]+S[i-1] for a in memo[i-1]}
      v = {a[1:]+S[i-1] for a in memo[i-1]}
      memo.append(memo[i-1] | t | u | v)
  return len(memo[n])

print(dp(N))

Submission status: Time Limit Exceeded

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

def exists(n, S):
    n0 = n[0]
    n1 = n[1]
    n2 = n[2]
    for i in range(N-2):
        if S[i] == n0:
            for j in range(i+1, N-1):
                if S[j] == n1:
                    for k in range(j+1, N):
                        if S[k] == n2:
                            return True
    return False

cnt = 0
for i in range(0, 1000):
    n = str(i).zfill(3)
    if exists(n, S):
       cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
input()
ns = [n for n in input()]
 
answers = []
first = []
second = []
third = []
 
for i in range(len(ns) - 2):
  if i in first:
    continue
  else:
    first.append(i)
  for j in range(i+1, len(ns) - 1):
    if ''.join([ns[i], ns[j]]) in second:
      continue
    else:
      second.append(''.join([ns[i], ns[j]]))
    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=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
    for k in range(j+1,N):
      kk=int(s[k])
      d[ii*100+jj*10+kk]=1
      
print(sum(d))

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()
d = n-3
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:
import numpy as np
n= int(input())
s = input()
na = np.zeros(n)
for i in range(n):
  na[i] = int(s[i])
ans = set()
h = set()
for i in range(n-2):
  if na[i] not in h:
    h.add(na[i])
    for j in range(i+1,n-1):
      for k in range(j+1,n):
        tmp = str(na[i]) + str(na[j]) + str(na[k])
        if tmp not in ans:
          ans.add(tmp)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def int2str(i):
  if i <10:
    a="0"
    b="0"
    c=str(i)[-1]
  elif i <100:
    a="0"
    b=str(i)[-2]
    c=str(i)[-1]
  else:
    a=str(i)[-3]
    b=str(i)[-2]
    c=str(i)[-1]
  return a,b,c

N=int(input())
S=input()
ans=0
for i in range(1000):
  a,b,c=int2str(i)
  flag=0
  for j in S:
    if flag==0 and j==a:
      flag=1
      continue
    elif flag==1 and j==b:
      flag=2
      continue
    elif flag==2 and j==c: 
      ans+=1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
sl=[c for c in s]
ans=0
l=[]
for i in range(n):
  for j in range(i+1,n):
    if not sl[i]+sl[j] in l:
      l.append(sl[i]+sl[j])
      ans+=len(set(sl[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()
l = list(itertools.combinations(S, 3))

for x in l:
    s.add(x[0]+x[1]+x[2])

print(len(s))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
lis = list(input())

ans = list(itertools.combinations(lis, 3))
anss = tuple(set(ans))
print(len(anss))

Submission status: Time Limit Exceeded

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

L=[0]*9
D=[0]*100
C=0
R=len(set(S))**3

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
del_n = n - 3
ch_n = len(s) - del_n
import itertools
lis = []
for i in itertools.combinations(s, ch_n):
    tmp_ch = ''.join(i)
    if tmp_ch not in lis:
        lis.append(tmp_ch)
print(len(lis))

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
pattern = [tuple(s[:3])]
for c in s[3:]:
    for i in range(len(pattern)):
        p1, p2, p3 = pattern[i]
        if (p1, p2, c) not in pattern:
            pattern.append((p1, p2, c))
        if (p1, p3, c) not in pattern:
            pattern.append((p1, p3, c))
        if (p2, p3, c) not in pattern:
            pattern.append((p2, p3, c))
print(len(pattern))

Submission status: Time Limit Exceeded

Solution code:
def judge(candidate,S):
    for i in range(0,len(S)):
        if(S[i]==candidate[0]):
            for j in range(i+1,len(S)):
                if(S[j]==candidate[1]):
                    for k in range(j+1,len(S)):
                        if(S[k]==candidate[2]):
                            return 1
                        elif(S[k]==S[j]):
                            j=k
                elif(S[j]==S[i]):
                    i=j  
    return 0
def main():
    count=0
    N=int(input())
    S=input()
    number=[]
    for i in S:
     if int(i) not in number:
        number.append(int(i))
    number_list=[]
    max_number=max(number)
    for i in range(max_number+1):
        for j in range(max_number+1):
            for k in range(max_number+1):
                number_list.append(str(i)+str(j)+str(k))

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

main()

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(1000):
	sec = str(i).zfill(3)
	nex = 0
	for j in range(n):
		if nex == 0 and s[j] == sec[0]:
			nex += 1
		elif nex == 1 and s[j] == sec[1]:
			nex += 1
		elif nex == 2 and s[j] == sec[2]:
			cnt += 1
			break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(input())
tmp = n - 3

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

local = ''
result = []
for i in range(len(s_list)):
    for j in range(3):
        local += s_list[i][j]
    result.append(local)
    local = ''

print(len(set(result)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

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

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

Submission status: Time Limit Exceeded

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

firsts = []
firsts_seconds = []

for i in range(n-2):
    if len(firsts) == 10:
        break
    first =  s[i]
    if first in firsts:
        continue
    firsts.append(first)
    for j in range(i+1,n-1):
        second = s[j]
        first_second = first + second
        if first_second in firsts_seconds:
            continue

        firsts_seconds.append(first_second)
        for k in range(j+1, n):
            password = first_second + s[k]
            if password not in passwords:
                passwords.append(password)

print(len(passwords))

Submission status: Time Limit Exceeded

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

c = 0

flag0 = False
flag1 = False
flag2 = False

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

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

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

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

    flag0 = False
    flag1 = False
    flag2 = False

print(c)

Submission status: Time Limit Exceeded

Solution code:

from itertools import combinations

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

p_list = list(combinations(S, 3))
#print(p_list)
x_list = list(set(p_list))
#print(x_list)
print(len(x_list))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

cmb = list(combinations(S, 3))
print(len(set(cmb)))

Submission status: Time Limit Exceeded

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

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

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 = m1 + S[j]
            for k in range(2, N):
                if (k > j):
                    m = 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()
lst = []
List = []
result = []

for i in s :
    lst += [i]

for i in range(n) :
    for j in range(i+1, n) :
        for k in range(j+1, n) :
            List += [int(lst[i] + lst[j] + lst[k])]

for i in List :
    if not i in result :
        result += [i]

print(len(result))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s = list(input())
l = list(itertools.combinations(s,3))
c = []
for i in l:
  if not i in c:
    c.append(i)

print(len(c))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

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

Submission status: Time Limit Exceeded

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

num = []
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]
      if tmp not in num:
      	num.append(tmp)
print(len(num))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

st = set()

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

for item in l:
    st.add(item)

#print(st)
print(len(st))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

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):
      ans.add(s[i]+s[j]+s[k])
      
print(len(ans))

Submission status: Time Limit Exceeded

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

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])
ss=set(ans)
print(len(ss))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math

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

c = []
for i in range(0,N):
    st = S[0:i] + S[i+1:N+1]
    c += list(itertools.combinations(st, 3))
print(len(set(c)))

Submission status: Time Limit Exceeded

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

arr = list(str(S))
ans = []

for i in range(N):
  for j in range(N - i -1):
    for k in range(N - i - j - 2):
      
      a = int(arr[i])
      b = int(arr[j+i+1])
      c = int(arr[k+j+i+2])
      d = 100*a + 10*b + c
      
      if ans.count(d) == 0:
        ans.append(d)
      
      
a =len(ans)
print(a)

Submission status: Time Limit Exceeded

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

# 集合を使う
shugo = set()

keta = [i for i in range(N)]
r = N - 3

ncr = list(combinations(keta, r))

for i in ncr:
    s = ""
    for j in range(len(S)):
        if j in i:
            pass
        else:
            s += S[j]
    shugo.add(s)

print(len(shugo))

Submission status: Time Limit Exceeded

Solution code:
#import time

#t1=time.time()
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
    check=info[kind]
    for i in range(n):
        if point==0:  
            if check[0]==s[i]:
                point+=1
                continue
        if point==1:
            if check[1]==s[i]:
                point+=1
                continue
        if point==2:
            if check[2]==s[i]:
                point+=1
                break
    if point==3:
        ans+=1
        #print(info[kind])
    kind+=1
print(ans)
#t2=time.time()
#print(t2-t1)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

input = sys.stdin.readline
#sys.setrecursionlimit(1e9)

def main():
    """code here"""
    N = int(input())
    S = list(input())
    S = S[:-1]

    keta = N -3

    num = len(S)
    num = num-keta

    ans = []

    for v in itertools.combinations(S,num):
        #print(v)
        ans.append(v)
    print(len(set(ans)))

    
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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:
def main():
    N = int(input())
    S = input().rstrip()
    u = len(set(list(S)))
    first = set()
    tmp = set()
    ans = 0
    for index, i in enumerate(range(N - 2)):
        if i in first:
            continue
        first.add(i)
        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:])))
                if len(tmp) == u ** 2:
                    print(ans)
                    quit()
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
se = set()
check = set()
for first in range(10):
    temp = ''
    for i in range(n):
        if s[i] in check:
            continue
        if int(s[i])==first:
            temp+=s[i]
            check.add(temp)
            for second in range(10):
                for j in range(i+1,n):
                    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]
print(len(se))

Submission status: Time Limit Exceeded

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

S = "1234" * 3000
from itertools import product
from re import search

ans = 0
for i in product(map(str, range(10)), repeat=3):
    res = search(".*?".join(i), S)
    if res:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
n0=input()
s=input()
ans=0

for i in range(1000):
    n = str(i).zfill(3)
#    print(n[0])
    p = ".*"+ n[0] + ".*" + n[1] + ".*" + n[2] +".*"
    if re.search(p,s):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = input()
S = input()
perm = combinations([i for i in S], 3)
print(len(set(perm)))

Submission status: Time Limit Exceeded

Solution code:
import collections

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(collections.Counter(ans)))
#print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

passwords = list(itertools.combinations(S, 3))

print(len(set(passwords)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

flag = False
count = 0

for i in range(0,1000):
    third = i % 10
    second = ((i-third) % 100) // 10
    first = (i-third-second*10) // 100
    checkcount = 0
    for t in s:
        if str(first) == t:
            first = second
            second = third
            checkcount += 1
        if checkcount == 3:
            flag = True
            break
    if flag:
        count += 1
        flag = False
        
print(count)

Submission status: Time Limit Exceeded

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

#import bisect

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

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

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

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

    return result

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

def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
    n=int(input())
    s=list(map(int,input()))
    c = [[-2 for j in range(11)] for i in range(10)]
    d={0}
 #   print(c)

    for i in range(n):
        for j in range(10):
            if c[j][10] > -2:
                for k in range(10):
                    if c[j][k]>-2:
                        d.add(str(j)+str(k)+str(s[i]))
                c[j][s[i]]=-1
        c[s[i]][10] = -1
#    print(d)

 #   print(c)
    for i in range(100):
        d.discard(str(i))
    d.discard(0)
#    print(d)
    print(len(d))
            #    print(n,kingaku(a,b,x))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

d=[0]*1000
di=[0]*10
dj=[0]*10
dk=[0]*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]) 
    for k in range(j+1,N):
      kk=int(s[k])
      d[ii*100+jj*10+kk]=1
      
print(sum(d))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
lis = list(input())

ans = list(itertools.combinations(lis, 3))
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=input()
c=set()
for i in range(a):
  for j in range(i+1,a):
    for k in range(j+1,a):
      c.add(b[i]+b[j]+b[k])
print(len(c))

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)