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=[str(i) for i in input()]
l=[]
for i in range(10):
  for j in range(10):
    for k in range(10):
      l.append(str(i)+str(j)+str(k))

ans=0
for i in range(len(l)):
  now=l[i]
  j=0
  for s in range(N):
    if S[s]==now[j]:
      j+=1

    if j==3:
      ans+=1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    N=int(input())
    S=input()
    ans = 0
    char = list(set(map(int,S)))
    for i in range(10):
        if i not in char:
            continue
        for j in range(10):
            if j not in char:
                continue
            for k in range(10):
                if k not in char:
                    continue
                t = 0
                ls = [i,j,k]
                for c in map(int, S):
                    if c == ls[t]:
                        t += 1
                    if t == 3:
                        ans += 1
                        break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
ans = 0
char = list(set(map(int,S)))
for i in range(10):
    if i not in char:
        continue
    for j in range(10):
        if j not in char:
            continue
        for k in range(10):
            if k not in char:
                continue
            t = 0
            ls = [i,j,k]
            for c in map(int, S):
                if c == ls[t]:
                    t += 1
                if t == 3:
                    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):
            t = 0
            ls = [i,j,k]
            for c in S:
                if int(c) == ls[t]:
                    t += 1
                if t == 3:
                    ans += 1
                    break
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for num in range(1000):
    target = str(num).zfill(3)
    cur = 0
    for s in S:
        if s == target[cur]:
            cur += 1
        if cur == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(1000) :
    num_1 = i // 100
    num_2 = (i - num_1*100) // 10
    num_3 = (i - num_1*100 - num_2*10) % 100
    for j in range(n-2) :
        if int(s[j]) == num_1 :
            for k in range(j+1,n-1) :
                if int(s[k]) == num_2 :
                    for l in range(k+1,n) :
                        if int(s[l]) == num_3 :
                            c += 1
                            break
                    break
            break

print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

# print(f"{n} {s}")

l = list(s)
# print(l)


set1 = set()
for v1, v2, v3 in itertools.combinations(l, 3):
    # print(f"{v1} {v2} {v3}")
    set1.add(int(v1 + v2 + v3))
    
print(len(set1))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S =list(str(input()))
a=[]
for i in range(10):
    for k in range(N-2):
        if str(i)==S[k]:
            for u in range(10):
                for j in range(k+1,N-1):
                    if str(u)==S[j]:
                        for y in range(10):
                            for h in range(j+1,N):
                                if str(y)==S[h]:
                                    a.append(S[k]+S[j]+S[h])
print(len(set(a)))

Submission status: Time Limit Exceeded

Solution code:
#6
N = int(input())
S =list(str(input()))
a=[]
for i in range(N-2):
    for u in range(i+1,N-1):
        for y in range(u+1,N):
            a.append(S[i]+S[u]+S[y])
