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: Accepted

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":
        ret +=dfs(s+c)
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:

n=int(input())



def dfs(s):
    ans=0
    if int(s)>n:
        return 0
    else:
        ans+=all(map(s.count,"357"))
        for i in "357":
            ans+=dfs(s+i)
    return ans
print(dfs("0"))

Submission status: Accepted

Solution code:
import copy

n = input()
a = {'7','5','3'}
for _ in range(len(n)-1):
    b = copy.copy(a)
    for s in a:
        for i in [7,5,3]:
            b.add(s + str(i))
    a = b
a = {i for i in a if not ('3' not in i or '5' not in i or '7' not in i)}

n = int(n)
a = {i for i in a if int(i)<=n}
print(len(a))

Submission status: Accepted

Solution code:
import copy

n = input()
a = {'7','5','3'}
for _ in range(len(n)-1):
    b = copy.copy(a)
    for s in a:
        for i in (7,5,3):
            b.add(s + str(i))
    a = b
a = {i for i in a if not ('3' not in i or '5' not in i or '7' not in i)}

n = int(n)
a = {i for i in a if int(i)<=n}
print(len(a))

Submission status: Accepted

Solution code:
#C-755
#復習課題
n=int(input())
lists=[3,5,7]
def caliculate(n):
    if n==1:
        return lists
    elif n>=2:
        listsed=[0]*(3**n)

        index=0
        x=caliculate(n-1)

        for i in x:
            listsed[index]=10*i+3
            index+=1
            listsed[index]=10*i+5
            index+=1
            listsed[index]=10*i+7
            index+=1
        return listsed
ans=0
for i in range(1,10):
    for some in caliculate(i):
        if all( str(i) in str(some) for i in lists) and some<=n:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ary = '357'
def f(s):
    if int(s) > N:
        return 0
    cnt = 1 if all(s.count(c) > 0 for c in ary) else 0
    for c in ary:
        cnt += f(s + c)
    return cnt
    
print(f("0"))

Submission status: Accepted

Solution code:
import math, itertools

N = int(input())

n_digit = int(math.log10(N))+1

# N = 10**9-1のときでも七五三数は26484個しかないので、これを全て列挙する

# 桁数を渡すと、その桁数の七五三数を返す関数
memo = [-1]*10
def shichigosan(digit):
    if memo[digit] != -1:
        output = memo[digit]
    else:
        output = set(itertools.product([3, 5, 7], repeat=digit))
        tmp = set(itertools.product([3,5], repeat=digit))|set(itertools.product([5,7], repeat=digit))|set(itertools.product([3,7], repeat=digit))
        output -= tmp
        memo[3] = output
        memo[digit] = output
    return output

ans = 0
for i in range(3,n_digit):
    ans += len(shichigosan(i))

ans += len([x for x in shichigosan(n_digit) if int("".join(map(str, x))) <= N])

print(ans)

Submission status: Accepted

Solution code:
def slove():
    import sys
    import itertools
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    ls = list("357")
    cnt = 0
    for i in range(1, 10):
        for v in itertools.product(ls, repeat=i):
            if "3" in v and "5" in v and "7" in v:
                t = int("".join(v))
                if t > n:
                    break
                else:
                    cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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


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':
        ret += dfs(s + c)
    return ret


print(dfs("0"))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

semi = []
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":
		ret += dfs(s + c)
	return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())

numlist=set(['3','5','7'])
for i in range(8):
    numlist2=set()
    for num in numlist:
        numlist2.add('3'+num)
        numlist2.add('5'+num)
        numlist2.add('7'+num)
    numlist = numlist.union(numlist2)
    #print(numlist2)
#print(len(numlist))
def chk753(a):
    c3=0
    c5=0
    c7=0
    for i in range(len(a) ):
        if a[i]=='7':
            c7+=1
        elif a[i] == '5':
            c5+=1
        elif a[i] == '3':
            c3+=1
    if c7>0 and c5>0 and c3>0 :
        return True
    else:
        return False

def chkN(a,N):
    if int(a) <= N:
        return True
    else:
        return False

