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
import re
for i in range(10):
    for j in range(10):
        for k in range(10):
            if re.search(f'{i}.*{j}.*{k}', s):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())
S = input()
P = 0
count = 0
for j in range(1000):
    V = str(P).zfill(3)
    p1 = False
    p2 = False
    for i in range(N):
        if S[i] == V[0] and not p1:
            p1 = True
            continue
        if S[i] == V[1] and p1 and not p2:
            p2 = True
            continue
        if S[i] == V[2] and p2:
            count += 1
            break
    P += 1
print (count)

Submission status: Time Limit Exceeded

Solution code:
N  = int(input())
S = input()
result = []
for i in range(0, 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 result:
                result.append(num)
print(len(result))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for x in range(10):
    for y in range(10):
        for z in range(10):
            for i in range(N):
                if x != int(S[i]):
                    continue
                for j in range(i+1, N):
                    if y != int(S[j]):
                        continue
                    for k in range(j+1, N):
                        if z != int(S[k]):
                            continue
                        ans += z == int(S[k])
                        break
                    break
                break
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  center = -1
  for r in range(1, N-1):
    if S[N-r] == z[2]:
      right = N-r
      break
  if right == -1:
    continue
  for c in range(1, right):
    if S[right-c] == z[1]:
      center = right-c
      break
  if center == -1:
    continue
  if z[0] in S[:center]:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

counter = 0
for i in range(10):
    str_i = str(i)
    for j in range(10):
        str_j = str(j)
        for k in range(10):
            str_k = str(k)

            ok_i = False
            ok_j = False

            for _s in s:
                if not ok_i:
                    if _s == str_i:
                        ok_i = True
                else:
                    if not ok_j:
                        if _s == str_j:
                            ok_j = True
                    else:
                        if _s == str_k:
                            counter += 1
                            break

print(counter)

Submission status: Time Limit Exceeded

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

digit_numbers = [v for v in range(len(s))]
num_set = set()

import itertools
for p in itertools.permutations(digit_numbers, 3):
    p = sorted(list(p))
    num = s[p[0]] + s[p[1]] + s[p[2]]
    num_set.add(num)
print(len(num_set))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(input())
d={}
ans=0
for i in range(0,10):
  for x in range(0,n-2):
    if s[x]==str(i):
      
      for j in range(0,10):
        for y in range(x+1,n-1):
          if s[y]==str(j):
           
          
            for k in range(0,10):
              for z in range(y+1,n):
                if s[z]==str(k):
                  v=str(i)+str(j)+str(k)
                  v1=int(v)
                  if v1 not in d:
                    d[v1]=0
                    ans+=1
                  
print(ans)

Submission status: Time Limit Exceeded

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

N = int(readline())
S = readline().rstrip()

ans = 0
for i in range(1000):
  target = str(i).zfill(3)
  ind = 0
  tar_ind = 0
  while ind < N:
    if S[ind] == target[tar_ind]:
      tar_ind += 1
      if tar_ind == 3:
        ans += 1
        break
    ind += 1
  
print(ans)

Submission status: Time Limit Exceeded

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

for v in range(1000):
  V = str(v).zfill(3)
  flag = False

  for i in range(len(S)):
    if S[i] == V[0]:
      p1 = i
      for i in range(p1+1,len(S)):
        if S[i] == V[1]:
          p2 = i
          for i in range(p2+1,len(S)):
            if S[i] == V[2]:
              p3 = i
              flag = True
  if flag:
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

lst = []
lst2 = []
lst3 = []
for i in range(n):
  pin = ''
  if numbers[i] not in lst:
    pin += numbers[i]
    lst.append(pin)
    for j in range(i+1, n):
      pin += numbers[j]
      if pin not in lst2:
        lst2.append(pin)
        for k in range(j+1, n):
          pin += numbers[k]
          if pin not in lst3:
            lst3.append(pin)
          pin = pin[0] + pin[1]
      pin = pin[0]
    if ('0' in lst) and ('1' in lst) and ('2' in lst) and ('3' in lst) and ('4' in lst) and ('5' in lst) and ('6' in lst) and ('7' in lst) and ('8' in lst) and ('9' in lst):
      break
print(len(lst3))

Submission status: Time Limit Exceeded

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

lst = []
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      pin = ''
      pin = numbers[i] + numbers[j] + numbers[k]
      if pin not in lst:
        lst.append(pin)
print(len(lst))

Submission status: Time Limit Exceeded

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

lst = []
lst2 = []
lst3 = []
for i in range(n):
  pin = ''
  if numbers[i] not in lst:
    pin += numbers[i]
    lst.append(pin)
    for j in range(i+1, n):
      pin += numbers[j]
      if pin not in lst2:
        lst2.append(pin)
        for k in range(j+1, n):
          pin += numbers[k]
          if pin not in lst3:
            lst3.append(pin)
          pin = pin[0] + pin[1]
      pin = pin[0]
print(len(lst3))

Submission status: Time Limit Exceeded

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

lst = []
lst2 = []
lst3 = []
for i in range(n):
  pin = ''
  if numbers[i] not in lst:
    pin += numbers[i]
    lst.append(i)
    for j in range(i+1, n):
      pin += numbers[j]
      if pin not in lst2:
        lst2.append(pin)
        for k in range(j+1, n):
          pin += numbers[k]
          if pin not in lst3:
            lst3.append(pin)
          pin = pin[0] + pin[1]
      pin = pin[0]
print(len(lst3))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  center = -1
  for r in range(1, N-1):
    if S[N-r] == z[2]:
      right = N-r
      break
  if right == -1:
    continue
  for c in range(1, right):
    if S[right-c] == z[1]:
      center = right-c
      break
  if center == -1:
    continue
  for l in range(1, center+1):
    if S[center-l] == z[0]:
      ans += 1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
S = str(input())

l = []
li = deque([])
for i in range(1, N-1):
  if S[N-i] not in l:
    l.append(S[N-i])
    li.appendleft(N-i)
    
lis = []
ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    s = S[i] + S[j]
    if s not in lis:
      lis.append(s)
      for k in range(len(li)):
        if j < li[k]:
          ans += len(li)-k
          break

print(ans)

Submission status: Time Limit Exceeded

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

l = []
for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      s = S[i]+S[j]+S[k]
      l.append(s)

l = set(l)
ans = len(l)
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

def run():
    N = input()
    S = input()
    dp = [0] * 1000
    ans = 0
    for n in S:
        n = int(n)
        #print(dp)
        for i in range(1000):
            if i // 100 == n and dp[i] == 0:
                dp[i] = 1
                #print(f'{i} -> 1')
            elif (i // 10) % 10 == n and dp[i] == 1:
                dp[i] = 2
                #print(f'{i} -> 2')
            elif i % 10 == n and dp[i] == 2:
                dp[i] = 3
                #print(f'{i} -> 3')
                ans += 1
    print(ans)

    #print(factorials)
if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s = [_ for _ in input()]

a = set()
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      a.add(''.join([s[i],s[j],s[k]]))

print(len(a))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = input()
p = {i for i in itertools.combinations(s,3)}
print(len(p))

Submission status: Time Limit Exceeded

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

passwords =[]

a_log=[]
ab_log=[]

for a in range(n-2):
    
    is_a_kaburi = 0
    
    for i in a_log:
        
        if i == s[a]:
            is_a_kaburi = 1
            
    if is_a_kaburi == 0:
        
        a_log.append(s[a])
        
        for b in range(a+1,n-1):
            
            is_ab_kaburi = 0
            
            for i in ab_log:
                
                if i == s[a]+s[b]:
                    is_ab_kaburi = 1
                    
            if is_ab_kaburi == 0:
                
                ab_log.append(s[a]+s[b])
    
                for c in range(b+1,n):
                    
                    is_abc_kaburi = 0
                    pw = s[a] + s[b] + s[c] 
                    
                    for i in passwords:
                
                        if i == pw:
                            is_abc_kaburi = 1
                            
                    if is_abc_kaburi == 0:
                        passwords.append(pw)
    
                        
                        # print(pw, is_a_kaburi, is_ab_kaburi)

print(len(passwords))

Submission status: Time Limit Exceeded

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

passwords =[]

a_log=[]
ab_log=[]

for a in range(n-2):
    
    is_a_kaburi = 0
    
    for i in a_log:
        
        if i == s[a]:
            is_a_kaburi = 1
            
    if is_a_kaburi == 0:
        
        a_log.append(a)
        
        for b in range(a+1,n-1):
            
            is_ab_kaburi = 0
            
            for i in ab_log:
                
                if i == s[a]+s[b]:
                    is_ab_kaburi = 1
                    
            if is_ab_kaburi == 0:
                
                ab_log.append(a+b)
    
                for c in range(b+1,n):
                    
                    is_abc_kaburi = 0
                    pw = s[a] + s[b] + s[c] 
                    
                    for i in passwords:
                
                        if i == pw:
                            is_abc_kaburi = 1
                            
                    if is_abc_kaburi == 0:
                        passwords.append(pw)
    
                        
                        # print(pw, is_a_kaburi, is_ab_kaburi)

print(len(passwords))

Submission status: Time Limit Exceeded

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

passwords =[]

a_log=[]
ab_log=[]

for a in range(n-2):
    
    is_a_kaburi = 0
    
    for i in a_log:
        
        if i == s[a]:
            is_a_kaburi = 1
            
    if is_a_kaburi == 0:
        
        a_log.append(a)
        
        for b in range(a+1,n-1):
            
            is_ab_kaburi = 0
            
            for i in ab_log:
                
                if i == s[a]+s[b]:
                    is_ab_kaburi = 1
                    
            if is_ab_kaburi == 0:
                
                ab_log.append(a+b)
    
                for c in range(b+1,n):
                    
                    pw = s[a] + s[b] + s[c] 
                    passwords.append(pw)
                    passwords = list(set(passwords))
                    
                    # print(pw, is_a_kaburi, is_ab_kaburi)

print(len(passwords))

Submission status: Time Limit Exceeded

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

passwords =[]

for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            
            pw = s[a] + s[b] + s[c] 
            passwords.append(pw)
            passwords = list(set(passwords))
            
            # print(pw)

print(len(passwords))

Submission status: Time Limit Exceeded

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

passwords =[]

for a in range(n-2):
    for b in range(a+1,n-1):
        for c in range(b+1,n):
            
            pw = s[a] + s[b] + s[c] 
            passwords.append(pw)
            
            # print(pw)
passwords = list(set(passwords))
print(len(passwords))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = input()
ans = set()
for i in combinations(s, 3):
    a = ''.join(i)
    if not a in ans:
        ans.add(a) 
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
s = input()
ans = []
for i in combinations(s, 3):
    ans += [''.join(i)]
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
lis = [0]*1000
#one = [0]*10
#two = [0]*10
#three=[0]*10
from itertools import combinations
for i,j,k in combinations(list(range(n)), 3):
  temp = int("".join([s[i], s[j], s[k]]))
  if lis[temp]==0:
    ans+=1
    lis[temp]=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
lis = [0]*1000
for i in range(n):
  for j in range(i+1, n):
    for k in range(j+1, n):
      num = int("".join([s[i],s[j],s[k]]))
      #print(num)
      if lis[num]==0:
        ans+=1
        lis[num]=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cou = 0
for i in range(1000):
  i = "{0:03d}".format(i)
  t = 0
  r = 0
  while r!=n:
    if s[r]==i[t]:
      t += 1
    if t==3:
      cou += 1
      r = n-1
    r += 1            
print(cou)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cou = 0
for i in range(1000):
  i = "{0:03d}".format(i)
  t = 0
  r = 0
  while r!=n:
    if s[r]==i[t]:
      t += 1
    if t==3:
      t = 0
      cou += 1
      r = n-1
    r += 1
    
              
print(cou)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cou = 0
for i in range(1000):
  i = "{0:03d}".format(i)
  t = 0
  r = 0
  while r!=n:
    if s[r]==i[t]:
      t += 1
    if t==3:
      t = 0
      cou += 1
      break
    r += 1
    
              
print(cou)

Submission status: Time Limit Exceeded

Solution code:
"""
全探索
左から文字を1個ずつ取っていく
かぶりをなくすために一回リストに格納した後セットにする
"""
n = int(input())
s = input()
ans = 0
l = []
for n1 in range(n-2) :
    for n2 in range(n1+1,n-1) :
        for n3 in range(n2+1,n) :
            l.append(s[n1]+s[n2]+s[n3])
l = set(l)
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
flg = [0 for i in range(1000)]
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(10):
            if str(k) in s[j + 1:]:
                flg[int(s[i] + s[j] + str(k))] = 1
print(flg.count(1))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
flg = [0 for i in range(1000)]
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            flg[int(s[i] + s[j] + s[k])] = 1
print(flg.count(1))

Submission status: Time Limit Exceeded

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

N = int(input())
S = input()
q = collections.deque()
pm = itertools.combinations(range(N),3)

for i in pm:
    s = S[i[0]]+S[i[1]]+S[i[2]]
    q.append(s)
print(len(set(q)))

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = input()

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
def check(string):
    for j in range(n - 2):
        if s[j] != temp[0]:continue 
        for k in range(j + 1, n - 1):
            if s[k] != temp[1]:continue 
            for l in range(k + 1, n):
                if s[l] == temp[2]:return 1
            
            return 0
    return 0
n = int(input())
s = input()
res = 0

for i in range(1000):
    temp = '00' + str(i)
    temp = temp[-3:]
    res += check(temp)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
S = input()
S_list = [S[i] for i in range(N)]
S_c = collections.Counter(S_list)
list12 = []
ans = 0
for i in range(N-2):
    s1 = S_list[i]
    S_c[s1] = S_c[s1]-1
    S_c23 = S_c.copy()

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

        s2 = S_list[j]

        S_c23[s2] = S_c23[s2] - 1
        if (s1+s2) in list12:
            pass
        else:
            list12.append(s1+s2)
            for key in S_c23.keys():
                if S_c23[key] != 0:
                    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    s = input().strip().decode()
    ans = 0
    for p in product(range(10), repeat=3):
        matched = 0
        for i in range(n):
            if s[i] == str(p[matched]):
                matched += 1
            if matched == 3:
                ans += 1
                break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import product


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    s = input().strip().decode()
    ans = 0
    for p in product(range(10), repeat=3):
        pointer = 0
        for c in map(str, p):
            while pointer < n:
                if s[pointer] == c:
                    pointer += 1
                    break
                pointer += 1
            else:
                break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
#m1,d1=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
S=list(input())
d=list('0123456789')
ans=0
for d1 in d:
    for d2 in d:
        for d3 in d:
            v=d1+d2+d3
            i=0
            p=0
            while i < N :
                if v[p]==S[i]:
                    p+=1
                    if p == 3:
                        break
                i+=1
            if p==3 :
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

list = []

for i in range(0, N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      list.append(S[i] + S[j] + S[k])

list = set(list)

print(len(list))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N=int(input())
S=input()
num=list(itertools.combinations([i for i in range(N)],3))
l=[]
for i in range(len(num)):
	l.append(S[num[i][0]]+S[num[i][1]]+S[num[i][2]])

print(len(list(set(l))))

Submission status: Time Limit Exceeded

Solution code:
# 5
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
s = S()
ciphers = [f'{i:03}' for i in range(1000)]
ans = 0
for v in ciphers:
    j = 0
    for i in range(n):
        if s[i] == v[j]:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from re import *
n=int(input())
s=input()
l=["0","1","2","3","4","5","6","7","8","9"]
ans=0
for i in l:
    for j in l:
        for k in l:
            if match(".*{}.*{}.*{}".format(i,j,k),s):
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re

n = int(input())
s = input()
cnt = 0

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

Submission status: Time Limit Exceeded

Solution code:
import re

n = int(input())
s = input()
cnt = 0

for i in range(1000):
    tgt = str(i).zfill(3)
    pattern = '.*' + tgt[0] + '.*' + tgt[1] + '.*' + tgt[2] + '.*'
    if re.match(pattern, s):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1000):
    t = str(i)
    t = t.zfill(3)
    now = t[0]
    count = 0
    for j in S:
        if count == 0 and now == j:
            now = t[1]
            count += 1
            continue
        if count == 1 and now == j:
            now = t[2]
            count += 1
            continue
        if count == 2 and now == j:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    S = str(input())
    cnt = 0

    for i in range(1000):
        c = [int(i / 100), int(i / 10) % 10, int(i % 10)]
        f = 0

        for j in range(N):
            if S[j] == ('0' + str(c[f])) or S[j] == str(c[f]):
                f += 1
            if f == 3:
                break

        if f == 3:
            cnt += 1
    print(cnt)
    return

resolve()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

def resolve():
    N = int(input())
    S = str(input())
    ans = []
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                ans.append(S[i] + S[j] + S[k])

    print(len(set(ans)))
    return

resolve()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

def resolve():
    N = int(input())
    S = str(input())
    ans = []
    for i in range(N):
        for j in range(N):
            for k in range(N):
                if i < j and j < k:
                    ans.append(S[i] + S[j] + S[k])

    print(len(set(ans)))
    return

resolve()

Submission status: Time Limit Exceeded

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

result = 0
for i in range(0, 1000):
    number = ''.join(['00', str(i)])[-3:]
    number_i = 0
    for s in S:
        if number[number_i] == s:
            number_i += 1
            if number_i == 3:
                result += 1
                break

print(result)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
s=input()
l=[0]*1000
for _ in range(n):
    i=s[_]
    for j in range(1000):
        k=str(j).zfill(3)
        if k[0]==i:
            if l[j]==2:
                l[j]=3
        if k[1]==i:
            if l[j]==1:
                l[j]=2
        if k[2]==i:
            if l[j]==0:
                l[j]=1
ans=0
for i in l:
    if i==3:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

a = []
ans = 0

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]
            if not t in a:
                a.append(t)
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

print(len(set_S))

Submission status: Time Limit Exceeded

Solution code:
#2020.07.13
N = int(input())
S = input()
ans = 0
for number in range(1000):
    strnum = str(number).zfill(3)
    a,b,c = list(strnum)
    
    for i in range(N-2):
        if a != S[i]:
            continue
        
        flag = False
        
        for j in range(i+1, N-1):
            if b != S[j]:
                continue
            
            if c in S[j+1:]:
                ans += 1
                flag = True
                break
        
        if flag:
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

N=int(input())
S=list(input())
bango=[]
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            s=[S[i],S[j],S[k]]
            n=''.join(s)
            if n not in bango:
                ans+=1
            bango.append(n)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 視点を変えてやる全探索 000~999までが達成できたらおｋ
n = int(input())
s = list(input())
ans = 0
for i in range(1000):
    t = list(f"{i:0>3}")
    j = 0
    tmp = ""
    for c in s:
        if t[j] == c:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations 

n=int(input())
s=input()
con=set()
for i in combinations(s,3):
  con.add(i)
  
print(len(con))

Submission status: Time Limit Exceeded

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

pin = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            pin.append(str(i)+str(j)+str(k))

count = 0
for i in range(len(pin)):
    l, m, n = pin[i][0], pin[i][1], pin[i][2]
    l_idx, m_idx, n_idx = -1, -1, -1
    for i in range(N):
        if S[i] == l:
            l_idx = i
            break
    if l_idx != -1:
        for i in range(l_idx+1, N):
            if S[i] == m:
                m_idx = i
                break
    if m_idx != -1:
        for i in range(m_idx+1, N):
            if S[i] == n:
                n_idx = i
                break
    if l_idx != -1 and m_idx != -1 and n_idx != -1:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

for x in range(n - 2):
    for y in range(x + 1, n - 1):
        for z in range(y + 1, n):
            name.add(int(s[x] + s[y] + s[z]))

print(len(name))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
S=input()
dic={}
for i in range(N-2):
    if len(dic)==1000:
        break
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            tmp=S[i]+S[j]+S[k]
            dic[tmp]=1
print(len(dic))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
S=input()
dic={}
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            tmp=S[i]+S[j]+S[k]
            dic[tmp]=1
print(len(dic))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
S=input()
dic={}
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            tmp=S[i]+S[j]+S[k]
            if tmp in dic:
                pass
            else:    
                dic[tmp]=1
print(len(dic))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
S.append("a")
n = list(map(str,range(0,10)))
ans = 0
for i in n:
    for j in n:
        for k in n:
            num = i+j+k
            now = 0

            for l in range(N+1):
                if now == 3:
                    ans += 1
                    break
                if num[now] == S[l]:
                    now += 1
print(ans)

Submission status: Time Limit Exceeded

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

for j in range(1000):
    l = str(j)
    if len(l) == 1:
        l = "00"+l
    if len(l) == 2:
        l = "0" + l
    k = 0
    for i in range(N):
        if S[i] == l[k]:
            k += 1
        if k == 3:
            ans += 1
            break
print(ans)