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: Wrong Answer

Solution code:
import numpy as np

N = int(input())
S = input()
d = {}
for i in range(N):
  c = S[i]
  if c not in d.keys():
    d[c] = [i]
  else:
    if len(d[c])>=3:
      continue
    else:
      d[c].append(i)
#print(d)

ans=0
for i in range(1000):
  code = str(i)
  while len(code)<3:
    code = "0" + code
  #print(len(code))
    #continue
  if code[0] not in d.keys() or code[1] not in d.keys() or code[2] not in d.keys():
    continue
  first = np.array(d[code[0]])
  current = d[code[0]][0]
  
  second = np.array(d[code[1]])
  if len(second[second>current])==0:
    continue
  current = second[second>current].min()
  
  third = np.array(d[code[2]])
  if len(third[third>current])==0:
    continue
  ans+=1
  
print(ans)
#print(d)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
s = input()
tmp = []
for si in s:
    if len(tmp) == 0:
        tmp.append(si)
    elif len(tmp)>0 and tmp[-1] != si:
        tmp.append(si)
new_s = ''.join(tmp)
m = len(new_s)
se = set()
for i in range(0,m-2):
    for j in range(i+1,m-1):
        for k in range(j+1,m):
            se.add(new_s[i]+new_s[j]+new_s[k])
print(len(se))

Submission status: Wrong Answer

Solution code:
import bisect
import numpy as np
N = int(input())
S = input()

dic_ = {}

for i in range(N):
    dic_[S[i]] = dic_.get(S[i], []) + [i]

ans = [False]*1000
dp = -1*np.ones((10, 300001), np.int8)
#print(dp)

def get_first_pos(i, k):
    if dp[i, k] != -1:
        return dp[i, k]
    if dic_.get(str(i)) is not None:
        ind = bisect.bisect_right(dic_[str(i)], k)
        if ind != len(dic_[str(i)]):
            dp[i,k] = dic_[str(i)][ind]
            return dic_[str(i)][ind]
    return None


for i in range(10):
    x1 = get_first_pos(i, -1)
    if x1 is None:
        continue
    for j in range(10):
        x2 = get_first_pos(j, x1)
        if x2 is None:       
            continue
        for k in range(10):
            x3 = get_first_pos(k, x2)
            if x3 is None:       
                continue
            ans[int(str(i)+str(j)+str(k))] = True
print(np.count_nonzero(ans))

Submission status: Wrong Answer

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

ss = s[::-1]

ans = 0

for i in range(1,1000):
    if i < 100:
        a = 0
    else:
        a = i // 100
    if i < 10:
        b = 0
    else:
        b = (i-a*100)//10
    c = i-(a*100+b*10)
    if str(a) in s and str(c) in s:
        k = s.index(str(a))
        l = n-1-ss.index(str(c))
        for j in range(k+1,l):
            if s[j] == str(b):
                ans += 1
                break
            
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
se = set()
check = set()
for first in range(10):
    temp = ''
    for i in range(n):
        if int(s[i]) in check:
            continue
        if int(s[i])==first:
            temp+=s[i]
            check.add(int(temp))
            for second in range(10):
                for j in range(i+1,n):
                    if int(temp+s[j]) in check:
                        continue
                    if int(s[j])==second:
                        temp+=s[j]
                        check.add(int(temp))
                        for third in range(10):
                            for k in range(j+1,n):
                                if int(temp+s[k]) in check:
                                    continue
                                if int(s[k])==third:
                                    temp+=s[k]
                                    check.add(int(temp))
                                    if len(temp)==3:
                                        se.add(temp)
                                    temp=temp[:-1]
                        temp=s[i]
print(len(se))

Submission status: Wrong Answer

Solution code:
n = int(input())
code = input()
f = 0
total = 0
for i in range(100,1000):
  s = str(i)
  idx = -1
  for dig in range(3):
    idx = code.find(s[dig], idx+1) 
    if idx == -1:
      break
  if idx != -1:
    total += 1
print(total)

Submission status: Wrong Answer

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

c = 0

flag0 = False
flag1 = False
flag2 = False

for i in range(1000):
    for n in reversed(S):
        if flag0 and flag1:
            if len(str(i)) >= 3:
                if int(str(i)[-3]) == int(n):
                    flag2 = True
            else:
                if 0 == int(n):
                    flag2 = True

        if flag0:
            if len(str(i)) >= 2:
                if int(str(i)[-2]) == int(n):
                    flag1 = True
            else:
                if 0 == int(n):
                    flag1 = True

        if int(str(i)[-1]) == int(n):
            flag0 = True

        if flag0 and flag1 and flag2:
            c += 1
            flag0 = False
            flag1 = False
            flag2 = False
            break

    flag0 = False
    flag1 = False
    flag2 = False
    print("{}:{}".format(i, c))

