Problem:


Score: 400 points

Problem Statement

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

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

How many different PIN codes can he set this way?

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

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

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

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
  
ans = 0
for i1 in range(10):
  for i2 in range(10):
    for i3 in range(10):
      n1 = 0
      n2 = 0
      n3 = 0
      p1 = 0
      p2 = 0
      p3 = 0
      while(p1 < len(S)):
        if(int(S[p1]) == i1):
          p2 = p1 + 1
          n1 = 1
          break
        p1 += 1
      while(p2 < len(S)):
        if(int(S[p2]) == i2):
          p3 = p2 + 1
          n2 = 1
          break
        p2 += 1
      while(p3 < len(S)):
        if(int(S[p3]) == i3):
          n3 = 1
          break
        p3 += 1
      if(n1 == 1 and n2 == 1 and n3 == 1):
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
  
ans = 0
for i1 in range(10):
  for i2 in range(10):
    for i3 in range(10):
      n1 = 0
      n2 = 0
      n3 = 0
      p1 = 0
      p2 = 0
      p3 = 0
      while(p1 < len(S)):
        if(int(S[p1]) == i1):
          p2 = p1 + 1
          n1 = 1
          break
        p1 += 1
      while(p2 < len(S)):
        if(int(S[p2]) == i2):
          p3 = p2 + 1
          n2 = 1
          break
        p2 += 1
      while(p3 < len(S)):
        if(int(S[p3]) == i3):
          n3 = 1
          break
        p3 += 1
      if(n1 == 1 and n2 == 1 and n3 == 1):
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

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

ret = set()

import itertools
for v in itertools.combinations(s, 3):
    ret.add(''.join(v))

print(len(ret))

Submission status: Time Limit Exceeded

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

length = len(S)

number_list = []
for v in itertools.combinations(S, 3):
    number = ''.join(v)
    number_list.append(number)

uniq_number_list = set(number_list)

print(len(uniq_number_list))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import itertools

N = int(input().split()[0])
S = input()

index_list = [i for i in range(N)]
p_list = []

for pattern in itertools.combinations(index_list, 3):
    a, b, c = list(sorted(list(pattern)))

    s = S[a] + S[b] + S[c]
    p_list.append(s)

ans = len(set(p_list))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

memory = []
for v in itertools.combinations(S, 3):
  memory.append(v)
