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

passwords = set()
for password in combinations(s, r=3):
    passwords.add(''.join(password))

print(len(passwords))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = [s for s in input()]
ans = []
for (i, j, k) in itertools.combinations(S, 3):
    s = i + j + k
    #print(s)
    if s not in ans:
        ans.append(s)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import re

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)

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.append(t[i]+t[j]+t[k])
                res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
z=int(input())
s=input()
a=[]

for i in range(10):
    for j in range(z-2):
        if int(s[j]) == i:
            for k in range(10):
                for l in range(j+1,z-1):
                    if int(s[l]) == k:
                        for m in range(10):
                            for n in range(l+1,z):
                                if int(s[n]) == m:
                                    a.append(s[j]+s[l]+s[n])

print(len(set(a)))

Submission status: Time Limit Exceeded

Solution code:
z=int(input())
s=input()
a=[]



for i in range(10):
    for j in range(z-2):
        if int(s[j]) == i:
            for k in range(10):
                for l in range(j+1,z-1):
                    if int(s[l]) == k:
                        for m in range(10):
                            for n in range(l+1,z):
                                if int(s[n]) == m:
                                    a.append(s[j]+s[l]+s[n])

print(len(set(a)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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])
                res += 1
print(res)

Submission status: Time Limit Exceeded

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

