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:
N = int(input())
S = list(input())
S = map(int, S)
cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = True
            flag2 = True

            for a in S:
                if flag1:
                    if a == i:
                        flag1 = False
                    continue
                elif flag2:
                    if a == j:
                        flag2 = False
                    continue
                elif a == k:
                    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int, list(input())))
cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = True
            flag2 = True

            for a in S:
                if flag1:
                    if a == i:
                        flag1 = False
                    continue
                elif flag2:
                    if a == j:
                        flag2 = False
                    continue
                elif a == k:
                    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = True
            flag2 = True

            for a in S:
                if flag1:
                    if a == i:
                        flag1 = False
                    continue
                elif flag2:
                    if a == j:
                        flag2 = False
                    continue
                elif a == k:
                    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

cnt = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1 = True
            flag2 = True

            for a in S:
                if flag1:
                    if a == i:
                        flag1 = False
                    continue
                if flag2:
                    if a == j:
                        flag2 = False
                    continue
                if a == k:
                    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
h = [0]*1000

for i in range(n-2):
  tmp = int(s[i:i+3])
  h[tmp]=1

print(sum(h))

Submission status: Wrong Answer

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

def aruka(a,b,c):
    i = 0
    while i <= n:
        if i == n:
            return False
        if s[i] == a:
            i += 1
            break
        i += 1
    while i <= n:
        if i == n:
            return False
        if s[i] == b:
            i += 1
            break
        i += 1
    while i <= n:
        if i == n:
            return False
        if s[i] == c:
            return True
        i += 1


ans = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            if aruka(i,j,k):
                ans += 1

Submission status: Wrong Answer

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

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

s = list(S)
lens = len(s)
for i in range(lens):
    ni = int(s[i])
    for j in range(i+1, lens):
        nj = int(s[j])
        for k in range(j+1, lens):
            nk = int(s[k])
            a[ni][nj][nk] = 1

ans = sum(sum(a, []), [])
print(ans)

Submission status: Wrong Answer

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

N=int(input())
S=input()
ans=0
for i in range(1000):
  a,b,c=int2str(i)
  flag=0
  i1 = S.find(a)
  if i1 !=-1:
    S1=S[i1:]
    i2=S1.find(b)
    if i2 !=-1:
      S2=S1[i1:]
      i3=S2.find(c)
      if i3 !=-1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    s = input()

    # まず文字列の圧縮を図る 3回以上出た文字列は省略する
    s_dic = {}
    sa = ''
    for i in range(n):
        if not s[i] in s_dic:
            sa += s[i]
            s_dic[s[i]] = 1
        elif s_dic[s[i]] > 2 and i < n - 2:
            continue
        else:
            sa += s[i]
            s_dic[s[i]] += 1

    ans_dic = {}
    for i in range(len(sa) - 2):
        for j in range(i+1, len(sa)-1):
            for k in range(j+1, len(sa)):
                ans_dic[int(sa[i]+sa[j]+sa[k])] = int(sa[i]+sa[j]+sa[k])

    print(len(ans_dic))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
if n >= 6:
    n = 6
s = input()

d = {}

for i in range(n-2):
    for j in range(i+1, n-1):
        for l in range(j+1, n):
            r = ""
            r = s[i] + s[j] + s[l]
            if r not in d:
                d[r] = 0
            d[r] += 1

print(len(d))

Submission status: Wrong Answer

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

list=list(S)

kei=[]
for a in range(N-2):
    for b in range(N-1):
        if b<=a:
            continue
        for c in range(N):
            if c<=b:
                continue
            print(a,b,c)
            retsu=''
            retsu=retsu+list[a]+list[b]+list[c]
            kei.append(retsu)
last=set(kei)
print(len(last))

Submission status: Wrong Answer

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


for i in range(1000):
  ai=str(i)
  ai=ai.zfill(3)
  for i in range(n):
    if ai[0]==s[i]:
      for j in range(i+1,n):
        if ai[1]==s[j]:
          for k in range(j+1,n):
            if ai[2]==s[k]:
              
              ans+=1
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            fi = S.find(str(i))
            fj = S.find(str(j))
            fk = S.find(str(k))
            if fi >= 0 and fj >= 0 and fk >= 0 and fi < fj and fj < fk:
                ans += 1

