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 sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = set()
for i in range(10):
  for I in range(n-2):
    if s[I] == str(i):
      for j in range(10):
        for J in range(I+1,n-1):
          if s[J] == str(j):
            for l in range(10):
              for L in range(J+1,n):
                if s[L] == str(l):
                  ans.add(i*100+j*10+l)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = input()
ans = set()
for i in range(n-2):
  for j in range(i+1,n-1):
    for l in range(j+1,n):
      ans.add(int(s[i])*100+int(s[j])*10+int(s[l]))
print(len(ans))

Submission status: Time Limit Exceeded

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

def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for p in range(1000):
        pattern = str(p).zfill(3)
        key = 0
        cnt = 0
        for n in pattern:
            for i in range(key,N):
                if S[i] == n:
                    key = i+1
                    cnt += 1
                    break
        if cnt == 3:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import re
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for i in range(1000):
        a,b,c = str(i).zfill(3)
        pattern = r'.*?{}.*?{}.*?{}.*?'.format(a, b, c)
        match = re.search(pattern, S)

        if match:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():  
  import sys
  input = sys.stdin.readline
  n = int(input())
  s = input()
  def multi_index(l,x):
    return tuple([i for i,_x in enumerate(l) if _x == x])

  ans = 0
  for i in range(10):
    e = 0
    if str(i) in s:
      c = multi_index(s,str(i))[0]
      for j in range(10):
        if str(j) in s and i!=j and c<=len(s)-2:
          for q in range(c+1,len(s)-1):
            if str(j) == s[q]:
              d = q
              break
          else:
            d = -1
        elif str(j) in s and i==j and len(multi_index(s,str(i)))>=2:
          d = multi_index(s,str(i))[1]
        else:
          d = -1
        if d > c:
          for l in range(10):
            if str(l) in s and i!=j and j!=l and i!=l:
              e = multi_index(s,str(l))[-1]
              if e > d:
                ans += 1
            if str(l) in s and i!=j and j==l:
              e = multi_index(s,str(l))[-1]
              if e > d:
                ans += 1
            if str(l) in s and i==j and j!=l:
              e = multi_index(s,str(l))[-1]
              if e > d:
                ans += 1
            if str(l) in s and i==j and j==l:
              e = multi_index(s,str(l))[-1]
              if e > d:
                ans += 1
            if str(l) in s and i==l and j!=l:
              e = multi_index(s,str(l))[-1]
              if e > d:
                ans += 1
  print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
def multi_index(l,x):
  return [i for i,_x in enumerate(l) if _x == x]

ans = 0
for i in range(10):
  e = 0
  if str(i) in s:
    c = multi_index(s,str(i))[0]
    for j in range(10):
      if str(j) in s and i!=j and c<=len(s)-2:
        chk = s[c+1:]
        #print(chk)
        if str(j) in chk:
          d = multi_index(chk,str(j))[0]+c+1
        else:
          d = -1
      elif str(j) in s and i==j and len(multi_index(s,str(i)))>=2:
        d = multi_index(s,str(i))[1]
      else:
        d = -1
      if d > c:
        for l in range(10):
          if str(l) in s and i!=j and j!=l and i!=l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
              #print(i,j,l)
          if str(l) in s and i!=j and j==l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
              #print(i,j,l)
          if str(l) in s and i==j and j!=l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
              #print(i,j,l)
          if str(l) in s and i==j and j==l:
            e = multi_index(s,str(l))[-1]
            if e > d:
              ans += 1
              #print(i,j,l)
          if str(l) in s and i==l and j!=l:
            e = multi_index(s,str(l))[-1]
            #print(i,j,l,c,d,e)
            if e > d:
              ans += 1
              #print(i,j,l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

anlis = set(list(itertools.combinations(S,3)))
print(len(anlis))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
from collections import defaultdict
d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)

for s in lis:
    flag = 0
    for i in range(N-2):
        if flag:break
        if S[i] == s[0]:
            for j in d[s[1]]:
                if j > i:
                    if d[s[2]] and max(d[s[2]]) > j:
                        ans += 1
                        flag = 1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
from collections import defaultdict
d = defaultdict(list)
for i,s in enumerate(S):
    d[s].append(i)