res = 0
for i in range(1000): # PINの組み合わせは高々1000通りなのでこちらを全探索
    one = str(i//100) # （左から数えて）一つ目
    two = str(i%100//10) # 二つ目
    three = str(i%10) # 三つ目。これらがこの順番にsに登場するかを調べる

    flg1 = False
    flg2 = False
    flg3 = False

    ptr = 0 # 現在の走査位置を表すポインタ
    for j in range(ptr, n-2): # 一つ目を探すループ（n-2までみてなかったらあってもNG）
        if(s[j] == one):
            flg1 = True # 一つ目があった
            ptr = j+1 # 二つ目は一つ目のひとつ右から走査開始
            break # これをしないと一番右側の一つ目を採用しちゃう

    for j in range(ptr, n-1): # 一つ目より右から二つ目を探す
        if(s[j] == two):
            flg2 = True
            ptr = j+1
            break

    for j in range(ptr, n): # 二つ目より右から三つ目を探す
        if(s[j] == three):
            flg3 = True
            break

    if(flg1 and flg2 and flg3): res += 1 # 条件を満たせばflgが全部trueとなりその時だけ結果をインクリメント

print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0
for i in range(1000):
    num = "{:03}".format(i)
    cur_idx = 0
    for c in S:
        if c == num[cur_idx]:
            cur_idx += 1
        if cur_idx == 3:
            count += 1
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1000):
  t=str(i).zfill(3)
  j=0
  for s_i in s:
    if j<3 and t[j]==s_i:
      j+=1
  if j==3:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = (input())
from operator import itemgetter
from itertools import combinations
L = [int(i) for i in range(N)]
memo = []
for i in list(combinations(L,3)):
    memo.append(itemgetter(*i)(S))
print(len(set(memo)))

Submission status: Time Limit Exceeded

Solution code:
import re
def main():
    S = input()
    S = input()
    cnt = 0

    for i in range(1000):
        PIN = "{:03d}".format(i)
        pattern = '^.*' + PIN[0] + '.*' + PIN[1] + '.*' + PIN[2] + '.*$' 
        repatter = re.compile(pattern)
        if repatter.match(S):
            cnt+=1
        
    print(cnt)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

P=[]
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      t=S[i]+S[j]+S[k]
      if not(t in P):
        P.append(t)

print(len(P))

Submission status: Time Limit Exceeded

Solution code:
import sys


def my_input(): return sys.stdin.readline().rstrip()


def main():

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

    ans = 0
    for i in range(1000):
        d1 = (i // 100) % 10
        d2 = (i // 10) % 10
        d3 = i % 10
        d1_flag = True
        d2_flag = True

        for i in range(N):

            now = int(S[i])
            if d1_flag:
                if d1 == now:
                    d1_flag = False
                continue

            if d2_flag:
                if d2 == now:
                    d2_flag = False
                continue

            if d3 == now:
                ans += 1
                break

    print(ans)


if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
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 t[ti] == S[si]:
            ti += 1
            if ti == 3:
                break
    if ti == 3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys


def my_input(): return sys.stdin.readline().rstrip()


def main():

    N = int(my_input())
    S = my_input()

    ans = 0
    for i in range(1000):
        d1 = (i // 100) % 10
        d2 = (i // 10) % 10
        d3 = i % 10
        d1_flag = True
        d2_flag = True

        for i in range(N):

            now = int(S[i])
            if d1_flag:
                if d1 == now:
                    d1_flag = False
                continue

            if d2_flag:
                if d2 == now:
                    d2_flag = False
                continue

            if d3 == now:
                ans += 1
                break

    print(ans)


if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


def my_input(): return sys.stdin.readline().rstrip()


def main():

    N = int(my_input())
    S = my_input()

    ans = 0
    for i in range(1000):
        d1 = (i // 100) % 10
        d2 = (i // 10) % 10
        d3 = i % 10
        d1_flag = True
        d2_flag = True

        for j in S:

            now = int(j)
            if d1_flag:
                if d1 == now:
                    d1_flag = False
                continue

            if d2_flag:
                if d2 == now:
                    d2_flag = False
                continue

            if d3 == now:
                ans += 1
                break

    print(ans)


if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:

def main():

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

    ans = 0
    for i in range(1000):
        d1 = (i // 100) % 10
        d2 = (i // 10) % 10
        d3 = i % 10
        d1_flag = True
        d2_flag = True

        for j in S:

            now = int(j)
            if d1_flag:
                if d1 == now:
                    d1_flag = False
                continue

            if d2_flag:
                if d2 == now:
                    d2_flag = False
                continue

            if d3 == now:
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():

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

    ans = 0
    for i in range(1000):
        d1 = (i // 100) % 10
        d2 = (i // 10) % 10
        d3 = i % 10
        d1_flag = False
        d2_flag = False

        for j in S:
            now = int(j)
            if not d1_flag:
                if d1 == now:
                    d1_flag = True
            elif not d2_flag:
                if d2 == now:
                    d2_flag = True
            elif d3 == now:
                ans += 1
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import sys
# import bisect
# import numpy as np
# from scipy.special import comb


def main():

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

    ans = 0
    for i in range(1000):
        d1 = (i // 100) % 10
        d2 = (i // 10) % 10
        d3 = i % 10
        d1_flag = False
        d2_flag = False

        for j in S:
            now = int(j)
            if not d1_flag:
                if d1 == now:
                    d1_flag = True
            elif not d2_flag:
                if d2 == now:
                    d2_flag = True
            elif d3 == now:
                ans += 1
                #print(d1, d2, d3)
                break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import sys
# import bisect
# import numpy as np
# from scipy.special import comb

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


def main():

    ans = 0
    for i in range(1000):
        d1 = (i // 100) % 10
        d2 = (i // 10) % 10
        d3 = i % 10
        d1_flag = False
        d2_flag = False
        d3_flag = False

        for j in range(N):
            now = int(S[j])
            if not d1_flag:
                if d1 == now:
                    d1_flag = True
            elif not d2_flag:
                if d2 == now:
                    d2_flag = True
            elif not d3_flag:
                if d3 == now:
                    ans += 1
                    #print(d1, d2, d3)
                    break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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

    ans = 0
    for p in range(1000):
        p = str(p).zfill(3)

        i = 0
        for j in range(N):
            if S[j] == p[i]:
                i += 1

                if i == 3:
                    ans += 1
                    break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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

    ans = 0
    for p in range(1000):
        p = str(p).zfill(3)

        i = 0
        for j in range(N):
            if S[j] == p[i]:
                i += 1

            if i == 3:
                ans += 1
                break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N = int(input())
    S = input()
    pins = set()

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

        if i == N:
            return

        # i文字目を使う場合
        rec(s + S[i], i + 1)

        # i文字目を使わない場合
        rec(s, i + 1)

    rec("", 0)
    print(len(pins))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(1000):
    l = list()
    l.append(i // 100)
    l.append((i // 10) % 10)
    l.append(i % 10)
    f = 0
    for j in range(N):
        if int(S[j]) == l[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
for i in range(1000):
    num = ''
    num += str(i // 100)
    num += str((i // 10) % 10)
    num += str(i % 10)
    j = 0
    for n in range(N):
        if S[n] == num[j]:
            j += 1
        if j == 3:
            break
    if j == 3:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

print(len(passwords))

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
n = int(input())
s = input()
s_list = [i for i in s]
a = list(itertools.combinations(s_list, 3))
print(len(list(set(a))))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
val1=input()
s=input()
n=int(val1)
count=0
for i in range(0,1000):
    a=str(i).zfill(3) #ゼロうめ
    p=0
    for j in range(0,n):
        if a[p]==s[j]:
            p+=1
            if p==3:
                count+=1
                break
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = input()
L = []
for s in S:
    L.append(s)
P = []
for n in itertools.combinations(L, 3):
    o = ''
    for i in list(n):
        o += i
    P.append(o)
P = set(P)
print(len(P))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May 16 20:08:38 2020

@author: Kanaru Sato
"""

def search(s,t):
    if not t:
        return True
    elif not s:
        return False
    else:
        if t[0] in set(s):
            for i in range(len(s)):
                if s[i] == t[0]:
                    return search(s[i+1:],t[1:])
                    break
        else:
            return False

n = int(input())
s = list(input())
count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            num = [i,j,k]
            num = list(map(str,num))
            if search(s,num):
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May 16 20:08:38 2020

@author: Kanaru Sato
"""

def search(s,t):
    if not t:
        return True
    elif not s:
        return False
    else:
        flag = 0
        for i in range(len(s)):
            if s[i] == t[0]:
                return search(s[i+1:],t[1:])
                flag = 1
                break
        if flag == 0:
            return False

n = int(input())
s = list(input())
count = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            num = [i,j,k]
            num = list(map(str,num))
            if search(s,num):
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

cnt = 0
for num in range(1000):
    t = str(num).zfill(3)
    i = 0
    for st in S:
        if st == t[i]:
            i += 1
            if i == 3:
                cnt += 1
                break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    ans = 1
    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:
N = int(input())
S = input()

cnt = 0
for num in range(1000):
    lock_num = str(num).zfill(3)
    t = 0
    for st in S:
        if st == lock_num[t]:
            t += 1
            if t == 3:
                break
    if t == 3:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def judge(lock_arr, S):
    for j in range(len(S)):
        if S[j] == lock_arr[0]:
            for k in range(j+1, len(S)):
                if S[k] == lock_arr[1]:
                    for l in range(k+1, len(S)):
                        if S[l] == lock_arr[2]:
                            return True
    return False

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

cnt = 0
for i in range(1000):
    num = str(i)
    if len(num) < 3:
        num = '0'*(3-len(num)) + num

    if judge(num, S):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = input()
S = list(itertools.combinations(s, 3))
ss = set(S)
ls = len(ss)

print(ls)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import sys
import itertools

def main():
    N = int(sys.stdin.readline())
    S = str(sys.stdin.readline())
    # print(S)
    
    idx = [i for i in range(N)]
    comb_idx = itertools.combinations(idx, 3)
    
    ans = []
    for comb in comb_idx:
        # print(comb, comb[1])
        candidate = S[comb[0]] + S[comb[1]] + S[comb[2]]
        if candidate not in ans:
            ans.append(candidate)
            
    print(len(ans))
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

D = [set() for _ in range(N+1)]
D[0].add((3,""))

for i in range(N):
    for curr in D[i]:
        l = curr[0]
        s = curr[1]
        # そのまま
        D[i+1].add((l,s))
        # 末尾の1文字を採用する場合
        if l-1 >= 0:
            D[i+1].add((l-1,s+S[i]))

r = filter(lambda x:x[0]==0, D[N])
print(len(list(r)))

Submission status: Time Limit Exceeded

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

pins = []
for i in range(1000):
    i = str(i)
    if len(i) == 1:
        pins.append(str('00')+i)
    elif len(i) == 2:
        pins.append(str('0')+i)
    else:
        pins.append(i)

ans = 0
for pin in pins:
    c = 0
    for i in s:
        if pin[c] == i:
            c += 1
        if c == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

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

K = set()
K.add(S[0:3])
K2 = set()
K2.add(S[0]+S[1])
K2.add(S[0]+S[2])
K2.add(S[1]+S[2])


for i in range(3,N):   
    c = S[i]
    tmp = set()
    tmp2 = set()
    for k in K2:
        tmp.add(k+c)
        tmp2.add(k[0]+c)
        tmp2.add(k[1]+c)
    K = K.union(tmp)
    K2 = K2.union(tmp2)

print(len(K))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt=0
for i in range(1000):
    x = str(i).zfill(3)
    j=0
    for s in S:
        if x[j]==s:
            j+=1
            if j==3:
                cnt+=1
                break
print(cnt)

Submission status: Time Limit Exceeded

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

K = set()
K.add(S[0:3])

for i in range(3,N):   
    c = S[i]
    tmp = set()
    for k in K:
        tmp.add(k[0]+k[1]+c)
        tmp.add(k[0]+k[2]+c)
        tmp.add(k[1]+k[2]+c)
    K = K.union(tmp)

print(len(K))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt=0
for i in range(1000):
    x = str(i).zfill(3)
    k=0
    j=0
    while j<3 and k<n:
        if x[j] in S[k]:
            if j==2:
                cnt+=1
                break
            else:
                j+=1
                k+=1
        else:
            k+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
N = int(input())
S = input()
S = [int(s) for s in S]
ans = 0
for q in product(range(10),repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                ans += 1
                break
            else:
                i+=1
print (ans)

Submission status: Time Limit Exceeded

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

def f(n):
    n = str(n).zfill(3)
    # print(n)
    found = False
    for i in range(len(S)):
        if S[i] == n[0]:
            found = True
            break
    if found == False:
        return 0
    
    found = False
    for j in range(i+1, len(S)):
        if S[j] == n[1]:
            found = True
            break
    if found == False:
        return 0

    found = False
    for k in range(j+1, len(S)):
        if S[k] == n[2]:
            found = True
            break
    if found:
        return 1
    return 0

ans = 0
for i in range(1000):
    ans += f(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
for i in range(1000):
    pas = format(i).zfill(3)
    a, b = 0, 0
    for j in range(N-2):
        if S[j] == pas[0]:
            a = j
            for k in range(a+1, N-1):
                if S[k] == pas[1]:
                    b = k
                    for l in range(b+1, N):
                        if S[l] == pas[2]:
                            count += 1
                            break
                    break
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = input()
step = 1
ans = 0
for i in range(10):
    for i2 in range(10):
        for i3 in range(10):
            step = 1
            for i4 in range(len(S)):
                if step == 1:
                    if S[i4] == str(i):
                        step += 1
                elif step == 2:
                    if S[i4] == str(i2):
                        step += 1
                elif step == 3:
                    if S[i4] == str(i3):
                        ans += 1
                        break
print(ans)

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
  s=0
  while(True):
    if S[s]==now[j]:
      s+=1
      j+=1
    else:
      s+=1

    if j==3:
      ans+=1
      break

    if N<=s:
      break
      
print(ans)

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:
#三井住友2019 D 貪欲法
def main():
    import sys
    N = int(sys.stdin.readline())
    S = sys.stdin.readline().rstrip()
    ans = 0
    for i in range(1000):
        num = str(i).zfill(3)
        L = []
        k = 0
        for j in range(N):
            #print(num, S[j])
            if int(S[j])==int(num[k]):
                #print('Yes', num)
                L.append(S[j])
                k+=1
            if len(L)==3:
                #print(L)
                ans +=1
                break
                
    print(ans)
        
    
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#三井住友2019 D 全列挙
def main():
    import sys
    N = int(sys.stdin.readline())
    S = sys.stdin.readline().rstrip()
    tmp = [-1,-1,-1]
    L = set()
    for i in range(N-2):
        tmp[0]=S[i]
        for j in range(i+1, N-1):
            tmp[1]=S[j]
            for k in range(j+1, N):
                tmp[2]=S[k]
                L.add(''.join(tmp))
    #print(tmp)
    print(len(L))
    
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#三井住友2019 D
def main():
    import sys
    import itertools as ite
    N = int(sys.stdin.readline())
    S = sys.stdin.readline().rstrip()
    #print(N-3)
    #print(S)
    L = set(list(ite.combinations(S, 3)))
    print(len(L))

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = input()
dat = []
for i in range(n):
    dat.append(set([]))
for i in range(n):
    for j in range(max(i, 2), 0, -1):
        for x in dat[j-1]:
            dat[j].add(x + s[i])
    dat[0].add(s[i])
print(len(dat[2]))
#print(dat[2])

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = input()
dat = []
for i in range(n):
    dat.append(set([]))
for i in range(n):
    for j in range(i, 0, -1):
        for x in dat[j-1]:
            dat[j].add(x + s[i])
    dat[0].add(s[i])
print(len(dat[2]))
#print(dat[2])

Submission status: Time Limit Exceeded

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

import itertools
pw_list = []
for i in range(N):
    for j in range(N):
        for k in range(N):
            if i == j or j == k or k == i:
                continue
            list_n = [i, j, k]
            list_n.sort()
            a1, a2, a3 = list_n[0], list_n[1], list_n[2]
            pw = S[int(a1)] + S[int(a2)] + S[int(a3)]
            if not pw in pw_list:
                pw_list.append(pw)

print(len(pw_list))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

s = input()

numlist = [0] * 1000

for i in range(1000):
    top = i // 100
    mid = (i - top * 100) // 10
    bot = (i - top * 100 - mid * 10)


    found = False
    for j in range(n):
        if s[j] == str(top):
            for k in range(j+1, n):
                if s[k] == str(mid):
                    for l in range(k+1, n):
                        if s[l] == str(bot):
                            numlist[i] += 1
                            found = True
                            break 
                if found:
                    break
        if found:
            break

ans = numlist.count(1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())

s = input()

numlist = []

for v in itertools.combinations(range(n), 3):
    numlist.append(s[v[0]] + s[v[1]] + s[v[2]])

numlist = set(numlist)
ans = len(numlist)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = read().rstrip().decode()
cnt = 0
for i in range(1000):
    num = ''
    if i < 100:
        num += '0'
        if i < 10:
            num += '0'
    num += str(i)
    index = 0
    for ss in s:
        if ss == num[index]:
            index += 1
            if index == 3:
                cnt += 1
                break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=0
for i in range(1000):
  flag=0
  pin=str(i).zfill(3)
  for j in range(n):
    if s[j]==pin[0] and flag==0:
      flag=1
      num1=j
    if s[j]==pin[1] and flag==1 and num1<j:
      flag=2
      num2=j
    if s[j]==pin[2] and flag==2 and num2<j:
      cnt+=1
      break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=0
for i in range(1000):
  flag=0
  pin=str(i).zfill(3)
  for j in range(n-2):
    if s[j]==pin[0]:
      flag=1
      break
  if flag==1:
    for k in range(j+1,n-1):
      if s[k]==pin[1]:
        flag=2
        break
  if flag==2:
    for l in range(k+1,n):
      if s[l]==pin[2]:
        cnt+=1
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for n in range(1000):
    num = "0"*(3-len(str(n))) + str(n)
    index = 0
    can_set = False
    for i in range(N):
        if S[i] == num[index]:
            if index == 2:
                can_set = True
                break
            index += 1
    if can_set:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
code = [[n,n,n] for i in range(1000)]

for i in range(n):
    si = int(s[i])
    for j in range(100):
        if code[j*10+si][1] < i and code[j*10+si][2] == n:
            code[j*10+si][2] = i
            #print(i,j*10+si,2)
        if code[si*100+j][0] == n:
            code[si*100+j][0] = i
            #print(i,si*100+j,0)
        if code[(j//10)*100+si*10+j%10][0] < i and code[(j//10)*100+si*10+j%10][1] == n:
            code[(j//10)*100+si*10+j%10][1] = i
            #print(i,(j//10)*100+si*10+j%10,1)

ans = 0
for i in range(1000):
    if code[i][2] < n:
        ans += 1

print(ans)