print(ans)

Submission status: Wrong Answer

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

result = 0
for i in range(10):
  if str(i) in S:
    T = S[S.index(str(i)):]

    for j in range(10):
      if str(j) in T:
        U = T[T.index(str(j)):]

        for k in range(10):
          if str(k) in U:
            result += 1

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
count=0
count2=0
d=[]
hk3=0
hk2=0
hk1=0
for j in range(100,1000):
  k3=j//100
  k2=(j-k3*100)//10
  k1=j-k3*100-k2*10
  for i in range(n):
    if str(k3)==s[i]:
      hk3=1
    if str(k2)==s[i] and hk3==1:
      hk2=1
    if str(k1)==s[i] and hk2==1:
      hk1=1
    if hk1==1 and hk2==1 and hk3==1:
      d.append(j)
  hk1=0
  hk2=0
  hk3=0
for j in range(1,10):
  for i in range(n):
    if s[i]=="0":
      count=1
    if count==1 and s[i]=="0":
      count2=1
    if count2==0 and s[i]==str(j):
      d.append(j)
  count=0
  count2=0
for j in range(10,100):
  k2=j//10
  k1=j-k2*10
  for i in range(n):
    if s[i]=="0":
      count=1
    if str(k2)==s[i] and count==1:
      hk2=1
    if str(k1)==s[i] and hk2==1 and count==1:
      hk1=1
    if hk1==1 and hk2==1:
      d.append(j)
  count=0
  hk1=0
  hk2=0
print(len(set(d)))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = str(10**(n+1))
ans = []
cnt1 = []
cnt2 = []
for i in range(n-2):
    if s[i] not in cnt1:
        for j in range(i+1,n-1):
            if s[i]+s[j] not in cnt2:
                for k in range(j+1,n):
                    ans.append(s[i]+s[j]+s[k])
            cnt2.append(s[i]+s[j])
        cnt1.append(s[i])
print(len(set(ans)))

Submission status: Wrong Answer

Solution code:
import itertools
import copy
N = int(input())
S = list(input())
result=[]
for c in itertools.combinations(S, N - 3):
    s=copy.deepcopy(S)
    for i in range(N-3):
        s.remove(c[i])
        if s not in result:
            result.append(s)

print(len(result))

Submission status: Wrong Answer

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

list=list(S)

kei=[]
for a in range(N-2):
    for b in range(N-1):
        if b<a:
            break
        for c in range(N):
            if c<b:
                break
            retsu=''
            retsu=retsu+list[a]+list[b]+list[c]
            kei.append(retsu)
last=set(kei)
print(len(last))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
Slist = list(S)
import itertools
X = set(Slist)
a = [0]*(len(X))
j = 0
for i in X:
    a[j] =  S.find(i)
    j += 1
S1 = S[max(a)+1:]
X1 = set(list(S1))
b = [0]*(len(X))
j = 0
for i in X1:
    b[j] =  S1.find(i)
    j += 1
S2 = S1[max(b)+1:]
X2 = set(list(S2))

if X == X1 ==X2:
    print(int(len(X)**3))
    
print(len(set(list(itertools.combinations(S[:max(a)+max(b)+100],3)))))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

from math import factorial
import itertools

def permutations_count(n, r):
    ''' 順列 '''
    return factorial(n) // factorial(n - r)

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

n = int(input())
*s, = map(int, list(input().split()[0]))

ans = 0
for i in range(1000):
    num_str = str(i)
    if i < 100:
        num_str = '0'+num_str
    if i<10:
        num_str = '0'+num_str
    idx = 0
    for j in s:
        # print(j, idx)
        if j == int(s[idx]):
            idx += 1
            if idx==3:
                break
    if idx == 3:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = input()