for s in lis:
    flag = 0
    for i in range(N-2):
        if flag:break
        if S[i] == s[0]:
            for j in d[s[1]]:
                if j > i:
                    if d[s[2]] and max(d[s[2]]) > j:
                        ans += 1
                        flag = 1
                        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
for s in lis:
    flag = 0
    for i in range(N-2):
        if flag:break
        if S[i] == s[0]:
            if s[1] in set(S[i+1:]):
                a = S[i+1:].index(s[1])
                if s[2] in set(S[i+a+2:]):
                    ans += 1
                    flag = 1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
for s in lis:
    flag = 0
    for i in range(N-2):
        if flag:break
        if S[i] == s[0]:
            for j in range(i+1,N-1):
                if S[j] == s[1]:
                    if s[2] in set(S[j+1:]):
                        ans += 1
                        flag = 1
                        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = 0
for s in lis:
    flag = 0
    for i in range(N-2):
        if flag:break
        if S[i] == s[0]:
            if s[1] not in S[i+1:]:continue
            elif s[2] not in S[i+2:]:continue
            else:
                for j in range(i+1,N-1):
                    if S[j] == s[1]:
                        if s[2] in S[j+1:]:
                            ans += 1
                            flag = 1
                            break
                        else:continue
                    else:continue
        else:continue
# print(lis[10:20])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
ans = set()
for s in lis:
    for i in range(N-2):
        if S[i] == s[0]:
            if s[1] not in S[i+1:]:continue
            elif s[2] not in S[i+2:]:continue
            else:
                for j in range(i+1,N-1):
                    if S[j] == s[1]:
                        if s[2] in S[j+1:]:
                            ans.add(s)
                            break
                        else:continue
                    else:continue
        else:continue
