Problem:


Score : 300 points

Problem Statement

You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?

Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

Sample Input 1

575

Sample Output 1

4

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

Sample Input 2

3600

Sample Output 2

13

There are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.

Sample Input 3

999999999

Sample Output 3

26484



Sample input:
575


Sample output:
4

Submission status: Wrong Answer

Solution code:
def number_lst(x): #x桁での753
    lst = ['3', '5', '7']
    flag = False
    while True:
        for i in range(len(lst)):
            if len(lst[0])==x:
                flag = True
                break

            number = lst[i]
            y1 = number + '3'
            y2 = number + '5'
            y3 = number + '7'
            lst.append(y1)
            lst.append(y2)
            lst.append(y3)

        if flag:
            break

        min_lst = len(lst[0])
        new_lst = []
        for i in range(len(lst)):
            if len(lst[i])!=min_lst:
                new_lst.append(lst[i])
        lst = new_lst.copy()

    new_lst = []
    for i in range(len(lst)):
        number = lst[i]
        tmp_lst = [number.count('3'), number.count('5'), number.count('7')]
        if 0 not in tmp_lst:
            new_lst.append(number)

    return new_lst

n = str(input())
digit = len(n)

if digit<3:
    answer = 0
else:
    tmp1 = 3**(digit-1) - 3*2**(digit-1) + 3 #一個くらいを消去した時の個数
    tmp2 = 0

    lst_1 = number_lst(digit).copy()

    for i in range(len(lst_1)):
        number = int(lst_1[i])

        if number<=int(n):
            tmp2 += 1

    answer = tmp1 + tmp2
    print(tmp1)
    print(tmp2)

print(answer)

Submission status: Wrong Answer

Solution code:
def number_lst(x): #x桁での753
    lst = ['3', '5', '7']
    flag = False
    while True:
        for i in range(len(lst)):
            number = lst[i]
            if len(number)==x:
                flag = True
                break

            y1 = number + '3'
            y2 = number + '5'
            y3 = number + '7'
            lst.append(y1)
            lst.append(y2)
            lst.append(y3)

        if flag:
            break

        z_lst = []
        for i in range(len(lst)):
            z_lst.append(len(lst[i]))
        min_z = min(z_lst)

        new_lst = []
        for i in range(len(lst)):
            if len(lst[i])!=min_z:
               new_lst.append(lst[i])
        lst = new_lst.copy()

    new_lst = []
    for i in range(len(lst)):
        number = lst[i]
        tmp_lst = [number.count('3'), number.count('5'), number.count('7')]
        if 0 not in tmp_lst:
            new_lst.append(number)

    return new_lst

n = str(input())
digit = len(n)

if digit<3:
    answer = 0
else:
    x = digit-1
    tmp1 = (3**(x-1) - 2**x + 1) * 3 #一個くらいを消去した時の個数
    tmp2 = 0

    lst_1 = number_lst(digit).copy()

    for i in range(len(lst_1)):
        number = int(lst_1[i])

        if number<=int(n):
            tmp2 += 1

    answer = tmp1 + tmp2

print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())

def bfs(s):
  if int(s) >= n:
    return 0
  return ('3' in s and '5' in s and '7' in s) + bfs(s+'3') + bfs(s+'5') + bfs(s+'7')

print(bfs('0'))

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left

def sft(n, s):
    d = len(s[0])
    if s and d == n:
        return sorted([int(i) for i in s])
    a = []
    for i, si in enumerate(s):
        for k in range(3):
            ai = si + "357"[k]
            da = len(set(list(ai)))
            if d == n - 2 and da < 2:
                continue
            if d == n - 1 and da < 3:
                continue
            a.append(ai)
    return sft(n, a)