cnt=0
for t in numlist:
    if chk753(t) and chkN(t,N):
        cnt+=1
        #print(t)

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
n = ("7","5","3")
def dfs(a):
    global ans
    if int(a) > N:
        return 0
    if set(n) == set(a):
        ans += 1
    for i in range(3):
        dfs(a+n[i])

ans = 0
for i in range(3):
    dfs(n[i])
print(ans)

Submission status: Accepted

Solution code:
def rec(s):
    if s and int(s) > n:
        return 0

    res = 0
    if all(c in s for c in '753'):
        res += 1
    for c in '753':
        res += rec(s + c)
    return res


n = int(input())
print(rec(''))

Submission status: Accepted

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":
        ret += dfs(s+c)
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())
count = 0
values = []
def dfs(s):
    if s != '':
        if int(s) > N:
            return None
    values.append(s)
    dfs(s+'3')
    dfs(s+'5')
    dfs(s+'7')
dfs('')
for e in values:
    if '3' in e and '5' in e and '7' in e:
        count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())


def func(s):
    if int(s) > n:
        return 0
    count = 1 if all(s.count(l) for l in "357") else 0
    for l in "357":
        count += func(s+l)
    return count


print(func("0"))

Submission status: Accepted

Solution code:
from collections import deque
s = input()
n = len(s)
s = int(s)
if n<3:
    print(0)
    exit()
nums = deque(['7','5','3'])
kouho= deque()
while nums:
    num = nums.popleft()
    num3 = num+'3'
    num5 = num+'5'
    num7 = num+'7'
    if (3<= len(num3) <= n):
        kouho.append(num3)
        kouho.append(num5)
        kouho.append(num7)
    if len(num3)<n:
        nums.append(num3)
        nums.append(num5)
        nums.append(num7)

ans = 0
while kouho:
    number = kouho.pop()
    if ("3" in number)and("5" in number)and("7" in number):
        if int(number)<=s:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

S = input().rstrip()
N = len(S)

def dfs(num):
    if len(num) == N:
        return 1 if '3' in num and '5' in num and '7' in num and 1 <= int(num) <= int(S) else 0

    ret = 0
    if len(num) == 0 or '3' not in num and '5' not in num and '7' not in num:
        ret += dfs(num+'0')
        ret += dfs(num+'3')
        ret += dfs(num+'5')
        ret += dfs(num+'7')
    else:
        ret += dfs(num+'3')
        ret += dfs(num+'5')
        ret += dfs(num+'7')

    return ret

def main():
    """ main """
    print(dfs(''))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
N_ = input()
N = int(N_) 
n = len(list(N_)) #Nの桁数

#(方針) N<=10**9 だと3,5,7のみを使ってできる数は多くても3**9=2*10**4通りなので全探索
A = ['3','5','7']

ans = 0
if(n >= 3): #桁数が3以上なら
 for i in range(3,n+1):
  Comb = list(itertools.product(A, repeat=i)) #重複組み合わせ
  
  for j in range(len(Comb)):
   tmp = list(Comb[j])
   #print(tmp) #########
   judge = 1 #条件を満たす数: 1,満たさない数: 0
    
   #選んだ数がN以下かの判定
   tmp_num = ''
   for k in range(len(tmp)):
     tmp_num += tmp[k]
   tmp_num = int(tmp_num)
   if(tmp_num > N):
      judge = 0
   #print(tmp_num) #########
    
   #選んだ数が3,5,7を1回以上含むかの判定
   three,five,seven = 0,0,0
   for k in range(len(tmp)):
     if(tmp[k]=='3'): three += 1
     elif(tmp[k]=='5'): five += 1
     elif(tmp[k]=='7'): seven += 1
   if(three*five*seven == 0): #どれか1つでも0なら積は0
    judge = 0
   
   #条件をみたすならカウント+1 
   if(judge == 1): ans += 1

print(ans)

Submission status: Accepted

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':
        ret += dfs(s+c)
    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs("0"))

Submission status: Accepted

Solution code:
n=int(input())

