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:
def resolve():
    n=int(input())
    s=list(input())
    l=[]
    ans=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            x=s[i]+s[j]
            if x in l:
                continue
            else:
                l.append(x)
                ans+=len(set(s[j+1:]))
    print(ans)


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = input()
    x = set()

    table = [[0 for _ in range(10)] for _ in range(10)]

    for i in range(n)[:-2]:
        for j in range(n)[i + 1:-1]:
            s_i, s_j = int(s[i]), int(s[j])
            if table[s_i][s_j] == 10:
                continue
            for k in range(n)[j + 1:]:
                item = s[i] + s[j] + s[k]
                if item not in x:
                    x.add(item)
                    table[s_i][s_j] += 1

    print(len(x))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = input()
    x = set()

    for i in range(n)[:-2]:
        for j in range(n)[i + 1:-1]:
            for k in range(n)[j + 1:]:
                item = s[i] + s[j] + s[k]
                if item not in x:
                    x.add(item)

    print(len(x))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = input()
    x = set()

    for i in range(n)[:-2]:
        for j in range(n)[i + 1:]:
            for k in range(n)[j + 1:]:
                item = s[i] + s[j] + s[k]
                if item not in x:
                    x.add(item)

    print(len(x))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = input()
    ls = []

    for i in range(n)[:-2]:
        for j in range(n)[i + 1:]:
            for k in range(n)[j + 1:]:
                ls.append(s[i] + s[j] + s[k])

    print(len(set(ls)))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# 6
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN

import itertools
from collections import deque

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

ans = 0
iter = itertools.product("0123456789", repeat=3)

for it in iter:
    _s_dq = deque(s)
    for i in it:
        while len(_s_dq) > 0:
            _s = _s_dq.popleft()
            if _s == i:
                break
        else:
            break
    else:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

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

# 100の位
for i in range(10):
    # Sのn-2番目までにiがあるか
    now_i = -1
    for a in range(n-2):
        if s[a] == str(i):
            now_i = a
            break
    # 作れない場合以降の探索は打ち切り
    if now_i == -1:
        continue
    # 10の位
    for j in range(10):
        now_j = -1
        for b in range(now_i+1,n-1):
            if s[b] == str(j):
                now_j = b
                break
        if now_j == -1:
            continue
        # 1の位
        for k in range(10):
            for c in range(now_j+1,n):
                # 暗証番号がそろった
                if s[c] == str(k):
                    point += 1
                    break

print(point)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

n = int(input())
s = input()
point = 0

# 100の位
for i in range(10):
    # Sのn-2番目までにiがあるか
    now_i = -1
    for a in range(n-2):
        if s[a] == str(i):
            now_i = a
            break
    # 作れない場合以降の探索は打ち切り
    if now_i == -1:
        continue
    # 10の位
    for j in range(10):
        now_j = -1
        for b in range(now_i+1,n-1):
            if s[b] == str(j):
                now_j = b
                break
        if now_j == -1:
            continue
        # 1の位
        for k in range(10):
            for c in range(now_j+1,n):
                # 暗証番号がそろった
                if s[c] == str(k):
                    point += 1
                    break

print(point)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

n = int(input())
s = input()
point = 0

# 暗証番号を全探索する
@lru_cache(maxsize=None)
def count(i):
    t = str(i).zfill(3)
    now = 0
    # sで暗証番号が作れるかを検証
    for j in s:
        if j == t[now]:
            now += 1
        if now == 3:
            break
    if now == 3:
        return 1
    else:
        return 0

for i in range(1000):
    point += count(i)

print(point)

Submission status: Time Limit Exceeded

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

# ラッキーナンバーを全探索する
for i in range(1000):
    t = str(i).zfill(3)
    now = 0
    # sでラッキーナンバーが作れるかを検証
    for j in s:
        if j == t[now]:
            now += 1
        if now == 3:
            point += 1
            break

