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:
import copy
import math

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    n = get_int()
    s_list = get_string_char_list()
    ans_set = set([])

    for i in range(0,n):
        for ii in range(i+1, n):
            for iii in range(ii+1, n):
                ans_set.add(int(s_list[i]) * 100 + int(s_list[ii]) * 10 + int(s_list[iii]) * 1)

    print(len(ans_set))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt
                elif j==N-1 and cnt!=2:
                    return 0
        elif i==N-1 and cnt!=1:
            return 0
    return 0



if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))
    for i in range(10):
        for j in range(10):
            for k in range(10):
                cnt = count_match(i, j, k)
                if cnt==3:
                    ans += 1
    
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt
    return 0



if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))
    
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if i not in S: continue
                if j not in S: continue
                if k not in S: continue
                cnt = count_match(i, j, k)
                if cnt==3:
                    ans += 1
    
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt
    return 0



if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))
    
    for i in range(10):
        for j in range(10):
            for k in range(10):
                cnt = count_match(i, j, k)
                if cnt==3:
                    ans += 1
    
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt

if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))
    for n in range(0, 999+1):
        first = n//100
        second = n//10-(first*10)
        third = n%10
        cnt = count_match(first, second, third)
        if cnt==3:
            ans += 1
    
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
ans = 0
def count_match(first, second, third):
    cnt = 0
    for i in range(N):
        if S[i]==first:
            cnt += 1
            for j in range(i+1, N):
                if S[j]==second:
                    cnt += 1
                    for k in range(j+1, N):
                        if S[k]==third:
                            cnt += 1
                            return cnt, [first, second, third]
    return 0, []

if __name__ == '__main__':
    N = int(input())
    S = list(map(int, list(input())))
    for n in range(0, 999+1):
        first = n//100
        second = n//10-(first*10)
        third = n%10
        cnt, num = count_match(first, second, third)
        if cnt==3:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
ans_set=set()
N=int(input())
s=input()

for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            ans_set.add(s[i]+s[j]+s[k])

print(len(ans_set))

Submission status: Time Limit Exceeded

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

sapp = [[0] * n for _ in range(10)]

for idx, s in enumerate(S):
    si = int(s)
    sapp[si][idx] = 1

from itertools import accumulate
sacc = [list(accumulate(sa)) for sa in sapp]

pins = set()
for i in range(1, n-1):
    for lnum in range(10):
        lnumc = sacc[lnum][i-1]
        if lnumc == 0:
            continue
        for rnum in range(10):
            # i+1から最後までで出現するか
            rnumc = sacc[rnum][-1] - sacc[rnum][i]
            if rnumc > 0:
                pins.add(str(lnum) + S[i] + str(rnum))