def ju(n):
    l=list(str(n))
    j=[0]*3
    f=0
    for i in range(len(l)):
        if l[i]=='3':
            j[0]=1
        elif l[i]=='5':
            j[1]=1
        elif l[i]=='7':
            j[2]=1
        else:
            f=1
    if sum(j)==3 and f==0:
        return 1
    else:
        return 0

zenbu=[3,5,7]

for i in range(8):
    tmp=[]
    for j in zenbu:
        tmp.append(j+3*(10**(i+1)))
        tmp.append(j+5*(10**(i+1)))
        tmp.append(j+7*(10**(i+1)))
        tmp.append(j)
    zenbu=tmp
  
ans=0
for i in zenbu:
    if i<=n and ju(i)==1:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
def shime(s):
    if int(s) > N:
        return 0
    if '7' in s and '5' in s and '3' in s:
        tmp = 1
    else:
        tmp = 0
    tmp += shime(s+'7')
    tmp += shime(s+'5')
    tmp += shime(s+'3')
    return tmp
print(shime('0'))

Submission status: Accepted

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':
        ret += dfs(s+c)
    return ret
print(dfs('0'))

Submission status: Accepted

Solution code:
import math
n = int(input())
keta = int(math.log10(n))+1

num_list = []

def append_number(n):
    numbers = []
    for s in [3,5,7]:
        numbers.append(str(n)+str(s))
    return numbers

def make_numbers(n_list,keta):
    if keta == 0:
        return n_list
    else:
        append_numbers = []
        for n in n_list:
            for s in append_number(n):
                append_numbers.append(s)
            num_list.append(n)
        return(make_numbers(append_numbers,keta-1))

make_numbers(["3","5","7"],keta)

ans = 0
for i in num_list:
    if int(i) <= n and ("3" in i) and ("5" in i) and ("7" in i):
        ans += 1
print(ans)

Submission status: Accepted

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 '357') else 0
    for c in '357':
        ret += dfs(s + c)
    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
import sys

n = int(input())
sys.setrecursionlimit(2*10**9+1)


def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))

Submission status: Accepted

Solution code:
n = int(input())

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

print(dfs("0"))

Submission status: Accepted

Solution code:
def judge(x):
  a=0
  b=0
  c=0
  d=len(x)
  for i in range(d):
    if x[i]=='3':
      a=1
    elif x[i]=='5':
      b=1
    else:
      c=1
      
  if a+b+c==3:
    return True
  else:
    return False

N=int(input())

nums=[['3', '5', '7']]
for i in range(8):
  temp=[]
  lastnums=nums[-1]
  for j in lastnums:
    temp+=[j+'3', j+'5', j+'7']
    
  nums.append(temp)
  
counter=0
nums=nums[2:]
for i in nums:
  for j in i:
    if int(j)<=N and judge(j)==True:
      counter+=1
      
print(counter)

Submission status: Accepted

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


def main():
    N = input()[:-1]

    cnt = 0
    for i in range(1, len(N)+1):
        for C in itertools.product(['7','5','3'], repeat=i):
            if ('7' not in C) or ('5' not in C) or ('3' not in C):
                continue
            M = ''.join(C)
            if int(M)<=int(N):
                cnt += 1
    
    print(cnt)
        


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())

l=[3,5,7]
l_ans=[]
l_ans+=l

if N<357:
    print(0)
else:
    for i in range(8):
        temp=[]
        for item in l:
            temp.append(item+3*10**(i+1))
            temp.append(item+5*10**(i+1))
            temp.append(item+7*10**(i+1))
        l.clear()
        l+=temp
        l_ans+=temp
    l_ans.sort()
    
    count=0
    for i in range(len(l_ans)):
        if l_ans[i]>N:
            break
        elif  ("3" in str(l_ans[i]) and "5" in str(l_ans[i]) and "7" in str(l_ans[i]))==False:
            pass
        else:
            count+=1
            
    print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
symbols = list("357")

