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:
def search(a):
    x=0
    a="0"*(3-len(a))+a
    for i in range(n):
        if a[x]==s[i]:
            x+=1
            if x==3:
                return True
    return False
n=int(input())
s=input()
ans=0
k=[False]*1000
for i in range(1000):
    k[i]=search(str(i))
for i in k:
    if i:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

n=int(input())
S=input()
l=list("0123456789")

ret=[False]*1000
for i in (l):
    for j in (l):
        for k in (l):
            flg1=flg2=False
            for s in S:
                if s==i and not flg1:
                    flg1=True
                    continue
                if flg1 and s==j and not flg2:
                    flg2=True
                    continue
                if flg2 and s==k:
                    tmp=int(i+j+k)
                    # print(tmp)
                    ret[tmp]=True
                    break
          
print(sum(ret))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    A = [i // 100, (i % 100) // 10, i % 10]
    
    idx = 0
    for s in S:
        if str(A[idx]) == s:
            idx += 1
        if idx == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

N = int(input())
S = input()
vv = []
cc = [0] * 1000
for v in itertools.combinations(S[0:-1], 3):
	cc[int(v[0]+v[1]+v[2])]=1
print(sum(cc))

Submission status: Time Limit Exceeded

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

N = int(input())
S = input()
vv = []
cc = [False] * 1000
for v in itertools.combinations(S[0:-1], 3):
	cc[int(v[0]+v[1]+v[2])]=True
print(cc.count(True))

Submission status: Time Limit Exceeded

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

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

vv = []
for v in itertools.combinations(S[0:-1], 3):
	vv.append(str(v))
print(len(list(set(vv))))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
c = [str(i) for i in range(10)]
cands = []
for c1 in c:
    for c2 in c:
        for c3 in c:
            cands.append(c1 + c2 + c3)

cnt = 0
for c in cands:
    i = 0
    for s in S:
        if i == 3:
            break
            
        if c[i] == s:
            i += 1

    if i == 3:
        # print(c)
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())

def main():
    n = ni()
    s = ns()

    cnt = 0
    for i in range(1000):
        tmp = str(i).zfill(3)
        idx = 0
        for ss in s:
            if tmp[idx] == ss:
                idx += 1
            if idx == 3:
                break
        if idx == 3:
            cnt += 1
    
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

from itertools import permutations

def main():
    n = ni()
    s = ns()

    cnt = 0
    for i in range(1000):
        tmp = str(i).zfill(3)
        idx = 0
        for ss in s:
            if tmp[idx] == ss:
                idx += 1
            if idx == 3:
                break
        if idx == 3:
            cnt += 1
    
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(10):
  l = 0
  while(True):
    if(i == int(S[l])):
      for j in range(10):
        m = l + 1
        while(True):
          if(j == int(S[m])):
            for k in range(10):
              for n in range(m+1, N):
                if(k == int(S[n])):
                  ans += 1
                  break
          m += 1
          if(m >= N - 1 or j == int(S[m - 1])):
             break
    l += 1
    if(l >= N - 2 or i == int(S[l - 1])):
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
l = input()
dp = [0]*1110
qp = [0]*1110
L = []
#print('###############')
def bfs(i,x,y):
	#print(i,x)
	if y == 3:
		qp[int(x)] = 1
		return 0
	else:
		for j in range(i,a):
			if x+str(l[j]) not in L:bfs(j+1,x+str(l[j]),y+1)
			L.append(x+str(l[j]))
bfs(0,'',0)
print(sum(qp))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
l = input()
dp = [0]*1010
#print('###############')
def bfs(i,x,y):
	if y == 3:
		dp[int(x)] = 1
	else:
		for j in range(i,a):
			bfs(j+1,x+str(l[j]),y+1)
bfs(0,'',0)
print(sum(dp))

Submission status: Time Limit Exceeded

Solution code:
number=input().rstrip()
lucky=input()
count=1
password=[]
for i in range(len(lucky)-2):
    word=lucky[i]
    for j in range(i+1,len(lucky)-1):
        word=word+lucky[j]
        for k in range(j+1,len(lucky)):
            word=word+lucky[k]
            password.append(word)
            word=lucky[i]+lucky[j]
        word=lucky[i]