# print(lis[10:20])
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
#lis = [str(i)+str(j)+str(k) for i in range(10) for j in range(i,10) for k in range(j,10)]
past = set()
ans = 0
for i in range(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 past:
                past.add(S[i]+S[j]+S[k])
                ans += 1
            else:continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [s for s in input()]
from itertools import combinations
lis = set(combinations(S,3))
print(len(lis))

Submission status: Time Limit Exceeded

Solution code:
import math,time
N = int(input())
S = input()
# length = len(S)
ans = 0
t1 = time.time()
for i in range(1000):
    locknum = str(i).zfill(3)
    digit = 0
    for j in range(N):
        if digit<2 and locknum[digit] == S[j]:
            digit +=1
        elif digit==2 and locknum[digit]==S[j]:
            ans +=1
            break

    # a = S.find(locknum[0])
    # b = S.find(locknum[1],a+1)
    # c = S.find(locknum[2],b+1)
    # if a!=-1 and b!=-1 and c!=-1:
    #     # print(i)
    #     ans +=1

t2 = time.time()
# print(t2-t1)                 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    pw = str(i).zfill(3)
    ok1 = False
    ok2 = False
    ok3 = False
    for j in range(N):
        if S[j] == pw[0] and not ok1:
            ok1 = True
            continue
        if ok1 and not ok2:
            if S[j] == pw[1]:
                ok2 = True
                continue
        if ok2:
            if S[j] == pw[2]:
                ok3 = True
                # print(pw)
                break
    if ok3:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math,time
N = int(input())
S = input()
length = len(S)
ans = 0
# t1 = time.time()
for i in range(1000):
    locknum = str(i).zfill(3)
    digit = 0
    for j in range(length):
        if S[j] == locknum[digit]:
            if digit == 2:
                ans += 1
                # print(str(i).zfill(3))
                break
            else:
                digit += 1
# t2 = time.time()
# print(t2-t1)                 
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(0,1000):
    flag = False
    locknum = str(i).zfill(3)
    digit = 0
    for j in range(len(S)):
        if S[j] == locknum[digit]:
            if digit == 2:
                ans += 1
                break
            else:
                digit += 1

                    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
S = input()
# print(len(S))

case =[]

for i in range(10):
    # dummy1 = [i]
    dummy = [] 
    for num in range(len(S)):
        if int(S[num]) == i:
            dummy.append(num)
    case.append(dummy)

ans = 0

for i in range(0,1000):
    flag = False
    locknum = str(i).zfill(3)
    # print(locknum)
    a = int(locknum[0])
    b = int(locknum[1])
    c = int(locknum[2])
    if len(case[a])==0 or len(case[b]) == 0 or len(case[c]) == 0:
        continue 
    for p in range(len(case[a])):
        if flag == True:break
        for q in range(len(case[b])):
            if flag == True:break
            for r in range(len(case[c])):
                if flag == True:break
                if case[a][p]<case[b][q] and case[b][q]<case[c][r]:
                    # print(a,b,c,case[a][p],case[b][q],case[c][r])
                    ans += 1
                    flag = True
                    
print(ans)
# print(case)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

res = 0
for i in range(1000):
    one = str(i//100)
    two = str(i%100//10)
    three = str(i%10)
    
    flg1 = False
    flg2 = False
    flg3 = False
    
    ptr = 0
    for j in range(ptr, n-2):
        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

print(res)

Submission status: Time Limit Exceeded

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

result_dic = {}

for  k in range(1, N-1):
    for i in range(k):
        for j in range(k+1, N):
            result_dic[S[i] + S[k] + S[j]] = 1

print(len(result_dic))

Submission status: Time Limit Exceeded

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

ans = 0
for sec in range(0, 1000):
    # can make sec?
    count = 0
    for i in range(N):
        if int(S[N - 1 - i]) == sec % 10:
            sec = sec // 10
            count += 1
        if count == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().strip()
ans = []

for j in range(1, N - 1):
  left, right = [0 for i in range(10)], [0 for i in range(10)]
  for l in range(0, j):
    left[int(S[l])] += 1
  for r in range(j + 1, N):
    right[int(S[r])] += 1
  
  for i, l in enumerate(left):
    for k, r in enumerate(right):
      if l >= 1 and r >= 1:
        ans.append(str(i) + str(S[j]) + str(k))

print(len(set(ans)))

Submission status: Time Limit Exceeded

Solution code:
import pprint
import copy
N=int(input())
S=input()
dig=[[] for i in range(10)]
chkigid=[0]*10
ansdigid=[0]*10
#print(dig)
cnt=0
for i in range(N):
    dig[int(S[i])].append([int(S[i]),chkigid[int(S[i])],i])#dig[int(S[i])][chkigid[int(S[i])]][2]=i
    chkigid[int(S[i])]=chkigid[int(S[i])]+1
    #pprint.pprint(dig)
    #pprint.pprint(chkigid)
    #input()
for i in range(10):
    for j in range(10):
        dig2=copy.deepcopy(dig)
        v1 = float("inf")
        if len(dig2[i])!=0:
            v1 = dig2[i][0][2]
            dig2[i].pop(0)#pop(dig2[i][0])
        v2 = float("inf")
        for k in range(len(dig2[j])):
            #print(dig2[j][len(dig2[j])-1- k])
            if len(dig2[j])!=0:
                v2=dig2[j][len(dig2[j])-1-k][2]
                dig2[j].pop(len(dig2[j])-1-k)
                break
        if (v1<v2)and(v1!=float("inf"))and(v2!=float("inf")):
            for k in range(10):
                for l in range(len(dig2[k])):
                    if v1<dig2[k][l][2]<v2:
                        #print(dig2[k][l][0])
                        cnt=cnt+1
                        break
        #pprint.pprint(dig2)
        #print(i,v1,j,v2,cnt)
        #input()
print(cnt)

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])
            l=list(set(l))
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
#n,s=map(str, input().split())
n=int(input())
s=str(input())
l=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            l.append(s[i]+s[j]+s[k])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N = int(input())
S = input()
ans = 0
for v in range(1000):
    v = str(v).zfill(3)
    flag = [False for _ in range(3)]
    for i in range(len(S)):
        if not flag[0] and v[0] == S[i]:
            flag[0] = True
            continue
        if not flag[1] and v[1] == S[i]and flag[0]:
            flag[1] = True
            continue
        if not flag[2] and v[2] == S[i] and flag[1]:
            flag[2] = True
            break
    if sum(flag) == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N = int(input())
S = input()
ans = 0
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    flag = [False for _ in range(3)]
    idx = 0
    for i in range(len(S)):
        if not flag[0] and v[0] == S[i] and not used[i]:
            used[i] = True
            flag[0] = True
            continue
        if not flag[1] and v[1] == S[i] and not used[i] and sum(used[:i]) == 1:
            used[i] = True
            flag[1] = True
            continue
        if not flag[2] and v[2] == S[i] and not used[i] and sum(used[:i]) == 2:
            used[i] = True
            flag[2] = True
            break
    if sum(flag) == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N = int(input())
S = input()
ans = []
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    idx = 0
    for i in range(len(S)):
        if v[0] == S[i] and not used[i]:
            used[i] = True
            idx = i + 1
            break
    for i in range(idx, len(S)):
        if v[1] == S[i] and not used[i]:
            used[i] = True
            idx = i + 1
            break
    for i in range(idx, len(S)):
        if v[2] == S[i] and not used[i]:
            used[i] = True
            break
    if sum(used) == 3 and v not in ans:
        ans.append(v[:])
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N=int(input())
S=list(map(int,input()))

ans=0

for i in range(1000):
    Num=list(map(int,str(i).zfill(3)))
    flg=[False for i in range(3)]
    
    for j in range(N):
        if S[j]==Num[0] and not flg[0]:
            flg[0]=True
            continue
        if flg[0] and S[j]==Num[1] and not flg[1]:
            flg[1]=True
            continue
        if flg[1] and S[j]==Num[2]:
            flg[2]=True
            break
    if flg[2]:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
V=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            s=""
            a=str(i)
            b=str(j)
            c=str(k)
            s=a+b+c
            V.append(s)
ans=0
for i in range(len(V)):
    v=V[i]
    flag1=False
    flag2=False
    flag3=False
    for j in range(N):
        if not flag1:
            if S[j]==v[0]:
                flag1=True
                continue
        if not flag2:
            if flag1:
                if S[j]==v[1]:
                    flag2=True
                    continue
        if flag2:
            if S[j]==v[2]:
                flag3=True
        if flag3:
            ans+=1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 13:15:15 2020

@author: liang
"""

"""
1.全探索 i,j,kを固定してそれぞれの番号を調べる => O(N^3)
2.全探索3桁の暗証番号000~999が文字列Sにあるか調べる =>O(N)
"""
"""
解1.コード　=> TLE
#使用済みリストを用意することで枝刈り
N = int(input())
S = list(map(int,input().split()))
num_used = [list() for i in range(10)]
numbers = list()
for i in range(N):
    for j in range(i+1, N):
        if S[j] in num_used[S[i]]:
            continue
        else:
            num_used[S[i]].append(S[j])
            for k in range(j+1,N):
                number = str(S[i]) + str(S[j]) + str(S[k])
                if number not in numbers:
                    numbers.append(number)
print(len(numbers))
"""
#解2コード => O(N)
N = int(input())
S = input()
ans = 0
for i in range(1000):
    a = i//100
    b = i%100//10 ###400//10 = 40
    c = i%10
    num = str(a) + str(b) + str(c) 
    flag = 0
    for j in range(N) :
        if S[j] == num[flag]:
            flag += 1
        if flag == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 31 13:15:15 2020

@author: liang
"""

N = int(input())
S = input()
numbers = list()
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1,N):
            number = str(S[i]) + str(S[j]) + str(S[k])
            if number not in numbers:
                numbers.append(number)