L = [S[0:3]]
M = [S[0:2],S[1:3],S[0]+S[2]]
used = [0]*10
used[int(S[0])] = 1
used[int(S[1])] = 1
used[int(S[2])] = 1
M = list(set(M))
for i in range(3,n):
    for j in range(len(M)):
        k = M[j]+S[i]
        L.append(k)
    for j in range(10):
        if used[j] == 1:
            t = str(j)+S[i]
            M.append(t)
    if used[int(S[i])] != 0:
      used[int(S[i])] = 1
    L = list(set(L))
    M = list(set(M))
L = list(set(L))
print(len(L))

Submission status: Wrong Answer

Solution code:
#　三井住友D
from collections import defaultdict
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
s = si()

one = []
two = []
three = []

d=defaultdict(int)

for ss in s:
    t = int(ss)
    d[t] += 1

for v in d.items():
    if v[1]>=1:
        one.append(v[0])
    if v[1]>=2:
        two.append(v[0])
    if v[1]>=3:
        three.append(v[0])


one_cnt = len(one)
two_cnt = len(two)
three_cnt = len(three)
ans_one = 0
ans_two = 0
ans_three = 0
ans = 0

if one_cnt>=3:
    ans_one = (one_cnt*(one_cnt-1)*(one_cnt-2))

if two_cnt>0 and one_cnt>0:
    ans_two = one_cnt*((two_cnt*(two_cnt-1)))

if three_cnt>0:
    ans_three = three_cnt
ans = ans_one+ans_two+ans_three
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline
N = int(input())
S = input()
pred = {}
d = {}
count = 0
delcount = 0

for i in range(4, N-3):
    if S[i] not in pred:
        pred[S[i]] = 1
    elif pred[S[i]] == 5:
        S = S[:i] + S[i+1:]
        delcount +=1
        i+=1
    else:
        pred[S[i]] += 1
    if i > N-delcount-2:
        break

combs = list(itertools.combinations(range(N-delcount), 3))
for c in combs:
    if S[c[0]]+S[c[1]]+S[c[2]] not in d:
        d[S[c[0]]+S[c[1]]+S[c[2]]] = 1
        count +=1
    else:
        pass
#print(d)
print(count)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline
N = int(input())
S = input()
pred = {}
d = {}
count = 0
delcount = 0

for i in range(0, N):
    if S[i] not in pred:
        pred[S[i]] = 1
    elif pred[S[i]] == 5:
        S = S[:i] + S[i+1:]
        delcount +=1
        i+=1
    else:
        pred[S[i]] += 1
    if i > N-delcount-2:
        break

combs = list(itertools.combinations(range(N-delcount), 3))
for c in combs:
    if S[c[0]]+S[c[1]]+S[c[2]] not in d:
        d[S[c[0]]+S[c[1]]+S[c[2]]] = 1
        count +=1
    else:
        pass
#print(d)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
dum = []
for i in range(n):
    if dum.count(s[i])<=3:
        dum.append(s[i])
dum_3 = []
for i in range(len(dum)-2):
    for j in range(len(dum)-2-i):
        for k in range(len(dum)-2-i-j):
            if dum[i]+dum[j+i+1]+dum[k+j+i+2] not in dum_3:
                dum_3.append(dum[i]+dum[j+i+1]+dum[k+j+i+2])
print(len(dum_3))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import factorial


N = int(input())
S = input().strip()

d = defaultdict(int)
for s in S:
    d[s] += 1

n = N
r = N-3
a = factorial(n) / factorial(r) / factorial(n - r)

p = 0
for k, v in d.items():
    p += v-1

print(int(a-p))

Submission status: Wrong Answer

Solution code:

from sys import stdin
from math import factorial
from itertools import combinations
 
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
s = [int(i) for i in s]
 
lin = list(combinations(s,n-3))
 
lin = list(set(lin))
 
