Problem:


Score: 400 points

Problem Statement

AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code.

The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code.

How many different PIN codes can he set this way?

Both the lucky number and the PIN code may begin with a 0.

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

Thus, he can set three different PIN codes: 022, 024, and 224.

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数
 
for a in range(10): #1文字目
  for b in range(10): #2文字目
    for c in range(10): #3文字目
        flg = False
        for i in range(n-2):
            if str(a) == s[i]:
                tmp_i = i + 1
                for j in range(tmp_i,n-1):
                    if str(b) == s[j]:
                        tmp_i = j + 1
                        for k in range(tmp_i,n):
                            if str(c) == s[k]:
                                cnt = cnt + 1
                                flg = True
                                break
                        else:
                        	break
                        if flg:
                            break
                if flg:
                    break
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

for ii in range(1000):
    v = str(ii).zfill(3)
    #print(v[0])
    s2=s
    #print("s=",v)
    for j in range(3):
        f=0
        for i in range(len(s2)):
            if s2[i] == v[j]:
                s2=s2[i+1:]
                f=1
                #print("aa",s2)
                break

        if f == 0 :
            break

    if f == 1:
        ans += 1
        #print(v)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #長さ
s = str(input()) #文字列
cnt = 0 #暗証番号数
 
for a in range(10): #1文字目
  for b in range(10): #2文字目
    for c in range(10): #3文字目
        flg = False
        for i in range(n-2):
            if str(a) == s[i]:
                tmp_i = i + 1
                for j in range(tmp_i,n-1):
                    if str(b) == s[j]:
                        tmp_i = j + 1
                        for k in range(tmp_i,n):
                            if str(c) == s[k]:
                                cnt = cnt + 1
                                flg = True
                                break
                        if flg:
                            break
                if flg:
                    break
            
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
chk = [0]*1000
for j in range(1000):
    j = str(j).zfill(3)
    for i, s in enumerate(S):
        if chk[int(j)] == 1:
            continue
        if s == j[0]:
            for ii, ss in enumerate(S[i+1:]):
                if ss == j[1]:
                    if chk[int(j)] == 1:
                        continue
                    for iii, sss in enumerate(S[i+ii+2:]):
                        if sss == j[2]:
                            if chk[int(j)] == 1:
                                continue
                            chk[int(j)] = 1
                            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
chk = [0]*1000
for j in range(1000):
    j = str(j).zfill(3)
    for i, s in enumerate(S):
        if s == j[0]:
            for ii, ss in enumerate(S[i+1:]):
                if ss == j[1]:
                    for iii, sss in enumerate(S[i+ii+2:]):
                        if sss == j[2]:
                            if chk[int(j)] == 1:
                                continue
                            chk[int(j)] = 1
                            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = tuple(input())