print(point)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    t = key[k]
    for j in range(len(s)):
        if t == s[j]:
            k += 1
            if k == 3:
                ans += 1
                break
            t = key[k]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    for j in range(len(s)):
        if key[k] == s[j]:
            k += 1
            if k == 3:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    for j in range(len(s)):
        if key[k] == s[j]:
            k += 1
        if k == 3:
            ans += 1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
divide = 0
count = 0
for i in range(1000):
    num = str(i)
    while(len(num)<3):
        num = "0"+num
    flag = [0,0,0]
    for j in range(3):
        for k in range(divide,N):
            if num[j] == S[k]:
                flag[j] = 1
                divide = k+1
                break
    divide = 0      
    if(flag == [1,1,1]):
        count +=1
print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for p in range(1000):
  s = '{:03}'.format(p)
  i = 0
  for j in range(N):
    if i < 3 and S[j] == s[i]:
      i += 1
  if i == 3:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
M = {}
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            M[S[i]+S[j]+S[k]] = 1
print(len(M))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
re_list=[]
ele = list(map(str, S))
for i in range(1,len(ele)+1):
    for j in range(i+1,len(ele)+1):
        for k in range(j+1,len(ele)+1):
            re_str=ele[i-1]+ele[j-1]+ele[k-1]
            re_list.append(re_str)
