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:
from itertools import combinations

def main():
    N = int(input())
    S = input()
    C = [i for i in range(N)]
    COM = list(combinations(C, 3))
    SET = set()
    for c in COM:
        # print(c)
        s = ""
        for x in c:
            s += S[x]
        SET.add(s)
    print(len(SET))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
mu=int(input())
my_list = input()
tlist = []
for i in range(0,mu-2):
    for t in range(i+1,mu-1):
        for p in range(t+1,mu):
            s = my_list[i]+my_list[t]+my_list[p]
            if tlist.count(s)==0:
                tlist.append(s)

print(len(tlist))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
password_set = set()
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      password = "".join([S[i],S[j],S[k]])
      password_set.add(password)
print(len(password_set))

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())
    ans=set()
    for com in list(itertools.combinations(s,3)):
        ans.add(com)
    print(len(ans))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

lst = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            moji1 = lst[i]
            moji2 = lst[j]
            moji3 = lst[k]
            cnt = 0
            kuraberu = [moji1, moji2, moji3]
            for moji in s:
                if moji == kuraberu[cnt]:
                    cnt += 1
                if cnt == 3:
                    ans += 1
                    break

print(ans)

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:
n=int(input())
S=input()
l=[]
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])
print(len(l))

Submission status: Time Limit Exceeded

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

right = [[0 for _ in range(10)] for _ in range(N + 1)]
left = [[0 for _ in range(10)] for _ in range(N + 1)]
C = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(10)]

for i in range(N - 1):
    for j in range(10):
        right[i + 1][j] += right[i][j]
    right[i + 1][int(S[i])] += 1

for i in range(N - 1, 0, -1):
    for j in range(10):
        left[i][j] += left[i + 1][j]
    left[i][int(S[i])] += 1

for i in range(1, N - 1):
    for a in range(10):
        for b in range(10):
            if right[i][a] != 0 and left[i + 1][b] != 0:
                C[a][int(S[i])][b] += 1

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if C[i][j][k] != 0:
                res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

c = set(list(itertools.combinations(S,3)))

print(len(c))

Submission status: Time Limit Exceeded

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

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

for i in range(1000):
    first = i//100
    second = (i-first*100)//10
    third = i-first*100-second*10
    if count[first] == 0 or count[second] == 0 or count[third] == 0:
        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 = input()

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
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):
		for k in range(j + 1, N):
			a = (S[i], S[j], S[k])
			if not a in dic:
				dic[a] = 1
				ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      target = [i,j,k]
      b = False
      for l in range(n):
        if int(s[l]) == target[0]:
          target.pop(0)
          if len(target)==0:
            b = True
            break
      if b: ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

dict = {}

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]
      dict[key] = 0
print(len(dict))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
keta = 10
count = 0
for i in range(keta):
    for j in range(keta):
        for k in range(keta):
            nnn = str(i) + str(j) + str(k)
            now = 0
            nownnn = nnn[now]
            flag = False
            for l in range(N):
                if S[l] == nownnn:
                    if now == 2:
                        flag = True
                        break
                    else:
                        now += 1
                        nownnn = nnn[now]
            if flag:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = input()
for i in range(10):
	c = str(i)
	if c.count(s) >= 4:
		s = s.replace(c, "")
		s = s + c*3
a = list(combinations(list(s),3))
b = set(a)
print (len(b))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

conb = list(itertools.combinations(s, 3))
#print(conb)

for i in range(len(conb)):
    nums.add(str(conb[i]))

#print(nums)
print(len(nums))

Submission status: Time Limit Exceeded

Solution code:
n=input()
n=int(n)
arrstr=input()
ans=0
for no in range(1000):
    no=str(no);
    no=no.zfill(3)
    suc=0
    poi=0
    for i in range(len(arrstr)):
        if(arrstr[i]==no[poi]):
            poi+=1
            if poi==3:
                suc=1
                break
             
    if suc:ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
n = int(input())
l = input()
pre = [{e} for e in l]
suf = [{e} for e in l]
for i in range(1, n):
    pre[i] |= pre[i - 1]
    suf[n - 1 - i] |= suf[n - i]
res = set()
for i in range(1, n - 1):
    res.update(a + l[i] + b for a, b in product(pre[i - 1], suf[i + 1]))
print(len(res))

Submission status: Time Limit Exceeded

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