print(len(lin))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
a = [str(i)+str(j)+str(k) for i in range(10) for j in range(10) for k in range(10)]
cnt = 0
tmp_i = -1
tmp_j = -1
for num in a:
    for i in range(N):
        if S[i]==num[0]:
            tmp_i = i
            break
    if tmp_i == -1:
        continue
    for j in range(N-1,-1,-1):
        if S[j]==num[2]:
            tmp_j = j
            break
    if tmp_j == -1:
        tmp_i = -1
        continue
    if tmp_i+1<tmp_j:
        if num[1] in S[tmp_i+1:tmp_j]:
            print(num)
            cnt+=1
    tmp_i = -1
    tmp_j = -1
print(cnt)

Submission status: Wrong Answer

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

dp1000 = [[False for _ in range(10)] for _ in range(100)]
dp100 = [False for _ in range(100)]
l = []

ans = 1
dp1000[int(s[:2])][int(s[3])] = True
dp100[int(s[:2])] = True
l.append(s[:2])

for i in range(3,n):
	count = 0
	for j in range(i-1):
		string = s[j]+s[i-1]
		if not dp100[int(string)]:
			l.append(s[j]+s[i-1])
			dp100[int(string)] = True

	for j in l:
		if not dp1000[int(j)][int(s[i])]:
			dp1000[int(j)][int(s[i])] = True
			count += 1

	ans += count

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
new_s = ""
for i in range(len(s)):
    if i<3:
        new_s+=s[i]
    else:
        if s[i-1] == s[i] and s[i-2] == s[i]:
            pass
        else:
            new_s+=s[i]
pas = -1
ans = 0
for i in range(1000):
    ott = 0
    pas = int(pas)+1
    if pas < 10:
        pas = "00"+str(pas)
    elif pas < 100:
        pas = "0"+str(pas)
    pas = str(pas)
    idx = -1
    while idx < len(new_s)-1:
        idx += 1
        if ott == 0:
            if pas[0] == new_s[idx]:
                ott += 1
        elif ott == 1:
            if pas[1] == new_s[idx]:
                ott += 1
        elif ott == 2:
            if pas[2] == new_s[idx]:
                ott += 1
                ans += 1
        if ott == 3:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
# your code goes here
import itertools

num = int(input())
arr = input()
 
lens = len(arr)
 
mat = []
 
c = list(itertools.combinations(list(arr), num-3))
 
mat = list(set(c))
 
print(len(mat))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
input = sys.stdin.readline
N = int(input())
S = input()
pred = {}
d = {}
count = 0
delcount = 0

for i in range(0, N):
    if S[i] not in pred:
        pred[S[i]] = 1
    elif pred[S[i]] == 4:
        S = S[:i] + S[i+1:]
        delcount +=1
        i+=1
    else:
        pred[S[i]] += 1
    if i > N-delcount-2:
        break

combs = list(itertools.combinations(range(N-delcount), 3))
for c in combs:
    if S[c[0]]+S[c[1]]+S[c[2]] not in d:
        d[S[c[0]]+S[c[1]]+S[c[2]]] = 1
        count +=1
    else:
        pass
#print(d)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
dum = []
for i in range(n):
    if dum.count(s[i])<=3:
        dum.append(s[i])
    if len(dum)>=30:
        break
dum_3 = []
for i in range(len(dum)-2):
    for j in range(len(dum)-2-i):
        for k in range(len(dum)-2-i-j):
            if dum[i]+dum[j+i+1]+dum[k+j+i+2] not in dum_3:
                dum_3.append(dum[i]+dum[j+i+1]+dum[k+j+i+2])