def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in symbols) else 0
    for c in symbols:
        ret += dfs(s + c)
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s): # 文字列sで始まる七五三数の個数
    if int(s) > N: # s>Nなら個数は当然0
        return(0)
    else:
        if s.count('7') > 0 and s.count('5') > 0 and s.count('3') > 0: # s自体が七五三数なら+1
            num = 1
        else:
            num = 0
        for c in '753': # sに7,5,3をそれぞれ後ろからくっつける
            num += dfs(s + c)
        return(num)

print(dfs('0')) # 0が先頭にくっつくが特に影響はない

Submission status: Accepted

Solution code:
n = int(input())
global count
count = 0
def dfs(s):
    if int(s) > n:
        return 0
    if set(list(s[1:])) == {'3','5','7'}:
        global count
        count += 1
    for i in '753':
        dfs(s + i)
dfs('0')
print(count)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
numbers=0
uselists=[]
for j in itertools.product(["3","5","7"],repeat=len(str(n))):
        s="".join(j)
        uselists.append(s) 

for _ in uselists:
    if int(_)<=n and len(set(_))>=3:
        numbers+=1
        
        
    else:
        continue
        
listss=[0, 0, 0, 6, 36, 150, 540, 1806, 5796, 18150]
for x in range(len(str(n))):
    numbers+=listss[x]
print(numbers)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
s = input()
L = len(s)
N = int(s)
ls = [3, 5, 7]
dic = defaultdict(int)
def dfs(s):
  if len(s)<L:
    return dfs(s+'3')+dfs(s+'5')+dfs(s+'7')+dfs('0'+s)
  if (not '3' in s) or(not '5' in s) or(not '7' in s):
    return 0
  if int(s)<=N and dic[s]==0:
    dic[s]=1
    return 1
  else:
    return 0
print(dfs(''))

Submission status: Accepted

Solution code:
import itertools

def test():
    n = input()
    N = int(n)
    ans = 0
    for i in range(1,len(n)+1):
        for j in itertools.product(["3","5","7"],repeat=i):
            s="".join(j)
            v = int(s)
            if "3" in s and "5" in s and "7" in s and v <= N:
                ans += 1
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
ans = 0
if N <= 2:
  print(0)
  exit()
  
for i in range(3, len(str(N))+1):
  for num in list(product('735',repeat=i)):
    if int(''.join(num)) <= N and '7' in num and '5' in num and '3' in num:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

N = INT()

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':
        ret += dfs(s + c)
    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    def dfs(s):
        if int(s)>n: return 0
        res=int(all(s.count(c)>=1 for c in "753"))
        for c in "753":
            res+=dfs(s+c)
        return res
    print(dfs('0'))
resolve()

Submission status: Accepted

Solution code:
N = int(input())

def dfs(num):
    if int(num) > N:
        return 0
    ret = 1 if all(num.count(c) > 0 for c in '753') else 0

    for c in '753':
        ret += dfs(num + c)
    return ret


print(dfs('0'))

Submission status: Accepted

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(input())

def dfs(X, bit, count):
    if bit == 7:
        if X <= N:
            count += 1

    if X >= N:
        return count


    count = dfs(X*10+7, bit|4, count)
    count = dfs(X*10+5, bit|2, count)
    count = dfs(X*10+3, bit|1, count)

    return count


count = dfs(0, 0, 0)
print(count)

Submission status: Accepted

Solution code:
# ABC114c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
okForm = set((3, 5, 7))
memo = dict()


def create(cn, nn):
    if memo.get((cn, nn)) != None:
        return memo[(cn, nn)]
    num = int(str(nn)+str(cn))
    if (num > n):
        return 0
    ans = 1 if set(map(int, list(str(num)))) == okForm else 0
    #print(num, cn, nn)
    ans += create(num, 3) + create(num, 5) + create(num, 7)
    memo[(cn, nn)] = ans
    return ans


print(create('', 3)+create('', 5)+create('', 7))

Submission status: Accepted

Solution code:
import itertools as it
import collections as col
import heapq
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N=input()