print(len(pins))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int, list(input())))
ans = 0
for i in range(1000):
    pin = [i // 100, i // 10 % 10, i % 10]
    idx = 0
    for c in s:
        if c == pin[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

dp = [[[False] * 1000 for _ in range(4)] for _ in range(N + 1)]
dp[0][0][0] = True
for i in range(N):
    for j in range(4):
        for k in range(1000):
            if not dp[i][j][k]:
                continue

            dp[i + 1][j][k] = dp[i][j][k]
            to = k * 10 + int(S[i])
            if j < 3 and to < 1000:
                dp[i + 1][j + 1][to] = dp[i][j][k]

print(sum(dp[-1][-1]))

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):
            ref = s[i] + s[j] + s[k]
            ans[ref] = 1

print(len(ans))

Submission status: Time Limit Exceeded

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

nums = set()
from itertools import combinations
for c in combinations(list(range(n)), 3):
    ss = S[c[0]]  + S[c[1]]  + S[c[2]]
    nums.add(ss)

print(len(nums))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = input()
A = list(input())
print(len(set([i for i in combinations(A,3)])))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
pattern = [False] * 1000

for i in range(1000):
    str_i = str(i)
    str_i = str_i.zfill(3)
    now = 0
    for c in S:
        if c == str_i[now]:
            now += 1
        if now == 3:
            pattern[i] = True
            break
print(sum(pattern))

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n = int(input())
    s = list(map(int, input()))
    allper = [(s[a], s[b], s[c]) for a, b, c in itertools.combinations(range(n), 3)]
    print(len(set(allper)))
    return 0

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = input()
delete_length = N - 3
pass_dict = {}

count = 0
for c in itertools.combinations(range(N), delete_length):
    pass_word = ''
    for i in range(N):
        if i not in c:
            pass_word = pass_word + S[i]
    
    if pass_word not in pass_dict:
        pass_dict[pass_word] = 1
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = input()
delete_length = N - 3
pass_dict = {}

for c in itertools.combinations(range(N), delete_length):
    pass_word = ''
    for i in range(N):
        if i not in c:
            pass_word = pass_word + S[i]
    
    if pass_word not in pass_dict:
        pass_dict[pass_word] = 1
        
print(len(pass_dict))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
code=list(set(list(S)))
ans=0
for i in range(10):
    if str(i) not in code:
        continue
    for j in range(10):
        for k in range(10):
            count=0
            for s in S:
                if count==0:
                    if s==str(i):
                        count+=1
                elif count==1:
                    if s==str(j):
                        count+=1
                elif count==2:
                    if s==str(k):
                        count+=1
                if count==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):
            count=0
            for s in S:
                if count==0:
                    if s==str(i):
                        count+=1
                elif count==1:
                    if s==str(j):
                        count+=1
                elif count==2:
                    if s==str(k):
                        count+=1
                if count==3:
                    ans+=1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = input()

    import re
    num_li = [False]*1000
    for i in range(1000):
        pattern = r'{0[0]}.*{0[1]}.*{0[2]}'.format(list('{:3d}'.format(i))).replace(' ','0')
        # print(i,pattern)
        if re.search(pattern,S):
            num_li[i]=True
            
    print(sum(num_li))

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    n = int(input())
    s = input()
    l = list(itertools.combinations(list(range(n)),3))
    a = set()
    for i in l:
        k = s[i[0]]+s[i[1]]+s[i[2]]
        a.add(k)
    print(len(a))

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1000):
    p100 = i // 100
    ki = i % 100
    p10  = ki // 10
    ki = ki % 10
    p1   = ki // 1
    j = 0
    flag = False
    while j < n:
        if flag:
            break
        if int(s[j]) == p100:
            j += 1
            while j < n:
                if flag:
                    break
                if int(s[j]) == p10:
                    j += 1
                    while j < n:
                        if flag:
                            break
                        if int(s[j]) == p1:
                            ans += 1
                            flag = True
                            break
                        else:
                            j += 1
                else:
                    j += 1
        else:
            j += 1
            
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1000):
    p100 = i // 100
    ki = i % 100
    p10  = ki // 10
    ki = ki % 10
    p1   = ki // 1
    flag1, flag2, flag3 = False, False, False
    for j in range(n):
        if (not flag1) and int(s[j]) == p100:
            flag1 = True
            continue
        if (not flag2) and flag1 and int(s[j]) == p10:
            flag2 = True
            continue
        if (not flag3) and flag1 and flag2 and int(s[j]) == p1:
            flag3 = True
            break
    if flag1 and flag2 and flag3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
S = S()
after_lis = [set() for _ in range(N+1)]
i = N-1
for s in reversed(S):
    after_lis[i] = (after_lis[i] | after_lis[i+1])
    after_lis[i].add(int(s))
    i -= 1

ans_lis = np.zeros([10, 10, 10], dtype=np.int32)

for i_100 in range(N - 2):
    s_100 = int(S[i_100])
    for i_10 in range(i_100+1, N-1):
        s_10 = int(S[i_10])
        # print(after_lis[i_10+1])
        ans_lis[s_100, s_10, list(after_lis[i_10+1])] = 1

        # sは暗証番号の一番左