print(len(dum_3))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
s = input()
ans_li = []
for i in range(0,n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            block = int(s[i]+s[j]+s[k])
            ans_li.append(block)

print(ans_li)
ans = len(set(ans_li))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
l=[]
for i in range(n):
    for j in range(n):
      if i==j:continue
      for k in range(n):
        if i==k or j==k:continue
        a=s[i]+s[j]+s[k]
        if a in l:continue
        l.append(a)

print(len(l))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import copy

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

res = {
    '0': [],
    '1': [],
    '2': [],
    '3': [],
    '4': [],
    '5': [],
    '6': [],
    '7': [],
    '8': [],
    '9': [],
}

for i in range(0, N - 3):
    c = S[i]
    cmb = list(combinations(S[i+1:], 2))
    res[c].extend(cmb)

ans = 0
for c in ['0','1','2','3','4','5','6','7','8','9']:
    ans += len(set(res[c]))

print(ans)

Submission status: Wrong Answer

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

cnt = 0
for h in range(1000):
    x, y, z = str(h).zfill(3).strip()
    if re.search('{}[1-9]*{}[1-9]*{}'.format(x, y, z) , S):
        cnt +=1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
S = input()
L = [[]for i in range(10)]


for i in range(N):
    L[int(S[i])].append(i)
count = 0


for i in range(10):
    L2 = copy.deepcopy(L)
   
    if len(L2[i])==0:
        
        continue 
   
    for j in range(10):
        if len(L2[j])==0:
            continue
        for k in range(10):
            L2 = copy.deepcopy(L)
            if len(L2[k])==0:
                continue
            
            
            m1 = min(L2[i])
            L2[i].remove(m1)
            if len(L2[k]) == 0:
                continue
            m2 = max(L2[k])
            L2[k].remove(m2)

            flag = False
            
            for p in range(m1,m2 +1):
                if p in L2[j] and (not flag):
                    flag = True
                    count +=1


print(count)

Submission status: Wrong Answer

Solution code:
N= int(input())
S=input()
pointer = 0
counter = 0

S_new=""
i_flag =0
for j in range(N-1):
    if S[j]!=S[j+1]:
        i_flag =0
    else:
        i_flag=i_flag+1
    if i_flag < 4:
        S_new = S_new + S[j]
    
#print(S_new)
    
S = S_new
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 = 0
    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=input()

d=[0]*1000
di=[0]*10
dj=[[0]*10]*10
for i in range(N):
  ii=int(s[i])
  if di[ii]==1:continue
  else:di[ii]=1
  for j in range(i+1,N):
    jj=int(s[j])
    dk=[0]*10
    if dj[ii][jj]==1:continue
    else:dj[ii][jj]=1
    
    for k in range(j+1,N):
      kk=int(s[k])
      d[ii*100+jj*10+kk]=1
      dk[kk]=1
      if sum(dk) ==10:break
      
print(sum(d))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = input()
def my_count(l):
  p = 0
  for i in range(10):
    i = str(i)
    if i in l:
      p = p + 1
  return p
s = []
ans = 0
for i in range(10):
  k = str(i)  
  s.append(b.find(k))
  if s[i] >= 0:
    for j in range(10):
      h = str(j)  
      y = b[s[i]+1:len(b)]
      t = y.find(h)
      if t >= 0:
        c = y[t+1:len(b)]
        ans = ans + my_count(c)
print(s)
print(ans)

Submission status: Wrong Answer

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

li=[]
uni_list=[]

for i in range(N-2):
    for j in range(N-1):
        if j>i:
            for k in range(N):
                if k>j:
                    if ("S[i]+S[j]+S[k]" in li)=="True":
                        pass
                    else:
                        li.append(S[i]+S[j]+S[k])
    



print(len(uni_list))

Submission status: Wrong Answer

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

s = set()
for i in range(0, N - 2):
    s1 = S[i]
    if s1 in s:
        continue
    s.add(s1)
    for j in range(i + 1, N - 1):
        s2 = s1 + S[j]
        if s2 in s:
            continue
        s.add(s2)
        for k in range(j + 1, N):
            s3 = s2+S[k]
            s.add(s3)

print(len(s))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# get a integer
def subset_sum(numbers, target, partial=[]):
    s = sum(partial)
    ans = 0
    # check if the partial sum is equals to target
    if s == target:
        return  1
    if s >= target:
        return 0
        # if we reach the number why bother to continue

    for i in range(len(numbers)):
        n = numbers[i]
        remaining = numbers[i + 1:]
        ans = subset_sum(remaining, target, partial + [n])
        if ans ==1:
            break
    return ans

a = int(raw_input())
r = 0
checkBoth = False
if a <=  735:
  opt = [100, 101, 102, 103, 104, 105]
  r = subset_sum(opt, a)
  print(r)
else:
  #a = a/2
  if a %2==0:
    a /=2
  else:
    checkBoth = True
    a = (a-1)/2
  opt = [100, 101, 102, 103, 104, 105,
         1000,1000,1000,1000,1000,
         10000,10000,10000,10000,
         10000,10000,100000,
         100000,100000,100000]
  
  for i in opt:
    if a % i ==0:
      r =1
      break
    if r != 1:
        if checkBoth:
            r1 = subset_sum(opt, a)
            r2 = subset_sum(opt, a + 1)
            if r1 == 1 and r2 == 1:
                r = 1
        else:
            r = subset_sum(opt, a)
  print(r)

Submission status: Wrong Answer

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

dp = [[0]*10 for _ in range(10)]

count = [0]*10

result = []

for i in range(n-2):
    if count[int(s[i])]==0:
        for j in range(i+1,n-1):
            if dp[int(s[i])][int(s[j])]==0:
                tem = "".join(set(s[j+1:]))
                for k in range(len(tem)):
                    result.append(s[i]+s[j]+tem[k])
                dp[int(s[i])][int(s[j])]=1
        count[int(s[i])]=1

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
l=[]
for i in range(n):
    for j in range(n):
      if i!=j:continue
      for k in range(n):
        if i!=k or j!=k:continue
        a=s[i]+s[j]+s[k]
        if a in l:continue
        l.append(a)

print(len(l))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    s = input()

    # まず文字列の圧縮を図る 3回以上出た文字列は省略する
    s_dic = {}
    sa = ''
    for i in range(n):
        if not s[i] in s_dic:
            sa += s[i]
            s_dic[s[i]] = 1
        elif s_dic[s[i]] > 3:
            continue
        else:
            sa += s[i]
            s_dic[s[i]] += 1

    ans_dic = {}
    for i in range(len(sa) - 2):
        for j in range(i+1, len(sa)-1):
            for k in range(j+1, len(sa)):
                ans_dic[int(sa[i]+sa[j]+sa[k])] = int(sa[i]+sa[j]+sa[k])

    print(len(ans_dic))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import math
input = sys.stdin.readline
#sys.setrecursionlimit(1e9)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
    """code here"""
    N = int(input())
    S = list(input())
    S = S[:-1]

    keta = N -3

    num = len(S)
    num = num-keta

    ans = []
    tyouhuku = len(S) - len([x[0] for x in itertools.groupby(set(S))])
    aaa = combinations_count(len(S),num)

    print(aaa-tyouhuku)

    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
l=[]
for i in range(n):
    for j in range(n):
      if i!=j:continue
      for k in range(n):
        if i!=k or j!=k:continue
        a=s[i]+s[j]+s[k]
        if a in l:
          l.append(a)

print(len(l))

Submission status: Wrong Answer

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

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

count = 0

ls_si = []
for i in range(n-2):
    print("i={}".format(i))
    if s[i] in ls_si:
        pass
    else:
        ls_si.append(s[i])
        ls_sj = []
        for j in range(i+1,n-1):
            if s[j] in ls_sj:
                pass
            else:
                ls_sj.append(s[j])
                # ls = s[j+1:-1]
                # st = set(ls)
                # l = len(st)
                # print(ls)
                # print(st)
                # print(l)
                count += len(set(list(s[j+1:-1])))

# print(ls_si)
# print(ls_sj)
print(count)

Submission status: Wrong Answer

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

a = N - 3

s = set()
for i in range(0, N - 2):
    s1 = S[0:i]
    for j in range(i + 1, N - 1):
        s2 = s1+S[i+1:j]
        for k in range(j + 1, N):
            s3 = s2+S[j+1:k]+S[k+1:]

            s.add(s3)

print(len(s))

Submission status: Wrong Answer

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

cnt = 0
for h in range(1000):
    x, y, z = str(h).zfill(3).strip()
    if re.search('{}[1-9]*{}[1-9]*{}'.format(x, y, z) , S):
        cnt +=1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect

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

idx_list = [[] for _ in range(10)]
for i in range(N):
    idx_list[S[i]].append(i)

ans = 0
for first_pin in range(10):
    if len(idx_list[first_pin]) == 0 or idx_list[first_pin][0] >= N-2:
        continue
    tmp = idx_list[first_pin][0]
    for second_pin in range(10):
        if second_pin == first_pin:
            if len(idx_list[first_pin]) >= 2 and idx_list[first_pin][-1] < N-1:
                tmp_s = S[idx_list[first_pin][1]+1:]
                ans += len(set(tmp_s))
        else:
            if len(idx_list[second_pin]) == 0 or idx_list[second_pin][-1] < tmp:
                continue
            tmp2 = idx_list[second_pin][bisect.bisect_left(
                idx_list[second_pin], tmp)]
            if tmp2 == N-1:
                continue
            tmp_s = S[tmp2+1:]
            ans += len(set(tmp_s))

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from collections import Counter
n=int(input())
s=input()
a=list(s)
c=list(combinations(a,3))
print(c)
print(Counter(c))
num=len(Counter(c))
print(num)

Submission status: Wrong Answer

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

S10 = [0 for i in range(10)]
S100 = [list(S10) for i in range(10)]
S1000 =[list([list(S10) for i in range(10)]) for i in range(10)]

for n in S:
    for i in range(10):
        for j in range(10):
            if list(S100)[i][j] == 1:
                S1000[i][j][int(n)] = 1
        if list(S10)[i] == 1:
            S100[i][int(n)] = 1
    S10[int(n)] = 1
    print(S10,S100,S1000)
    


ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if S1000[i][j][k] == 1:
                ans += 1

print(ans)

Submission status: Wrong Answer

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

d=[0]*1000
di=[0]*10
dj=[[[0]*10]*10]*10
for i in range(N):
  ii=int(s[i])
  if di[ii]==1:break
  else:di[ii]=1
  for j in range(i+1,N):
    jj=int(s[j])
    dk=[0]*10
    if dj[ii][jj]==1:break
    else:dj[ii][jj]=0
    
    for k in range(j+1,N):
      kk=int(s[k])
      d[ii*100+jj*10+kk]=1
      dk[kk]=1
      if sum(dk) ==10:break
      
print(sum(d))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
pass_list = list(map(lambda x: str(x).zfill(3), range(1, 1000)))
res = 0

for p in pass_list:
    
    ptr = 0
    one = False
    two = False
    three = False
    
    for i in range(len(s)):
        if(s[i] == p[0]):
            ptr = i
            one = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[1]):
            ptr = i
            two = True
            break
    
    for i in range(ptr+1, len(s)):
        if(s[i] == p[2]):
            ptr = i
            three = True
            break
    
    if(one and two and three): res += 1

print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=input()
t=0
for i in range(10):
  for a in range(n):
    if s[a]==str(i):
      for j in range(10):
        for b in range(a+1,n-1)[::-1]:
          if s[b]==str(j):
            t+=len(set(list(s[a+1:b])))
print(t)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import math
input = sys.stdin.readline
#sys.setrecursionlimit(1e9)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
    """code here"""
    N = int(input())
    S = list(input())
    S = S[:-1]

    keta = N -3

    num = len(S)
    num = num-keta

    ans = []
    tyouhuku = len(S) - len([x[0] for x in itertools.groupby(S)])

    aaa = combinations_count(len(S),num)

    print(aaa-tyouhuku)

    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

candidates = set()
for i in range(n-1):
    for j in range(i+1,n):
        candidates = candidates.union([str_s[i] + str_s[j] + k for k in str_s[j:]])
print(len(candidates))

Submission status: Wrong Answer

Solution code:
import itertools

#入力
N=int(input())
A = [int(x) for x in list(input())]

dict = {}
print(dict)
for i,j,k in itertools.combinations(A, 3):
    dict[i,j,k]=1
    #print(dict)
print(len(dict))