def main():
    n = input()
    d = len(n)
    s = []
    l = list("357")
    for i in range(3, d + 1):
        s += sft(i, l)
    print(bisect_left(s, int(n)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=input()
ans=0
n_len=len(n)
a=[0]
for i in range(1,n_len):
    a_i=3*(a[i-1]+2**(i)-2)
    a.append(a_i)
buf=1
check=[0]*3
for i in range(n_len-3):
    a_sum=sum(a[:n_len-i-1])
    n_i=int(n[i])
    if n_i<=2:
        ans=a_sum
        buf=0
        break
    elif n_i==3:
        ans+=a_sum
        if check[0]==0:
            check[0]=1
    elif n_i==4:
        ans+=a_sum+a[n_len-i-1]//3
        buf=0
        break
    elif n_i==5:
        ans+=a_sum+a[n_len-i-1]//3
        if check[1]==0:
            check[1]=1
    elif n_i==6:
        ans+=a_sum+2*(a[n_len-i-1]//3)
        buf=0
        break
    elif n_i==7:
        ans+=a_sum+2*(a[n_len-i-1]//3)
        if check[2]==0:
            check[2]=1
    elif n_i>7:
        ans+=a_sum+a[n_len-i-1]
        buf=0
        break
if buf==0:
    print(ans)
else:
    n_3=int(n[-3:])
    check0=[0]*3
    for i in range(333,n_3+1):
        for j in range(3):
            check0[j]=check[j]
        i_s=str(i)
        buf=0
        for j in range(3):
            if i_s[j]=="3":
                check0[0]=1
                buf+=1
            elif i_s[j]=="5":
                check0[1]=1
                buf+=1
            elif i_s[j]=="7":
                check0[2]=1
                buf+=1
        if check0==[1,1,1] and buf==3:
            ans+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
ans=0
n_len=len(n)
a=[0]
for i in range(1,n_len):
    a_i=3*(a[i-1]+2**(i)-2)
    a.append(a_i)
buf=1
check=[0]*3
for i in range(n_len-3):
    a_sum=sum(a[:n_len-i-1])
    n_i=int(n[i])
    if n_i<=2:
        ans=a_sum
        buf=0
        break
    elif n_i==3:
        ans+=a_sum
        if check[0]==0:
            check[0]=1
    elif n_i==4:
        ans+=a_sum+a[n_len-i-1]//3
        buf=0
        break
    elif n_i==5:
        ans+=a[n_len-i-1]//3
        if check[1]==0:
            check[1]=1
    elif n_i==6:
        ans+=a_sum+2*(a[n_len-i-1]//3)
        buf=0
        break
    elif n_i==7:
        ans+=2*(a[n_len-i-1]//3)
        if check[2]==0:
            check[2]=1
    elif n_i>7:
        ans+=a_sum+a[n_len-i-1]
        buf=0
        break
if buf==0:
    print(ans)
else:
    n_3=int(n[-3:])
    check0=[0]*3
    for i in range(333,n_3+1):
        for j in range(3):
            check0[j]=check[j]
        i_s=str(i)
        buf=0
        for j in range(3):
            if i_s[j]=="3":
                check0[0]=1
                buf+=1
            elif i_s[j]=="5":
                check0[1]=1
                buf+=1
            elif i_s[j]=="7":
                check0[2]=1
                buf+=1
        if check0==[1,1,1] and buf==3:
            ans+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    candidate = ["3","5","7"]
    for i in range(9):
        for c in candidate.copy():
            candidate.append(c+"3")
            candidate.append(c+"5")
            candidate.append(c+"7")
    
    ans = 0
    for c in candidate:
        if int(c)<=N and 0 not in (c.count("3"),c.count("5"),c.count("7")):
            ans += 1
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools


n = int(input())

def calculate(n,length):
    count = 0
    for i in itertools.product([3,5,7],repeat=length):
        if isValid(i) == False:
            continue
        sum = 0
        print(i)
        for j in range(length):
            sum = sum + i[j] * 10 ** j
        if sum <= n:
            count = count + 1

    return count

def isValid(n):
    dict = {}
    for s in n:
        if dict.get(s) == None:
            dict.__setitem__(s,1)
        else:
            dict.__setitem__(s,dict.get(s) + 1)

    s1 = dict.get(3) != None and dict.get(3) > 0
    s2 = dict.get(5) != None and dict.get(5) > 0
    s3 = dict.get(7) != None and dict.get(7) > 0

    return s1 and s2 and s3

length = len(str(n))

result = 0
for i in range(3,length+1):
    result = result + calculate(n,i)

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [_ for _ in range(1, n+1)]

x =[357,375,537,573,735,753]

z = 0
for i in range(n):
    a = list(set([str(j) for j in list(str(l[i]))]))
    b = int(''.join(a))
    if b in x:
        z += 1

print(z)

Submission status: Wrong Answer

Solution code:
import itertools


n = int(input())

def calculate(n,length):
    count = 0
    for i in itertools.product([3,5,7],repeat=length):
        if isValid(i) == False:
            continue
        sum = 0
        for j in range(length):
            sum = sum + i[j] * 10 ** j
        if sum < n:
            count = count + 1

    return count

def isValid(n):
    dict = {}
    for s in n:
        if dict.get(s) == None:
            dict.__setitem__(s,1)
        else:
            dict.__setitem__(s,dict.get(s) + 1)

    s1 = dict.get(3) != None and dict.get(3) > 0
    s2 = dict.get(5) != None and dict.get(5) > 0
    s3 = dict.get(7) != None and dict.get(7) > 0

    return s1 and s2 and s3

length = len(str(n))

result = 0
for i in range(3,length+1):
    result = result + calculate(n,i)

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        print(s+c)
        ret += dfs(s+c)
    return ret

print(dfs('0'))

Submission status: Wrong Answer

Solution code:
def function(n):
    digit=len(str(n))
    N=str(n)
    k=int(N[0])
    if digit<3:
        return 0
    else:
        if k<3:
            return function(10**(digit-1)-1)
        elif k==3:
            return function(10**(digit-1)-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(5,7,n%(10**(digit-1)))
        elif k==4:
            return function(4*(10**(digit-1))-1)
        elif k==5:
            return function(4*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,7,n%(10**(digit-1)))
        elif k==6:
            return function(6*(10**(digit-1))-1)
        elif k==7:
            return function(6*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,5,n%(10**(digit-1)))
        else:
            return function(8*(10**(digit-1))-1)

def subfunction(a,b,n):
    digit=len(str(n))
    N=str(n)
    k=int(N[0])
    if digit<2:
        return 0
    else:
        if k<a:
            return 0
        elif k==a:
            if n%(10**(digit-1))<b*(10**(digit-1)-1)//9:
                s=0
            else:
                s=1
            return subfunction(a,b,n%(10**(digit-1)))+s
        elif a<k<b:
            return subfunction(a,b,(a+1)*(10**(digit-1))-1)
        elif k==b:
            if n%(10**(digit-1))<a*(10**(digit-1)-1)//9:
                s=0
            else:
                s=1
            return subfunction(a,b,(a+1)*(10**(digit-1))-1)+subfunction(a,b,n%(10**(digit-1)))+s
        else:
            return subfunction(a,b,(b+1)*(10**(digit-1))-1)

N=int(input())
print(function(N))

Submission status: Wrong Answer

Solution code:
import itertools
import bisect

n = int(input())
m = len(str(n))
li = []

for i in range(3,m+1):
    li_tmp = list(itertools.product([3,5,7], repeat = i))
    for j in li_tmp:
        if 3 in j and 5 in j and 7 in j:
            a = 0
            for k in range(i):
                a += j[k] * 10**(i-k-1)
            li.append(a)

print(bisect.bisect_left(li, n))

Submission status: Wrong Answer

Solution code:
from sys import setrecursionlimit

setrecursionlimit(10**6)
def recur(N_:int,limit:int):
    if N_ > limit:
        return 0
    else:
        N_ *= 10
        return recur(N_ + 3,limit) + recur(N_ + 5,limit) + recur(N_ + 7,limit) + 1


def main():
    N = int(input())
    tmp = [753,735,573,537,375,357]
    ans = 0
    for t in tmp:
        ans += recur(t,N)
    print(ans)
    return   

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools

N=int(input())
num=[3,5,7]
dig=10
p=[1]*dig
for i in range(dig-1):
    p[i+1]=p[i]*10
    
ans=0

def check(n):
    strn=str(n)
    for i in range(len(num)):
        if not (str(num[i]) in strn):
            return False
    return True
        
ans=0
flag=1
for d in range(3,dig):#桁数
    if flag==0:
        break
    for pro in itertools.product(num, repeat=d):
        temp=0
        for j in range(d):
            temp+=pro[-1-j]*p[j]
        print(temp)
        if temp>N:
            flag=0
            break
        if check(temp):
            ans+=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N=int(input())
num=[3,5,7]
dig=10
p=[1]*dig
for i in range(dig-1):
    p[i+1]=p[i]*10
    
ans=0

def check(n):
    strn=str(n)
    for i in range(len(num)):
        if not (str(num[i]) in strn):
            return False
    return True
        
ans=0
flag=1
for d in range(3,dig):#桁数
    if flag==0:
        break
    for pro in itertools.product(num, repeat=d):
        temp=0
        for j in range(d):
            temp+=pro[-1-j]*p[j]
        if check(temp):
            ans+=1
        if temp>=N:
            flag=0
            break
        
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product


def main():
    N = int(input())
    result = 0
    numbers = ["3", "5", "7"]
    for i in range(3, len(str(N)) + 1):
        for p in product(numbers, repeat=i):
            flag = True
            tmp = "".join(p)
            for n in numbers:
                if n in tmp:
                    continue
                else:
                    flag = False
            if flag:
                if int(tmp) <= N:
                    print(int(tmp), flag)
                    result += 1
    print(result)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
def dfs(s): # 文字列 s で始まる七五三数の個数 
  if int(s) > N:
    return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1 
  for c in '753':
    ret += dfs(s + c)
    return ret
print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
nums = [3, 5, 7]
num_357 = set()

# retrieval
candidates = []
for i in range(3, 10):
    candidates += list(itertools.product(nums, repeat=i))
for c in candidates:
    for n in nums:
        if n not in c:
            break
    else:
        # c contains 3 && 5 && 7
        tmp = 0
        for ind, i in enumerate(c):
            tmp += i * pow(10, ind)
        num_357.add(tmp)

# result
ans = 0
for n_357 in num_357:
    if n_357 < N:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def f4(n):
  s=0
  d=1
  q=0
  while n>0:
    s+=d*(n%4)
    d*=10
    n=n//4
  return s

n=input()
d=len(n)
if d>3 and n[0] in ['1','2']:
  d-=1
  n='7'*d
ans=0
m=''
for i in range(d):
  x=n[i]
  if x in '12':
    m+='0'
  elif x in '34':
    m+='1'
  elif x in '56':
    m+='2'
  else:
    m+='3'
ans=0
for i in range(1,1+int(m,4)):
  q=str(f4(i))
  l=[x for x in q]
  l=list(set(l))
  if len(l)==3 and 6==int(l[0])+int(l[1])+int(l[2]):
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
def f4(n):
  s=0
  d=1
  q=0
  while n>0:
    s+=d*(n%4)
    d*=10
    n=n//4
  return s

n=input()
d=len(n)
if d>3 and n[0] in ['1','2']:
  d-=1
  n='7'*d
ans=0
m=''
for i in range(d):
  x=n[i]
  if x in '12':
    m+='0'
  elif x in '34':
    m+='1'
  elif x in '56':
    m+='2'
  else:
    m+='3'
ans=0
for i in range(1,1+int(m,4)):
  l=[x for x in str(f4(i))]
  l=list(set(l))
  if len(l)==3 and 6==int(l[0])+int(l[1])+int(l[2]):
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
def f4(n):
  s=0
  d=1
  q=0
  while n>0:
    s+=d*(n%4)
    d*=10
    n=n//4
  return s

n=input()
d=len(n)
if d>3 and n[0] in ['1','2']:
  d-=1
  n='7'*d
ans=0
m=''
for i in range(d):
  x=n[i]
  if x in '12':
    m+='0'
  elif x in '34':
    m+='1'
  elif x in '56':
    m+='2'
  else:
    m+='3'
ans=0
for i in range(1,1+int(m,4)):
  l=[x for x in str(f4(i))]
  l=list(set(l))
  if len(l)==3 and 6==int(l[0])+int(l[1])+int(l[2]):
    ans+=1

print(m,ans)

Submission status: Wrong Answer

Solution code:
def f4(n):
  s=0
  d=1
  q=0
  while n>0:
    s+=d*(n%4)
    d*=10
    n=n//4
  return s

n=input()
d=len(n)
if d>3 and n[0:2] in ['11','12','21','22']:
  d-=1
  n='7'*d
ans=0
m=''
for i in range(d):
  x=n[i]
  if x in '12':
    m+='0'
  elif x in '34':
    m+='1'
  elif x in '56':
    m+='2'
  else:
    m+='3'
for i in range(1,1+int(m,4)):
  l=[x for x in str(f4(i))]
  l=list(set(l))
  if len(l)==3 and 6==int(l[0])+int(l[1])+int(l[2]):
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
def f4(n):
  s=0
  d=1
  q=0
  while n>0:
    s+=d*(n%4)
    d*=10
    n=n//4
  return s

n=input()
d=len(n)
if d>3 and n[0:2] in ['11','12','21','22']:
  d-=1
  n='7'*d
ans=0
m=''
for i in range(d):
  x=n[i]
  if x in '12':
    m+='0'
  elif x in '34':
    m+='1'
  elif x in '56':
    m+='2'
  else:
    m+='3'
ans=0
for i in range(1,1+int(m,4)):
  l=[x for x in str(f4(i))]
  l=list(set(l))
  if len(l)==3 and 6==int(l[0])+int(l[1])+int(l[2]):
    ans+=1

print(m,ans)

Submission status: Wrong Answer

Solution code:
def f4(n):
  s=0
  d=1
  q=0
  while n>0:
    s+=d*(n%4)
    d*=10
    n=n//4
  return s

n=input()
d=len(n)
ans=0
m=''
for i in range(d):
  x=n[i]
  if x in '12':
    m+='0'
  elif x in '34':
    m+='1'
  elif x in '56':
    m+='2'
  else:
    m+='3'
ans=0
for i in range(1,1+int(m,4)):
  l=[x for x in str(f4(i))]
  l=list(set(l))
  if len(l)==3 and 6==int(l[0])+int(l[1])+int(l[2]):
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = str(N)
keta = len(n)
# dp[d][smaller][c3][c5][c7] := d桁目まで追加して3, 5, 7だけを含む数字の個数
# c3, c5, c7 : 3, 5, 7がすでに出たかどうか．出ているなら1, 出ていないなら0
# smaller : Nより小さいことが確定している場合は1, 未確定なら0
dp = [[[[[0] * 2 for _ in range(2)] for __ in range(2)] for ___ in range(2)] for ____ in range(keta+1)]
dp[0][0][0][0][0] = 1

# start dp
for d in range(keta):
    now_digit = int(n[d])
    for i in range(10):
        if i == 3:
            if i < now_digit:
                dp[d+1][1][1][0][0] += dp[d][0][1][0][0] + dp[d][0][0][0][0] + dp[d][1][1][0][0] + dp[d][1][0][0][0]
                dp[d+1][1][1][1][0] += dp[d][0][1][1][0] + dp[d][0][0][1][0] + dp[d][1][1][1][0] + dp[d][1][0][1][0]
                dp[d+1][1][1][0][1] += dp[d][0][1][0][1] + dp[d][0][0][0][1] + dp[d][1][1][0][1] + dp[d][1][0][0][1]
                dp[d+1][1][1][1][1] += dp[d][0][1][1][1] + dp[d][0][0][1][1] + dp[d][1][1][1][1] + dp[d][1][0][1][1]
            elif i == now_digit:
                dp[d+1][1][1][0][0] += dp[d][1][1][0][0] + dp[d][1][0][0][0] 
                dp[d+1][1][1][1][0] += dp[d][1][1][1][0] + dp[d][1][0][1][0] 
                dp[d+1][1][1][0][1] += dp[d][1][1][0][1] + dp[d][1][0][0][1] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][0][1][1] 
                
                dp[d+1][0][1][0][0] += dp[d][0][1][0][0] + dp[d][0][0][0][0] 
                dp[d+1][0][1][1][0] += dp[d][0][1][1][0] + dp[d][0][0][1][0] 
                dp[d+1][0][1][0][1] += dp[d][0][1][0][1] + dp[d][0][0][0][1] 
                dp[d+1][0][1][1][1] += dp[d][0][1][1][1] + dp[d][0][0][1][1] 
            else:
                dp[d+1][1][1][0][0] += dp[d][1][1][0][0] + dp[d][1][0][0][0] 
                dp[d+1][1][1][1][0] += dp[d][1][1][1][0] + dp[d][1][0][1][0] 
                dp[d+1][1][1][0][1] += dp[d][1][1][0][1] + dp[d][1][0][0][1] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][0][1][1] 
        elif i == 5:
            if i < now_digit:
                dp[d+1][1][0][1][0] += dp[d][0][0][1][0] + dp[d][0][0][0][0] + dp[d][1][0][1][0] + dp[d][1][0][0][0]
                dp[d+1][1][0][1][1] += dp[d][0][0][1][1] + dp[d][0][0][0][1] + dp[d][1][0][1][1] + dp[d][1][0][0][1]
                dp[d+1][1][1][1][0] += dp[d][0][1][1][0] + dp[d][0][1][0][0] + dp[d][1][1][1][0] + dp[d][1][1][0][0]
                dp[d+1][1][1][1][1] += dp[d][0][1][1][1] + dp[d][0][1][0][1] + dp[d][1][1][1][1] + dp[d][1][1][0][1]
            elif i == now_digit:
                dp[d+1][1][0][1][0] += dp[d][1][0][1][0] + dp[d][1][0][0][0]
                dp[d+1][1][0][1][1] += dp[d][1][0][1][1] + dp[d][1][0][0][1]
                dp[d+1][1][1][1][0] += dp[d][1][1][1][0] + dp[d][1][1][0][0]
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][1][0][1]

                dp[d+1][0][0][1][0] += dp[d][0][0][1][0] + dp[d][0][0][0][0] 
                dp[d+1][0][0][1][1] += dp[d][0][0][1][1] + dp[d][0][0][0][1] 
                dp[d+1][0][1][1][0] += dp[d][0][1][1][0] + dp[d][0][1][0][0] 
                dp[d+1][0][1][1][1] += dp[d][0][1][1][1] + dp[d][0][1][0][1] 
            else:
                dp[d+1][1][0][1][0] += dp[d][1][0][1][0] + dp[d][1][0][0][0] 
                dp[d+1][1][0][1][1] += dp[d][1][0][1][1] + dp[d][1][0][0][1] 
                dp[d+1][1][1][1][0] += dp[d][1][1][1][0] + dp[d][1][1][0][0] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][1][0][1] 
        elif i == 7:
            if i < now_digit:
                dp[d+1][1][0][0][1] += dp[d][0][0][0][1] + dp[d][0][0][0][0] + dp[d][1][0][0][1] + dp[d][1][0][0][0]
                dp[d+1][1][0][1][1] += dp[d][0][0][1][1] + dp[d][0][0][1][0] + dp[d][1][0][1][1] + dp[d][1][0][1][0]
                dp[d+1][1][1][0][1] += dp[d][0][1][0][1] + dp[d][0][1][0][0] + dp[d][1][1][0][1] + dp[d][1][1][0][0]
                dp[d+1][1][1][1][1] += dp[d][0][1][1][1] + dp[d][0][1][1][0] + dp[d][1][1][1][1] + dp[d][1][1][1][0]
            elif i == now_digit:
                dp[d+1][1][0][0][1] += dp[d][1][0][0][1] + dp[d][1][0][0][0] 
                dp[d+1][1][0][1][1] += dp[d][1][0][1][1] + dp[d][1][0][1][0] 
                dp[d+1][1][1][0][1] += dp[d][1][1][0][1] + dp[d][1][1][0][0] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][1][1][0] 
                
                dp[d+1][0][0][0][1] += dp[d][0][0][0][1] + dp[d][0][0][0][0] 
                dp[d+1][0][0][1][1] += dp[d][0][0][1][1] + dp[d][0][0][1][0] 
                dp[d+1][0][1][0][1] += dp[d][0][1][0][1] + dp[d][0][1][0][0] 
                dp[d+1][0][1][1][1] += dp[d][0][1][1][1] + dp[d][0][1][1][0] 
            else:
                dp[d+1][1][0][0][1] += dp[d][1][0][0][1] + dp[d][1][0][0][0] 
                dp[d+1][1][0][1][1] += dp[d][1][0][1][1] + dp[d][1][0][1][0] 
                dp[d+1][1][1][0][1] += dp[d][1][1][0][1] + dp[d][1][1][0][0] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][1][1][0] 
        else:
            pass
##print(dp)
print(dp[-1][1][1][1][1] + dp[-1][0][1][1][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
n = str(N)
keta = len(n)
# dp[d][smaller][c3][c5][c7] := d桁目まで追加して3, 5, 7だけを含む数字の個数
# c3, c5, c7 : 3, 5, 7がすでに出たかどうか．出ているなら1, 出ていないなら0
# smaller : Nより小さいことが確定している場合は1, 未確定なら0
dp = [[[[[0] * 2 for _ in range(2)] for __ in range(2)] for ___ in range(2)] for ____ in range(keta+1)]
dp[0][0][0][0][0] = 1

# start dp
for d in range(keta):
    now_digit = int(n[d])
    for i in range(10):
        if i == 3:
            if i < now_digit:
                dp[d+1][1][1][0][0] += dp[d][0][1][0][0] + dp[d][0][0][0][0] + dp[d][1][1][0][0] + dp[d][1][0][0][0]
                dp[d+1][1][1][1][0] += dp[d][0][1][1][0] + dp[d][0][0][1][0] + dp[d][1][1][1][0] + dp[d][1][0][1][0]
                dp[d+1][1][1][0][1] += dp[d][0][1][0][1] + dp[d][0][0][0][1] + dp[d][1][1][0][1] + dp[d][1][0][0][1]
                dp[d+1][1][1][1][1] += dp[d][0][1][1][1] + dp[d][0][0][1][1] + dp[d][1][1][1][1] + dp[d][1][0][1][1]
            elif i == now_digit:
                dp[d+1][1][1][0][0] += dp[d][1][1][0][0] + dp[d][1][0][0][0] 
                dp[d+1][1][1][1][0] += dp[d][1][1][1][0] + dp[d][1][0][1][0] 
                dp[d+1][1][1][0][1] += dp[d][1][1][0][1] + dp[d][1][0][0][1] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][0][1][1] 
                
                dp[d+1][0][1][0][0] += dp[d][0][1][0][0] + dp[d][0][0][0][0] 
                dp[d+1][0][1][1][0] += dp[d][0][1][1][0] + dp[d][0][0][1][0] 
                dp[d+1][0][1][0][1] += dp[d][0][1][0][1] + dp[d][0][0][0][1] 
                dp[d+1][0][1][1][1] += dp[d][0][1][1][1] + dp[d][0][0][1][1] 
            else:
                dp[d+1][1][1][0][0] += dp[d][1][1][0][0] + dp[d][1][0][0][0] 
                dp[d+1][1][1][1][0] += dp[d][1][1][1][0] + dp[d][1][0][1][0] 
                dp[d+1][1][1][0][1] += dp[d][1][1][0][1] + dp[d][1][0][0][1] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][0][1][1] 
        elif i == 5:
            if i < now_digit:
                dp[d+1][1][0][1][0] += dp[d][0][0][1][0] + dp[d][0][0][0][0] + dp[d][1][0][1][0] + dp[d][1][0][0][0]
                dp[d+1][1][0][1][1] += dp[d][0][0][1][1] + dp[d][0][0][0][1] + dp[d][1][0][1][1] + dp[d][1][0][0][1]
                dp[d+1][1][1][1][0] += dp[d][0][1][1][0] + dp[d][0][1][0][0] + dp[d][1][1][1][0] + dp[d][1][1][0][0]
                dp[d+1][1][1][1][1] += dp[d][0][1][1][1] + dp[d][0][1][0][1] + dp[d][1][1][1][1] + dp[d][1][1][0][1]
            elif i == now_digit:
                dp[d+1][1][0][1][0] += dp[d][1][0][1][0] + dp[d][1][0][0][0]
                dp[d+1][1][0][1][1] += dp[d][1][0][1][1] + dp[d][1][0][0][1]
                dp[d+1][1][1][1][0] += dp[d][1][1][1][0] + dp[d][1][1][0][0]
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][1][0][1]

                dp[d+1][0][0][1][0] += dp[d][0][0][1][0] + dp[d][0][0][0][0] 
                dp[d+1][0][0][1][1] += dp[d][0][0][1][1] + dp[d][0][0][0][1] 
                dp[d+1][0][1][1][0] += dp[d][0][1][1][0] + dp[d][0][1][0][0] 
                dp[d+1][0][1][1][1] += dp[d][0][1][1][1] + dp[d][0][1][0][1] 
            else:
                dp[d+1][1][0][1][0] += dp[d][1][0][1][0] + dp[d][1][0][0][0] 
                dp[d+1][1][0][1][1] += dp[d][1][0][1][1] + dp[d][1][0][0][1] 
                dp[d+1][1][1][1][0] += dp[d][1][1][1][0] + dp[d][1][1][0][0] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][1][0][1] 
        elif i == 7:
            if i < now_digit:
                dp[d+1][1][0][0][1] += dp[d][0][0][0][1] + dp[d][0][0][0][0] + dp[d][1][0][0][1] + dp[d][1][0][0][0]
                dp[d+1][1][0][1][1] += dp[d][0][0][1][1] + dp[d][0][0][1][0] + dp[d][1][0][1][1] + dp[d][1][0][1][0]
                dp[d+1][1][1][0][1] += dp[d][0][1][0][1] + dp[d][0][1][0][0] + dp[d][1][1][0][1] + dp[d][1][1][0][0]
                dp[d+1][1][1][1][1] += dp[d][0][1][1][1] + dp[d][0][1][1][0] + dp[d][1][1][1][1] + dp[d][1][1][1][0]
            elif i == now_digit:
                dp[d+1][1][0][0][1] += dp[d][1][0][0][1] + dp[d][1][0][0][0] 
                dp[d+1][1][0][1][1] += dp[d][1][0][1][1] + dp[d][1][0][1][0] 
                dp[d+1][1][1][0][1] += dp[d][1][1][0][1] + dp[d][1][1][0][0] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][1][1][0] 
                
                dp[d+1][0][0][0][1] += dp[d][0][0][0][1] + dp[d][0][0][0][0] 
                dp[d+1][0][0][1][1] += dp[d][0][0][1][1] + dp[d][0][0][1][0] 
                dp[d+1][0][1][0][1] += dp[d][0][1][0][1] + dp[d][0][1][0][0] 
                dp[d+1][0][1][1][1] += dp[d][0][1][1][1] + dp[d][0][1][1][0] 
            else:
                dp[d+1][1][0][0][1] += dp[d][1][0][0][1] + dp[d][1][0][0][0] 
                dp[d+1][1][0][1][1] += dp[d][1][0][1][1] + dp[d][1][0][1][0] 
                dp[d+1][1][1][0][1] += dp[d][1][1][0][1] + dp[d][1][1][0][0] 
                dp[d+1][1][1][1][1] += dp[d][1][1][1][1] + dp[d][1][1][1][0] 
        else:
            pass