ans=0
for i in range(1000):
    j="0"*(3-len(str(i)))+str(i)
    flag1=False
    flag2=False
    flag3=False
    for i in range(n):
        if not flag1 and S[i]==j[0]:
            flag1=True
            continue
        if flag1 and not flag2:
            if S[i]==j[1]:
                flag2=True
                continue
        if flag2 and not flag3:
            if S[i]==j[2]:
                flag3=True
                break
    if flag3:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
l = {}
a = [set() for i in range(N)]
a[-1].add(s[-1])

for i in range(N-2, -1 , -1):
  a[i] = a[i+1] | {s[i]} 

for i1 in range(N-2):
  for i2 in range(i1+1, N-1):
    l[s[i1] + s[i2]] = l.get(s[i1] + s[i2], set()) | a[i2+1]

r = 0
for i in l.values():
  r += len(i)
print(r)

Submission status: Time Limit Exceeded

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

A=[0]*1000

for i in range(10):
  for ii in range(N):
    if i==S[ii]:
      for j in range(10):
        for jj in range(ii+1,N):
          if j==S[jj]:
            for k in range(10):
              for kk in range(jj+1,N):
                if k==S[kk]:
                  A[i*100+j*10+k]=1
                  break
print(sum(A))

Submission status: Time Limit Exceeded

Solution code:
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 = 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:
from itertools import combinations
n = int(input())
s = input()

explo = list(combinations(range(n),3))

tem = []
for per in explo:
    tem.append(s[per[0]]+s[per[1]]+s[per[2]])

ans = set(tem)


print(len(ans))

Submission status: Time Limit Exceeded

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

keys = []

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            keys.append(''.join([s[i], s[j], s[k]]))