ans = 0
for i in range(1000):
  if i<10:
    cnt0= 0
    cnt1 = 0
    for j in range(N):
      if 2<=cnt0 and S[j]=="%d"%i:
        ans+=1
        break
      if S[j]=="0":
        cnt0+=1
        continue
  elif 10<=i<=99:
    cnt0=0
    cnt1=0
    cnt2=0
    i = list(str(i))
    for j in range(N):
      if 1<=cnt0 and 1<=cnt1 and S[j]=="%s"%i[1]:
        ans+=1
        break
      if S[j]=="0" and cnt0!=1:
        cnt0+=1
        continue
      if 1<=cnt0 and S[j]=="%s"%i[0]:
        cnt1 +=1
        continue
  elif 100<=i:
    cnt0=0
    cnt1=0
    cnt2=0
    i = list(str(i))
    for j in range(N):
      if 1<=cnt0 and 1<=cnt1 and S[j]=="%s"%i[2]:
        ans+=1
        #print(i)
        break
      if S[j]=="%s"%i[0] and cnt0!=1:
        cnt0+=1
        continue
      if 1<=cnt0 and S[j]=="%s"%i[1]:
        cnt1 +=1
        continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(1000):
  if i<10:
    cnt0= 0
    cnt1 = 0
    for j in range(N):
      if S[j]=="%d"%i and 2<=cnt0 :
        ans+=1
        break
      if S[j]=="0":
        cnt0+=1
        continue
  elif 10<=i<=99:
    cnt0=0
    cnt1=0
    cnt2=0
    i = list(str(i))
    for j in range(N):
      if S[j]=="%s"%i[1] and 1<=cnt0 and 1<=cnt1:
        ans+=1
        break
      if S[j]=="0" and cnt0!=1:
        cnt0+=1
        continue
      if S[j]=="%s"%i[0] and 1<=cnt0:
        cnt1 +=1
        continue
  elif 100<=i:
    cnt0=0
    cnt1=0
    cnt2=0
    i = list(str(i))
    for j in range(N):
      if S[j]=="%s"%i[2] and 1<=cnt0 and 1<=cnt1:
        ans+=1
        #print(i)
        break
      if S[j]=="%s"%i[0] and cnt0!=1:
        cnt0+=1
        continue
      if S[j]=="%s"%i[1] and 1<=cnt0:
        cnt1 +=1
        continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(1000):
  if i<10:
    cnt0= 0
    cnt1 = 0
    for j in range(N):
      if 2<=cnt0 and S[j]=="%d"%i:
        ans+=1
        break
      if S[j]=="0":
        cnt0+=1
        continue
  elif 10<=i<=99:
    cnt0=0
    cnt1=0
    cnt2=0
    i = list(str(i))
    for j in range(N):
      if 1<=cnt0 and 1<=cnt1 and S[j]=="%s"%i[1]:
        ans+=1
        break
      if S[j]=="0" and cnt0!=1:
        cnt0+=1
        continue
      if 1<=cnt0 and S[j]=="%s"%i[0]:
        cnt1 +=1
        continue
  elif 100<=i:
    cnt0=0
    cnt1=0
    cnt2=0
    i = list(str(i))
    for j in range(N):
      if 1<=cnt0 and 1<=cnt1 and S[j]=="%s"%i[2]:
        ans+=1
        #print(i)
        break
      if S[j]=="%s"%i[0] and cnt0!=1:
        cnt0+=1
        continue
      if 1<=cnt0 and S[j]=="%s"%i[1]:
        cnt1 +=1
        continue
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(input())
ans = []
for i in range(len(S)):
  for j in range(i+1,len(S)):
    for k in range(j+1,len(S)):
      if not S[i]+S[j]+S[k] in set(ans):
      	ans.append(S[i]+S[j]+S[k])
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
key=[]
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      s=S[i]+S[j]+S[k]
      if s in key:continue
      else:key.append(s)
print(len(key))

Submission status: Time Limit Exceeded

Solution code:
def main():
  import itertools
  N = int(input())
  S = input()
  S = list(S)
  L = set()
  for i, j, k in itertools.combinations(S,3):
    L.add(i + j + k)
  print(len(L))
main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = list(map(int,input()))
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      flg = False
      flg2 = False
      for x in range(N):
        if flg2:
          break
        if not flg:
          if S[x] == i:
            flg = True
        else:
          if S[x] == j:
            flg2 = True
            if k in S[x+1:]:
              ans +=1
print(ans)

Submission status: Time Limit Exceeded

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


def main():
    sc = Scan()
    N = sc.intarr()[0]
    S = sc.strarr()[0]

    count = 0

    for i in range(1000):
        # print("--------")
        lucky = format_str(i)
        Flag = 0
        for j in range(N):
            if S[j] == lucky[Flag]:
                Flag += 1
            if Flag == 3:
                count += 1
                break
    print(count)


def format_str(num):
    if num < 10:
        return "00" + str(num)
    elif num < 100:
        return "0" + str(num)
    else:
        return str(num)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Submission status: Time Limit Exceeded

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


def main():
    sc = Scan()
    N = sc.intarr()[0]
    S = sc.strarr()[0]

    count = 0

    for i in range(1000):
        # print("--------")
        lucky = format_str(i)
        Flag_j, Flag_m, Flag_n = -1, -1, -1
        # print("check001")

        for j in range(N-2):
            if S[j] == lucky[0]:
                Flag_j = j
                break
        # print("check002")
        if Flag_j == -1:
            continue
        # print("check003")

        for m in range(Flag_j+1, N-1):
            if S[m] == lucky[1]:
                Flag_m = m
                break
        # print("check004")
        if Flag_m == -1:
            continue
        # print("check005")

        for n in range(Flag_m+1, N):
            if S[n] == lucky[2]:
                Flag_n = n
                break
        # print("check006")
        if Flag_n == -1:
            continue
        # print("check007")
        count += 1

    print(count)


def format_str(num):
    if num < 10:
        return "00" + str(num)
    elif num < 100:
        return "0" + str(num)
    else:
        return str(num)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Submission status: Time Limit Exceeded

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