print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
n = int(input())
s = input()
no_dict = {}
count = 0
suuzi_list = []

for i in range(0, 10):
    if str(i) in s:
        suuzi_list.append(i)
for no_100 in suuzi_list:
    for no_10 in suuzi_list:
        for no_1 in suuzi_list:
            k = 1

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int, list(input())))
dici, dicm = set(), set()

for i in range(N):
  if len(dici) == 10:
    break
  dici.add(S[i])
  dicj = set()
  for j in range(i + 1, N):
    if len(dicj) == 10:
      break
    dici.add(S[j])
    dick = set()
    for k in range(j + 1, N):
      dicm.add((S[i],S[j],S[k]))
      if len(dicm) == 1000:
        break
      dick.add(S[k])
      if len(dick) == 10:
        break
print(len(dicm))

Submission status: Wrong Answer

Solution code:
def int2str(i):
  if i <=10:
    a="0"
    b="0"
    c=str(i)
  elif i <=100:
    a="0"
    b=str(i//10)
    c=str(i%10)
  else:
    a=str(i//100)
    b=str(i)[-2]
    c=str(i%10)
  return a,b,c

N=int(input())
S=input()
ans=0
for i in range(1000):
  a,b,c=int2str(i)
  flag=0
  for j in S:
    if flag==0 and j==a:
      flag=1
      continue
    elif flag==1 and j==b:
      flag=2
      continue
    elif flag==2 and j==c: 
      ans+=1
      break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
count = 0
for i in range(1000):
    j = i + 1
    if(j<10):
        first = S.find('0')    
        if(first >= 0 and first < N):
            second = S[first+1:].find('0')    
            if(second >= 0 and first+second+1 < N):
                third = S[first+second+2:].find(str(j))
                if(third>=0):
                    count += 1
    elif(j<100):
        first = S.find('0')
        if(first >= 0 and first < N):
            second = S[first+1:].find(str((j%100)//10))
            if(second >= 0 and first+second+1 < N):
                third = S[first+second+2:].find(str(j%10))
                if(third>=0):
                    count += 1
    else:
        first = S.find(str(j//100))    
        if(first >= 0 and first < N):
            second = S[first+1:].find(str((j%100)//10))    
            if(second >= 0 and first+second+1 < N):
                third = S[first+second+2:].find(str(j%10))
                if(third>=0 ):
                    count += 1  
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
seen = set()
list_s =[]
n = input()
s = input()
list_s = list(s)
list_s = [s for s in list_s]
print(len(set(list(itertools.combinations_with_replacement(list_s, 3)))))
print(set(list(itertools.combinations_with_replacement(list_s, 3))))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
f=0
for i in range(1,n+1):
    x = math.floor(i*1.08)

    if x==n:
        f=1
        xx = i
        break

if f:
    print(xx)
else:
    print(':(')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
l = [d for d in input()]
k = set(l[:-2])
c = 0
for kk in list(k):
    i = l[:-2].index(kk)
    o = set(l[i + 1:-1])
    for oo in list(o):
        ii = l[i + 1:-1].index(oo) + (i + 1)
        p = set(l[ii + 1:])
        c += len(p)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(str, input()))
st = set()
def dfs(i, v, now):
  if i == 3:
    st.add(v)
    return

  for k in range(now, n):
    dfs(i+1, v+s[k], k+1)
  
  return 

dfs(0, "", 0)

Submission status: Wrong Answer

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

cnt = 0
for i in range(1,1000):
    num = str(i).zfill(3)
    j = 0
    for t in s:
        if num[j] == t:
            if j == 2:
                cnt += 1
                break
            j += 1
print(cnt)

Submission status: Wrong Answer

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

c = 0

flag0 = False
flag1 = False
flag2 = False

for i in range(1000):
    for n in reversed(S):
        if flag0 and flag1 and flag2:
            c += 1
            break
        if flag0 and flag1:
            if len(str(i)) >= 3:
                if int(str(i)[-3]) == int(n):
                    flag2 = True
            else:
                if 0 == n:
                    flag2 = True

        if flag0:
            if len(str(i)) >= 2:
                if int(str(i)[-2]) == int(n):
                    flag1 = True
            else:
                if 0 == n:
                    flag1 = True

        if int(str(i)[-1]) == int(n):
            flag0 = True

print(c)

Submission status: Wrong Answer

Solution code:
def f():
    n = int(input())
    s = input()
    leftMemo = [None]*10
    rightMemo = [None]*10
    for i in range(10):
        char = str(i)
        for j in range(n):
            if s[j] == char:
                leftMemo[i] = j
                break
        for k in range(n-1,-1,-1):
            if s[k] == char:
                rightMemo[i] = k
                break
    ans = 0
    for leftNum in range(10):
        if leftMemo[leftNum] is None:
            continue
        start = leftMemo[leftNum]+1
        for rightNum in range(10):
            if rightMemo[rightNum] is None:
                continue
            end = rightMemo[rightNum]
            ans += len(set(s[start:end]))
    print(ans)

Submission status: Wrong Answer

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

count=0
for i in range(1001):
    W=str(i).rjust(3,'0')
    a,b,c=W[0],W[1],W[2]
    t=0
    while S[t]!=a and t<N-1:
        t+=1
    t+=1
    if t>N-1:
        continue
    while S[t]!=b and t<N-1:
        t+=1
    t+=1
    if t>N-1:
        continue
    while S[t]!=c and t<N-1:
        t+=1
    if t<N:
        if S[t]==c:
            count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
l = [d for d in input()]
#print(l)
k = set(l[:-2])
c = 0
# print(k)
for kk in list(k):
    # print('1桁目')
    # print(kk)
    i = l[:-2].index(kk)
    # print(i)
    o = set(l[i + 1:-1])
    # print(o)
    for oo in list(o):
        # print('2桁目')
        # print(oo)
        ii = l[i + 1:-1].index(oo) + (i + 1)
        # print(ii)
        p = set(l[ii + 1:])
        # print('３桁目')
        # print(p)
        c += len(p)
# print('合計')
print(c)

Submission status: Wrong Answer

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

def main():
    N = int(input())
    S = input().strip()
    ans = 0
    for i in range(1000+1):
        s = "{:03}".format(i)
        a = S.find(s[0])
        b = S.find(s[1], a+1)
        c = S.find(s[2], b+1)
        if a >= 0 and b >= 0 and c >= 0 and (a < b < c):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re

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

num_list = ['{:0=3}'.format(i) for i in range(1, 1000)]
pattern_list = [j[0]+"[0-9]*?"+j[1]+"[0-9]*?"+j[2] for j in num_list]
#print(pattern_list[0])

count = 0
for pattern in pattern_list:
  if re.search(pattern, S):
    #print(pattern)
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N= int(input())
S=input()
pointer = 0
counter = 0
def search(point,string, num):
    l_point = point
    for i in range(len(string)-point):
        if int(string[l_point])==num:
            return l_point
        l_point = l_point+1
    return -1
for i in range(0,10):
    pointer = search(pointer,S, i)
    #print("pointer = ",pointer)
    if pointer ==-1:
        pointer = 0
        continue;
    else:
        for j in range(0,10):
            pointer_1 = search(pointer+1,S,j)
            if pointer_1 == -1:
                pointer_1 = 0
                continue;
            else:
                for k in range(0,10):
                    pointer_2 = search(pointer_1+1,S,k)  
                    if pointer_2 == -1:
                        pointer_2 = 0
                        continue;
                    else:
                        #print(i,j,k)
                        counter = counter+1
print(counter)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=list(input())
L=[str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
n=0
I=N
J=N
for l in L:
  for i in range(N):
    if S[i]==l[0]:
      I=i
      break
    else:
      I=N
  for j in range(I+1,N):
    if S[j]==l[1]:
      J=j
      break
    else:
      J=N
  for k in range(J+1,N):
    if S[k]==l[2]:
      n+=1
      break
print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
kouho = [str(i).zfill(3) for i in range(0,100)]
cnt =0
for k in kouho:
    ok = True
    S_temp = S
    for l in k:
        if l in S_temp:
            basho = S_temp.index(l)
            S_temp = S_temp[basho+1:]
        else:
            ok = False
            break
    if ok == True:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
kouho = [str(i).zfill(3) for i in range(1,1001)]
cnt =0
for k in kouho:
    ok = True
    S_temp = S
    for l in k:
        if l in S_temp:
            basho = S_temp.index(l)
            S_temp = S_temp[basho+1:]
        else:
            ok = False
            break
    if ok == True:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

S = list(S)
S1 = []
S12 = []
ans = 0
for i in range(n-2):
    if S[i] not in S1:
        S1.append(S[i])
    if len(S1) == 10:
        break
    for j in range(i+1, n-1):
        s = S[i]+S[j]
        if s not in S12:
            S12.append(s)
            ans += len(set(S[j+1:]))

print(ans)

Submission status: Wrong Answer

Solution code:
N= int(input())
S=input()
pointer = 0
counter = 0
def search(point,string, num):
    l_point = point
    for i in range(len(string)-1-point):
        if int(string[l_point])==num:
            return l_point
        l_point = l_point+1
    return -1
for i in range(0,10):
    pointer = search(pointer,S, i)
    #print("pointer = ",pointer)
    if pointer ==-1:
        pointer = 0
        continue;
    else:
        for j in range(0,10):
            pointer_1 = search(pointer,S,j)
            if pointer_1 == -1:
                pointer_1 = 0
                continue;
            else:
                for k in range(0,10):
                    pointer_2 = search(pointer_1,S,k)  
                    if pointer_2 == -1:
                        pointer_2 = 0
                        continue;
                    else:
                        counter = counter+1
print(counter)

Submission status: Wrong Answer

Solution code:
import math
a=int(input())
b=str(input())
"""
#print(a,b)
path=[]
for nan in range(a-3):
  for i in range(a):
    list_b = list(b)
    del list_b[i]
    list_b = "".join(list_b)
    #print(list_b)
    path.append(list_b)
#print(path)
#print(len(set(path)))
"""
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

#print(combinations_count(a, 3))
import collections
c = collections.Counter(b)

#print(len(c))
print(combinations_count(a, 3)-len(c))
# Counter({'a': 4, 'c': 2, 'b': 1})

Submission status: Wrong Answer

Solution code:
import re

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

num_list = ['{:0=3}'.format(i) for i in range(1, 1000)]
pattern_list = ["[0-9]*?"+j[0]+"[0-9]*?"+j[1]+"[0-9]*?"+j[2]+"[0-9]*?" for j in num_list]
#print(pattern_list[0])

count = 0
for pattern in pattern_list:
  if re.match(pattern, S):
    #print(pattern)
    count += 1
print(count)

Submission status: Wrong Answer

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

num_dict = {}
removed = 0
for i in range(10):
    ap_lis = []
    for j in range(n):
        if len(ap_lis) >= 3:
            break
        if s[j] == str(i):
            ap_lis.append(j)
    ap_lis2 = []
    for j in range(n-1, 0, -1):
        if len(ap_lis2) >= 3:
            break
        if s[j] == str(i):
            ap_lis2.append(j)
    tmp = list(set(ap_lis + ap_lis2))
    num_dict[i] = tmp
    removed += len(tmp)

idx_dict = {}
for k, v in num_dict.items():
    for vi in v:
        idx_dict[vi] = k


removed_list = []
for idx in (sorted(idx_dict)):
    removed_list.append(idx_dict[idx])

res_list = []
for i in range(removed):
    for j in range(i+1, removed):
        for k in range(j+1, removed):
            res_list.append(removed_list[i]*100+removed_list[j]*10+removed_list[k])
print(len(set(res_list)))

Submission status: Wrong Answer

Solution code:
import sys
import itertools

sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    input()
    s=input()
    print(len(list(itertools.combinations(s,3))))



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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

ans = 0

pos = [
    [] for _ in range(10)
]


def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect_right(a, x)
    if i != len(a):
        return a[i]
    return None


for j in range(n):
    pos[int(s[j])].append(j)

for i in range(1001):
    t = '000' + str(i)
    t = t[-3:]
    a, b, c = map(int, tuple(t))

    p = -1
    p = find_gt(pos[a], p)
    if p is None:
        continue
    q = find_gt(pos[b], p)
    if q is None:
        continue
    r = find_gt(pos[c], q)
    if r is None:
        continue

    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

dict = {}
nCr = math.factorial(N)//math.factorial(N-3)//6

#ダブり数のカウント
for word in S:
    if word not in dict:
        dict[word] = 0
    else:
        dict[word] += 1

#print(dict)
sum = 0
for i in dict:
    sum += dict[i]

print(nCr - sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    idx = defaultdict(list)
    for i, s in enumerate(S):
        idx[int(s)].append(i)

    import pprint
    pprint.pprint(idx)
    ans = 0
    for i in range(0, 10):
        if not idx[i]:
            continue
        l = idx[i][0]
        for j in range(0, 10):
            if not idx[j]:
                continue
            ll = bisect.bisect_right(idx[j], l)
            if ll == len(idx[j]):
                continue
            ll = idx[j][ll]
            for k in range(0, 10):
                if not idx[k]:
                    continue
                lll = bisect.bisect_right(idx[k], ll)
                if lll != len(idx[k]):
                    ans += 1

    return ans


def main():
    N = read_int()
    S = read_str()
    print(slv(N, S))

    # N = 300000
    # S = '0123456789' * (N //10)
    # print(slv(N, S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

count = 0
for i in range(9):
  for j in range(9):
    for k in range(9):
      pas = [str(i),str(j),str(k)]
      key = 0
      for c in S:
        if c == pas[key]:
          key += 1
          if key ==3:
            count +=1
            break
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import Counter
N = int(input())
S = input()
new_S = [0]*10
C = Counter(S)
for x in C:
    new_S[int(x)] = min(C[x],3)
s = ""
for n in range(10):
    s += str(n)*new_S[n]
length = sum(new_S)
l = list()
for n in range(length-2):
    for m in range(n+1, length-1):
        for k in range(m+1, length):
            l.append(s[n]+s[m]+s[k])
print(len(np.unique(l)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
s = input()
ans = 0

for i in range(1000):
    tmp = str('{:03}'.format(i))
    s0 = s.find(tmp[0])
    if s0 == -1:
        continue
    else:
        s1 = s.find(tmp[1], s0 + 1)
        if s1 == -1:
            continue
        else:
            s2 = s.find(tmp[2], s1 + 1)
            if s2 == -1:
                continue
            else:
                print(i, tmp,s0, s1, s2)
                ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

num = [[int(-1)] * 3 for i in range(10)]

for i in range(N):
  p = int(S[i])
  if num[p][0] == int(-1):
    num[p][0] = i
  elif num[p][1] == int(-1):
    num[p][1] = i
  elif num[p][2] == int(-1):
    num[p][2] = i
    
#print(num)
ans2 = []
for i in range(10):
  if num[i][0] != int(-1):
    limit1 = num[i][0]
    for j in range(10):
      for k in range(3):
        if num[j][k] > limit1:
          limit2 = num[j][k]
          for p in range(10):
            for q in range(3):
              if num[p][q] > limit2:
                x = int(S[num[i][0]])*100 + int(S[num[j][k]])*10 +int(S[num[p][q]])
                if x not in ans2:
                  ans += 1
                  ans2.append(x)
                  #print(num[i][0], num[j][k], num[p][q])
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
n = int(input())
s = input()
for i in range(10):
	c = str(i)
	if c.count(s) >= 4:
		s = s.replace(c, "")
		s = s + c*3
if len(s) >= 30:
	print (1000)
	exit()
a = list(combinations(list(s),3))
b = set(a)
print (len(b))

Submission status: Wrong Answer

Solution code:
import re


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

#s_list = list(set([si for si in s]))

count=0
for i in range(10+1):
  for j in range(10+1):
    for k in range(10+1):
      pattern = str(i)+".*"+str(j)+".*"+str(k)
      result = re.search(pattern, s)
      
      if result:
        count+=1


print(count)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
S = input()
comb = list(itertools.combinations(list(range(N)),3))
ans = []
for i in comb:
    pw = []
    for j in range(len(comb[0])):
        pw.append(S[i[j]])
    pw = "".join(pw)
    if pw not in ans:
        ans.append(pw)
print(len(ans))
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1001):
    t = '000' + str(i)
    t = t[-3:]
    k = 0
    for j in range(n):
        if s[j] == t[k]:
            if k < 2:
                k += 1
            else:
                ans += 1
                break

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby


N = int(input())
S = input()
S = ''.join([x[0] for x in groupby(S)])

ans = 0
for i in range(0, 1000):
    num = str(i).zfill(3)
    flag = True
    _idx = 0
    for s in num:
        idx = S[_idx:].find(s)
        if idx == -1:
            flag = False
            break
        else:
            _idx += idx + 1
    if flag:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
s = np.array(list(map(int, input())))
res = 0
seen0 = set()
for i, ss in enumerate(s):
    if ss in seen0:
        continue
    seen0.add(ss)
    part = s[i+1:]
    seen1 = set()
    comp_mat = np.full((10, 10), False)
    for j, t in enumerate(part):
        if t in seen1:
            continue
        seen1.add(t)
        part1 = part[j+1:]
        seen2 = set()
        for k, u in enumerate(part1):
            if u in seen2:
                continue
            seen2.add(u)
            comp_mat[t, u] = True
    res += comp_mat.sum()
print(res)

Submission status: Wrong Answer

Solution code:
x=int(input())
dp=[0]*(x+1)
dp[0]=1
for j in range(6):
    val=100+j
    for i in range(len(dp)-1,0,-1):
        if i>=val:
            if dp[i-val]:
                dp[i]=1
if dp[-1]:
    print(1)
else:
    print(0)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1000):
    pin = '{:03d}'.format(i)
    j = 0
    k = 0
    while True:
        if k == N:break
        if S[k] == pin[j]:
            if j == 2:
                ans += 1
                break
            else:
                j += 1
        k += 1

print(ans)

Submission status: Time Limit Exceeded

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

S = set()
cnt = 0
for i in range(1000):
    i = str(i).zfill(3)
    num = 0
    for j in range(n):
        if L[j] == i[0] and num == 0:
            num =1
        elif L[j] == i[1] and num == 1:
            num =2
        elif L[j] == i[2] and num == 2:
            S.add(i)
            
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=input()
anslist=[]
c=0
#3けたの暗証番号なので000~999までの最大1000通り
for i in range(1000):
    c=0
    if i<10:
        i="00"+str(i)
    elif i<100:
        i="0"+str(i)
    else:
        i=str(i)
    tmp=""
    j=0
    while j<n:
        if S[j]==i[0]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[1]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[2]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    if tmp==i:
        anslist.append(tmp)
                        
#print(anslist)
print(len(anslist))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
_d = {}
d = {}
for i in range(N-2):
    if S[i] == S[i-1] and i >= 1: continue
    for j in range(i+1, N-1):
        _st = ''.join([S[i], S[j]])
        if _st in _d: continue
        else: _d[_st] = True
        for k in range(j+1, N):
            st = ''.join([S[i], S[j], S[k]])
            d[st] = True
print(len(d))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=input()
anslist=[]
c=0
#3けたの暗証番号なので000~999までの最大1000通り
for i in range(1000):
    c=0
    if i<10:
        i="00"+str(i)
    elif i<100:
        i="0"+str(i)
    else:
        i=str(i)
    tmp=""
    for j in range(n):
        if c==1:
            break
        if S[j]==i[0]:
            tmp+=S[j]
            for k in range(j+1,n):
                if c==1:
                    break
                if S[k]==i[1]:
                    tmp+=S[k]
                    for r in range(k+1,n):
                        if c==1:
                            break
                        if S[r]==i[2]:
                            tmp+=S[r]
                            anslist.append(tmp)
                            c=1
                        
print(len(anslist))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=input()
anslist=[]
c=0
#3けたの暗証番号なので000~999までの最大1000通り
for i in range(1000):
    c=0
    if i<10:
        i="00"+str(i)
    elif i<100:
        i="0"+str(i)
    else:
        i=str(i)
    tmp=""
    for j in range(n):
        if S[j]==i[0]:
            tmp+=S[j]
            for k in range(j+1,n):
                if c==1:
                    break
                if S[k]==i[1]:
                    tmp+=S[k]
                    for r in range(k+1,n):
                        if c==1:
                            break
                        if S[r]==i[2]:
                            tmp+=S[r]
                            anslist.append(tmp)
                            c=1
                        
#print(anslist)
print(len(anslist))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
d = {}
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            st = ''.join([S[i], S[j], S[k]])
            d[st] = True
print(len(d))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
res = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tnp = [i,j,k]
            flag = 0
            for s in S:
                if int(s) == tnp[flag]:
                    flag += 1
                if flag == 3:
                    res += 1
                    break
print(res)

Submission status: Time Limit Exceeded

Solution code:
digits = int(input())
num_list = [int(i) for i in list(input())]
flag1 = 0
flag2 = 0
counter = 0


for num1 in range(10):
	for num2 in range(10):
		for num3 in range(10):
			flag1 = 0
			flag2 = 0
			for digit in range(digits):
				if flag1 == 0 and flag2 == 0 and num1 == num_list[digit]:
					flag1 = 1
					continue
				if flag1 == 1 and num2 == num_list[digit]:
					flag2 = 1
					flag1 = 0
					continue
				if flag2 == 1 and num3 == num_list[digit]:
					counter += 1
					flag2 = 0
					break
print(counter)