print(np.sum(ans_lis))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
s = set()
max_count = len(set(S)) ** 3
for x in range(N - 2):
    for y in range(x + 1, N  - 1):
        for z in set(S[y + 1:]):
            s.add(f"{S[x]}{S[y]}{z}")
            if len(s) == max_count:
                print(max_count)
                exit()
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
s = set()
for x in range(N - 2):
    for y in range(x + 1, N  - 1):
        for z in set(S[y + 1:]):
            s.add(f"{S[x]}{S[y]}{z}")
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
s = set()
for x in range(N - 2):
    for y in range(x + 1, N  - 1):
        for z in range(y + 1, N):
            s.add(S[x] + S[y] + S[z])
print(len(s))

Submission status: Time Limit Exceeded

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

for i in range(0,1000):
    num = str(i)
    if i < 10:
        num = "00"+num
    elif i <100:
        num = "0" + num
    f = 0
    for j in range(n):
        if s[j] == num[f]:
            f += 1
        if f == 3:
            break
    if f==3:
        ans +=1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(0,1000):
    flag = False
    num = str(i)
    if i < 10:
        num = "00"+num
    elif i <100:
        num = "0" + num
    for j in range(n):
        if s[j] == num[0]:
            for k in range(j+1,n):
                if s[k] == num[1]:
                    for l in range(k+1,n):
                        if s[l] == num[2]:
                            flag = True
                            ans.add(i)
                if flag:
                    break
        if flag:
            break
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]


n = int(input())
s = input()
ans = set()

for i in range(0,1000):
  b = 1
  num = str(i)
  if i < 10:
    num = "00"+num
  elif i <100:
    num = "0" + num
  for j in range(n):
    if b == 0:
      break
    if s[j] == num[0]:
      for k in range(j+1,n):
        if b == 0:
          break
        if s[k] == num[1]:
          for l in range(k+1,n):
            if b == 0:
              break
            if s[l] == num[2]:
              ans.add(i)
              b = 0
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]


n = int(input())
s = input()
ans = set()

for i in range(0,1000):
    num = str(i)
    if i < 10:
        num = "00"+num
    elif i <100:
        num = "0" + num
    for j in range(n):
        if s[j] == num[0]:
            for k in range(j+1,n):
                if s[k] == num[1]:
                    for l in range(k+1,n):
                        if s[l] == num[2]:
                            ans.add(i)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


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


# In[9]:


ans = 0
for i in range(1000):
    tmp = str(i).zfill(3)
    cnt = 0
    f = False
    for s in S:
        if s == tmp[cnt]:
            cnt += 1
            if cnt == 3:
                f = True
                break
    if f:
        ans += 1