print(len(set(memory)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

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

memory = set()
for v in itertools.combinations(S, 3):
  memory.add(v)
print(len(set(memory)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

memory = []
for v in itertools.combinations(S, 3):
  if v not in memory:
    memory.append(v)
print(len(memory))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = readline()
count = 0
for i in range(0,1000):
    c = (i//100,(i//10)%10,i%10)
    f = 0
    for j in range(0,N):
        if int(S[j]) == int(c[f]):
            f += 1
        if f == 3:
            break
    if f == 3:
        count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = readline()
count = 0
for i in range(0,1000):
    c = [i//100,(i//10)%10,i%10]
    f = 0
    for j in range(0,N):
        if int(S[j]) == int(c[f]):
            f += 1
        if f == 3:
            break
    if f == 3:
        count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = readline()
count = 0
for i in range(0,1000):
    c = [i//100,(i//10)%10,i%10]
    f = 0
    for j in range(0,N):
        if int(S[j]) == int(c[f]):
            f += 1
        if f == 3:
            break
    if f == 3:
        count += 1
            
print(count)

Submission status: Time Limit Exceeded

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

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            state = 0
            for c in s:
                if int(c) == i and state == 0:
                    state = 1
                elif int(c) == j and state == 1:
                    state = 2
                elif int(c) == k and state == 2:
                    state = 3
            if state == 3:
                res += 1
print(res)

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

Solution code:
# 20/4/20 Youtube解説の方法
n = int(input())
s = input()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input()))
k=len(l)
H=[]
I=[]
J=[]
for h in range(k-2):
    for i in range(h+1,k-1):
        for j in range(i+1,k):
            H.append(l[h])
            I.append(l[i])
            J.append(l[j])
p=len(H)
count=1
for q in range(p-1):
    flag=True
    for r in range(q+1,p):
        if H[q]!=H[r] or I[q]!=I[r] or J[q]!=J[r]:
            continue
        else:
            flag=False
            break
    if flag==True:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
S = input()
c = 0
for i in range(1000):
    if 0 <= i and i <= 9:
        s0 = "0"
        s1 = "0"
        s2 = str(i)
    elif 10 <= i and i <= 99:
        s0 = "0"
        s = str(i)
        s1 = s[0]
        s2 = s[1]
    else:
        s = str(i)
        s0 = s[0]
        s1 = s[1]
        s2 = s[2]
    i0 = -1
    i1 = -1
    i2 = -1
    for k in range(N-2):
        if S[k] == s0:
            i0 = k
            break
    if i0 == -1:
        continue
    for j in range(i0+1,N-1):
        if S[j] == s1:
            i1 = j
            break
    if i1 == -1:
        continue
    for l in range(i1+1,N):
        if S[l] == s2:
            i2 = l
            break
    if i2 != -1:
        c +=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
st=set()
seti=set()
for i in range(n-2):
    if i in seti:
        continue
    seti.add(i)
    
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            pas=str(s[i])+str(s[j])+str(s[k])
            st.add(pas)


print(len(st))

Submission status: Time Limit Exceeded

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

st=set()
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            pas=str(s[i])+str(s[j])+str(s[k])
            st.add(pas)


print(len(st))

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):
            p = 0
            for f in range(n):
                if p == 0 and s[f] == str(i):
                    p = 1
                elif p == 1 and s[f] == str(j):
                    p = 2
                elif p == 2 and s[f] == str(k):
                    ans += 1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N = int(input())
    S = input()
    count = 0
    for i in range(0,1000):
        num = str(i).zfill(3)
        digit = 0
        for j in range(N):
            if S[j] == num[digit]:
                digit += 1
            if digit == 3:
                break
        if digit ==3:
            count += 1

    print(count)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
for i in range(0,1000):
    num = str(i).zfill(3)
    digit = 0
    for j in range(N):
        if S[j] == num[digit]:
            digit += 1
        if digit == 3:
            break
    else:
        continue
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
for i in range(0,1000):
    num = str(i).zfill(3)
    for j in range(N):
        for k in range(j+1, N):
            for l in range(k+1, N):
                if num == S[j]+ S[k]+S[l]:
                    count += 1
                    break
            else:
                continue
            break
        else:
            continue
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
numbers=[str(i).zfill(3) for i in range(1000)]
 
count=0
for num in numbers:
  j=0
  for i in range(N):
    if num[j]==S[i]:
      j+=1
      if j==3:
        count+=1
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
 
lis = [0 for _ in range(1000)]
 
usiro_lis = [[0 for _ in range(10)] for _ in range(N)]
for i in range(N)[::-1]:
  for j in range(0, i):
    usiro_lis[j][int(S[i])] = 1

for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(10):
      if usiro_lis[j][k] == 1:
      	lis[100*int(S[i])+10*int(S[j])+k] = 1
      
print(sum(lis))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
 
lis = [0 for _ in range(1000)]
 
for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      lis[100*int(S[i])+10*int(S[j])+int(S[k])] = 1
      
print(sum(lis))

Submission status: Time Limit Exceeded

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

lis = [0 for _ in range(1000)]

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

for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(10):
      if usiro_lis[j][k] == 1:
      	lis[100*int(S[i])+10*int(S[j])+k] = 1
      
print(sum(lis))

Submission status: Time Limit Exceeded

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

lis = [0 for _ in range(1000)]

for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      lis[100*int(S[i])+10*int(S[j])+int(S[k])] = 1
      
print(sum(lis))

Submission status: Time Limit Exceeded

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

from itertools import combinations
y = list(combinations(x, 3))

print(len(set(y)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [int(x) for x in list(input())]
total = 0
for a in range(1000):
  tmp = [a//100,a//10%10,a%10]
  i = 0
  for x in range(N):
    if tmp[i] == S[x]:
      i+=1
    if i==3:
      total+=1
      break
print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [int(x) for x in list(input())]
total = 0
flag = True
for a in range(1000):
  flag = True
  for x in range(N-2):
    if S[x] == a//100:
      for y in range(x+1,N-1):
        if S[y] == a//10%10:
          for z in range(y+1,N):
            if a == S[x]*100+S[y]*10+S[z]:
              flag = False
              total += 1
              break
        if not flag:
          break
    if not flag:
      break
print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [int(x) for x in list(input())]
total = []
for x in range(N-2):
  for y in range(x+1,N-1):
    for z in range(y+1,N):
      total.append(S[x]*100+S[y]*10+S[z])
print(len(set(total)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [int(x) for x in list(input())]
total = []
for x in range(N-2):
  for y in range(x+1,N-1):
    for z in range(y+1,N):
      total.append(S[x]*100+S[y]*10+S[z])
print(len(set(total)))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as cnt
n = int(input())
s = list(input())

count = cnt(s)
num_rest = []
for i in range(n):
  count[s[i]] -= 1
  rest = 0
  for value in count.values():
    if value != 0:
      rest += 1
  num_rest.append(rest)
#print(num_rest)

checked = {}
total = 0
for i in range(n-2):
  if s[i] not in checked:
    checked[s[i]] = set()
  elif len(checked[s[i]]) == 10:
    continue
  for j in range(i+1, n-1):
    if s[j] not in checked[s[i]]:
      checked[s[i]].add(s[j])
      total += num_rest[j]
print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as cnt
n = int(input())
s = list(input())

count = cnt(s)
num_rest = []
for i in range(n):
  count[s[i]] -= 1
  rest = 0
  for value in count.values():
    if value != 0:
      rest += 1
  num_rest.append(rest)
#print(num_rest)

checked = set()
total = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    if s[i] + s[j] not in checked:
      checked.add(s[i] + s[j])
      total += num_rest[j]
print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as cnt
import copy
n = int(input())
s = input()

count = cnt(s)
num_rest = []
for i in range(n):
  count[s[i]] -= 1
  rest = 0
  for value in count.values():
    if value != 0:
      rest += 1
  num_rest.append(rest)
#print(num_rest)

checked = set()
total = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    if s[i] + s[j] not in checked:
      checked.add(s[i] + s[j])
      total += num_rest[j]
print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as cnt
import copy
n = int(input())
s = input()

count = cnt(s)
num_rest = []
for i in range(n):
  count[s[i]] -= 1
  num_rest.append(len([i for i in count.values() if i != 0]))
#print(num_rest)

checked = set()
total = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    if s[i] + s[j] not in checked:
      checked.add(s[i] + s[j])
      total += num_rest[j]
print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as cnt
import copy
n = int(input())
s = input()

count = cnt(s)
num_rest = []
for i in range(n):
  dic = copy.copy(count)
  dic[s[i]] -= 1
  num_rest.append(len([i for i in dic.values() if i != 0]))
  count = dic
#print(num_rest)

checked = set()
total = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    if s[i] + s[j] not in checked:
      checked.add(s[i] + s[j])
      total += num_rest[j]
print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip() # ignore trailing spaces 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

def sumitrust2019_d(a,b,c,s):
    a,b,c = map(str,[a,b,c])
    for idx_a in range(len(s)-2):
        if s[idx_a] == a:
            for idx_b in range(idx_a+1,len(s)-1):
                if s[idx_b] == b:
                    for idx_c in range(idx_b+1,len(s)):
                        if s[idx_c] == c:
                                return True
    else:
        return False

def main():
    n = ni()
    s = ns()
    ans = 0
    for a in range(10):
        for b in range(10):
            for c in range(10):
                if sumitrust2019_d(a,b,c,s):
                    ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = set()
for comb in combinations(range(len(S)), 3):
    password = ""
    for c in comb:
        password += S[c]
    ans.add(password)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def DFS(word,N):
    if len(word)==3:A.add(word)
    if len(word)>3:return
    for i in range(N+1,n):
        DFS(word+s[i],i)


n=int(input())
s=input()
A=set()
for i in range(n):
    DFS(s[i],i)
print(len(A))

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:
N = int(input())
S = input()

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

print(len(key))

Submission status: Time Limit Exceeded

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

key = set()
for i in range(0, N-2):
    for j in range(i+1, N-1):
        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:
import sys
from itertools import accumulate


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


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

    def find(a, b, c):
        for j in range(N - 2):
            if int(S[j]) == a:
                for k in range(j + 1, N - 1):
                    if int(S[k]) == b:
                        for l in range(k + 1, N):
                            if int(S[l]) == c:
                                return 1
        return 0

    for i in range(1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
        ans += find(a, b, c)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#from math import factorial
n = int(input())
s = input()
ans = 0
for i in range(1000):
    i=str(i).zfill(3)
    now = 0
    for S in s:
        if S==i[now]:
            now+=1
        if now == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
l=set()
r=set()
for i in range(0,n-2):
    if s[i] in r:
        continue
    else:
        r.add(s[i])
    for j in range(i+1,n-1):
        # print(i,s[i])
        if i==0 and j>=2 and s[j]==s[1]  :
            continue
        for k in range(j+1,n):
            if j==1 and k>=3 and s[k]==s[2]:
                continue
            m=s[i]+s[j]+s[k]
            l.add(m)
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
l=set()
for i in range(0,n-2):
    if i>=1 and s[i]==s[0]  :
        continue
    for j in range(i+1,n-1):
        # print(i,s[i])
        if i==0 and j>=2 and s[j]==s[1]  :
            continue
        for k in range(j+1,n):
            if i==0 and j==1 and k>=3 and s[k]==s[2]:
                continue
            m=s[i]+s[j]+s[k]
            l.add(m)



print(len(l))

Submission status: Time Limit Exceeded

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

y = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            # print(i,j,k)
            c = str(i)
            p = 0
            l = 0
            while l < N:
                if p == 0 and S[l] == c:
                    c = str(j)
                    p = 1
                elif p == 1 and S[l] == c:
                    c = str(k)
                    p = 2
                elif p == 2 and S[l] == c:
                    y += 1
                    # print("pin")
                    break
                l += 1
print(y)

Submission status: Time Limit Exceeded

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

L = []
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            num = S[i]+S[j]+S[k]
            if num not in L:
                L.append(num)
print(len(L))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import deque
n=int(input())
s=list(input())
ans=deque()
for i in itertools.combinations(s, 3):
	a,b,c=map(int,i)
	ans.appendleft(100*a+10*b+c)
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import deque
n=int(input())
s=input()
ans=deque()
for i in itertools.combinations(range(n), 3):
	a,b,c=map(int,i)
	ans.appendleft(100*s[a]+10*s[b]+s[c])
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import deque
n=int(input())
s=input()
ans=deque()
for i in itertools.combinations(range(n), 3):
	a,b,c=map(int,i)
	an=(s[a],s[b],s[c])
	ans.appendleft(''.join(an))
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import deque
n=int(input())
s=input()
ans=deque()
for i in itertools.combinations(range(n), 3):
	a,b,c=map(int,i)
	an=(s[a],s[b],s[c])
	ans.append(''.join(an))
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
s=input()
ans=[]
for i in itertools.combinations(range(n), 3):
	a,b,c=map(int,i)
	an=(s[a],s[b],s[c])
	ans.append(''.join(an))
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
s=input()
ans=[]
for i in itertools.combinations(range(n), 3):
	an=[]
	a,b,c=map(int,i)
	an.append(s[a])
	an.append(s[b])
	an.append(s[c])
	ans.append(''.join(an))
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
n=int(input())
s=input()
ans=[]
for i in itertools.combinations(range(n), 3):
	d=s
	an=[]
	a,b,c=map(int,i)
	an.append(d[a])
	an.append(d[b])
	an.append(d[c])
	ans.append(''.join(an))
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int, list(input())))
ans = 0
for i in range(1000):
    c = 0
    for j in s:
        if i % 10 == j:
            if c == 2:
                ans += 1
                break
            c += 1
            i //= 10
print(ans)

Submission status: Time Limit Exceeded

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

res = []
pw = ""
for i in range(2 ** N):
    cnt = 0
    for j in range(N):
        if (i >> j) & 1 == 1:
            cnt += 1
            pw += S[j]
        if cnt > 3:
            break
    if cnt == 3:
        res.append(pw)
        pw = ""
    else:
        pw = ""

print(len(set(res)))

Submission status: Time Limit Exceeded

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

res = []
pw = ""
for i in range(2 ** N):
    cnt = 0
    for j in range(N):
        if (i >> j) & 1 == 1:
            cnt += 1
            pw += S[j]
    if cnt == 3:
        res.append(pw)
        pw = ""
    else:
        pw = ""

print(len(set(res)))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline  # 改行コード「\n」を呼んでしまうため、文字数など、注意！！

n = int(input().replace("\n",""))
s = input().replace("\n","")

anslist = []
ans = 0

for i in range(1000):
    if i < 10:
        chk = '00' + str(i)
    elif i < 100:
        chk = '0' + str(i)
    else:
        chk = str(i)

    for j in range(len(s)):
        if s[j] == chk[0]:
            for k in range(j+1, len(s)):
                if s[k] == chk[1]:
                    for l in range(k+1, len(s)):
                        if s[l] == chk[2]:
                            # print(chk)
                            anslist.append(chk)
            continue
ans = len(set(anslist))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


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

    for p in range(1000):
        p = str(p).zfill(3)
        i = 0
        for j in range(N):
            if p[i] == S[j]:
                i += 1
            if i == 3:
                ans += 1
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for p in range(1000):
    p = str(p).zfill(3)
    i = 0
    for j in range(N):
        if p[i] == S[j]:
            i += 1
        if i == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

# 真ん中を固定
for i in range(1, N - 1):
    left = set(S[:i])
    right = set(S[i + 1 :])
    for l in left:
        for r in right:
            ans.add(l + S[i] + r)

print(len(ans))

Submission status: Time Limit Exceeded

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

    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                num = [i,j,k]
                idx = 0
                for digit in S:
                    digit = int(digit)
                    if digit == num[idx]:
                        idx += 1
                    if idx == 3:
                        ans += 1
                        break
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

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

    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                num = [i,j,k]
                idx = 0
                for digit in S:
                    digit = int(digit)
                    if digit == num[idx]:
                        idx += 1
                    if idx == 3:
                        ans += 1
                        break
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    s = str(i)
    num = [0]*3
    if len(s) == 1:
        num[2] = i
    elif len(s) == 2:
        num[1] = int(s[0])
        num[2] = int(s[1])
    else:
        num[0] = int(s[0])
        num[1] = int(s[1])
        num[2] = int(s[2])
    flag2 = True
    start = 0
    for j in range(3):
        flag = False
        for k in range(start,N):
            if num[j] == int(S[k]):
                flag = True
                start = k+1
                break
        if flag == False:
            flag2 = False
            break    
    if flag2:
        ans+=1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

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

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

print(len(collections.Counter(comb)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s = input()
c = []
for i in range(n):
    c.append(i)
p_list = list(itertools.combinations(c, 3))
d = []
for i in range(len(p_list)):
    a = p_list[i][0]
    b = p_list[i][1]
    c = p_list[i][2]
    d.append(s[a] + s[b] + s[c])
print(len(set(d)))

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):
            flag = 0
            for c in s:
                p = flag == 0 and c == str(i)
                q = flag == 1 and c == str(j)
                r = flag == 2 and c == str(k)
                if p or q or r:
                    flag += 1
            if flag == 3:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

def check(pin):
    i = 0
    pi = 0
    while i<n and pi<3:
        if s[i]==pin[pi]:
            pi += 1
        i += 1
    return pi==3

res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if check(str(i)+str(j)+str(k)):
                res += 1

print(res)

Submission status: Time Limit Exceeded

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

def listup(s):
    ans = [0 for i in range(10)]
    for i in range(len(s)):
        ans[int(s[i])] += 1
    return ans

ans = [0 for i in range(1000)]
l = '0123456789'
for i in range(1,N):
    b = S[i]
    for a in l:
        A = listup(S[:i])
        if A[int(a)] > 0:
            for c in l:
                C = listup(S[i+1:])
                if C[int(c)] > 0:
                    s = a + b + c
                    ans[int(s)] = 1
print(sum(ans))

Submission status: Time Limit Exceeded

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

ans = [0 for i in range(1000)]
l = '0123456789'
for i in range(1,N):
    b = S[i]
    for a in l:
        if a in S[:i]:
            for c in l:
                if c in S[i+1:]:
                    s = a + b + c
                    ans[int(s)] = 1
print(sum(ans))

Submission status: Time Limit Exceeded

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

ans = [0 for i in range(1000)]
for i in range(N):
    a = S[i]
    for j in range(i+1,N):
        b = S[j]
        for c in '0123456789':
            if c in S[j+1:]:
                s = a + b + c
                ans[int(s)] = 1
print(sum(ans))

Submission status: Time Limit Exceeded

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

ans = [0 for i in range(1000)]
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            s = S[i] + S[j] + S[k]
            ans[int(s)] = 1
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = set()
for i in range(10):
  for I in range(n-2):
    if s[I] == str(i):
      for j in range(10):
        for J in range(I+1,n-1):
          if s[J] == str(j):
            for l in range(10):
              for L in range(J+1,n):
                if s[L] == str(l):
                  ans.add(i*100+j*10+l)
                  break
                  
            break
print(len(ans))