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()

num = [0,1,2,3,4,5,6,7,8,9]
memo = []
for i in num:
  for j in num:
    for k in num:
      memo.append(str(num[i]) + str(num[j]) + str(num[k]))

ans = 0

for i in memo:
  x = 0
  for j in range(n):
    if i[x] == s[j]:
      x += 1
      if x == 3:
        break
  if x == 3:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Jun  1 16:47:45 2020

@author: NEC-PCuser
"""

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Jun  1 16:47:45 2020

@author: NEC-PCuser
"""

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Jun  1 16:47:45 2020

@author: NEC-PCuser
"""

N = int(input())
S = input()
count = 0
for i in range(0, 1000):
    j = 0
    a = str(i).zfill(3)
    for k in range(0, len(S)):
        if (a[j] == S[k]):
            j += 1
        if (j == 3):
            count += 1
            break
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit

setrecursionlimit(10 ** 9)

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

pins = set([])


def make_pin(s, i):
    if len(s) == 3:
        pins.add(s)
        return

    if i == N:
        return

    make_pin(s + S[i], i + 1)
    make_pin(s, i + 1)


make_pin("", 0)

print(len(pins))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
box = []
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if not str(s[i])+str(s[j])+str(s[k]) in box:
                box.append(str(s[i])+str(s[j])+str(s[k]))
print(len(box))

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            num = str(i) + str(j) + str(k)
            tmp = 0

            for s in S:
                if num[tmp] == s:
                    tmp += 1

                if tmp >= 3:
                    break

            if tmp == 3:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

dp = [[[[False for _ in range(11)] for _ in range(11)]
       for _ in range(11)] for _ in range(N + 1)]

for i in range(N):
    num = int(S[i])
    for j in range(11):
        for k in range(11):
            for l in range(11):
                dp[i + 1][num][10][10] = True

                dp[i + 1][j][10][10] = dp[i][j][10][10]
                dp[i + 1][j][num][10] = dp[i][j][10][10]

                dp[i + 1][j][k][10] = dp[i][j][k][10]
                dp[i + 1][j][k][num] = dp[i][j][k][10]

                dp[i + 1][j][k][l] = dp[i][j][k][l]

ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if dp[N][i][j][k]:
                # print(i, j, k)
                ans += 1

print(ans)

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, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, 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, insort, insort_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
from decimal import *

N = INT()
S = input()
A = list(digits)

ans = 0
for x in product(A, repeat=3):
	i = 0
	for y in S:
		if y == x[i]:
			if i == 2:
				ans += 1
				break
			else:
				i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s = [int(x) for x in input()]

print(len(set(itertools.combinations(s, 3))))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(input())
list = list(itertools.combinations(s,3))
result  = []
[x for x in list if x not in result and not result.append(x)]
print(len(result))

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
result = 0
for i in range(1000):
    x = format(i, "03")
    p = 0
    for j in range(n):
        if s[j]==x[p]:
            p += 1
            if p==3:
                result += 1
                break
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = list(str(input()))
ans = 0
for i in range(1000):
    q = 0
    p = list(str(i).zfill(3))
    s = p[q]
    for j in range(len(S)):
        if s == S[j]:
            q+=1
            if q == 3:
                break
            else:
                s = p[q]
        else:
            continue
    if q == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int, input().rstrip()))

ans = 0
for i in range(1000):
    if i < 10:
        x, y, z = 0, 0, i
    elif i < 100:
        x, y, z = 0, i // 10, i % 10
    else:
        x = i // 100
        y = (i - x * 100) // 10
        z = i % 10
    flg = 0
    for a in range(len(s) - 2):
        if flg == 1:
            break
        elif x != s[a]:
            continue
        else:
            for b in range(a + 1, len(s) - 1):
                if flg == 1:
                    break
                elif y != s[b]:
                    continue
                else:
                    for c in range(b + 1, len(s)):
                        if z != s[c]:
                            continue
                        else:
                            ans += 1
                            flg = 1
                            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int, input().rstrip()))
ans = [0] * 1000

for i in range(1000):
    if i < 10:
        x, y, z = 0, 0, i
    elif i < 100:
        x, y, z = 0, i // 10, i % 10
    else:
        x = i // 100
        y = (i - x * 100) // 10
        z = i % 10
    flg = 0
    for a in range(len(s) - 2):
        if flg == 1:
            break
        elif x != s[a]:
            continue
        else:
            for b in range(a + 1, len(s) - 1):
                if flg == 1:
                    break
                elif y != s[b]:
                    continue
                else:
                    for c in range(b + 1, len(s)):
                        if z != s[c]:
                            continue
                        else:
                            ans[x * 100 + y * 10 + z] = 1
                            flg = 1
                            break

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int, input().rstrip()))
ans = [0] * 1000

for i in range(1000):
    if i < 10:
        x, y, z = 0, 0, i
    elif i < 100:
        x, y, z = 0, i // 10, i % 10
    else:
        x = i // 100
        y = (i - x * 100) // 10
        z = i % 10
    for a in range(len(s) - 2):
        if x != s[a]:
            continue
        else:
            for b in range(a + 1, len(s) - 1):
                if y != s[b]:
                    continue
                else:
                    for c in range(b + 1, len(s)):
                        if z != s[c]:
                            continue
                        else:
                            ans[x * 100 + y * 10 + z] = 1

print(sum(ans))

Submission status: Time Limit Exceeded

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

ans = []

for i in range(len(s)-2): #1桁目
    for j in range(i+1 , len(s)-1): #2桁目
        for k in range(j+1 , len(s)): #3桁目
            ans.append(s[i]+s[j]+s[k])

print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import copy
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(10):
            for j in range(10):
                    for k in range(10):
                        flag_i = False
                        flag_j = False
                        flag_k = False
                        for t in range(N):
                            if not flag_i and S[t] == str(i):
                                flag_i = True
                            elif flag_i and not flag_j and S[t] == str(j):
                                flag_j = True                           
                            elif flag_i and flag_j and not flag_k  and S[t] == str(k):
                                flag_k = True
                        if flag_i and flag_j and flag_k:
                            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

result = set()
for i in range(1000):
    v = str(i).zfill(3)
    key = []
    p = -1
    for j in range(3):
        for k in range(n):
            if v[j] == s[k] and k > p:
                key.append(s[k])
                p = k
                break
    if len(key) == 3:
        result.add(''.join(key))

print(len(result))

Submission status: Time Limit Exceeded

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

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

#print(result)
print(len(result))

Submission status: Time Limit Exceeded

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

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      break

  if idx == 3:
    count += 1
      
print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(1000):
  pin = "00" + str(i)
  pin = pin[-3:]
  
  idx = 0
  for j in range(n):
    if s[j] == pin[idx]:
      idx += 1
      
    if idx == 3:
      count += 1
      break
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
ans = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      for x in range(n-2):
        if int(S[x]) == i:
          for y in range(x+1,n):
            if int(S[y]) == j:
              for z in range(y+1,n):
                if int(S[z]) == k:
                  ans.append(100*i+10*j+k)
print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=int(input())
s=input()
p = itertools.combinations(range(n),3)
l=[]
for a,b,c in p:
    x=s[a]+s[b]+s[c]
    l.append(x)
print(len(set(l)))

Submission status: Time Limit Exceeded

Solution code:
squares=[]
N=int(input())
L=input()
for i in range(N-2):
  for j in range(i+1,N):
    for k in range(j+1,N):
      t = [L[i], L[j], L[k]]
      s = ''.join(t)
      squares.append(s)
list1=list(set(squares))
print(len(list1))

Submission status: Time Limit Exceeded

Solution code:
squares=[]
N=int(input())
L=input()
for i in range(N-2):
  for j in range(i+1,N):
    for k in range(j+1,N):
      a=L[i]+L[j]+L[k]
      squares.append(a)
list1=list(set(squares))
print(len(list1))

Submission status: Time Limit Exceeded

Solution code:

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

num = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            num.append("{}{}{}".format(i, j, k))

ans = 0
for n in num:
    i = 0
    j = 0
    while j < N:
        # print(i, j)
        if n[i] == S[j]:
            i += 1
            j += 1
        else:
            j += 1
        if i == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
pin_li = []
for i in range(len(s)):
    if len(set(pin_li)) >1000:
        break
    for j in range(i+1,len(s)):
        for k in range(j+1,len(s)):
            pin_li.append(s[i]+s[j]+s[k])
            if len(set(pin_li)) > 1000:
                break
print(len(set(pin_li)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(input())
pin_li = []
for i in range(len(s)):
    for j in range(i+1,len(s)):
        for k in range(j+1,len(s)):
            pin_li.append(s[i]+s[j]+s[k])
            if len(set(pin_li)) > 1000:
                break
print(len(set(pin_li)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    total = 0

    for n in range(0, 1000):
        FLAG = False
        n_str = str(n)
        
        while (len(n_str) < 3):
            n_str = '0' + n_str
        
        pos = 0
        cnt = 0
        
        for i in range(3):
            number = int(n_str[i])
            
            while (pos < N_keta):
                num = int(S[pos])
                if (num == number):
                    cnt += 1
                    pos += 1
                    break
                else:
                    pos += 1
            
            if (cnt == 3):
                FLAG = True
                break
        
        if (FLAG):
            total += 1

    print(total)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n=int(input())
s=input()
a=list(combinations(range(n),3))
b=set()
for i,j,k in a:
    b.add(s[i]+s[j]+s[k])
print(len(b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
cnt=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            A=[i,j,k]
            m=0
            for l in range(N):
                #print("i,j,k,l,m,cnt",i,j,k,l,m,cnt)
                if int(S[l]) == A[m]:
                    m += 1
                if m == 3:
                    cnt += 1
                    break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

n = int(input())
s = input()
cnt = 0
for i in range(1000):
    c = str(i)
    one,two,three = -1,-1,-1
    if len(c)<3:
        while True:
            if len(c) == 3:
                break
            c = "0" + c
    for j in range(n):
        if s[j] == c[0]:
            one = j
            break
    if one != -1:
        for j in range(one+1,n):
            if s[j] == c[1]:
                two = j
                break
    if two != -1:
        for j in range(two+1,n):
            if s[j] == c[2]:
                three = j
                break
    if three != -1:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

candi = list(itertools.product(range(10),repeat=3))

cnt = 0

for i in candi:
    flag1 = False
    flag2 = False
    flag3 = False
    for j in S:
        if flag1 == False and int(j) == i[0]:
            flag1 = True
            continue
        if flag1 == True and flag2 == False and int(j)==i[1]:
            flag2 = True
            continue
        if flag2 == True and flag3 == False and int(j)==i[2]:
            flag3 = True
            cnt += 1    
            break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
num = []
for i in range(1000):
    num.append( int(i/100) )
    num.append( int((i/10)%10) )
    num.append( int(i%10) )
    c = 0
    for j in range(n):
        if s[j] == str(num[c]):
            c += 1
        if c == 3:
            ans += 1
            break
    c = 0
    num = []

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
l = []
i_list = []
for i in range(0, n-2):
    if s[i] in i_list:
        continue
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if s[i]+s[j]+s[k] not in l:
                l.append(s[i]+s[j]+s[k])
                if s[i] not in i_list:
                    i_list.append(s[i])

print(len(l))

Submission status: Time Limit Exceeded

Solution code:

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

ans = 0
List = []
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            word = S[i]+S[j]+S[k]
            if not word in List:
                List.append(word)
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
l = []
for i in range(0, n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if s[i]+s[j]+s[k] not in l:
                l.append(s[i]+s[j]+s[k])

print(len(l))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
counts = 0
for i in range(1000):
    I = [i//100,i//10%10,i%10]
    ok = 0
    for j in range(N):
        if int(S[j])==I[ok]:
            ok+=1
        if ok == 3:
            break
    if ok==3:
        counts+=1
print(counts)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

#Sから暗証番号Vを作るのではなく、VからSを作れるかを判定する
n = int(input())
s = input()
ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    ti = 0
    for si in range(n):
        if s[si] == t[ti]:
            ti += 1
            if ti == 3:
                break
    if ti == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#Sから暗証番号Vを作るのではなく、VからSを作れるかを判定する
n = int(input())
s = input()
ans = 0
for i in range(1000):
    t = str(i).zfill(3)
    ti = 0
    for si in range(n):
        if s[si] == t[ti]:
            ti += 1
            if ti == 3:
                break
    if ti == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(10):
    for j in range(10):
        for k in range(10):
            current = 0
            require = [str(i), str(j), str(k)]
            for v in s:
                if v == require[current]:
                    current += 1
                    if current == 3:
                        res += 1
                        break
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

n = int(input())
t = input()
p = t[0]
ans = 0
s = t[0]
# 連続4文字以上を圧縮
for x in t[1:]:
    if x == p:
        ans += 1
        if ans < 4:
            s += x
    else:
        ans = 1
        s += x

ans = 0
for t in range(1000):
    q = str(int(t/100))
    if not q in s:
        continue
    z = s.index(q) + 1
    p = deque([int((t%100 - t%10)/10), t%10, -1])
    q = p.popleft()
    for x in s[z:]:
        if q == int(x):
            q = p.popleft()
        if q == -1:
            ans += 1
            break
    else:
        if q == -1:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

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

ans = 0
for t in range(1000):
    q = str(int(t/100))
    if not q in s:
        continue
    z = s.index(q) + 1
    p = deque([int((t%100 - t%10)/10), t%10, -1])
    q = p.popleft()
    for x in s[z:]:
        if q == -1:
            ans += 1
            break
        if q == int(x):
            q = p.popleft()
    else:
        if q == -1:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

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

ans = 0
for t in range(1000):
    p = deque([int(t/100), int((t%100 - t%10)/10), t%10, -1])
    q = p.popleft()
    for x in s:
        if q == -1:
            ans += 1
            break
        if q == int(x):
            q = p.popleft()
    else:
        if q == -1: ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
s = input()
ar = [[0 for i in range(3)] for j in range(1000)]
kakunin = [0 for i in range(1000)]
index = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            ar[index][0] = i
            ar[index][1] = j
            ar[index][2] = k
            index += 1



for i in range(n):
    # print(s[i])
    for j in range(1000):
        if kakunin[j] < 3 and ar[j][kakunin[j]] ==int(s[i]):

            kakunin[j] += 1

res = 0
for i in range(1000):
    if kakunin[i] == 3:
        res +=1
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = {}
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if not s[i]+s[j]+s[k] in ans:
                ans[s[i]+s[j]+s[k]] = 0
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
int(input())
u = input()
l = []
res = 0


def remove_ad(li):
    li2 = ""
    q = ""
    r = ""
    s = ""
    for p in str(li):
        if (p != q):
            li2 = li2 + p
        else:
            if (p != r):
                li2 = li2 + p
            else:
                if (p != s): li2 = li2 + p
        s = r
        r = q
        q = p
    return(li2)



t = remove_ad(u)
n = len(t)
l = set([])

for i in range(0,n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if(t[i]+t[j]+t[k] not in l):
                l.add(t[i]+t[j]+t[k])
                res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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


res = 0
for q in product(range(10), repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                res += 1
                break
            else:
                i+=1
print (res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=(int)(input())
moji = []
s=input()
for i in itertools.combinations(range(n), 3):
  #print(i)
  moji.append(s[i[0]] + s[i[1]] + s[i[2]])
  #print(moji)
print(len(list(set(moji))))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j, s in enumerate(S):
        if v[idx] in S[j:]:
            if v[idx] == s:
                idx += 1
                if idx < 3 and v[idx] not in S[j+1:]:
                    break
            if idx == 3:
                ans += 1
                break
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n=(int)(input())
moji = []
s=input()
for i in itertools.combinations(range(n), n-3):
  t = list(s)
  #print(i)
  for j in range(n-3):
    del t[i[j]-j]
  moji.append(''.join(t))
print(len(list(set(moji))))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j, s in enumerate(S):
        if v[idx] == s:
            idx += 1
            if idx < 3 and v[idx] not in S[j+1:]:
                break
        if idx == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
ans = 0
for i in range(1000):
    v = str(i).zfill(3)
    idx = 0
    for j, s in enumerate(S):
        if v[idx] in S[j:]:
            if v[idx] == s:
                idx += 1
            if idx == 3:
                ans += 1
                break
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
num = {s:[] for s in S}
for i, s in enumerate(S):
    num[s].append(i)
ans = 0
for i in range(1000):
    s = str(i).zfill(3)
    if s[0] in num.keys() and s[1] in num.keys() and s[2] in num.keys():
        for a in num[s[0]]:
            for b in num[s[1]]:
                for c in num[s[2]]:
                    if a < b < c:
                        ans += 1
                        break
                else:
                    continue
                break
            else:
                continue
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from operator import mul
from functools import reduce
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
N = int(input())
S = [int(s) for s in input()]
num = {s:[] for s in S}
for i, s in enumerate(S):
    num[s].append(i)
ans = combinations_count(N, 3)
check = []
for i in list(num.keys()):
    for j in list(num.keys()):
        for k in list(num.keys()):
            s = str(i) + str(j) + str(k)
            if s not in check and (len(num[i]) > 1 or len(num[j]) > 1 or len(num[k]) > 1):
                temp = 0
                check.append(s)
                for a in num[i]:
                    for b in num[j]:
                        for c in num[k]:
                            if a < b < c:
                                temp += 1
                #print(i, j, k, temp)
                if temp > 0:
                    ans -= (temp-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from operator import mul
from functools import reduce
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
N = int(input())
S = [int(s) for s in input()]
num = {s:[] for s in S}
for i, s in enumerate(S):
    num[s].append(i)
ans = combinations_count(N, 3)
#print(ans)
check = []
for i in list(num.keys()):
    for j in list(num.keys()):
        for k in list(num.keys()):
            s = str(i) + str(j) + str(k)
            if s not in check and (len(num[i]) > 1 or len(num[j]) > 1 or len(num[k]) > 1):
                temp = 0
                check.append(s)
                for a in num[i]:
                    for b in num[j]:
                        for c in num[k]:
                            if a < b < c:
                                temp += 1
                #print(i, j, k, temp)
                if temp > 0:
                    ans -= (temp-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

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

s = []
counter = Counter()
for c in S:
    if counter[c] > 3:
        continue
    s.append(c)

print(len(set(combinations(s, r=3))))