Problem:


Score: 400 points

Problem Statement

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

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

How many different PIN codes can he set this way?

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

Constraints

4 \leq N \leq 30000

S is a string of length N consisting of digits.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of different PIN codes Takahashi can set.

Sample Input 1

4
0224

Sample Output 1

3

Takahashi has the following options:

Erase the first digit of S and set 224.

Erase the second digit of S and set 024.

Erase the third digit of S and set 024.

Erase the fourth digit of S and set 022.

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

Sample Input 2

6
123123

Sample Output 2

17

Sample Input 3

19
3141592653589793238

Sample Output 3

329



Sample input:
4
0224


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
check = [0]*1000

for i in range(10):
    for j in range(N):
        if int(S[j]) == i:
            for k in range(10):
                for l in range(j+1,N):
                    if int(S[l]) == k:
                        for m in range(10):
                            for n in range(l+1,N):
                                if int(S[n]) == m:
                                    if check[i*100+k*10+m] == 0:
                                        ans += 1
                                        check[i*100+k*10+m] = 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            nums = [str(x) for x in [i, j, k]]
            for s in S:
                if s == nums[0]:
                    nums = nums[1:]
                    if len(nums) == 0:
                        ans += 1
                        break
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a = [i, j, k]
            l = 0
            for s in S:
                if l < 3  and a[l] == int(s):
                    l += 1
            if l == 3:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
S = list(map(int, input()[:]))
ans = 0
for num in range(1000):
    n1,n2,n3 = 0, 0, num%10
    n2= (num %100-n3)// 10
    n1 = (num-n2*10- n3) //100
    f1 = False
    f2 = False
    f3 = False
    for n in S:
        if not f1:
            if n == n1:
                f1 = True
        elif not f2:
            if n == n2:
                f2 = True
        elif not f3:
            if n == n3:
                f3 = True
                break
    if f1 and f2 and f3:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    lucky = str(i)
    if 0 <= i <= 9:
        lucky = "00" + lucky
    elif 10 <= i <= 99:
        lucky = "0" + lucky
    else:
        pass
    now = 0
    index = 0
    while index < N:
        if lucky[now] == S[index]:
            now += 1
        if now == 3:
            ans += 1
            break
        index += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