print(len(numbers))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().strip()
ans = set()

for j in range(1, N - 1):
  left, right = [0 for i in range(10)], [0 for i in range(10)]
  for l in range(0, j):
    left[int(S[l])] += 1
  for r in range(j + 1, N):
    right[int(S[r])] += 1
  
  for i, l in enumerate(left):
    for k, r in enumerate(right):
      if l >= 1 and r >= 1:
        ans.add(str(i) + str(S[j]) + str(k))

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input().strip()
ans = set()

for j in range(1, N - 1):
  left, right = set(), set()
  for l in range(0, j):
    left.add(S[l])
  for r in range(j + 1, N):
    right.add(S[r])
  
  for l in left:
    for r in right:
      ans.add(str(l) + str(S[j]) + str(r))

print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def canMakeNumber(k, s):
    k = str(k).zfill(3)
    dic = {0: False, 1: False, 2: False}
    rep = False
    for t in s:
        if dic[0] is False:
            if t == k[0]:
                dic[0] = True
        else:
            if dic[1] is False:
                if t == k[1]:
                    dic[1] = True
            else:
                if dic[2] is False:
                    if t == k[2]:
                        dic[2] = True
                else:
                    continue
    if dic[0] == dic[1] == dic[2] == True:
        rep = True
    return rep