print(dp)
print(dp[-1][1][1][1][1] + dp[-1][0][1][1][1])

Submission status: Wrong Answer

Solution code:
from itertools import product
N = int(input())
strN = str(N)
lenN = len(strN)
num = ['7','5','3']
count = 0
if N < 357:
    print(0)
else:
    for i in range(3,lenN+1):
        for j in product(num,repeat = i):
            num2 = [str(i) for i in j]
            num2 = ''.join(num2)
            if ('7' in num2) and  ('5' in num2) and  ('3' in num2) and int(num2) <= N:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
str_N=input()
list_N=list(map(int,str_N))
N=int(str_N)
k=len(list_N)
ans=0

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

for i in range(k**4+1):
    s_tri=Base_10_to_n(i,4)
    tri=list(map(int,list(s_tri)))
    
    
    num=s_tri.replace("3","7")
    num=num.replace("1","3")
    num=num.replace("2","5")
   
    
    num=int(num)
    
    if num>N:
        break
    
    flg0=True
    flg3=False
    flg5=False
    flg7=False
    for t in tri:
        if t==0:
            flg0=False
        if t==1:
            flg3=True
        if t==2:
            flg5=True
        if t==3:
            flg7=True
            
    if flg0 and flg3 and flg5 and flg7:

        ans+=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product as p
n=input()

ans=0

for j in range(1,len(n)+1):
  for i in p(["3","5","7"],repeat=j):
    s="".join(i)
    t=int(s)
    if "3" in s and "5" in s and "7" in s and t<int(n):
      ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
import sys
import itertools

def solve(N: int):
    LEN = len(str(N))
    if LEN <= 2:
        print(0)
        return

    answer = 0
    for i in range(3,LEN+1):
        for j in list(itertools.product(['3','5','7'], repeat=i)):

            if j.count('3') >= 1 and j.count('5')>=1 and j.count('7') >=1 and int(''.join(j))<=N:
                answer +=1
    return answer
ans = solve(N)
print(ans)

Submission status: Wrong Answer

Solution code:
print("")