def main():
    sc = Scan()
    N = sc.intarr()[0]
    S = sc.strarr()[0]

    count = 0

    for i in range(1000):
        # print("--------")
        lucky = "000"
        Flag_j = -1
        Flag_m = -1
        Flag_n = -1
        # print("check001")
        if i < 10:
            lucky = "00" + str(i)
        elif i < 100:
            lucky = "0" + str(i)
        else:
            lucky = str(i)

        for j in range(N-2):
            if S[j] == lucky[0]:
                Flag_j = j
                break
        # print("check002")
        if Flag_j == -1:
            continue
        # print("check003")

        for m in range(Flag_j+1, N-1):
            if S[m] == lucky[1]:
                Flag_m = m
                break
        # print("check004")
        if Flag_m == -1:
            continue
        # print("check005")

        for n in range(Flag_m+1, N):
            if S[n] == lucky[2]:
                Flag_n = n
                break
        # print("check006")
        if Flag_n == -1:
            continue
        # print("check007")
        count += 1

    print(count)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Submission status: Time Limit Exceeded

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


def main():
    sc = Scan()
    N = sc.intarr()[0]
    S = sc.strarr()[0]

    count = 0

    for i in range(1000):
        # print("--------")
        lucky = "000"
        Flag_j = -1
        Flag_m = -1
        Flag_n = -1
        # print("check001")
        if i < 10:
            lucky = "00" + str(i)
        elif i < 100:
            lucky = "0" + str(i)
        else:
            lucky = str(i)

        for j in range(N):
            if S[j] == lucky[0]:
                Flag_j = j
                break
        # print("check002")
        if Flag_j == -1:
            continue
        # print("check003")

        for m in range(Flag_j+1, N):
            if S[m] == lucky[1]:
                Flag_m = m
                break
        # print("check004")
        if Flag_m == -1:
            continue
        # print("check005")

        for n in range(Flag_m+1, N):
            if S[n] == lucky[2]:
                Flag_n = n
                break
        # print("check006")
        if Flag_n == -1:
            continue
        # print("check007")
        count += 1

    print(count)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Submission status: Time Limit Exceeded

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

ans = set()
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp = str(i) + str(j) + str(k)

            f = -1
            s = -1
            t = -1
            for x in range(N):
                X = S[x]
                if f == -1 and X == str(i):
                    f = x
                if s == -1 and f != -1 and f < x and X == str(j):
                    s = x
                if t == -1 and s != -1 and s < x and X == str(k):
                    t = x
            if f < s < t:
                ans.add(tmp)
print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
L=int(input())
N=input()
n = list(itertools.combinations(N, 3))

a=[]
for i in range(len(n)):
        a.append(n[i][0]+n[i][1]+n[i][2])