b=''
c=[]
d=[]
cnt=0
for i in range(n):
  if s[i] in b:continue
  b+=s[i]
  for j in range(i+1,n):
    if s[i]+s[j] in c:continue
    c+=s[i]+s[j]
    for k in range(j+1,n):
      if s[i]+s[j]+s[k] not in d:
        cnt+=1
        d.append(s[i]+s[j]+s[k])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1000):
        d0 = str(i % 10)
        d1 = str((i // 10) % 10)
        d2 = str((i // 100) % 10)
        j = 0
        found = False
        while j < N:
            if S[j] == d0:
                found = True
                j += 1
                break
            j += 1
        if not found:
            continue
        found = False
        while j < N:
            if S[j] == d1:
                found = True
                j += 1
                break
            j += 1
        if not found:
            continue
        found = False
        while j < N:
            if S[j] == d2:
                found = True
                j += 1
                break
            j += 1
        if not found:
            continue
        if found:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

n = int(input())
s = input()
cnt = []
for i in range(n-2):
  for j in range(i+1, n-1):
    for f in range(j+1, n):
      if s[i] + s[j] + s[f] not in cnt:
        cnt.append(s[i] + s[j]  +s[f])
print(len(cnt))

Submission status: Time Limit Exceeded

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

cnt = 0

for a in range(10):
    for b in range(10):
        for c in range(10):
            flag = False
            for j in range(n):
                if s[j] == str(a):
                    for k in range(j+1,n):
                        if s[k] == str(b):
                            for l in range(k+1,n):
                                if s[l] == str(c):
                                    flag = True
                                    cnt+=1
                                    #print(a,b,c)
                                    break       
                                if flag:
                                    break
                                                               
                            if flag:
                                break
                        if flag:
                            break
                if flag:
                    break
                    
               
        
print(cnt)

Submission status: Time Limit Exceeded

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

ans = [0] * 3
count = 0
for i in range(0, 1000):
    if (i < 10):
        s = '00' + str(i)
    elif (i >= 10 and i < 100):
        s = '0' + str(i)
    else:
        s = str(i)
    idx = 0
    for i in range(N):
        if (S[i] == s[idx]):
            ans[idx] = i + 1
            idx += 1
        if (0 not in ans):
            count += 1
            ans = [0] * 3
            break
print(count)

Submission status: Time Limit Exceeded

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

count=0
pin=[]*721
for p in range(N-2):
    for q in range(1,N-1):
        if p>=q:
            continue
        for r in range(2,N):
            if q>=r:
                continue
            n=int(S[p]+S[q]+S[r])
            if not n in pin:
                pin.append(n)
print(len(pin))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l=set(itertools.combinations(S, 3))

print(len(l))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N=int(input())
S=input()
a,b,c=0,0,0

l=set(itertools.combinations(S, 3))

print(len(l))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N=int(input())
S=input()
a,b,c=0,0,0

l=set(itertools.combinations(S, 3))

print(len(l))

Submission status: Time Limit Exceeded

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

dp = [[[False for _ in range(1001)] for __ in range(4)] for ___ in range(N+1)]
# dp = [[[False]  * 1009]*4]*30009
# dp = [[[False]*30009]*4]*1009
dp[0][0][0] = True

for ix in range(N):
    for jx in range(4):
        for kx in range(1000):
            # print("dp[{}][{}][{}] = {}".format(ix, jx, kx, dp[ix][jx][kx]))
            if dp[ix][jx][kx] == False:
                continue

            dp[ix+1][jx][kx] = True
            # print("ins::dp[{}][{}][{}] = True".format(ix+1, jx, kx))
            if jx <= 2:
                dp[ix+1][jx+1][kx*10+(int(S[ix]))] = True
                # print("ins::dp[{}][{}][{}] = True".format(ix+1, jx+1, kx*10+(int(S[ix]))))

ans = 0
for p in range(1000):
    if dp[N][3][p] == True:
        ans += 1
# print(dp)
print(ans)

Submission status: Time Limit Exceeded

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

dp = [[[False for _ in range(1001)] for __ in range(4)] for ___ in range(30001)]
# dp = [[[False]  * 1009]*4]*30009
# dp = [[[False]*30009]*4]*1009
dp[0][0][0] = True

for ix in range(N):
    for jx in range(4):
        for kx in range(1000):
            # print("dp[{}][{}][{}] = {}".format(ix, jx, kx, dp[ix][jx][kx]))
            if dp[ix][jx][kx] == False:
                continue

            dp[ix+1][jx][kx] = True
            # print("ins::dp[{}][{}][{}] = True".format(ix+1, jx, kx))
            if jx <= 2:
                dp[ix+1][jx+1][kx*10+(int(S[ix]))] = True
                # print("ins::dp[{}][{}][{}] = True".format(ix+1, jx+1, kx*10+(int(S[ix]))))

ans = 0
for p in range(1000):
    if dp[N][3][p] == True:
        ans += 1
# print(dp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
L = []
ans = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      cnt = 0
      iflag = 0
      jflag = 0
      while True:
        if cnt >= n:
          break
        if iflag == 0 and S[cnt] == str(i):
          iflag = 1
          cnt += 1
          continue
        if iflag == 1 and jflag == 0 and S[cnt] == str(j):
          jflag= 1
          cnt += 1
          continue
        if jflag == 1 and S[cnt] == str(k):
          ans += 1
          break
        cnt += 1

print(ans)

Submission status: Time Limit Exceeded

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

ok = list()
ans = 0

for i in range(n):
    if len(ok) == 10:
        break
    same = 0
    for j in range(len(ok)):
        if ok[j] == s[i]:
            same = 1
    if same == 1:
        continue
    ok.append(s[i])
    nd = list()
    for j in range(i+1,n):
        same = 0
        if len(nd) == 10:
            break
        for k in range(len(nd)):
            if nd[k] == s[j]:
                same = 1
        if same == 1:
            continue
        nd.append(s[j])
        rd = list()
        for k in range(j+1, n):
            if len(rd) == 10:
                break
            same = 0
            for l in range(len(rd)):
                if rd[l] == s[k]:
                    same = 1
            if same == 1:
                continue
            rd.append(s[k])
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

ok = list()
ans = 0

for i in range(n):
    same = 0
    for j in range(len(ok)):
        if ok[j] == s[i]:
            same = 1
    if same == 1:
        continue
    ok.append(s[i])
    nd = list()
    for j in range(i+1,n):
        same = 0
        for k in range(len(nd)):
            if nd[k] == s[j]:
                same = 1
        if same == 1:
            continue
        nd.append(s[j])
        rd = list()
        for k in range(j+1, n):
            same = 0
            for l in range(len(rd)):
                if rd[l] == s[k]:
                    same = 1
            if same == 1:
                continue
            rd.append(s[k])
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = [0] * 1000
for i in range(1000):
    pin = str(i).zfill(3)
    for j in range(n):
        if S[j] == pin[0]:
            p1 = j
            break
    else:
        continue
    for k in range(p1+1, n):
        if S[k] == pin[1]:
            p2 = k
            break
    else:
        continue
    for l in range(p2+1, n):
        if S[l] == pin[2]:
            break
    else:
        continue
    cnt[i] += 1
print(sum(c > 0 for c in cnt))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = [0] * 1000
for i in range(1000):
    key = str(i).zfill(3)
    for j in range(n):
        if S[j] == key[0]:
            for k in range(j+1, n):
                if S[k] == key[1]:
                    for l in range(k+1, n):
                        if S[l] == key[2]:
                            cnt[int(key)] += 1
                            break
                    else:
                        continue
                    break
            else:
                continue
            break
print(sum(c > 0 for c in cnt))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = input()
cnt = [0] * 1000
for i in range(1000):
    key = str(i).zfill(3)
    for j in range(n):
        if S[j] == key[0]:
            for k in range(j+1, n):
                if S[k] == key[1]:
                    for l in range(k+1, n):
                        if S[l] == key[2]:
                            cnt[int(key)] += 1
print(sum(c > 0 for c in cnt))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    k = 0
    for j in range(N):
        if s[j] == v[k]:
            k += 1
        if k == 3:
            res += 1
            break
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = input()

res = 0

search = [("00"+str(s))[-3:] for s in range(0,1000)]

for v in search:
    # ステップ1
    p1 = -1
    for j in range(N-2):
        if s[j] == v[0]:
            p1 = j
            break
    
    if p1 < 0: continue

    # ステップ2
    p2 = -1
    for j in range(p1+1,N-1):
        if s[j] == v[1]:
            p2 = j
            break
    
    if p2 < 0: continue

    # ステップ3
    p3 = -1
    for j in range(p2+1,N):
        if s[j] == v[2]:
            res += 1
            break
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = input()

res = 0

for i in range(1000):
    if 99 < i:
        v = str(i)
    elif 9 < i:
        v = '0'+str(i)
    else:
        v = '0'+'0'+str(i)
    
    # ステップ1
    p1 = -1
    for j in range(N-2):
        if s[j] == v[0]:
            p1 = j
            break
    
    if p1 < 0: continue

    # ステップ2
    p2 = -1
    for j in range(p1+1,N-1):
        if s[j] == v[1]:
            p2 = j
            break
    
    if p2 < 0: continue

    # ステップ3
    p3 = -1
    for j in range(p2+1,N):
        if s[j] == v[2]:
            res += 1
            break
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = list(input())

res = 0

for i in range(1000):
    if 99 < i:
        v = list(str(i))
    elif 9 < i:
        v = list('0'+str(i))
    else:
        v = list('0'+'0'+str(i))
    
    # ステップ1
    p1 = -1
    for j in range(N):
        if s[j] == v[0]:
            p1 = j
            break
    
    if p1 < 0: continue

    # ステップ2
    p2 = -1
    for j in range(p1+1,N):
        if s[j] == v[1]:
            p2 = j
            break
    
    if p2 < 0: continue

    # ステップ3
    p3 = -1
    for j in range(p2+1,N):
        if s[j] == v[2]:
            res += 1
            break
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [str(i) for i in input()]

search = [("00"+str(s))[-3:] for s in range(0,1000)]
ans = []
for num in search:
    i = 0
    for s in S:
        if num[i] == s:
            i += 1
        if i == 3:
            ans.append(num)
            break
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    S = input()

    return N, S


def main(N: int, S: str) -> None:
    """
    メイン処理

    Args:\n
        N (int): 桁数
        S (str): ラッキーナンバー
    """
    # 求解処理
    ans = 0
    for n in range(1000):
        V = str(n).zfill(3)
        f = 0
        for j in range(N):
            if S[j] == V[f]:
                f += 1
            if f == 3:
                break
        ans += (f == 3)

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, S = get_input()

    # メイン処理
    main(N, S)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 標準入力を取得
N = int(input())
S = input()

# 求解処理
ans = 0
for n in range(1000):
    V = str(n).zfill(3)
    f = 0
    for j in range(N):
        if S[j] == V[f]:
            f += 1
        if f == 3:
            break
    ans += (f == 3)

# 結果出力
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

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

    ans = []
    for i in range(2**N, 2**(N+1)):
        if bin(i)[3:].count('1') == N - 3:
            t = ''
            for s, b in zip(S, bin(i)[3:]):
                if b != '1':
                    t += s
            ans.append(t)
        
    print(len(set(ans)))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

s=list(map(int,list(s)))

password=[str(i).zfill(3) for i in range(1000)]

cnt=0
can=[]
for word in password:
    w1=int(word[0])
    w2=int(word[1])
    w3=int(word[2])

    i=0
    while i<n-2:
        if s[i]==w1:
            i_1=i
            break
        else:
            i+=1

        if i==n-3 and s[i]!=w1:
            i_1=-1
            break
    
    if i_1==-1:
        continue

    j=i+1
    while j<n-1:
        if s[j]==w2:
            i_2=j
            break
        else:
            j+=1

        if j==n-2 and s[j]!=w2:
            i_2=-1
            break
    
    if i_2==-1:
        continue

    k=j+1
    while k<n:
        if s[k]==w3:
            i_3=k
            break
        else:
            k+=1
        
        if k>=n-1 and s[n-1]!=w3:
            i_3=-1
            break

    if i_3==-1:
        continue
    elif i_1<i_2 and i_2<i_3:
        cnt+=1
        can.append(word)


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

N = int(input())
S = input()
PW = []

for i in range(N-2):
    A = S[i]
    for j in range(i+1, N-1):
        B = S[j]
        for k in range(j+1, N):
            C = S[k]
            T = A + B + C
            if T in PW:
                continue
            else:
                PW.append(T)


ans = len(PW)

print(ans)

Submission status: Time Limit Exceeded

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

ans=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            tmp=str(s[i])+str(s[j])+str(s[k])

            if tmp not in ans:
                ans.append(tmp)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

def solve():
    n=int(input())
    s=input()
    setlist = set(list(itertools.combinations(s,3)))
    print(len(setlist))

if __name__=='__main__':
    solve()
#https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

Submission status: Time Limit Exceeded

Solution code:
import itertools

def solve():
    n=int(input())
    s=input()
    setlist = set(list(itertools.combinations(s,3)))
    print(len(setlist))

if __name__=='__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import itertools

def solve():
    n=int(input())
    s=input()
    setlist = set()
    for p in itertools.combinations(s,3):
        setlist.add(p)
    print(len(setlist))

if __name__=='__main__':
    solve()

Submission status: Time Limit Exceeded

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

result = 0
num_list = []
for i in range(1 << N): # 2**n 通り
    num = ''
    for j in range(N):
        if (i >> j) & 1 == 1: # 選んだ数を足していく（部分和を計算）
            num = num + S[j]
    if len(num) == 3: # 和が k と同じになった部分和を数える
        if num not in num_list:
            result += 1
            num_list.append(num)
print(result)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re

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

check_list = []

for i in range(0,10):
  for j in range(0,10):
    for k in range(0,10):
      check_list.append(str(i)+'.*'+str(j)+'.*'+str(k))
  
counter = 0  
for c in check_list:
  if re.findall(c, s):
    counter += 1
      
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=0
a=[]
b=[]
c=[]
for i in range(n):
  d=s[i]
  if d in b:continue
  else:b.append(d)
  for j in range(i+1,n):
    e=s[i]+s[j]
    if e in c:continue
    else:c.append(e)
    for k in range(j+1,n):
      f=s[i]+s[j]+s[k]
      if f not in a:
        a.append(f)
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=0
a=[]
b=[]
c=[]
for i in range(n):
  d=s[i]
  if d in b:continue
  else:b.append(d)
  for j in range(i+1,n):
    d=s[i]+s[j]
    if d in c:continue
    else:c.append(d)
    for k in range(j+1,n):
      e=s[i]+s[j]+s[k]
      if e not in a:
        a.append(e)
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
cnt=0
a=[]
b=[]
for i in range(n):
  for j in range(i+1,n):
    d=s[i]+s[j]
    if d in b:continue
    else:b.append(d)
    for k in range(j+1,n):
      c=s[i]+s[j]+s[k]
      if c not in a:
        a.append(c)
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

a=[]
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      c=s[i]+s[j]+s[k]
      if c not in a:
        a.append(c)
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(input())
flag=1
count=0
for i in range(1000):
  numS=''
  flag=1
  if i<10:
    numS='00'+str(i)
  elif i<100:
    numS='0'+str(i)
  else:
    numS=str(i)
  for j in range(N):
    if numS[0]==S[j]:
      for k in range(j+1,N):
        if numS[1]==S[k]:
          if numS[2] in S[k+1:]:
            count+=1
            flag=0
            break
          else:
            flag=0
            break
        elif k==N-1 and flag==1:
          flag=0
    if flag==0:
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(input())
flag=1
count=0
for i in range(1000):
  numS=''
  flag=1
  if i<10:
    numS='00'+str(i)
  elif i<100:
    numS='0'+str(i)
  else:
    numS=str(i)
  for j in range(N):
    if numS[0]==S[j]:
      for k in range(j+1,N):
        if numS[1]==S[k]:
          if numS[2] in S[k+1:]:
            count+=1
            flag=0
            break
          else:
            flag=0
            break
        elif k==N and flag==1:
          flag=0
    if flag==0:
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(input())
flag=1
count=0
for i in range(1000):
  numS=''
  flag=1
  if i<10:
    numS='00'+str(i)
  elif i<100:
    numS='0'+str(i)
  else:
    numS=str(i)
  for j in range(N):
    if numS[0]==S[j]:
      for k in range(j+1,N):
        if numS[1]==S[k]:
          if numS[2] in S[k+1:N]:
            count+=1
            flag=0
            break
        elif k==N and flag==1:
          flag=0
    if flag==0:
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(input())
flag=1
count=0
for i in range(1000):
  numS=''
  flag=1
  if i<10:
    numS='00'+str(i)
  elif i<100:
    numS='0'+str(i)
  else:
    numS=str(i)
  for j in range(N):
    if numS[0]==S[j]:
      for k in range(j+1,N):
        if numS[1]==S[k]:
          if numS[2] in S[k+1:N]:
            count+=1
            flag=0
            break
    if flag==0:
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [int(i) for i in input()]

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      Flag1 = True
      Flag2 = False
      Flag3 = False
      for x in S:
        if Flag3:
          if x == k:
            ans += 1
            break
        if Flag2:
          if x == j:
            Flag2 = False
            Flag3 = True
        if Flag1:
          if x == i:
            Flag1 = False
            Flag2 = True

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      Flag1 = True
      Flag2 = False
      Flag3 = False
      for x in S:
        if Flag3:
          if x == str(k):
            ans += 1
            break
        if Flag2:
          if x == str(j):
            Flag2 = False
            Flag3 = True
        if Flag1:
          if x == str(i):
            Flag1 = False
            Flag2 = True

print(ans)

Submission status: Time Limit Exceeded

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

rS = reversed(S)
cS = [0]
c1 = set()

for i, x in enumerate(rS):
  if x in c1:
    cS.append(cS[i])
  else:
    c1.add(x)
    cS.append(cS[i] + 1)

cS.reverse()

ans = 0
c2 = set()

for i in range(N-2):
  for j in range(i+1, N-1):
    x = S[i] + S[j]
    if x in c2:
      continue
    else:
      c2.add(x)
      ans += cS[j+1]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(0,1000):
  if i >= 100:
    i = str(i)
  elif i >= 10:
    i = "0" + str(i)
  else:
    i = "00" + str(i)
  checker = 0
  for j in range(N):
    if S[j] == i[checker]:
      checker += 1
    if checker == 3:
      cnt += 1
      break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(0,1000):
  if i >= 100:
    i = str(i)
  elif i >= 10:
    i = "0" + str(i)
  else:
    i = "00" + str(i)
  checker = 0
  for j in range(N):
    if S[j] == i[checker]:
      checker += 1
      if checker == 3:
        cnt += 1
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
S = input()

res = set()
for pair in combinations(range(N), 3):
  res.add("".join([S[i] for i in pair]))

print(len(res))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
res=0
for i in range(1000):
    digits=str(i)
    if i<100:
        digits='0'*(3-len(str(i)))+digits
        #print(digits)
    cnt = 0
    for j in s:
        if j==digits[cnt]:
            #print(digits)
            cnt+=1
        if cnt>=3:
            res+=1
            break
print(res)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

def solve(s):
    s = str(s)
    c = 0
    for i in range(1000):
        v = [i//100, i//10%10, i%10]
        f = 0
        for j in range(len(s)):
            if int(s[j]) == v[f]:
                f += 1
            if f == 3:
                break
        if f == 3:
            c += 1
    return c

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

def solve(s):
    s = str(s)
    a = list(range(10**3))
    c = [0]*1000
    for i in range(len(s)-2):
        for j in range(i+1,len(s)-1):
            for k in range(j+1,len(s)):
                d = int(s[i] + s[j] + s[k])
                if d in a:
                    c[d] = 1
    return sum(c)

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

print(len(set([a+b+c for a,b,c in combinations(s, 3)])))

Submission status: Time Limit Exceeded

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

ans=0
for i in range(1000):
    reg = '{}.*{}.*{}'.format(i//100, i%100//10, i%10)
    if re.search(reg, s):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for pin in range(0,1000):
  counter = 0
  for index in range(0, N):
    if str(pin).zfill(3)[counter] == S[index]:
      counter += 1
    if counter == 3:
      ans += 1
      break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

for pin in range(0,1000):
  counter = 0
  for s in S:
    if str(pin).zfill(3)[counter] == s:
      counter += 1
    if counter == 3:
      ans += 1
      break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
for i in range(0,1000):
  if i >= 100:
    t = str(i)
  elif i >= 10:
    t = "0"+str(i)
  else:
    t = "00"+str(i)
  ti = 0
  for j in range(N):
    if S[j] == t[ti]:
      ti += 1
      if ti == 3:
        count += 1
        break
print(count)

Submission status: Time Limit Exceeded

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

ans_list = []
for i in range(len(S)-2):
    for j in range(i+1, len(S)-1):
        for k in range(j+1, len(S)):
            ans_list.append(S[i]+S[j]+S[k])
            
print(len(set(ans_list)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
count = 0
for i in range(0,1000):
  if i <= 9:
    j = "00"+str(i)
  elif i <= 99:
    j = "0"+str(i)
  else:
    j = str(i)
  check = False
  for k in range(N-2):
    if S[k] == j[0]:
      for n in range(k+1,N-1):
        if S[n] == j[1]:
          for m in range(n+1,N):
            if S[m] == j[2]:
              count += 1
              check = True
              break
          if check:
            break
      if check:
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
pins = []
for i in range(0,N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      pin = S[i]+S[j]+S[k]
      if pins.count(pin) == 0:
        pins.append(pin)
print(len(pins))

Submission status: Time Limit Exceeded

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

used_i = [False] * 10
ans = []
for i in range(n - 2):
    if not used_i[s[i]]:
        used_j = [False] * 10
        for j in range(i + 1, n - 1):
            if not used_j[s[j]]:
                for k in set(s[j + 1 : n]):
                    pin = f"{s[i]}{s[j]}{k}"
                    if pin not in ans:
                        ans.append(pin)
print(len(ans))

Submission status: Time Limit Exceeded

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

used = [False] * 10
pins = []

for i in range(n - 2):
    if not used[s[i]]:
        used[s[i]] = True
        for j in range(i + 1, n - 1):
            for k in range(j + 1, n):
                pin = f"{s[i]}{s[j]}{s[k]}"
                if pin not in pins:
                    pins.append(pin)
print(len(pins))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
sm=0
for x in [(x,y,z) for x in range(10) for y in range(10) for z in range(10)]:
    token=0
    for i in range(n):
        if x[token]==int(s[i]):
            token+=1
            if token==3 : break
    if token==3 : sm+=1
print(sm)