print(len(set(keys)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[i for i in 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()
import itertools
print(len(set(itertools.combinations(list(s),3))))

Submission status: Time Limit Exceeded

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

for i in range(1000):
    num=list(str(i).zfill(3))
    k=0
    for j in range(n):
        if num[k]==s[j]:
            k+=1
            if k==3:
                break
    if k==3:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1000):
    first = i//100
    second = (i-first*100)//10
    third = i-first*100-second*10
    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 = input()

ans = {}

for i in range(N):
    for j in range(N):
        for k in range(N):
            if i < j and j < k:
                sum = S[i] + S[j] + S[k]
                ans.setdefault(sum, "1")

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
s = list(S)
password_set = set()
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      password = "".join([s[i],s[j],s[k]])
      password_set.add(password)
print(len(password_set))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n =int(input())

# 空白区切りの数列をリストに代入
k = list(input())
for i in range(n):
    k[i]= int(k[i])
answer = 0
for i in range(1000):
    a=i//100
    b=(i%100)//10
    c=i%10
    p=0
#    print(a,b,c,p,n)
    for j in range(p,n):
        if k[j] == a:
            p = j+1
            break
    else:
        continue
    for j in range(p,n):
        if k[j]== b:
            p = j+1
            break
    else:
        continue
    for j in range(p,n):
        if k[j]== c:
#            p = j+1
            answer += 1
#            print(i)
            break

print(answer)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = list(input())
a = list(combinations(s,3))
b = set(a)
print (len(b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    tmp = str(i)
    while len(tmp) < 3:
        tmp = '0' + tmp
    count = 0
    for k in S:
        if 3 <= count:
            break
        if k == tmp[count]:
            count += 1
    if count == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

N = int(input())
S = input().rstrip()
s = [int(x) for x in S]

remove= list(itertools.combinations(range(len(S)), N-3))
#print('to remove: ', remove)

ans = []
for i in range(len(remove)):
	ans.append([num for idx,num in enumerate(s) if not idx in remove[i]])

#print('answer: ',ans)
answer = len(set(map(tuple, ans)))
print(answer)

Submission status: Time Limit Exceeded

Solution code:
from itertools import 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()
ans = {}

for i in range(N-2):
    for s in range(i+1, N-1):
        for t in range(s+1, N):
            tmp = S[i] + S[s] + S[t]
            ans[tmp] = 0

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
def chk(x):
  x=str(x).zfill(3)
  res=False
  cur=0
  xx=x[0]
  for i in range(n):
    ss=s[i]
    if cur<2 and xx==ss:
      cur+=1
      xx=x[cur]
    elif xx==ss:
      res=True
      break
  return res

ans=0
for i in range(1000):
  if chk(i):
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

import re

n = ni()
s = ns()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            pattern = ".*" + str(i) + ".*" + str(j) + ".*" + str(k) + ".*"
            reptn = re.compile(pattern)
            if re.search(reptn, s):
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    tmp = str(i)
    while len(tmp) < 3:
        tmp = '0' + tmp
    count = 0
    for k in S:
        if count < 3 and k == tmp[count]:
            count += 1
    if count == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            left = 0
            for i in range(n):
                if left == 0 and int(s[i]) == a:
                    left = 1
                elif left == 1 and int(s[i]) == b:
                    left = 2
                elif left == 2 and int(s[i]) == c:
                    left = 3
                if left == 3:
                    ans += 1
                    break


print(ans)
exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
s = list(input())

from collections import defaultdict
ans = defaultdict(int)
def dfs(now, pos):
    if len(now) == 3:
        ans[now] = 1
        return
    if pos == n:
        return
    dfs(now+s[pos], pos+1)
    if ans[now] == 0:
        dfs(now, pos+1)
    ans[now] = 1

dfs("", 0)

anss = 0
for v,i in ans.items():
    if len(str(v)) == 3:
        anss += i

print(anss)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#mitsui d
import sys
import math
import collections
#sys.setrecursionlimit(100000)

n=int(input())

s=input()
#tmp = input().split()
#s = list(map(lambda a: int(a), tmp))

ans=0

for i in range(0,10):
	for j in range(0,10):
		for k in range(0,10):
			flg=0
			for index in range(0,n):
				if(flg==0)and(s[index]==str(i)):
					flg+=1
				elif(flg==1)and(s[index]==str(j)):
					flg+=1
				elif(flg==2)and(s[index]==str(k)):
					flg+=1
					break
			if(flg==3):
				tst=str(i)+str(j)+str(k)
#				print(tst)
				ans+=1
print(ans)

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

Submission status: Time Limit Exceeded

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

kset = []
cnt = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    k2 = s[i] + s[j]
    if k2 not in kset:
      kset.append(k2)
      k3 = set(list(s[j+1:]))
      cnt += len(k3)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re

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

count = 0
for c1 in range(10):
	for c2 in range(10):
		for c3 in range(10):
			if re.search("{}.*{}.*{}".format(c1, c2, c3), S):
				count += 1
print(count)

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(list(set(S[j+1:])))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
L = ["0","1","2","3","4","5","6","7","8","9"]
cnt = 0
for a in L:
    for b in L:
        for c in L:
            target = [a,b,c]
            T = 0
            for i in range(N):
                see = S[i]
                if target[T]==see:
                    T+=1
                    if T==3:
                        cnt += 1
                        break
print(cnt)

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:
from itertools import combinations as cmb
n=int(input())
s=input()
sss=[]
for i in range(len(s)):
    sss.append(s[i])
combiset=set(cmb(sss,3))
print(len(combiset))

Submission status: Time Limit Exceeded

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

keys = []

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

print(len(set(keys)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = []

for i in range(N-2):
    for s in range(i+1, N-1):
        for t in range(s+1, N):
            tmp = S[i] + S[s] + S[t]
            ans.append(int(tmp))

ans = list(set(ans))

print(len(ans))

Submission status: Time Limit Exceeded

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

from itertools import combinations
ans=set()
for i in combinations(s,3):
    ss="".join(i)
    ans.add(ss)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=input()
def check(a,S):
    c=0
    ret=0
    for s in S:
        if s==a[c]:
            c+=1
        if c==3:
            ret=1
            break
    return ret
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if check(str(i)+str(j)+str(k),S):
                ans+=1
print(ans)

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):
			f1 = False
			f2 = False
			f3 = False
			for c in s:
				if (not f1) and int(c) == i:
					f1 = True
					continue
				if (not f2) and f1 and int(c) == j:
					f2 = True
					continue
				if f2 and int(c) == k:
					f3 = True
					break
			if f3:
				count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = str(input())
c1 = [False for _ in range(10)]
c2 = [0 for _ in range(1000)]
for i in range(n-2):
  si = int(s[i])
  if c1[si] != True:
    c1[si] = True
    for j in range(i+1,n-1):
      for k in range(j+1,n):
        c2[si+int(s[j])*10+int(s[k])*100] = 1
print(sum(c2))

Submission status: Time Limit Exceeded

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

print(len(a))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
s = list(input())

from collections import defaultdict
ans = defaultdict(int)
def dfs(now, pos):
    if len(now) == 3:
        ans[now] = 1
        return
    if pos == n:
        return
    dfs(now+s[pos], pos+1)
    dfs(now, pos+1)

dfs("", 0)

anss = 0
for i in ans.values():
    anss += i

print(anss)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
lst = []
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if not S[i]+S[j]+S[k] in lst:
                lst.append(S[i]+S[j]+S[k])
print(len(lst))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


_ = input()
s = input()
seen = set()
for x in combinations(s, 3):
    if x not in seen:
        seen.add(x)

print(len(seen))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    p = '00' + str(i)
    k = -3
    for j in range(N):
        if p[k] == S[j]:
            k += 1
            if k == 0:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import itertools

N = int(input())
S = input()
stack = set()

for el in itertools.combinations(S, len(S) - (N-3)):
    stack.add(el)

print(len(stack))

Submission status: Time Limit Exceeded

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

results = set()
num = len(S)
for i in range(num):
    for j in range(i+1, num):
        for k in range(j+1, num):
            string = S[i] + S[j] + S[k]
            results.add(string)

print(len(results))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    input()
    s = raw_input()
    a2 = set()
    a3 = set()
    for i, c1 in enumerate(s[:-2]):
        for j, c2 in enumerate(s[i+1:-1], i + 1):
            ss = c1 + c2
            if ss in a2:
                continue
            a2.add(ss)
            for c3 in set(s[j+1:]):
                a3.add(ss + c3)
    print len(a3)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    S=list(map(int,list(input())))
    l={}
    for i in range(10):
        l[i]={}
        for j in range(10):
            l[i][j]=[]
    ans=0
    for i in range(N):
        for j in range(N-i-1):
            for k in range(N-i-j-2):
                if not S[i+j+k+2] in l[S[i]][S[i+j+1]]:
                    l[S[i]][S[i+j+1]].append(S[i+j+k+2])
                    ans+=1
    print(ans)
                

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def f(a):
    i = 0
    for j in range(N):
        if S[j] == a[i]:
            i += 1
            if i > 2:
                return True
    return False

res = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if f((i, j, k)):
                res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

cnt = 0
for num in product(range(10), repeat=3):
    i = 0
    for e in s:
        if str(num[i]) == e:
            i += 1
        if i == 3:
            break

    if i == 3:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    
    can = set([""])
    ans = set()
    for s in S:
        for c in deepcopy(can):
            res = c+s
            if len(res) == 3:
                ans.add(res)
            elif len(res) < 3:
                can.add(res)
    print(len(ans))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import re
n = int(input())
s = input()
ans = 0
for i in range(1000):
    t = '{:0=3}'.format(i)
    m = r'{}.*{}.*{}'.format(t[0], t[1], t[2])
    if re.search(m, s):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

def main():
    n, s = sys.stdin.read().split()
    n = int(n)
    res = set()
    for comb in combinations(s, 3):
        res.add(comb)
    
    ans = len(res)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#D
N = int(input())
S = list(str(input()))
count = 0
for i in range(1000):
    si = str(i)
    while len(si) < 3:
        si = "0"+si
        
    flag = 0
    for j in range(N):
        if S[j] == si[flag]:
            flag+=1
            if flag == 3:
                break
            
    if flag == 3:
        count+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
st=[str(i).zfill(3)for i in range(1000)]
dp=[0]*1000
for i in s:
  for j in range(1000):
    if dp[j]<3:
      if st[j][dp[j]]==i:dp[j]+=1
print(dp.count(3))

Submission status: Time Limit Exceeded

Solution code:
def lcs(str1, str2):
    '''文字列str1, str2の最長共通部分列(Lowest Common Subsequence, LCS)を求める
    計算量O(len(str1)*len(str2))  
    '''
    dp = [[0]*(len(str2) + 1) for _ in range(len(str1) + 1)]
    for i in range(len(str1)):
        for j in range(len(str2)):
            if str1[i] == str2[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])
    return dp[len(str1)][len(str2)]

n = int(input())
s = input()
ans = 0
for i in range(1000):
    t = ("000"+str(i))[::-1][0:3][::-1]
    num = lcs(t, s)
    if num == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    
    can = set([""])
    ans = set()
    for s in S:
        for c in deepcopy(can):
            res = c+s
            if len(res) == 3:
                ans.add(res)
            else:
                can.add(res)
    print(len(ans))

if __name__ == '__main__':
    main()