re_list=list(set(re_list))
print(len(re_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
k=list(input())

kk=0
for i in range(1000):
  if i<10:
    p=['0','0',str(i)]
  elif i<100:
    p=['0',str(i)[0],str(i)[1]]
  else:
    p=list(str(i))
    
    
  flag=False
  for x in range(n-2):
    if flag==True:break
    if k[x]!=p[0]:continue
    else:
      for y in range(x+1,n-1):
        if flag==True:break
        if k[y]!=p[1]:continue
        else:
          for z in range(y+1,n):
            if k[z]!=p[2]:continue
            else:
              flag=True
              break
  
  if flag==True:
    #print(i)
    kk+=1
  else:pass
print(kk)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cou = 0
for i in range(1000):
  i = "{0:03d}".format(i)
  a,b,c = i[0],i[1],i[2]
  bit = 0
  for j in range(n):
    if bit==1:
      break
    if s[j]==a:
      for k in range(j+1,n):
        if bit==1:
          break
        if s[k]==b:
          for m in range(k+1,n):
            if s[m]==c:
              cou += 1
              bit = 1
              break
              
print(cou)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N = int(input())
    S = input()
    q = []
    ans = 0
    for i in range(2, N):
        for j in range(1, i):
            for p in range(j):
                if S[i]+S[j]+S[p] in q:
                    continue
                else:
                    q.append(S[i]+S[j]+S[p])
                    ans += 1
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1000):
    T = str(i).zfill(3)
    j = 0
    for c in S:
        if c == T[j]:
            j += 1
            if j > 2:
                ans += 1
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(input())
import itertools
l=[]
for v in itertools.combinations(s, 3):
  l.append(v)
print(len(set(l)))

Submission status: Time Limit Exceeded

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

ans_list = []

for i in range(0,N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            S_ans = S[i] + S[j] +S[k]
            ans_list.append(S_ans)

set_ans = set(ans_list)
print(len(set_ans))

Submission status: Time Limit Exceeded

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

num1, num2, num3 = set([]), set([]), set([])
for i in range(n):
    if s[i] in num1:
        continue
    num1.add(s[i])
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            num3.add(s[i] + s[j] + s[k])
print(len(num3))

Submission status: Time Limit Exceeded

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

cnt = 0
for i in range(1000):
    p = str(i).zfill(3)
    f1,f2,f3 = 0,0,0
    for j in range(n):
        if not f1:
            if p[0] == s[j]:
                f1 = 1
        elif not f2:
            if p[1] == s[j]:
                f2 = 1
        elif not f3:
            if p[2] == s[j]:
                f3 = 1
        else:
            break

    if f1 and f2 and f3:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

ans = set()
for v in itertools.combinations(range(N), 3):
    tmp = S[v[0]] + S[v[1]] + S[v[2]]
    ans.add(tmp)
print(len(ans))

Submission status: Time Limit Exceeded

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

list = []

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

print(len(set(list)))

Submission status: Time Limit Exceeded

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

def check(num,s):
    curr = 0
    num += "_"
    for k in range(len(s)):
        if num[curr] == s[k]:
            curr += 1
    if curr == 3:
        return True
    else:
        return False

def main():
    N = int(input())
    S = input()
    ans = 0
    for k in range(1000):
        t = str(k).zfill(3)
        if check(t,S) == True:
            ans += 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input()
s1=[0]*10
s2=[0]*100
s3=[0]*1000
for i1 in range(len(S)-2):
    for i2 in range(i1+1,len(S)-1):
        for i3 in range(i2+1,len(S)):
            h1=int(S[i1])
            if s1[h1]==100:
                continue
            h2=h1*10+int(S[i2])
            if s2[h2]==10:
                continue
            h3=h2*10+int(S[i3])
            if s3[h3]==0:
                s3[h3]=1
                s2[h2]+=1
                s1[h1]+=1
print(sum(s3))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

for i in range(1000):
    s = str(i).zfill(3)
    for i in range(N):
        if S[i]==s[0]:
            p = i
            break
    else:
        continue
    for i in range(p+1, N):
        if S[i]==s[1]:
            p = i
            break
    else:
        continue

    for i in range(p+1, N):
        if S[i]==s[2]:
            p = i
            break
    else:
        continue
    
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
S = list(input())
a = set()
for data in combinations(S, 3):
    a.add(''.join(data))
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cou = 0
for i in range(1000):
  bit =0
  i = "{0:03d}".format(i)
  a,b,c = i[0],i[1],i[2]
  for j in range(n):
    if bit==1:
              break
    if s[j]==a and bit==0:
      for k in range(j+1,n):
        if bit==1:
              break
        if s[k]==b :
          for m in range(k+1,n):
            if bit==1:
              break
            if s[m]==c :
              cou += 1
              bit = 1 
print(cou)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cou = 0
for i in range(1000):
  bit =0
  i = "{0:03d}".format(i)
  a,b,c = i[0],i[1],i[2]
  for j in range(n):
    if s[j]==a and bit==0:
      for k in range(j+1,n):
        if s[k]==b and bit==0:
          for m in range(k+1,n):
            if s[m]==c and bit==0:
              cou += 1
              bit = 1 
print(cou)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(input())
ans=0
i=0
while i<1000:
  temp=i//100
  #temp.append(i//100)
  #temp.append((i-(i//100)*100)//10)
  #temp.append(i%10)
  cnt=0
  k=0
  for j in range(0,n):
    if temp==int(s[j]):
      cnt=cnt+1
      k=j
      break
  if cnt==0:
    i=i+100
  else:
    temp=(i-(i//100)*100)//10
    for j in range(k+1,n):      
      if temp==int(s[j]):
        cnt=cnt+1
        k=j
        break
    if cnt==1:
      i=i+10
    else:
      temp=i%10
      i=i+1
      for j in range(k+1,n):
        if temp==int(s[j]):
          ans=ans+1
          break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(input())
ans=0
for i in range(0,1000):
  temp=[]
  temp.append(i//100)
  temp.append((i-(i//100)*100)//10)
  temp.append(i%10)
  cnt=0
  k=0
  for j in range(0,n):
    if temp[0]==int(s[j]):
      cnt=cnt+1
      k=j
      break
  if cnt==1:
    for j in range(k+1,n):      
      if temp[1]==int(s[j]):
        cnt=cnt+1
        k=j
        break
  if cnt==2:
    for j in range(k+1,n):
      if temp[2]==int(s[j]):
        ans=ans+1
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(input())
ans=0
for i in range(0,1000):
  temp=[]
  temp.append(i//100)
  temp.append((i-(i//100)*100)//10)
  temp.append(i%10)
  cnt=0
  k=0
  for j in range(0,n):
    if cnt==0 and temp[0]==int(s[j]):
      cnt=cnt+1
      k=j
      break
  if cnt==1:
    for j in range(k+1,n):      
      if temp[1]==int(s[j]):
        cnt=cnt+1
        k=j
        break
  if cnt==2:
    for j in range(k+1,n):
      if temp[2]==int(s[j]):
        ans=ans+1
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(input())
ans=0
for i in range(0,1000):
  temp=[]
  temp.append(i//100)
  temp.append((i-(i//100)*100)//10)
  temp.append(i%10)
  cnt=0
  k=0
  for j in range(0,n):
    if cnt==0 and temp[0]==int(s[j]):
      cnt=cnt+1
      k=j
      break
  for j in range(k+1,n):      
    if cnt==1 and temp[1]==int(s[j]):
      cnt=cnt+1
      k=j
      break
  for j in range(k+1,n):
    if cnt==2 and temp[2]==int(s[j]):
      ans=ans+1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=str(input())
ans=0
for i in range(0,1000):
  temp=[]
  temp.append(i//100)
  temp.append((i-(i//100)*100)//10)
  temp.append(i%10)
  cnt=0
  k=0
  for j in range(0,n):
    if cnt==0 and temp[0]==int(s[j]):
      cnt=cnt+1
      k=j
      break
  for j in range(k+1,n):      
    if cnt==1 and temp[1]==int(s[j]):
      cnt=cnt+1
      k=j
  for j in range(k+1,n):
    if cnt==2 and temp[2]==int(s[j]):
      ans=ans+1
      break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import re

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

count = 0

for x in range(10):
    for y in range(10):
        for z in range(10):
            my_regex = "(\d)*"+str(x)+"(\d)*"+str(y)+"(\d)*"+str(z)
            p = re.compile(my_regex)
            if p.search(S):
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            ok1 = False
            ok2 = False
            ok3 = False
            for s in range(0, N):
                l = int(S[s])
                if k==l and ok2:
                    ok3 = True
                elif j==l and ok1:
                    ok2 = True
                elif i==l:
                    ok1 = True
                if ok1 and ok2 and ok3:
                    ans+=1
                    break
print(ans)

Submission status: Time Limit Exceeded

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

l = [30010] * 11
r = [-1] * 11
for i in range(n):
    c = int(s[i])
    r[c] = max(r[c], i)
    l[c] = min(l[c], i)
st = set([])
for i in range(n):
    c = int(s[i])
    for j in range(10):
        for k in range(10):
            if l[j] < i < r[k]:
                number = chr(j) + s[i] + chr(k)
                st.add(number)
print(len(st))

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):
            cnt = 0
            for s in range(N):
                if i == int(S[s]) and cnt == 0:
                    cnt += 1
                elif j == int(S[s]) and cnt == 1:
                    cnt += 1
                elif k == int(S[s]) and cnt == 2:
                    ans += 1
                    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
d = {}
n = int(input())
s = input()
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      d[s[i] + s[j] + s[k]] = True

print(len(d.keys()))

Submission status: Time Limit Exceeded

Solution code:
d = {}
for i in range(1000):
  d['{:0>3}'.format(i)] = False

n = int(input())
s = input()
for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      d[s[i] + s[j] + s[k]] = True

c = 0
for i in d.values():
  if i == True:
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
cou = []
for i in range(1000):
  i = "{0:03d}".format(i)
  a,b,c = i[0],i[1],i[2]
  for j in range(n):
    if s[j]==a:
      for k in range(j+1,n):
        if s[k]==b:
          for m in range(k+1,n):
            if s[m]==c:
              cou.append(i)
print(len(set(cou)))

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N=int(input())
S=input()
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0

for com in u:
  x_flag=False
  y_flag=False
  x=com[0]
  y=com[1]
  z=com[2]
    
  for i in range(N):
    if S[i]==x:
      x_flag=True
      break
  if x_flag:
    for j in range(i+1,N):
      if S[j]==y:
        y_flag=True
        break
  if y_flag:
    for k in range(j+1,N):
      if S[k]==z:
        ans+=1
        break
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N=int(input())
S=input()
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  x_search=True
  y_search=True
  flag=False
  x=com[0]
  y=com[1]
  z=com[2]
    
  for i in range(N):
    if x_search and S[i]==x:
      x_search=False
      for j in range(i+1,N):
        if y_search and S[j]==y:
          y_search=False
          for k in range(j+1,N):
            if S[k]==z:
              flag=True
              break
  if flag:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N=int(input())
S=input()
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  flag=False
  x=com[0]
  y=com[1]
  z=com[2]
  for i in range(N):
    if S[i]==x:
      for j in range(i+1,N):
        if S[j]==y:
          tmp=S[j+1:]
          if z in tmp:
            flag=True
            break
      else:
        break
  if flag:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N=int(input())
S=input()
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  flag=False
  x=com[0]
  y=com[1]
  z=com[2]
  for i in range(N):
    if S[i]==x:
      for j in range(i+1,N):
        if S[j]==y:
          tmp=S[j+1:]
          if z in tmp:
            flag=True
            break
  if flag:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N=int(input())
S=input()
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  flag=False
  x=com[0]
  y=com[1]
  z=com[2]
  for i in range(N):
    if S[i]==x:
      for j in range(i+1,N):
        if S[j]==y:
          for k in range(j+1,N):
            if S[k]==z:
              flag=True
  if flag:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n-2):
	for j in range(i+1,n-1):
		for k in range(j+1,n):
			pass_set.add(s[i]+s[j]+s[k])

print(len(pass_set))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#三井住友2019 D
def main():
    import sys
    import itertools as ite
    N = int(sys.stdin.readline())
    S = sys.stdin.readline().rstrip()
    L = ite.product([0,1,2,3,4,5,6,7,8,9], repeat=3)
    cnt=0
    for pw in L:
        #print(pw)
        num=0
        for i in range(N):
            if int(S[i])==pw[num]:
                num +=1
            if num==3:
                cnt +=1
                #print(pw)
                break
    print(cnt)


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ln = input()
sec_set = set()
first_set = set()

for first in range(n):
    if ln[first] in first_set:
        continue
    first_set.add(ln[first])
    for second in range(first+1,n):
        for third in range(second+1,n):
            sec_set.add(ln[first]+ln[second]+ln[third])

print(len(sec_set))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ln = input()
sec_set = set()

for first in range(n):
    for second in range(first+1,n):
        for third in range(second+1,n):
            sec_set.add(ln[first]+ln[second]+ln[third])

print(len(sec_set))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
S = input()
used_ls = [0] * 1000
def dfs(s):
    if len(s) == 3:
        target = ''
        for i in s:
            ind = int(i)
            target += S[ind]
        used_ls[int(target)] = 1
    if len(s) > 0:
        last = int(s[-1])
    else:
        last = -1
    for nex in range(last+1,n):
        s += str(nex)
        dfs(s)
        s = s[:-1]
dfs('')
print(sum(used_ls))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  s = input()
  memo = []
  for i in range(10):
    for j in range(10):
      for k in range(10):
        memo.append(str(i) + str(j) + str(k))
  ans = 0
  for i in memo:
    x = 0
    for j in range(n):
      if i[x] == s[j]:
        x += 1
        if x == 3:
          ans += 1
          break

  print(ans)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
memo = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      memo.append(str(i) + str(j) + str(k))
ans = 0
for i in memo:
  x = 0
  for j in range(len(s)):
    if i[x] == s[j]:
      x += 1
      if x == 3:
        ans += 1
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
memo = []
for i in range(10):
  for j in range(10):
    for k in range(10):
      memo.append(str(i) + str(j) + str(k))
ans = 0
for i in memo:
  x = 0
  for j in range(len(s)):
    if i[x] == s[j]:
      x += 1
    if x == 3:
      ans += 1
      break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(sys.stdin.readline().rstrip("\n"))
s = sys.stdin.readline().rstrip("\n")
pass_set = set([])
count = 0
while True:
    for j in range(1, n-count):
        for k in range(j+1, n-count):
            pass_set.add(s[0] + s[j] + s[k])
    if s == s[-3:]:
      break
    s = s[1:]
    count += 1
    
print(len(pass_set))

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(sys.stdin.readline().rstrip("\n"))
s = sys.stdin.readline().rstrip("\n")
pass_set = set([])

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            pass_set.add(s[i] + s[j] + s[k])
print(len(pass_set))

Submission status: Time Limit Exceeded

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

ans = []
for x in range(len(s)-2):
  for y in range(x+1, len(s)-1):
    Z = list(set(s[y+1:]))
    for z in Z:
      ans.append(s[x]+s[y]+z)
print(len(list(set(ans))))

Submission status: Time Limit Exceeded

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

ans = []
for x in range(len(s)-2):
  for y in range(x+1, len(s)-1):
    for z in range(y+1, len(s)):
      ans.append(s[x]+s[y]+s[z])
print(len(list(set(ans))))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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])
print(len(set(L)))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
word="0123456789"
number=["".join(i) for i in itertools.product(word,repeat=3)]

S=list(input())
ans=0
for i in number:
    count=0

    for s in range(N):
        if i[count]==S[s]:
            count+=1
            if count==2:
                if i[2] in S[s+1:]:
                    ans+=1
                break


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
word="0123456789"
number=["".join(i) for i in itertools.product(word,repeat=3)]

S=list(input())
ans=0
for i in number:
    count=0

    for s in range(N):
        if i[count]==S[s]:
            count+=1
            if count==3:
                ans+=1
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
word=set()
number=[]
S=list(map(int,input()))
for i in range(10):
    for j in range(10):
        for k in range(10):
           number.append([str(i)+str(j)+str(k)])
ans=0
for i in number:
    count=0
    for s in range(N):
        if int(i[0][count])==S[s]:
            count+=1
            if count==3:
                ans+=1
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
word=set()
number=[]
S=list(map(int,input()))
for i in range(10):
    for j in range(10):
        for k in range(10):
           number.append([str(i)+str(j)+str(k)])
ans=0
for i in number:
    i,j,k=int(i[0][0]),int(i[0][1]),int(i[0][2])
    p1,p2,p3=-1,-1,-1
    for s in range(N):
        if S[s]==i and p1==-1:
            p1=s
        elif S[s]==j and p2<p1:
            p2=s
        elif S[s]==k and p3<p2:
            p3=s
            break
    if p1!=-1 and p2!=-1 and p3!=-1:
        if p1<p2<p3:
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
word=set()
number=[]
S=list(map(int,input()))
for i in range(10):
    for j in range(10):
        for k in range(10):
           number.append([str(i)+str(j)+str(k)])
ans=0
for i in number:
    i,j,k=i[0][0],i[0][1],i[0][2]
    p1,p2,p3=-1,-1,-1
    for s in range(N):
        if S[s]==int(i) and p1==-1:
            p1=s
        elif S[s]==int(j) and p2<p1:
            p2=s
        elif S[s]==int(k) and p3<p2:
            p3=s
    if p1!=-1 and p2!=-1 and p3!=-1:
        if p1<p2<p3:
            # print(i, j, k)
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ss = input()
li1 = []
li2 = []
ans = 0
for i in range(n-2):
    f = ss[i]
    for j in range(i+1,n-1):
        s = ss[j]
        if f+s in li1:
            continue
        li1.append(f+s)
        li2 = []
        for k in range(j+1,n):
            if len(li2) == 10:
                break
            t = ss[k]
            if t in li2:
                continue
            ans += 1
            li2.append(t)
print(ans)