print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
#print(S)
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[False]*10 for _ in range(N+1)]
dpp = [[[False]*10 for _ in range(10)] for _ in range(N+1)]
dppp = [[[[False]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]
 
for i in range(N):
  now = S[i] #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = True
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = dp[i][x]|dp[i+1][x]
    for y in range(10):
      if y == now and dp[i][x]:
        dpp[i+1][x][y] = True
      else:
        dpp[i+1][x][y] = dpp[i][x][y]|dpp[i+1][x][y]
      for z in range(10):
        if z == now and dpp[i][x][y]:
          dppp[i+1][x][y][z] = True
        else:
          dppp[i+1][x][y][z] = dppp[i][x][y][z]|dppp[i+1][x][y][z]
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      if dppp[N][i][j][k]:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
ans = set([])
for v in range(1000):
  a = v//100
  b = (v-a*100)//10
  c = v-a*100-b*10
  for i in range(N):
    if a != S[i]:
      continue
    for j in range(i+1,N):
      if b != S[j]:
        continue
      for k in range(j+1,N):
        if c == S[k]:
          ans.add(v)
          break
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
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:
            a,b,c = i,j,k
            # print(a,b,c)
            for m in s:
                # print(m)
                if a==int(m):
                    # print(i)
                    a = -1
                elif a==-1 and b==int(m):
                    b = -1
                elif b==-1 and c==int(m):
                    ans+=1
                    # print(i,j,k)
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
#print(S)
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[0]*10 for _ in range(N+1)]
dpp = [[[0]*10 for _ in range(10)] for _ in range(N+1)]
dppp = [[[[0]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]

for i in range(N):
  now = S[i] #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = 1
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = max(dp[i][x],dp[i+1][x])
    for y in range(10):
      if y == now and dp[i][x] == 1:
        dpp[i+1][x][y] = 1
      else:
        dpp[i+1][x][y] = max(dpp[i][x][y],dpp[i+1][x][y])
      for z in range(10):
        if z == now and dpp[i][x][y] == 1:
          dppp[i+1][x][y][z] = 1
        else:
          dppp[i+1][x][y][z] = max(dppp[i][x][y][z],dppp[i+1][x][y][z])
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      ans += dppp[N][i][j][k]
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Stemp = str(input())
S = []
for i in range(N):
  temp = int(Stemp[i])
  S.append(temp)
#print(S)
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[0]*10 for _ in range(N+1)]
dpp = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]
dppp = [[[[0]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]

for i in range(N):
  now = S[i] #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = 1
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = max(dp[i][x],dp[i+1][x])
    for y in range(10):
      if y == now and dp[i][x] == 1:
        dpp[i+1][x][y] = 1
      else:
        dpp[i+1][x][y] = max(dpp[i][x][y],dpp[i+1][x][y])
      for z in range(10):
        if z == now and dpp[i][x][y] == 1:
          dppp[i+1][x][y][z] = 1
        else:
          dppp[i+1][x][y][z] = max(dppp[i][x][y][z],dppp[i+1][x][y][z])
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      ans += dppp[N][i][j][k]
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = str(input())
#i桁目までみて、1文字目がx、2文字目がy、3文字目がzのがあるか
dp = [[0]*10 for _ in range(N+1)]
dpp = [[[0 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]
dppp = [[[[0]*10 for _ in range(10)] for _ in range(10)] for _ in range(N+1)]

for i in range(N):
  now = int(S[i]) #i桁目 1index
  #dp[i+1][now] = 1
  for x in range(10):
    if x == now:
      dp[i+1][x] = 1
      #print(dp[i+1][x])
    else:
      dp[i+1][x] = max(dp[i][x],dp[i+1][x])
    for y in range(10):
      if y == now and dp[i][x] == 1:
        dpp[i+1][x][y] = 1
      else:
        dpp[i+1][x][y] = max(dpp[i][x][y],dpp[i+1][x][y])
      for z in range(10):
        if z == now and dpp[i][x][y] == 1:
          dppp[i+1][x][y][z] = 1
        else:
          dppp[i+1][x][y][z] = max(dppp[i][x][y][z],dppp[i+1][x][y][z])
#print(dp)
#print(dpp)
#print(dppp)
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      ans += dppp[N][i][j][k]
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=[0]*1001
for i in range(1000):
    v=0
    i="000"+str(i)
    for j in s:
        if j==i[-1] and v==2:v+=1
        if j==i[-2] and v==1:v+=1
        if j==i[-3] and v==0:v+=1
    if v==3:ans[int(i)]=1
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
a=set()
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            b=s[i]+s[j]+s[k]
            a=a|{b}
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = 0
set_ = set()
for val in range(1000):
    val = str(val).zfill(3)
    a =val[0]
    b = val[1]
    c = val[2]
    flag = False
    for i in range(n):
        if S[i]==a and flag == False:
            for j in range(i+1,n):
                if S[j]==b and flag == False:
                    for k in range(j+1,n):
                        if S[k]==c and flag == False: 
                            cnt += 1
                            flag = True
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = 0
set_ = set()
for val in range(1000):
    val = str(val).zfill(3)
    a =val[0]
    b = val[1]
    c = val[2]
    for i in range(n):
        if S[i]==a:
            for j in range(i+1,n):
                if S[j]==b:
                    for k in range(j+1,n):
                        if S[k]==c and S[i]+S[j]+S[k] not in set_: 
                            cnt += 1
                            set_.add(S[i]+S[j]+S[k])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, S = open(0).read().split()
N = int(N)
ans = set()
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            ans.add(S[i] + S[j] + S[k])
print(len(ans))

Submission status: Time Limit Exceeded

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

ans=0
import itertools
itr=itertools.product(list("1234567890"),repeat=3)

for it in itr:
    cnt=0
    for i in range(n):
        if S[i]==it[cnt]:
            cnt+=1
        if cnt==3:
            ans+=1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    S = input()
    cnt = 0
    for i in range(1000):
        ptn = str(i).zfill(3)
        j = 0
        flg = 0
        while j < N:
            if S[j] == ptn[flg]:
                flg += 1
                if flg == 3:
                    cnt += 1
                    break
            j += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    t = "{:0=3}".format(i)
    p = 0
    for j in range(N):
        if S[j] == t[p]:
            p += 1
        if p == 3:
            break
    if p == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
ans=0
for i in range(1000):
    one=str(i//100)
    two=str((i%100)//10)
    three=str(i%10)
    f1,f2,f3=False,False,False
    ptr=0
    for j in range(ptr,N-2):
        if S[j]==one:
            f1=True
            ptr=j+1
            break
    if f1:
        for j in range(ptr,N-1):
            if S[j]==two:
                f2=True
                ptr=j+1
                break
        if f2:
            for j in range(ptr,N):
                if S[j]==three:
                    f3=True
                    ans+=1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
ans=0
for i in range(1000):
    one=str(i//100)
    two=str((i%100)//10)
    three=str(i%10)
    f1,f2,f3=False,False,False
    ptr=0
    for j in range(ptr,N-2):
        if S[j]==one:
            f1=True
            ptr=j+1
            break
    for j in range(ptr,N-1):
        if S[j]==two:
            f2=True
            ptr=j+1
            break
    for j in range(ptr,N):
        if S[j]==three:
            f3=True
            break
    if f1 and f2 and f3:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def strKey(key):
    if key == 0:
        return '000'
    if 1<= key <= 9:
        return '00' + str(key)
    if 10<= key <=99:
        return '0' + str(key) 
    return str(key)

N = int(input())
s  = input().strip()

cnt = 0
for key in range(1000):
    key = strKey(key)    #; print(key)
    isFlag = False
    for i0 in range(N-2):
        if isFlag == True:
            break
        if s[i0] == key[0]:
            for i1 in range(i0+1, N-1):
                if isFlag == True:
                    break
                if s[i1] == key[1]:
                    for i2 in range(i1+1, N):
                        if s[i2] == key[2]:
                            cnt += 1     #; print(i0, i1, i2, key)
                            isFlag = True
                            break
                        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def strKey(key):
    if key == 0:
        return '000'
    if 1<= key <= 9:
        return '00' + str(key)
    if 10<= key <=99:
        return '0' + str(key) 
    return str(key)

N = int(input())
s  = input().strip()

cnt = 0
for key in range(1000):
    key = strKey(key)    #; print(key)
    isFlag = False
    for i0 in range(N-2):
        if isFlag == False and s[i0] == key[0]:
            for i1 in range(i0+1, N-1):
                if isFlag == False and s[i1] == key[1]:
                    for i2 in range(i1+1, N):
                        if s[i2] == key[2]:
                            cnt += 1     #; print(i0, i1, i2, key)
                            isFlag = True
                            break
                        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
s  = input().strip()

S = set()
for c in combinations(range(N), N-3):
    i0 = 0; x = ''
    for i in c:
        x += s[i0:i]
        i0 = i+1
    x += s[i0:]
    S.add(x)                                  
print(len(S))   #; print(S)

Submission status: Time Limit Exceeded

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

ans = [[[0 for _ in range(10)] for _ in range(10)]for _ in range(10)]
ans_total = 0

for i,s in enumerate(S):
  Xoo = list(set(S[:i]))
  ooX = list(set(S[i+1:]))
  #print(s,Xoo,ooX)
  for r in Xoo:
    for t in ooX:
      #print(r,s,t)
      if ans[r][s][t] == 0:
        ans_total += 1
      ans[r][s][t] = 1
  if ans_total == 999:
    break
print(ans_total)