password.sort()
#print(password)   
x=len(password)
#print(x)
for i in range(x-1):
    if password[i]!=password[i+1]:
        count+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [int(i) for i in input()]
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = 0
            for l in s:
                if i == l and tmp == 0:
                    tmp += 1
                elif j == l and tmp == 1:
                    tmp += 1
                elif k == l and tmp == 2:
                    cnt += 1
                    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cnt = 0
for i in range(1000):
    i = str(i).zfill(3)
    tmp = 0
    for j in s:
        if j == i[tmp]:
            tmp += 1
            if tmp == 3:
                cnt += 1
                break
print(cnt)

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):
            hit = 0
            for c in S:
                c_ = int(c)
                if hit == 0 and c_ == i:
                    hit += 1
                elif hit == 1 and c_ == j:
                    hit += 1
                elif hit == 2 and c_ == k:
                    ans += 1
                    break
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):
            hit = 0
            for c in S:
                if hit == 0 and c == str(i):
                    hit += 1
                elif hit == 1 and c == str(j):
                    hit += 1
                elif hit == 2 and c == str(k):
                    ans += 1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

N = int(input())
S = input()
stack = []
heapq.heapify(stack)
cnt = 0
for s in S:
    for i in range(len(stack)):
        if len(stack[i]) <= 2:
            new = s + stack[i]
            if new not in stack:
                stack.append(new)
                if len(new) == 3:
                    cnt += 1
    if s not in stack:
        stack.append(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
stack = []
cnt = 0
for s in S:
    for i in range(len(stack)):
        if len(stack[i]) <= 2:
            new = s + stack[i]
            if new not in stack:
                stack.append(new)
                if len(new) == 3:
                    cnt += 1
    if s not in stack:
        stack.append(s)
print(cnt)

Submission status: Time Limit Exceeded

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

for s in S:
    for i in range(len(stack)):
        if len(stack[i]) <= 2:
            new = s + stack[i]
            if new not in stack:
                stack.append(new)
    if s not in stack:
        stack.append(s)
        
cnt = 0
for w_ in stack:
    if len(w_) == 3:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, = map(int, input().split())
S = input().strip()

ans = 0
for i in range(1000):
    s = str(i).zfill(3)
    t = 0
    for v in S:
        if s[t] == v:
            t += 1
        if t == 3:
            break
    if t == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
number=input().rstrip()
lucky=input()
count=1
password=[]
for i in range(len(lucky)-2):
    word=lucky[i]
    for j in range(i+1,len(lucky)-1):
        word=word+lucky[j]
        for k in range(j+1,len(lucky)):
            word=word+lucky[k]
            password.append(word)
            word=lucky[i]+lucky[j]
        word=lucky[i]

password.sort()
#print(password)   
x=len(password)
#print(x)
for i in range(x-1):
    if password[i]!=password[i+1]:
        count+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
ans = 0
for a2 in range(10):
    for b2 in range(10):
        for c2 in range(10):
            a = str(a2)
            count = 0
            for i in s:
                if a == i:
                    count += 1
                    if count == 1:
                        a = str(b2)
                    if count == 2:
                        a = str(c2)
                    if count == 3:
                        break
            if count == 3:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
s = input()
ans = 0
for a2 in range(10):
    for b2 in range(10):
        for c2 in range(10):
            a = str(a2)
            b = str(b2)
            c = str(c2)
            count = 0
            for i in s:
                if a == i:
                    count += 1
                    if count == 1:
                        a = b
                    if count == 2:
                        a = c
            if count >= 3:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
s = input()
ans = set()
for i in combinations(s,3):
    ans.add(i)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, = map(int, input().split())
S = input().strip()

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

print(len(s)) # very slow

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    e = str(i).zfill(3)
    c = 0
    for s in S:
        if s == e[c]:
            c += 1
            if c == 3:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(0,1000):
  pos=0
  t="{0:03d}".format(i)
  for j in range(int(n)):
    if s[j] == t[pos]:
      pos+=1
    if pos == 3:
      cnt+=1
      break

print(cnt)

Submission status: Time Limit Exceeded

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

cnt=0
for i in range(0,1000):
  pos=-1
  t="{0:03d}".format(i)
  for j in t:
    pos+=1
    while pos < len(s) and j != s[pos]:
      pos+=1
    
  if pos < len(s):
    cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

import re

cnt=0
for i in range(0,1000):
  t="{0:03d}".format(i)
  reg=r'.*'+re.escape(t[0])+r'.*'+re.escape(t[1])+r'.*'+re.escape(t[2])
  if re.search(reg,s):
    cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
n= int(input())
s = str(input())
num = len(s)
ans = 0
for i in range(1000):
    t = (3-len(str(i))) * "0" + str(i)
    key1,key2 = 0,0
    num= len(s)
    for j in range(num):
        if s[j] == t[2] and key2:
            ans += 1
            break
        if s[j] == t[1] and key1:
            key2 = 1
        if s[j] == t[0]:
            key1 = 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().strip()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            cur = [i,j,k]
            ind = 0
            for n in range(N):
                if int(S[n])==cur[ind]:
                    ind += 1
                    if ind==3:
                      cnt += 1
                      break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().strip()
cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            cur = [i,j,k]
            ind = 0
            for n in range(N):
                if int(S[n])==cur[ind]:
                    ind += 1
                    if ind==3:break
            if ind==3:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
input()
S = [int(i) for i in input()]
cnt = 0
for i in range(0, 1000):
  c = (i//100, (i//10)%10, i%10)
  f = 0
  for s in S:
    if s == c[f]:
      f += 1 
      if f==3:break 
  if f==3:cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans1 = 0
for i in range(1000):
  ans = False
  for j in range(N):
    if S[j] == str(i).zfill(3)[0]:
      for k in range(j+1, N):
        if S[k] == str(i).zfill(3)[1]:
          for l in range(k+1, N):
            if S[l] == str(i).zfill(3)[2]:
              ans = True
              break
        if ans:
          break
    if ans:
      break
  if ans:
    ans1 += 1
print(ans1)

Submission status: Time Limit Exceeded

Solution code:
def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

# numpy and scipy are available for use
import numpy
import scipy
#https://atcoder.jp/contests/abc147/tasks/abc147_d
#Xor Sum 4
"""
iterate over bits
1. calculate how many bits we have on that position
2. for each 1, we need to add num 0s * num 1s * 2s
3. sum them up

This version has TLE
"""

# reads a single line
N = gi()
S = gw()

ans = 0
for fd in range(10):
    fi = -1
    for i in range(N):
        if int(S[i]) == fd:
            fi = i
            break
    if fi < 0:
        continue
    for sd in range(10):
        si = -1
        for i in range(fi + 1, N):
            if int(S[i]) == sd:
                si = i
                #                print(i, S[i])
                break
        if si < 0:
            continue
        for td in range(10):
            for i in range(si + 1, N):
                if int(S[i]) == td:
                    ans += 1
                    #                    print(fd, sd, td)
                    break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 組み合わせを全て考える
# タイムアウトになった
N = int(input())
S = input()
L = []
import itertools
seq = [i for i in range(N)]
combi = list(itertools.combinations(seq,3))
for c in combi:
    x = [S[j] for j in c]
    L.append("".join(x))
print(len(set(L)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
def solve():
    ans = 0
    for i in range(1000):
        t = str(i).zfill(3)
        t_index = 0 
        for s_index in range(N):
            if s[s_index] == t[t_index]:
                t_index += 1
                if t_index == 3:
                    break
        if t_index == 3:
            ans += 1
    print(ans)
solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
L = []
import itertools
seq = [i for i in range(N)]
combi = list(itertools.combinations(seq,3))
for c in combi:
    x = [S[j] for j in c]
    L.append("".join(x))
print(len(set(L)))

Submission status: Time Limit Exceeded

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


def main():
    n = int(input())
    s = input()
    ans = 0
    password = [0, 0, 0]
    for i in range(1000):
        for j in range(3):
            password[j] = i // (10 ** j) % 10
        index = 2
        for k in range(n):
            if password[index] == int(s[k]):
                index -= 1
            if index == -1:
                ans += 1
                break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
password = [0, 0, 0]
flag = False
for i in range(1000):
    for j in range(3):
        password[j] = i // (10 ** j) % 10
    index = 2
    for k in range(n):
        if password[index] == int(s[k]):
            index -= 1
        if index == -1:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
flag = False
for i in range(1000):
    a = i % 10
    b = i // 10 % 10
    c = i // 100 % 10
    for j in range(n):
        if int(s[j]) == c:
            for k in range(j + 1, n):
                if int(s[k]) == b:
                    for l in range(k + 1, n):
                        if int(s[l]) == a:
                            ans += 1
                            flag = True
                            break
                if flag:
                    break
        if flag:
            flag = False
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = set()
for i in range(1000):
    a = i % 10
    b = i // 10 % 10
    c = i // 100 % 10
    for j in range(n):
        if int(s[j]) == c:
            for k in range(j + 1, n):
                if int(s[k]) == b:
                    for l in range(k + 1, n):
                        if int(s[l]) == a:
                            ans.add(str(c) + str(b) + str(a))
print(len(ans))

Submission status: Time Limit Exceeded

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

for i in range(1000):
    pin = ("00" + str(i))[-3:]

    j = 0
    for num in S:
        if pin[j] == num:
            j += 1
        if j == 3:
            count += 1
            break

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools, numpy as np
N = int(input())
S = np.array(list(input()))
numbers = set()
for c1, c2, c3 in itertools.combinations(range(N), 3):
    if not S[c1] + S[c2] + S[c3] in numbers:
        numbers.add(S[c1] + S[c2] + S[c3])
print(len(numbers))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = input()
numbers = set()
for c1, c2, c3 in itertools.combinations(range(N), 3):
    if not int(S[c1] + S[c2] + S[c3]) in numbers:
        numbers.add(int(S[c1] + S[c2] + S[c3]))
print(len(numbers))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
c = 0
def cha_3(num_):
    d = 3 - len(num_)
    return d*"0" + num_

for i in range(1000):
    num = cha_3(str(i))
    num_c = 0
    for j in range(len(s)):
        if s[j] == num[num_c]:
            num_c += 1
            if num_c == 3:
                c += 1
                break
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
count=0
for i in range(1000):
    p=str(int(i/100))+str(int(i/10%10))+str(int(i%10))
    l=0
    for j in range(N):
        if S[j]==p[l]:
            l+=1
        if l==3:
            count+=1
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
key=set()
for i in range(N):
    if i>0 and S[i-1]==S[i]:
        continue
    for j in range(i+1, N):
        if j>i+1 and S[j-1]==S[j]:
            continue
        for k in range(j+1, N):
            if k>j+1 and S[k-1]==S[k]:
                continue
            key.add(S[i]+S[j]+S[k])
print(len(key))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

r = 0
for i in range(1000):
  t = str(i).zfill(3)
  ti = 0
  for si in range(n):
    if a[si] == t[ti]:
      ti += 1
      if ti == 3:
        break
  if ti == 3:
    r += 1
print(r)

Submission status: Time Limit Exceeded

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

b = ''
for ai in range(len(a)):
  b += '1'

bi = int(b, 2)
del_num = n - 3

kinds = []
for i in range(bi):
  bin_list = list(format(i, '0'+str(len(a))+'b'))
  if bin_list.count('0') != del_num:
    continue
  k = ''
  for index, s in enumerate(bin_list):
    if s == '1':
      k += str(a[index])
  kinds.append(k)

print(len(set(kinds)))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
  pin = '{:03d}'.format(i)
  j = 0
  for si in s:
    if si == pin[j]:
      j+=1
      if j==3:
        break        
  if j == 3:
    ans+=1
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
set2d = set()

for d1 in range(n-2):
  for d2 in range(d1+1,n-1):    
    if s[d1]+s[d2] not in set2d:      
      set2d.add(s[d1]+s[d2])      
      ans +=len(set(s[d2+1:]))

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
characters = list(S)
for n in range(1000):
    num_str = "{:03d}".format(n)
    i = 0
    for c in characters:
        if c == num_str[i]:
            i += 1
            if i == len(num_str):
                break
    if i == len(num_str):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
l = int(input())
s = input()
r = set()
for x in range(0, l - 2):
    for y in range(x + 1, l - 1):
        for z in range(y + 1, l):
            r.add(s[x] + s[y] + s[z])

print(len(r))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Sstr = str(S)
ListS = []

for i in range(0, N):
    ListS.append(S % 10)
    S = S // 10

ListS.reverse()
resultList = list(itertools.combinations(ListS, 3))
resultList = list(set(resultList))
print(len(resultList))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Sstr = str(S)
ListS = []

for i in range(0, N):
    ListS.insert(0, S % 10)
    S = S // 10
resultList = list(itertools.combinations(ListS, 3))
resultList = list(set(resultList))
print(len(resultList))

Submission status: Time Limit Exceeded

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

count = set([])

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
ans = 0
for i in range(1000):
    t = ""
    x = i
    for j in range(3):
        t += str(x % 10)
        x //= 10

    ti = 0
    for k in range(N):
        if S[k] == t[ti]:
            ti += 1
            if ti == 3:
                break

    if ti == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

c = 0
for i in range(1000):
    num_str = "{0:0>3}".format(i)
    j = 0
    for s in S:
        if num_str[j] == s:
            j += 1
        if j == 3:
            c += 1
            break

print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
s = S()
cnt = 0
for i in range(10 ** 3):
    flag = 0
    for j in range(n):
        for k in range(3):
            if flag == k and str(i).zfill(3)[k] == s[j]:
                flag += 1
                break
        if flag == 3:
            cnt += 1
            break


print(cnt)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(1000):
    flag = 0
    for s in S:
        if flag==0 and (i//100)%10==int(s):
            flag=1
        elif flag==1 and (i//10)%10==int(s):
            flag=2
        elif flag==2 and i%10==int(s):
            flag=3
            break
    if flag==3:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(1000):
    flag = 0
    for s in S:
        if flag==0 and (i//100)%10==int(s):
            flag+=1
        elif flag==1 and (i//10)%10==int(s):
            flag+=1
        elif flag==2 and i%10==int(s):
            flag+=1
    if flag==3:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(1000):
    flag = 0
    for j in range(N):
        if flag==0 and (i//100)%10==int(S[j]):
            flag+=1
        elif flag==1 and (i//10)%10==int(S[j]):
            flag+=1
        elif flag==2 and i%10==int(S[j]):
            flag+=1
    if flag==3:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

LLL=[]
for i in range(2**n):
      L=[0]*n
      for j in range(n):
            if ((i>>j)&1):
                  L[n-1-j]=1
      if sum(L)==3:
            LL=[]
            for k in range(n):
                  if L[k]==1:
                        LL.append(s[k])
            LLL.append(''.join(LL))
print(len(set(LLL)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
S = input()
ans = set({})
lid = list(range(N))

# print(lid)
for p in combinations(lid, 3):
    ss = '_'.join([S[i] for i in lid if i in p])
    # print(p, ss)
    ans.add(ss)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def res(n, s):
    size = len(s)
    arr = set()
    for i in range(size - 2):
        for j in range(i+1, size - 1):
            for k in range(j+1,size):
                arr.add((s[i] + s[j] + s[k]))

    return len(arr)

if __name__== "__main__":
    n = input()
    s = str(input())

    print(res(n, s))

Submission status: Time Limit Exceeded

Solution code:
def res(n, s):
    arr = []
    for i in range(len(s) - 2):
        for j in range(i+1, len(s) - 1):
            for k in range(j+1,len(s)):
                arr.append((s[i] + s[j] + s[k]))

    return len(list(set(arr)))

if __name__== "__main__":
    n = input()
    s = str(input())

    print(res(n, s))

Submission status: Time Limit Exceeded

Solution code:
def res(n, s):
    arr = []
    for i in range(len(s) - 2):
        for j in range(len(s) - 1):
            for k in range(len(s)):
                if i != j and j !=k and i != k and i < j and i < k and j < k:
                    arr.append((s[i] + s[j] + s[k]))
 
    return len(list(set(arr)))
 
if __name__== "__main__":
    n = input()
    s = input()
 
    print(res(n, s))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
S = input()

dp = list3d(N+1, 4, 1000, 0)
dp[0][0][0] = 1
for i in range(N):
    a = int(S[i])
    for j in range(4):
        for k in range(1000):
            dp[i+1][j][k] |= dp[i][j][k]
            if j == 0 and k+a*100 < 1000:
                dp[i+1][j+1][k+a*100] |= dp[i][j][k]
            if j == 1 and k+a*10 < 1000:
                dp[i+1][j+1][k+a*10] |= dp[i][j][k]
            if j == 2 and k+a < 1000:
                dp[i+1][j+1][k+a] |= dp[i][j][k]
ans = 0
for k in range(1000):
    ans += dp[N][3][k]
print(ans)