N = int(input())
S = input()
ans = 0
for i in range(0, 1000):
    if canMakeNumber(i, str(S)):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    input()
    s = input()
    ans = 0
    for i in range(1000):
        t = str(i)
        while(len(t)<3):
            t = '0'+t
        it = 0
        for i in s:
            if it==3:
                break
            if i==t[it]:
                it+=1
        if it==3:
            ans+=1
    print(ans)
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    input()
    s = input()
    ans = 0
    for i in range(1000):
        t = str(i)
        while(len(t)<3):
            t = '0'+t
        it = 0
        for i in s:
            if it==3:
                continue
            if i==t[it]:
                it+=1
        if it==3:
            ans+=1
    print(ans)
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
def check(pin):
    flag = 0
    for s in S:
        if flag == 0:
            if pin[0] in s:
                flag = 1
        elif flag == 1:
            if pin[1] in s:
                flag = 2
        else:
            if pin[2] in s:
                return True
    return False
            
n = int(input())
S = input()
ans = 0
# Sではなく,PINの候補を全探索
for i in range(10):
    for j in range(10):
        for k in range(10):
            PIN = str(i)+str(j)+str(k)
            if check(PIN):
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
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 sys
input = lambda: sys.stdin.readline().rstrip() 

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

    ans = 0
    for i in range(1000):
        s = str(i).zfill(3)
        j = 0
        flg0 = False
        flg1 = False
        flg2 = False
        for j in S:
            if not flg0 and j==s[0]:
                flg0 = True
            elif flg0 and not flg1 and j==s[1]:
                flg1 = True
            elif flg0 and flg1 and not flg2 and j==s[2]:
                flg2 = True
        if flg0 and flg1 and flg2:
            ans +=1

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
import re

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

    ans = 0
    for i in range(1000):
        s = str(i).zfill(3)
        p = '.*'+s[0]+'.*'+s[1]+'.*'+s[2]+'.*'
        if re.fullmatch(p, S):
            ans +=1

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 

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

    c = [False]*1000
    for i in range(N-2):
        for j in range(i+1, N-1):
            for k in range(j+1, N):
                c[int(S[i])*100+int(S[j])*10+int(S[k])] = True
    print(c.count(True))

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
from operator import mul

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

N = int(input())
s = input()

items_list = []

for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = [str(i), str(j), str(k)]
            items_list.append(tmp)

ans = 0
for pin in items_list:
    cnt = 0
    for i in range(len(s)):
        if s[i] == pin[cnt]:
            cnt += 1
            if cnt == 3:
                ans += 1
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# Author: cr4zjh0bp
# Created: Sun Mar 29 05:26:08 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
s = ns()

def ok(p):
    k = 0
    for i in range(n):
        if s[i] == p[k]:
            k += 1
        if k == 3:
            return True
    return False

ans = 0
for i in range(1000):
    p = "{:0>3}".format(i)
    if ok(p):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product
n = int(input())
s = input()

ans = 0
for pas in product(range(10), repeat=3):
    index = 0
    for i in range(len(s)):
        if pas[index] == int(s[i]):
            index += 1
        if index == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s = list(input())
ans = 0

for i in range(0,10):
    for j in range(0,10):
        for k in range(0,10):
            flag1 = 0
            flag2 = 0
            flag3 = 0
            for m in range(n):
                if flag1 == 0:
                    if int(s[m]) == i:
                        flag1 = 1
                elif flag2 == 0:
                    if int(s[m]) == j:
                        flag2 = 1
                elif flag3 == 0:
                    if int(s[m]) == k:
                        flag3 = 1
                        ans += 1
                        break
                    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env/ python3
N = int(input())
S = input()
#A, B, C = input().split()
#A, B, C, X, Y = map(int, input().split())

#N = int(input())
#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(A[0][0])

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