print(len(set(a)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = [int(c) for c in input()]
table = list(range(10))

count = 0
for p in itertools.product(table, repeat=3): # 重複を許して1~9の数値を３つならべる
    target = list(p)

    flag = False
    for i_1 in range(N-2):
        if S[i_1] == target[0]: # 1つ目の数字があったら次へ
            for i_2 in range(i_1+1, N-1):
                if S[i_2] == target[1]:
                    for i_3 in range(i_2+1, N):
                        if S[i_3] == target[2]:
                            count += 1
                            flag = True
                            break
                    
                    if flag:
                        break
            if flag:
                break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [int(c) for c in input()]

answer_set = set()
for i_1 in range(N-2):
    for i_2 in range(i_1+1, N-1):
        for i_3 in range(i_2+1, N):
            password = (S[i_1], S[i_2], S[i_3])
            answer_set.add(password)
            
answer = len(answer_set)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
def main():
    from itertools import combinations

    _ = int(input())
    S = input()

    seen = set()
    ans = 0
    for i, j, k in combinations(S, 3):
        string = ''.join([i, j, k])
        if string in seen:
            continue
        ans += 1
        seen.add(string)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
L = []
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(10):
            if str(k) in S[j+1:N]:
                L.append(S[i]+S[j]+str(k))
print(len(set(L)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def main():
    n=int(input())
    s=input()
    ss=[]
    for i in range(n):
        if i+3 < n and s[i] == s[i+1] == s[i+2] == s[i+3]:
            continue
        ss.append(s[i])
    if len(ss) < 4:
        ss = s
    ans=set()
    for i,j,k in combinations(range(len(ss)),3):
        ans.add((ss[i],ss[j],ss[k]))
    print(len(ans))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
ans=set()
for i in range(1000):
    a=i//100
    b=(i//10)%10
    c=i%10
    for j in range(len(S)-2):
        for k in range(j+1,len(S)-1):
            for l in range(k+1,len(S)):
                tmp=[S[j],S[k],S[l]]
                if int(S[j])==a and int(S[k])==b and int(S[l])==c:
                    ans.add(i)
print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
S = input()

ans = 0
for a,b,c in itertools.product(map(str,range(10)),repeat=3):
    aa = False
    bb = False
    for s in S:
        if aa == False and s == a:
            aa = True
            continue
        if bb == False and aa == True and s == b:
            bb = True
            continue
        if aa == True and bb == True and s == c:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():

    n = int(input())
    S = input() + 'eeee'

    cnt = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                # tmp = str(i)+str(j)+str(k)
                m = 0
                while S[m] != str(i):
                    m += 1
                    if m >= n:
                        break
                m += 1
                while S[m] != str(j):
                    m += 1
                    if m >= n:
                        break
                m += 1
                while S[m] != str(k):
                    m += 1
                    if m >= n:
                        break
                if m < n:
                    cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

ans = set()
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            ans.add(100*int(S[i])+10*int(S[j])+int(S[k]))

print(len(ans))

Submission status: Time Limit Exceeded

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

S += 'eeee'

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            # tmp = str(i)+str(j)+str(k)
            m = 0
            while S[m] != str(i):
                m += 1
                if m >= l:
                    break
            m += 1
            while S[m] != str(j):
                m += 1
                if m >= l:
                    break
            m += 1
            while S[m] != str(k):
                m += 1
                if m >= l:
                    break
            if m < l:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = input()
S = list(map(int, list(L)))

# print(S)
cnt = 0
# 000-999 1000
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            num = 0
            flag = False
            exist = [False] * 3
            while num != N and flag != True:
                # print(num)
                if exist[0] == False:
                    # print(S[num])
                    if S[num] != i:
                        num += 1
                    elif S[num] == i:
                        num += 1
                        exist[0] = True
                else:
                    if exist[1] == False:
                        if S[num] != j:
                            num += 1
                        elif S[num] == j:
                            num += 1
                            exist[1] = True
                    else:
                        if exist[2] == False:
                            if S[num] != k:
                                num += 1
                            elif S[num] == k:
                                num += 1
                                exist[2] == True
                                flag = True
            if flag == True:
                cnt += 1            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    s = list(S())
    itr = itertools.combinations(s,3)
    st = set()
    for i in itr:
        st.add(i)
    print(len(st))
main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
for i in range(10):
  flag1=False
  for a in range(n-2):
    if s[a]==str(i):
      flag1=True
      break
  if flag1:
    for j in range(10):
      flag2=False
      for b in range(a+1,n-1):
        if s[b]==str(j):
          flag2=True
          break
      if flag2:
        for k in range(10):
          for c in range(b+1,n):
            if s[c]==str(k):
              flag3=True
              ans+=1
              break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
for i in range(10):
  flag1=False
  for a in range(n-2):
    if s[a]==str(i):
      flag1=True
      break
  if flag1:
    for j in range(10):
      flag2=False
      for b in range(a+1,n-1):
        if s[b]==str(j):
          flag2=True
          break
      if flag2:
        for k in range(10):
          flag3=False
          for c in range(b+1,n):
            if s[c]==str(k):
              flag3=True
              break
          if flag3==1:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
for i in range(10):
  flag1=False
  for a in range(n-2):
    if s[a]==str(i):
      flag1=True
      min_a=a
      break
  if flag1:
    for j in range(10):
      flag2=False
      for b in range(min_a+1,n-1):
        if s[b]==str(j):
          flag2=True
          min_b=b
          break
      if flag2:
        for k in range(10):
          flag3=False
          for c in range(min_b+1,n):
            if s[c]==str(k):
              flag3=True
              break
          if flag3==1:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(1000):
    st="{:03}".format(i)

    cnt=0
    for nn in range(n):
        if s[nn]==st[cnt]:
            cnt+=1

        if cnt==3:
            ans+=1
            break
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    s = list()
    s.append(str(i // 100))
    s.append(str((i//10) % 10))
    s.append(str(i % 10))

    ind = 0
    cnt = 0
    while cnt < 3 and ind < N:
        if S[ind] == s[cnt]:
            cnt += 1
        ind += 1

        if cnt == 3:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(input())
a = ['0','1','2','3','4','5','6','7','8','9']
cnt=0
for i in list(itertools.product(a, repeat=3)):
  d =0
  e =0
  while d < n:
    if s[d] == i[e]:
      e+=1
    d+=1
    if e==3:
      cnt+=1
      break
print(cnt)

Submission status: Time Limit Exceeded

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
flag = [True] * 10
check = defaultdict(lambda : 0)
ans = 0
for i in range(n):
    if flag[int(s[i])]:
        for j in range(i+1, n):
            for k in range(j+1, n):
                x = s[i] + s[j] + s[k]
                if check[x]:
                    continue
                check[x] = 1
                ans += 1
        flag[int(s[i])] = False
print(ans)

Submission status: Time Limit Exceeded

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
flag = [True] * 10
check = defaultdict(lambda : 0)
ans = 0
for i in range(n):
    if flag[int(s[i])]:
        for j in range(i+1, n):
            for k in range(j+1, n):
                x = s[i] + s[j] + s[k]
                if check[x]:
                    continue
                check[x] = 1
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

n=int(input())
s=input()
d=set([])
t=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        if i in t: break
        for k in range(j+1,n):
            d.add(s[i]+s[j]+s[k])
    t.append(i)
print(len(d))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

list = []
for i in range(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])

#print(list)
list = set(list)
print(len(list))

Submission status: Time Limit Exceeded

Solution code:
import re


N = int(input())
S = input()
ans = 0

passwords = [str(i).zfill(3) for i in range(1000)]
for pw in passwords:
    if re.search(re.compile('.*{0[0]}.*{0[1]}.*{0[2]}.*'.format(pw)), S):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
import itertools
for a in list(itertools.product([str(b) for b in range(10)], repeat=3)):
  j=0
  for i in range(n):
    if s[i]==a[j]:
      j+=1
      if j==3:
        ans+=1
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = int((N*(N-1)*(N-2))/6)
# Count Duplicate
hash = {}
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if hash.get(S[i]+S[j]+S[k]):
                ans -= 1
            else :
                hash[S[i]+S[j]+S[k]] = True
print(ans)

Submission status: Time Limit Exceeded

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

ans_list = []
for x, y, z in combinations(range(N), 3):
    add = nums[x]+nums[y]+nums[z]
    ans_list.append(add)
    
print(len(set(ans_list)))

Submission status: Time Limit Exceeded

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

    password = set()

    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:]:
                    password.add(S[i] + S[j] + str(k))

    print(len(password))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

    password = set()

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

    print(len(password))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
cnt = 0
i = 1
for n1 in range(N - 2):
    if S[n1] in S[0:n1]:
        continue
    else:
        for n2 in range(n1 + 1, N - 1):
            if S[n2] in S[n1 + 1: n2]:
                continue
            else:
                for n3 in range(n2 + 1, N):
                    if S[n3] in S[n2 + 1: n3]:
                        continue
                    else:
                        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
pws = []
for n1 in range(N - 2):
    pw1 = S[n1]
    if pw1 in S[0:n1]:
        continue
    else:
        for n2 in range(n1 + 1, N - 1):
            pw2 = S[n2]
            if pw2 in S[n1 + 1: n2]:
                continue
            else:
                for n3 in range(n2 + 1, N):
                    pw3 = S[n3]
                    if pw3 in S[n2 + 1: n3]:
                        continue
                    else:
                        pw = pw1 + pw2 + pw3
                        pws.append(pw)

print(len(pws))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
S = input()
comb = list(combinations(range(N), 3))
pws = set()
for com in comb:
    pw = S[com[0]] + S[com[1]] + S[com[2]]
    pws.add(pw)

print(len(pws))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
key_list = {}

LENGTH = len(S)
count = 0
for i in range(LENGTH):
  for j in range(i+1,LENGTH):
    for k in range(j+1,LENGTH):
      #print(i,j,k)
      target = str(S[i]+S[j]+S[k])
      #print(target)
      if target in key_list:
        #print("exist")
        pass
      else:
        key_list[target] = 0
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import re
N = int(input())
S = input()
cnt = 0
for i in range(10):
    for j in range(10):
        for h in range(10):
            patrn = r".*" + re.escape(str(i)) + r".*" + re.escape(str(j)) + r".*" + re.escape(str(h)) + r".*"
            repatrn = re.compile(patrn)
            result = repatrn.match(S)
            #result = re.match(patrn, S)
            if result != None:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re
N = int(input())
S = input()
cnt = 0
for i in range(10):
    for j in range(10):
        for h in range(10):
            patrn = r".*" + re.escape(str(i)) + r".*" + re.escape(str(j)) + r".*" + re.escape(str(h)) + r".*"
            result = re.match(patrn, S)
            if result != None:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    smpl = format(i,"03")
#    patrn = r".*smpl[0].*smpl[1].*smpl[2].*"
    patrn = r".*" + re.escape(smpl[0]) + r".*" + re.escape(smpl[1]) + r".*" + re.escape(smpl[2]) + r".*"
    result = re.match(patrn, S)
    if result != None:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
lis=[[set([])]*10 for _ in range(10)]
set_i=set([])

for i in reversed(range(N-2)):
    set_i.add(S[i+1])
    #print(set_i)
    for n in set_i:
        j=S[i+1:-1].index(str(n))
        si,sj=int(S[i]),int(S[i+j+1])
        #print(si,sj,S[i+j+2:])
        lis[si][sj]=lis[si][sj]|set(list(S[i+j+2:]))
        #lis[si][sj]=set(list(S[i+j+2:]))

ans=0
for i in range(10):
    for j in range(10):
        ans+=len(lis[i][j])
        #print(i,j,lis[i][j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
lis=[[set([])]*10 for _ in range(10)]

for i in range(N-2):
    set_i=set(list(S[i+1:-1]))
    #print(set_i)
    for n in set_i:
        j=S[i+1:-1].index(str(n))
        si,sj=int(S[i]),int(S[i+j+1])
        #print(si,sj,S[i+j+2:])
        lis[si][sj]=lis[si][sj]|set(list(S[i+j+2:]))
        #lis[si][sj]=set(list(S[i+j+2:]))

ans=0
for i in range(10):
    for j in range(10):
        ans+=len(lis[i][j])
        #print(i,j,lis[i][j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
lis=[[set([])]*10 for _ in range(10)]

for i in range(N-2):
    for j in range(i+1,N-1):
        si,sj=int(S[i]),int(S[j])
        lis[si][sj]=lis[si][sj]|set(list(S[j+1:]))

ans=0
for i in range(10):
    for j in range(10):
        ans+=len(lis[i][j])
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1000):
    # 確認するpinの数字の組み合わせと桁の初期化
    # pin = f'{i:0>3}'
    pin = list(str(i).zfill(3))
    current_digit = 0

    for num in s:
        # 見つけると桁を右に一つずらす
        if num == pin[current_digit]:
            current_digit += 1
            # indexが3(桁が3→2→1→0)になったときはそのPINは作れる
            if current_digit == 3:
                ans += 1
                break

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1000):
    # 確認するpinの数字の組み合わせと桁の初期化
    pin = f'{i:0>3}'
    current_digit = 0

    for num in s:
        # 見つけると桁を右に一つずらす
        if num == pin[current_digit]:
            current_digit += 1
            # indexが3(桁が3→2→1→0)になったときはそのPINは作れる
            if current_digit == 3:
                ans += 1
                break

print(ans)

Submission status: Time Limit Exceeded

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

pins = []

for i in range(1000):
    # 確認するpinの数字の組み合わせと桁の初期化
    pin = f'{i:0>3}'
    current_digit = 0

    for num in s:
        # 見つけると桁を右に一つずらす
        if num == pin[current_digit]:
            current_digit += 1
            # indexが3(桁が3→2→1→0)になったときはそのPINは作れる
            if current_digit == 3:
                pins.append(pin)
                break

print(len(pins))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

result = []

for i in range(n - 2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            result.append(str(s[i])+str(s[j])+str(s[k]))

print(len(set(result)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
l = []
ans = 0
for x in range(1000) :
    X = list(str(x).zfill(3))
    c = 0
    I = 0
    J = 0
    for i in range(N-2) :
        if X[0] == S[i] :
            I = i
            c += 1
            break
    for j in range(I+1,N-1) :
        if X[1] == S[j] :
            c += 1
            J = j
            break
    for k in range(J+1,N) :
        if X[2] == S[k] :
            c += 1
            break
    if c == 3 :
        ans += 1
                        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
l = []
for i in range(N-2) :
    for j in range(i+1,N-1) :
        for k in range(j+1,N) :
            x = int(str(S[i]) + str(S[j]) + str(S[k]))
            l.append(x)

print(len(set(l)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
tbl=[[-1]*10 for _ in range(10)]
ans=0

for i in range(N-2):
    si=int(S[i])
    for j in range(i+1,N-1):
        sj=int(S[j])
        if tbl[si][sj]==-1:
            tbl[si][sj]=list(set(list(S[j+1:])))

for i in range(10):
    for j in range(10):
        if tbl[i][j]!=-1:
            ans+=len(tbl[i][j])
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for fi in range(n):
	for si in range(fi+1, n):
		for ti in range(si+1, n):
			list.append(s[fi]+ s[si]+ s[ti])
c = collections.Counter(list)
print(len(c))

Submission status: Time Limit Exceeded

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

S = set()
cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            dig = 1
            t = str(i)+str(j)+str(k)

            for r in range(n):
                if dig == 1 and t[0] == s[r]:
                    dig +=1

                elif dig == 2 and t[1] == s[r]:
                    dig +=1
                    
                elif dig == 3 and t[2] == s[r]:
                    S.add(t)

print(len(S))

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

N = int(input())
S = input()
 
l = list(combinations(S,3))
print(len(Counter(l)))

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(1000):
    if 0 <= i < 10:
        a = "00" + str(i)
    elif 10 <= i < 100:
        a = "0" + str(i)
    elif 100 <= i:
        a = str(i)
    
    idx = 0
    for j in range(N):
        if S[j] == a[idx]:
            idx += 1
            if idx == 3:
                cnt += 1
                break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#create date: 2020-08-11 09:28

import sys
stdin = sys.stdin
from itertools import product

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

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

    for a in product(range(10), repeat=3):
        i = 0
        for si in s:
            if int(si) == a[i]:
                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 i in range(0, 1000):
    count = 0
    val = list(str(i).zfill(3))
    for j in s:
        if j == val[count]:
            count += 1
            if count == 3:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

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

pin = []
cnt = 0

for i in range(0, 1000):
    pin.append(str(i).zfill(3))
#print(pin)

for i in range(0, 1000):
    k = 0
    for j in range(len(s)):
        if pin[i][k] == s[j]:
            k += 1
            if k == 3:
                cnt += 1
                break
                
print(cnt)