D=set()
for n in range(1,10):
    for d in it.product(['3','5','7'],repeat=n):
        x=0
        for i in range(n):
            x += (10**i)*int(d[n-i-1])
        if (x <= int(N) and '3' in d and '5' in d and '7' in d):
            D.add(x)
#print(N)
print(len(D))
#print(3*(1-3**9)//(1-3))

Submission status: Accepted

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

def dfs(x, a, b, c):
    global ans
    if x > N:
        return
    if (a & b & c):
        ans += 1
    dfs(10 * x + 3, 1, b, c)
    dfs(10 * x + 5, a, 1, c)
    dfs(10 * x + 7, a, b, 1)

dfs(0, 0, 0, 0)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
def sgs(s):
    if n < int(s):
        return 0
    ret = 1 if all(s.count(i) > 0 for i in '357') else 0
    for i in '357':
        ret += sgs(s + i)
    return ret
print(sgs('0'))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
sys.setrecursionlimit(10**6)

def check(n,a,b,c,t,l):
    tmp = 0
    if len(n) > l:
        return 0
    if n == "":
        return check(n+"3",a+1,b,c,t,l) + check(n+"5",a,b+1,c,t,l) + check(n+"7",a,b,c+1,t,l) + tmp
    if a and b and c and int(n) <= t:
        tmp = 1
    return check(n+"3",a+1,b,c,t,l) + check(n+"5",a,b+1,c,t,l) + check(n+"7",a,b,c+1,t,l) + tmp

def main():
    N = int(input())
    l = len(str(N))
    print(check("",0,0,0,N,l))

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def fn(x):
    global ans
    if int(x) > N:
        return
    if all(x.count(i) for i in '753'):
        ans += 1
    for i in '753':
        fn(x + i)


fn('0')
print(ans)

Submission status: Accepted

Solution code:
N = input()
L = len(N)

dp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
pp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
dp[0][0][0][0] = 1