print(len(set(a)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
L=int(input())
N=input()
n = list(itertools.combinations(N, 3))
a=[]
for i in range(len(n)):
        a.append(int(n[i][0])*100 + int(n[i][1])*10+int(n[i][2]))
print(len(set(a)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
input1 = int(input())
input2 = input()
inputbox = list(input2)
i=0
count = 0
for i in range(1000):
        c = [int(i/100),int(i/10)%10,i%10]
        f = 0
        for j in range(input1):
            if int(inputbox[j])==c[f]:
                f=f+1
            if f==3:
                break
        if f==3:
            count = count + 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:

input1 = int(input())
input2 = input()
inputbox = list(input2)
i=0
count = 0
for i in range(1000):
        c = [int(i/100),int(i/10)%10,i%10]
        f = 0
        for j in range(input1):
            if int(inputbox[j])==c[f]:
                f=f+1
            if f==3:
                break
        if f==3:
            count = count + 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
import copy
a=int(input())
b=int(input())
w=b
d=[0]*3
count=0
c=[int(i) for i in str(b)]
for i in range(a-len(c)):
    c.insert(0,0)
for i in range(0,1000,1):
    for j in range(2,-1,-1):
        d[j]=i%10
        i=i//10#ここまでは「０，０，０」とか
    for x in range(a-2):
        if d[0]==c[x]:
            for y in range(x+1,a-1):
                if d[1]==c[y]:
                    for z in range(y+1,a):
                        if d[2]==c[z]:
                            count+=1
                            break
                    break
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
 
n = int(input())
s = input()
pass_list = list(map(lambda x: str(x).zfill(3), range(1000)))
res = 0
 
for p in pass_list:
    
    ptr = 0
    one = False
    two = False
    three = False
    
    for i in range(len(s)):
        if(s[i] == p[0]):
            ptr = i
            one = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[1]):
            ptr = i
            two = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[2]):
            ptr = i
            three = True
            break
    
    if(one and two and three): res += 1
 
print(res)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  1 21:29:17 2019

@author: Shunya
"""

input1 = int(input())
input2 = input()
#input1 = len(input2)
kesu = input1 - 1
inputbox = list(input2)
li=[0 for _ in range(1000)]
kazu =""
number = []
i=0
while i < input1-2:
    del number[:]
    number.append(inputbox[i])
    j=0
    while j < input1 - 2 - i:
        number.append(inputbox[j+i+1])
        k=0
        while k < input1 - 2 - i - j:
            number.append(inputbox[k+j+i+2])
            kazu=""
            for n in range(3):
                kazu = kazu+str(number[n])
            kazu1 = int(kazu)
            li[kazu1]=1
            number.pop()
            k=k+1
        j=j+1
        number.pop()
    i=i+1

count = 0
for i in range (1000):
    if li[i] == 1:
        count =count+1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = input()

ans = 0

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

Submission status: Time Limit Exceeded

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

t = '000'
lst = []

for i in range(n-2):
	for j in range(i+1, n-1):
		for k in range(j+1, n):
			t = str(s[i]) + str(s[j]) + str(s[k])
			if not t in lst:
				lst.append(t)

print(len(lst))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = input()
    ans = 0
    for i in range(1000):
        key = "0" * (3 - len(str(i))) + str(i)
        j = 0
        flag = True
        while True:
            if j == n:
                flag = False
                break
            if s[j] == key[0]:
                j += 1
                break
            j += 1
        if not flag:
            continue
        while True:
            if j == n:
                flag = False
                break
            if s[j] == key[1]:
                j += 1
                break
            j += 1
        if not flag:
            continue
        while True:
            if j == n:
                flag = False
                break
            if s[j] == key[2]:
                j += 1
                break
            j += 1
        if flag:
            ans += 1
    print(ans)

main()

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):
            p = [i, j, k]
            idx = 0
            for l in range(n):
                if int(s[l]) == p[idx]:
                    idx += 1
                if idx == 3:
                    break
            if idx == 3:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    p = [i // 100, (i // 10) % 10 , i % 10, -1]
    idx = 0
    for j in range(n):
        if int(s[j]) == p[idx]:
            idx += 1
    if idx == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 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:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import*
_,s=open(0)
dp=defaultdict(bool)
for c in s[:-1]:
  for i in range(100):
    j=str(i).zfill(2)
    dp[j+c]|=dp[j]
  for i in range(10):
    j=str(i)
    dp[j+c]|=dp[j]
  dp[c]=True
print(sum(dp[str(i).zfill(3)]for i in range(1000)))

Submission status: Time Limit Exceeded

Solution code:
# 000~999で決め打ちして数える
n = int(input())
s = input()
ans = 0

for i in range(0, 1000):
    t = format(i, "0>3")
    idx = 0
    for c in s:
        if c == t[idx]:
            idx += 1
        if idx == 3:
            ans += 1
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = "0" * (3 - len(str(i))) + str(i)
    j = 0
    flag = True
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[0]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[1]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[2]:
            j += 1
            break
        j += 1
    if flag:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
#input = sys.stdin.readline
def solve():
  n = int(input())
  s = input()
  ans = 0
  for i in range(0,1000):
    t1,t2,t3 = 0,0,0
    c3 = i%10
    c2 = (i//10)%10
    c1 = i//100
    for t in range(n):
      if not t1:
        if int(s[t]) == c1:
          t1 = 1
      elif not t2:
        if int(s[t]) == c2:
          t2 = 1
      elif not t3:
        if int(s[t]) == c3:
          t3 = 1
    
    if t1 and t2 and t3: ans += 1
  print(ans)
solve()

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

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

cnt = 0
for i, j, k in product("0123456789", repeat=3):
    T = [i, j, k]
    cur = 0
    for s in S:
        if s == T[cur]:
            cur += 1
            if cur == 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):
  num = '{:03}'.format(i)
  t=0
  for j in range(n):
    if s[j] == num[t]:
      t += 1
      if t > 2:
        cnt += 1
        break
print(cnt)

Submission status: Time Limit Exceeded

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

c = 0
for i in range(10):
        for j in range(10):
            for k in range(10):
                count = 0
                for l in s:
                    if l == str(k) and count == 2:
                        count += 1
                    elif l == str(j) and count == 1:
                        count += 1
                    elif l == str(i) and count == 0:
                        count += 1
                    if count == 3:
                        c += 1
                        break

print(c)

Submission status: Time Limit Exceeded

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

count = 0
for a in range(10):
    for b in range(10):
        for c in range(10):
            f1 = False
            f2 = False
            p1 = 0
            p2 = 0
            for i in range(0, n-2):
                if int(s[i]) == a:
                    f1 = True
                    p1 = i
                    break
            if f1:
                for j in range(p1+1, n-1):
                    if int(s[j]) == b:
                        f2 = True
                        p2 = j
                        break
            if f2:
                for k in range(p2+1, n):
                    if int(s[k]) == c:
                        count += 1
                        break
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    n = "{:03}".format(i)
    index = 0
    c = 0
    for k in n:
        for j in range(index, len(S)):
            if S[j] == k:
                index = j+1
                c+=1
                break
    if c == 3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                flag1 = False
                flag2 = False
                for n in range(N):
                    if S[n] == str(i) and not flag1 and not flag2:
                        flag1 = True
                        continue
                    if S[n] == str(j) and flag1 and not flag2:
                        flag2 = True
                        continue
                    if S[n] == str(k) and flag1 and flag2:
                        ans += 1
                        break


    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def match(S,pat):
    i = 0
    for s in S:
        if s == pat[i]:
            i += 1
        if i == 3:
            return True
    return False

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

for n in range(1000):
    s = str(n)
    if len(s) == 1:
        s = '00'+s
    elif len(s) == 2:
        s = '0'+s
    else:
        pass
    if  match(S,s):
        ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
#print(N,S)

count=0


for n1 in range(10):
 cond=0
 for i in range(N-2):
   if n1==int(S[i]):
      p1=i
      cond=1
      break
 if cond==1:
  for n2 in range(10):
    for j in range(p1+1,N-1):
      if n2==int(S[j]):
        p2=j
        cond=2
        break
    if cond==2:
     for n3 in range(10):
      for k in range(p2+1,N):
        if n3==int(S[k]):
          count+=1
         # print(n1,n2,n3,S[p1]+S[p2]+S[k])
          cond=0
          break
      
              
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
#print(N,S)

count=0


for n1 in range(10):
 for n2 in range(10):
  for n3 in range(10):
   cond=0 
   for i in range(N):
     if cond==0:
       if n1==int(S[i]):
          cond+=1
     elif cond==1:
       if n2==int(S[i]):
          cond+=1
     else:
       if n3==int(S[i]):
        count+=1
        break
      
              
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
count = 0
for i in range(1000):
    x= i%10
    z= i//100
    y= (i-x-(z*100))//10
    
    p=0
    for j in range(N):
        if S[j]!=str(z):
            p = p+1
        else:
            break
    if p==N:
        count = count
    else:
        q=p+1
        for k in range(p+1,N):
            if S[k]!=str(y):
                q = q+1
            else:
                break
        if q == N:
            count = count
        else:
            r=q+1
            for l in range(q+1,N):
                if S[l]!=str(x):
                    r = r+1
                else:
                    break
            if r == N:
                count = count
            else:
                count = count+1

print(count)

Submission status: Time Limit Exceeded

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

    a = ['{:03d}'.format(i) for i in range(1000)]
    count = 0
    for i in range(len(a)):
        m,n,o = 0,1,2
        s = list(a[i])
        while m < n < o < len(lst) :
            if s[0] != lst[m]:
                m += 1
                n += 1
                o += 1
            elif s[1] != lst[n]:
                n += 1
                o += 1
            elif s[2] != lst[o]:
                o += 1
            else:
                count += 1
                break

    print(count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

    # 暗証番号を全探索
    ans = 0
    for v in range(1000):
        pin = '{0:03}'.format(v)
        current_searching = 0

        for ch in S:
            if ch == pin[current_searching]:
                current_searching += 1
            if current_searching == 3:
                ans += 1
                break
    return ans

print(d_lucky_pin())

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):
            flag = 0
            for l in range(n):
                dum = s[l]
                if flag == 0 and dum == str(i):
                    flag += 1
                elif flag == 1 and dum == str(j):
                    flag += 1
                elif flag == 2 and dum == str(k):
                    ans += 1
                    break
print(ans)