for i in range(L):
    pp, dp = dp, pp
    dp = [[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
    n = int(N[i])
    dp[0][0][0][1] += pp[0][0][0][1]
    dp[1][0][0][1] += pp[0][0][0][1] + pp[1][0][0][1]
    dp[0][1][0][1] += pp[0][0][0][1] + pp[0][1][0][1]
    dp[0][0][1][1] += pp[0][0][0][1] + pp[0][0][1][1]
    dp[1][1][0][1] += pp[1][0][0][1] + pp[0][1][0][1] + pp[1][1][0][1] * 2
    dp[1][0][1][1] += pp[1][0][0][1] + pp[0][0][1][1] + pp[1][0][1][1] * 2
    dp[0][1][1][1] += pp[0][1][0][1] + pp[0][0][1][1] + pp[0][1][1][1] * 2
    dp[1][1][1][1] += pp[1][1][0][1] + pp[1][0][1][1] + pp[0][1][1][1] + pp[1][1][1][1] * 3
    if n > 0:
        dp[0][0][0][1] += pp[0][0][0][0]
    if n > 3:
        dp[1][0][0][1] += pp[1][0][0][0] + pp[0][0][0][0]
        dp[1][1][0][1] += pp[1][1][0][0] + pp[0][1][0][0]
        dp[1][0][1][1] += pp[1][0][1][0] + pp[0][0][1][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[0][1][1][0]
    if n > 5:
        dp[0][1][0][1] += pp[0][1][0][0] + pp[0][0][0][0]
        dp[1][1][0][1] += pp[1][1][0][0] + pp[1][0][0][0]
        dp[0][1][1][1] += pp[0][1][1][0] + pp[0][0][1][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[1][0][1][0]
    if n > 7:
        dp[0][0][1][1] += pp[0][0][1][0] + pp[0][0][0][0]
        dp[1][0][1][1] += pp[1][0][1][0] + pp[1][0][0][0]
        dp[0][1][1][1] += pp[0][1][1][0] + pp[0][1][0][0]
        dp[1][1][1][1] += pp[1][1][1][0] + pp[1][1][0][0]
    if n == 0:
        dp[0][0][0][0] += pp[0][0][0][0]
    if n == 3:
        dp[1][0][0][0] += pp[1][0][0][0] + pp[0][0][0][0]
        dp[1][1][0][0] += pp[1][1][0][0] + pp[0][1][0][0]
        dp[1][0][1][0] += pp[1][0][1][0] + pp[0][0][1][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[0][1][1][0]
    if n == 5:
        dp[0][1][0][0] += pp[0][1][0][0] + pp[0][0][0][0]
        dp[1][1][0][0] += pp[1][1][0][0] + pp[1][0][0][0]
        dp[0][1][1][0] += pp[0][1][1][0] + pp[0][0][1][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[1][0][1][0]
    if n == 7:
        dp[0][0][1][0] += pp[0][0][1][0] + pp[0][0][0][0]
        dp[1][0][1][0] += pp[1][0][1][0] + pp[1][0][0][0]
        dp[0][1][1][0] += pp[0][1][1][0] + pp[0][1][0][0]
        dp[1][1][1][0] += pp[1][1][1][0] + pp[1][1][0][0]


print(sum(dp[1][1][1]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())


def dfs(s):
    # 上限を超えない範囲で再帰する
    if int(s) > n:
        return 0
    # s自身が条件を満たすか確認
    ret = 1 if all(s.count(c) > 0 for c in '357') else 0
    # 1文字増やして再帰
    for c in '357':
        ret += dfs(s + c)
    return ret


print(dfs('0'))

Submission status: Accepted

Solution code:
import copy

N=int(input())

tmp0=[]
tmp1=[3,5,7]
res=[3,5,7]
for i in range(1,9):
  for j in tmp1:
    for k in [3,5,7]:
      res.append(j*10+k)
      tmp0.append(j*10+k)
  tmp1=copy.deepcopy(tmp0)
  tmp0=[]

res2=[]
for i in res:
  if len(set(str(i)))==3:
    res2.append(i)
#print(res2)

ans=0
for i in res2:
  if i<=N:
    ans+=1
print(ans)

Submission status: Accepted

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':
    ret += dfs(s + c)
  return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
  if int(s) > N:
    return 0
  ret = 0
  if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
    ret = 1
  ret += dfs(s+'3') + dfs(s+'5') + dfs(s+'7')
  return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())
b = []

def seve(a):
    a = int(a)
    if a > N:
        return len(b)
    else:
        a = str(a)
        if a.count('3') >= 1 and a.count('5') >= 1 and a.count('7') >= 1:
            b.append(a)
        return seve(a+'3') + seve(a+'5') + seve(a+'7')

seve('7')
seve('5')
seve('3')
print(len(b))

Submission status: Accepted

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":
    ret += dfs(s+c)
  return ret
print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for d in range(1, 11):
    for i in range(3 ** d):
        x = 0
        for j in range(d):
            x += [3, 5, 7][i%3] * 10 ** j
            i = i // 3
        if x > N:
            break
        if len(set(str(x))) == 3:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product
import bisect
N=int(input())
A=[]
for n in range(3,len(str(N))+1):
    for s in product([3,5,7], repeat=n):
        if '3' in ''.join(map(str, s)) and '5' in ''.join(map(str, s)) and '7' in ''.join(map(str, s)):
            A.append(int(''.join(map(str, s))))
print(bisect.bisect_right(A,N))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

N=input()
A=[]
def func(d,n,t):
	if d==t:
		return
	for i in [3,5,7]:
		A.append(10*n+i)
		func(d+1, 10*n+i,t)
func(0,0,len(N))


ans=0
for a in A:
	a_str=str(a)
	if '3' in a_str and '5' in a_str and '7' in a_str and a<=int(N):
		ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
def aaa(n):
    if int(n) > N:
        return 0
    ans = 1 if set(str(int(n))) == {'7', '5', '3'} else 0
    for i in '753':
        ans += aaa(n+i)
    return ans
print(aaa('0'))

Submission status: Accepted

Solution code:
import math
from itertools import product

N = int(input())
if N <= 356:
    print(0)
    exit()
c = 0
for keta in range(3, int(math.log(N, 10)) + 2):
    for t in product("753", repeat=keta):
        if int("".join(t)) <= N and len(set(t)) == 3:
            c += 1
print(c)

Submission status: Accepted

Solution code:
n = int(input())

count = 0


def dfs(i, s):
    global count
    if i > 10:
        return

    ok = True
    for c in ['3', '5', '7']:
        if c not in s:
            ok = False
    if ok and int(s) <= n:
        count += 1

    for c in ['3', '5', '7']:
        dfs(i + 1, s + c)


dfs(0, '')
print(count)

Submission status: Accepted

Solution code:
from itertools import product
import math

n = int(input())
ss = []

for i in range(3, 10):
    for per in product('357', repeat=i):
        if '3' in per and '5' in per and '7' in per:
            ss.append(int(''.join(per)))

ss.append(1000000000)
i = 0
while True:
    if ss[i] > n:
        print(i)
        break
    i += 1

Submission status: Accepted

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

def f(target):
    for i in '753':
        targetJoin = str(target) + str(i)
        
        if int(targetJoin) > N:
            continue

        if  '7' in targetJoin and '5' in targetJoin and '3' in targetJoin :
            
            flag = True
            if '0' in targetJoin:
                flag = False
            if '1' in targetJoin:
                flag = False
            if '2' in targetJoin:
                flag = False
            if '4' in targetJoin:
                flag = False
            if '6' in targetJoin:
                flag = False
            if '8' in targetJoin:
                flag = False
            if '9' in targetJoin:
                flag = False
            
            if flag :
                global ans
                ans+=1
                
        f(targetJoin)
        
f(3)
f(5)
f(7)
print(ans)

Submission status: Accepted

Solution code:
from itertools import*
n=input()
print(sum(sum(2<len(set(a))and int("".join(a))<=int(n)for a in product("357",repeat=l))for l in range(len(n)+1)))

Submission status: Accepted

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

N=int(input())

def keta(x):
    a = 0
    while x>0:
        x//=10
        a+=1
    return a

N_keta = keta(N)

ans=0

for i in range(3,N_keta+1):
    for j in range(3**i):
        s=""
        tmp=j
        f0=False
        f1=False
        f2=False
        for k in range(i):
            r=tmp%3
            if r==0:
                f0=True
                s+="7"
            elif r==1:
                f1=True
                s+="5"
            else:
                f2=True
                s+="3"
            tmp//=3
        if f0 and f1 and f2 and N >= int(s):
            ans+=1
print(ans)

Submission status: Accepted

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

import math

N=int(input())

def keta(x):
    a = 0
    while x>0:
        x//=10
        a+=1
    return a

N_keta = keta(N)

ans=0
for i in range(3**N_keta):
    s=""
    tmp=i
    f0=False
    f1=False
    f2=False
    for j in range(N_keta):
        r=tmp%3
        if r==0:
            f0=True
            s+="7"
        elif r==1:
            f1=True
            s+="5"
        else:
            f2=True
            s+="3"
        tmp//=3
    if f0 and f1 and f2 and N >= int(s):
        ans+=1

for i in range(3,N_keta):
    for j in range(3**i):
        s=""
        tmp=j
        f0=False
        f1=False
        f2=False
        for k in range(i):
            r=tmp%3
            if r==0:
                f0=True
                s+="7"
            elif r==1:
                f1=True
                s+="5"
            else:
                f2=True
                s+="3"
            tmp//=3
        if f0 and f1 and f2:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
r = 0
for d in range(1, 11):
  for i in range(3**d):
    x = 0
    for j in range(d):
      x += [3, 5, 7][i%3]*10**j
      i = i//3
    if x > N:
      break
    if len(set(str(x))) == 3:
      #print(x)
      r += 1
print(r)

Submission status: Accepted

Solution code:
n=int(input())
def dsf(s):
  if int(s)>n:
    return 0
  else:
    if all(s.count(c)>0 for c in "753"):
      x=1
    else:
      x=0
    for c in "753":
      x+=dsf(s+c)
    return x
print(dsf("0"))