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:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def n_based(n:int, base:int) -> str:
    if n == 0:
        return "0"
    
    ans = ""
    res = n
    
    while abs(res) > 0:
        q = res%base
        if q>=0:
            ans = str(q) + ans
            res //= base
        else:
            q += abs(base)
            ans = str(q) + ans
            res //= base
            res += 1
        
    return ans

stf = ["7","5","3"]
n = ni()

ans = 0
for pw in range(3,11):
    for i in range(3**pw):
        s = str(n_based(i,3)).zfill(pw)
        num = ""
        for i in range(pw):
            num += stf[int(s[i])]
            
        if int(num) <= n and ("3" in num and "5" in num and "7" in num):
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())

num_753 = [7,5,3]
anslist = []

keta = len(str(N))
for i in range(3, keta+ 1):
    tmp = list(itertools.product(num_753, repeat=i))
    for item in tmp:
        item = list(item)
        item = map(str, item)
        item = "".join(item)
        anslist.append(int(item))

anslist = [s for s in anslist if s <= N]
anslist.sort()

anslist2 = []

for ans in anslist:
    tmp = str(ans)
    if "3" not in tmp:
        continue
    elif "5" not in tmp:
        continue
    elif "7" not in tmp:
        continue
    else:
        anslist2.append(tmp)

# print(anslist2)a
print(len(anslist2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools
N = input()
Nlen = len(N)
N = int(N)
l = ["3","5","7"]

ans = 0
for k in range(3,Nlen+1):
    for cs in itertools.product(l,repeat=k):
        tmp_num = ""
        for i, c in enumerate(cs):
            tmp_num = c + tmp_num

        if tmp_num.count("3") == 0 or tmp_num.count("5") == 0 or tmp_num.count("7") == 0:
            continue

        if int(tmp_num) <= N:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())

ans = 0
for i in range(3, 10):
    for ss in product('357', repeat=i):
        if len(set(ss)) < 3: continue
        k = int(''.join(ss))
        if k > N: break
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import itertools
n=int(input())


r=0
k=len(str(n))
for j in range(3,k+1):
  l=('3', '5', '7' )
  for i in itertools.product(l, repeat=j):
    if not ( '3' in i and '5' in i and '7' in i):
      continue
    x=int(''.join(map(str,i)))
    if x > n:
      break
    r=r+1
print(r)

Submission status: Accepted

Solution code:
def c_755(N):
    from itertools import product
    is_upper = False
    ans = 0
    for digit in range(3, 10):
        for s in product('357', repeat=digit):
            s = ''.join(s)
            if s.count('3') == 0 or s.count('5') == 0 or s.count('7') == 0:
                continue
            if int(s) <= N:
                ans += 1
    return ans

N = int(input())
print(c_755(N))

Submission status: Accepted

Solution code:
from itertools import product


def main():
    N = int(input())
    L = len(str(N))
    result = 0
    if N < 357:
        print(0)
        return

    for i in range(3, L+1):
        for p in product("357", repeat=i):
            c = [p.count(i) for i in ("3", "5", "7")]
            x = int("".join(p))
            if x > N:
                break
            if all(c):
                result += 1

    print(result)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
ans = 0
for k in range(3,11):
    for i in product([0,3,5,7],repeat=k):
        if set(i) != {3,5,7}:
            continue
        if sum([10**j*v for j,v  in enumerate(i)]) <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
cnt = 0
S = ''
Q = [[0, 0, 0, S]]
while Q:
  q0 = Q[0]
  Q = Q[1:]
  for i, s in enumerate(['3', '5', '7']):
    q = [q for q in q0]
    q[i] += 1
    q[3] += s
    if int(q[3]) <= N:
      Q.append(q)
      if q[0] and q[1] and q[2]:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

def f(xs):
    res = 0
    for i in xs:
        res = 10 * res + i
    return res

def dfs(xs):
    ans = 1 if f(xs) <= n and 3 in xs and 5 in xs and 7 in xs else 0
    if len(xs) == 9:
        return ans
    for i in [3,5,7]:
        xs.append(i)
        ans += dfs(xs)
        xs.pop(-1)
    return ans

print(dfs([]))

Submission status: Accepted

Solution code:
import itertools
import collections

def check(itr_list,N):
    tmp = collections.Counter(itr_list)
    if tmp[3] > 0 and tmp[5] > 0 and tmp[7] > 0:
        s_N = ''
        for i in itr_list:
            s_N += str(i)
        if int(s_N) <= N:
            return True

    return False


S = input()
N = int(S)

tmp = [7,5,3]
ans = 0

for keta in range(3,len(S)+1):
    itr = []
    itr = list(itertools.product(tmp, repeat=keta))

    for i in itr:
        if check(i,N):
#            print(i)
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools


N = int(input())
L = [int(''.join(l)) for i in range(3, 10) for l in list(itertools.product(['3', '5', '7'], repeat=i)) if '3' in l and '5' in l and '7' in l]
L = [l for l in L if l <= N]

print(len(L))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    retval = 0
    expected = set([3, 5, 7])
    stack = [(0, set())]
    while len(stack):
        current, used = stack.pop()
        if current <= N and used == expected:
            retval += 1
        for i in [3, 5, 7]:
            next_val = current * 10 + i
            if next_val > N:
                continue
            next_used = set(used)
            next_used.add(i)
            stack.append((next_val, next_used))
    print(retval)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# encoding: utf-8
N = int(input())

def count(pos, val, stat):
    ret = 0
    for i, num in enumerate([3, 5, 7]):
        if val + num * (10 ** pos) <= N: # oh...
            stat_tmp = stat | (1 << i)
            if stat_tmp == 7: ret += count(pos + 1, val + num * (10 ** pos), stat_tmp) + 1
            else: ret += count(pos + 1, val + num * (10 ** pos), stat_tmp)
        else: break
    return ret

print(count(0, 0, 0))

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())
num_digits = len(str(N))

num_shichigosans = 0
for d in range(3, num_digits):
    for num_string in product(["3", "5", "7"], repeat=d):
        if len(set(num_string)) < 3:
            continue
        num_shichigosans += 1

for num_string in product(["3", "5", "7"], repeat=num_digits):
    if len(set(num_string)) < 3:
        continue
    num = int("".join(num_string))
    if num <= N:
        num_shichigosans += 1
print(num_shichigosans)

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
q = deque()
q.append('')
res = set()
while q:
    m = q.popleft()
    for c in '357':
        if int(m+c) > n: continue
        q.append(m+c)
    for c in '357':
        if c not in m: break
    else:
        res.add(m)
print(len(res))

Submission status: Accepted

Solution code:
from itertools import product as p
n=input()
N=int(n)
ans=0

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
ans = 0
for k in range(3,len(str(N))+1):
    for ptn in itertools.product((3,5,7), repeat=k):
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
            continue
        a = int(''.join(list(map(str,ptn))))
        if a <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())

nums = []
for comb in product(['0', '7', '5', '3'], repeat=9):
    candidate = str(int(''.join(comb)))
    if all((x in candidate) for x in ['7', '5', '3']) \
       and '0' not in candidate:
        nums.append(int(candidate))
nums.sort()

ans = 0
for n in nums:
    if n <= N:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:

def main():
    buf = input()
    N = int(buf)
    table = []
    for i in range(1, 10):
        create_table("", 0, i, table)
    count = 0
    for i in table:
        if i <= N:
            count += 1
        else:
            break
    print(count)

def create_table(num, current_digit, maximum_digit, table):
    if current_digit < maximum_digit:
        create_table(num + "3", current_digit + 1, maximum_digit, table)
        create_table(num + "5", current_digit + 1, maximum_digit, table)
        create_table(num + "7", current_digit + 1, maximum_digit, table)
    else:
        appearance = [0, 0, 0]
        for _, x in enumerate(num):
            if x == "3":
                appearance[0] += 1
            elif x == "5":
                appearance[1] += 1
            elif x == "7":
                appearance[2] += 1
            else:
                return
        if min(appearance) >= 1:
            table.append(int(num))
        return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        print(*args,  file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, = getIntList()
#print(N)
re = 0
def check(now, d):
    global re
    if now >N: return
    if d[0]>0 and d[1]>0 and d[2]>0:
        re+=1
    now*=10
    d[0]+=1
    check( now+ 7, d)
    d[0]-=1
    d[1]+=1
    check( now+ 5, d)
    d[1]-=1
    d[2]+=1
    check( now+ 3, d)
    d[2]-=1
check(0, [0,0,0])    
print(re)

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())
P = []

for i in range(len(str(N))):
    P += list(product(["7", "5", "3"], repeat=i + 1))

ans = 0
for p in P:
    if ("7" not in p) or ("5" not in p) or ("3" not in p):
        continue
    else:
        p = int("".join(p))
        ans += (p <= N)

print(ans)

Submission status: Accepted

Solution code:
import itertools
ans=0
N=int(input())
for K in range(1,10):
    S=itertools.product(["3","5","7"],repeat=K)
    for seq in S:
        X=set()
        for i in seq:
            X.add(i)
        if len(X)!=3:
            continue
        T="".join(seq)
        if 1<=int(T)<=N:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    l = len(str(n))
    r = 0
    for i in range(3,l+1):
        for a in itertools.product(['3','5','7'], repeat=i):
            if '3' not in a or '5' not in a or '7' not in a:
                continue
            if i < l:
                r += 1
                continue
            t = int(''.join(a))
            if t <= n:
                r += 1

    return r


print(main())

Submission status: Accepted

Solution code:
from itertools import product

N = input()
ans = 0
for i in range(3,10):
  for b in product("753", repeat=i):
    if int("".join(b))<=N and "7" in b and "5" in b and "3" in b:
      ans += 1
print ans

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

ct = 0
for d in range(1,10):
    for i in range(3**d):
        k = i
        v = 0
        ptn = 0
        for j in range(d):
            if k % 3 == 0:
                v = v * 10 + 3
                ptn |= 1
            elif k % 3 == 1:
                v = v * 10 + 5
                ptn |= 2
            else:
                v = v * 10 + 7
                ptn |= 4
            k //= 3
        if v <= n and ptn == 7:
            ct += 1
print(ct)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)
N = input()
N_len = len(N)
'''
75333
'''


# t = []


def dfs(a, depth):
    if depth == N_len:
        if int(a) <= int(N) and a.count('3') > 0 \
                and a.count('5') > 0 and a.count('7') > 0 and str(int(a)).count('0') == 0:
            t.append(a)
            return 1
        else:
            return 0

    ret1 = dfs(a + '0', depth + 1)
    ret2 = dfs(a + '3', depth + 1)
    ret3 = dfs(a + '5', depth + 1)
    ret4 = dfs(a + '7', depth + 1)
    return ret1 + ret2 + ret3 + ret4


ans = dfs('', 0)
print(ans)
# print(t)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
N = input()
N_len = len(N)
'''
75333
'''


# t = []


def dfs(a, depth):
    if depth == N_len:
        if int(a) <= int(N) and a.count('3') > 0 \
                and a.count('5') > 0 and a.count('7') > 0 and str(int(a)).count('0') == 0:
            t.append(a)
            return 1
        else:
            return 0

    ret1 = dfs(a + '0', depth + 1)
    ret2 = dfs(a + '3', depth + 1)
    ret3 = dfs(a + '5', depth + 1)
    ret4 = dfs(a + '7', depth + 1)
    return ret1 + ret2 + ret3 + ret4


ans = dfs('', 0)
print(ans)
# print(t)

Submission status: Runtime Error

Solution code:
n = input()
from itertools import product
from collectins import Counter
sum = 0
for i in range(len(n)-2):
  for j in list(product("753", repeat=i+3)):
    if int(''.join(j)) <= int(n) and len(Counter(j))==3:
      sum+=1
print(sum)

Submission status: Runtime Error

Solution code:
n = input()
from itertools import product
from collectins import Counter
sum = 0
for i in range(len(n)-2):
  for j in product("753", repeat=i+3):
    if int(''.join(j)) <= int(n) and len(Counter(j))==3:
      sum+=1
print(sum)

Submission status: Runtime Error

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
from decorator import stop_watch


@stop_watch
def solve(N):
    dq = deque([(3, [1, 0, 0]), (5, [0, 1, 0]), (7, [0, 0, 1])])
    ans = 0
    while dq:
        num, check = dq.popleft()
        if num > N:
            break
        if sum(check) == 3:
            ans += 1
        for i in (3, 5, 7):
            new_num = num * 10 + i
            if new_num > N:
                break
            new_check = check.copy()
            if i == 3:
                new_check[0] = 1
            elif i == 5:
                new_check[1] = 1
            elif i == 7:
                new_check[2] = 1
            dq.append((new_num, new_check))
    print(ans)


if __name__ == '__main__':
    N = int(input())
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
count = 0
for i in range(3, len(str(N)) + 1):
    for j in itertools.product('753', repeat=i):
        if int(''.join(j)) =< N and '3' in str(j) and '5'in str(j) and '7' in str(j):
            count += 1

print(count)

Submission status: Runtime Error

Solution code:
N = int(f.input())
count = 0

for i in range(len(str(N))):
    for j in range(3 * (10**i), 4 * (10**i)):
        if j > N:
            break
        if '0' not in str(j) and '1' not in str(j) and '2' not in str(j) and '4' not in str(j) and '6' not in str(
                j) and '8' not in str(j) and '9' not in str(j) and('7' in str(j) and '5' in str(j) and '3' in str(j)):
            print(j)
            count += 1
    for j in range(5 * (10**i), 6 * (10**i)):
        if j > N:
            break

        if '0' not in str(j) and '1' not in str(j) and '2' not in str(j) and '4' not in str(j) and '6' not in str(
                j) and '8' not in str(j) and '9' not in str(j) and('7' in str(j) and '5' in str(j) and '3' in str(j)):
            print(j)
            count += 1

    for j in range(7 * (10**i), 8 * (10**i)):
        if j > N:
            break
        if '0' not in str(j) and '1' not in str(j) and '2' not in str(j) and '4' not in str(j) and '6' not in str(
                j) and '8' not in str(j) and '9' not in str(j) and('7' in str(j) and '5' in str(j) and '3' in str(j)):
            print(j)
            count += 1
    else:
        continue
    break

print(count)

Submission status: Runtime Error

Solution code:
from itertools import product

n = input()

if int(n) < 100:
    print(0)

else:
    ans = 0

    for i in range(3,len(n)+1):
        s = list(product("753",repeat=i))
        for combi in s:
            n_s = "".join(combi)
            if int(n_s) > int(n):
                continue
            if ("7" in combi) and ("5" in combi) and ("3" in combi):
                ans += 1
    
	print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product

n = input()

if int(n) < 100:
    print(0)

else:
    ans = 0

    for i in range(3,len(n)+1):
        s = list(product("753",repeat=i))
        for combi in s:
            n_s = "".join(combi)
            if int(n_s) > int(n):
                continue
            if ("7" in combi) and ("5" in combi) and ("3" in combi):
                ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000)
def dfs(i, s):
    if i == n:
        return s
    else:
        f = [False for _ in range(4)]
        f[3] = True
        for j in list(str(i)):
            if j == '7':
                f[0] = True
            elif j == '5':
                f[1] = True
            elif j == '3':
                f[2] = True
            else:
                f[3] = False
                break
        if all(f):
            s += 1
        return dfs(i+1, s)
n = int(input())
ans = 0
print(dfs(0, 0))

Submission status: Runtime Error

Solution code:
n=int(input())
tmp=2
ans=0
Flag=True
while Flag:
    tmp+=1
    iterator=product(range(3),repeat=tmp)
    for idxs in iterator:
        num=''.join(map(str,idxs))
        num753=str(num).replace('0', '3').replace('1', '5').replace('2', '7')
        if '7' in num753 and '5' in num753 and '3' in num753:
            if int(num753)<=n:
                ans+=1
            else:
                Flag=False
                break
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
def dfs(s):
    if int(s)>n:
        return 0
    res = 1 if all(s.count(c) > 0 for c in '753') else 0
    for i in '753':
        res += dfs(s+i)
dfs('0')

Submission status: Runtime Error

Solution code:
n = int(input())
def dfs(s):
    if int(s)>n:
        return 0
    res = 1 if all(s.count(c) > 0 for c in '753') else 0
    for i in '753':
        res += dfs(s+i)
dfs(0)

Submission status: Runtime Error

Solution code:
from itertools import permutations
target = [3,5,7]

clear_list = combinations(target, 4)
print(clear_list)

Submission status: Runtime Error

Solution code:
def resolve():
    from collections import deque

    def checker(n):
        n = str(n)
        OK3 = False
        OK5 = False
        OK7 = False
        for i in n:
            if i == "3":
                OK3 = True
            elif i== "5":
                OK5 = True
            elif i == "7":
                OK7 = True
        if OK3 and OK5 and OK7:
            return True
        else:
            return False

    n = int(input())
    if n < 357:
        print(0)
    else:
        ans = 0
        nxt = [3, 5, 7]
        nxt = deque(nxt)
        OK = True
        while OK:
            a = nxt.popleft()
            if a > n:
                break
            nxt.append(a*10+3)
            nxt.append(a * 10 + 5)
            nxt.append(a * 10 + 7)
            if checker(a):
                ans += 1
    print(ans)
resolve()

Submission status: Runtime Error

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

N = int(input())
V = [3, 5, 7]

li = []


def rec(curr, use):
    if curr > N:
        return cnt
    if use == 0b111:
        li.append(curr)
    for i, b in enumerate(V):
        rec(curr * 10 + b, use | max(1, i * 2))


rec(0, 0)

print(len(li))

Submission status: Runtime Error

Solution code:
n = int(input())
other = ['0', '1', '2', '4', '6', '8', '9']
def dfs(sss):
  if(int(sss) > n):
    return 0
  r = 1 if(sss == all(s.count(c) > 0 for c in '753')) else 0
  for c in '357':
    r += dfs(sss+c)
  return r
print(dfs('0'))

Submission status: Runtime Error

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'))

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 

cnt = 0
def include(x):
    global cnt
    s = str(x)
    if ('3' in s) and ('5' in s) and ('7' in s):
        cnt += 1  
     
def main():
    n = int(readline())
    dq = deque()
    dq.append(0)
    cnd = []
    dd = (3, 5, 7)
    while len(dq)>0:
        v = dq.popleft()
        for i in dd:
            if v*10+i>n:
                continue
            dq.append(v*10+i)
            cnd.append(v*10+i)
            include(v*10+i)
        if cnd[-1] > n:
            break
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
l = [True]*(10**9+1)
count = 0
stack = [3, 5, 7]
def check(n, k):
  s = str(n)
  if "3" in s and "5" in s and "7" in s:
    return True
  else:
    return False
while len(stack)>0:
  now = stack.pop()
  if l[now]:
    l[now] = False
    if check(now):
      count += 1
    if now < n:
      stack.append(now*10+3)
      stack.append(now*10+5)
      stack.append(now*10+7)
      stack.append(3*10**len(str(now))+now)
      stack.append(5*10**len(str(now))+now)
      stack.append(7*10**len(str(now))+now)
print(count)

Submission status: Runtime Error

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

# check
if N < 357:
    print(0)
else:
    max_dig = len(str(N))
    dig = 3
    sgs_nuns = []
    sgs = set(["7", "5", "3"])
    str_join = "".join
    for n in range(3, max_dig + 1):
        sgs_nuns += [
            str_join(n)
            for n in product(["7", "5", "3"], repeat=n)
            if set(str_join(n)) == sgs and int(str_join(n)) <= N
        ]

    cnt = len(sgs_nuns)
    print(cnt)

Submission status: Runtime Error

Solution code:
# check
if N < 357:
    print(0)
else:
    cnt = 1
    for n in range(358, N + 1):
        if set(str(n)) == set(['7', '5', '3']):
            cnt += 1
    print(cnt)

Submission status: Runtime Error

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

if n_int<357:
  print(0)
else:
  counter__ = 0
  for k in range(3 ,len(n)+1):
    counter__ += recursive_f([])
    def recursive_f(A):
      if len(A) == k:
        A_ = int("".join(map(str,A)))
        counter = 0
        if len(set(A)) == 3 and A_ <= n_int:
          counter += 1
        return counter
      counter_ = 0
      for i in [3,5,7]:
        A.append(i)
        counter_ += recursive_f(A)
        A.pop()
      return counter_
        
print(counter__)

Submission status: Runtime Error

Solution code:
n=input()           #  str 575
n_int = int(n)    #  int 575

if n_int<357:
    print(0)
else:
    counter__ = 0
    for k in range(3 ,len(n)+1):
        counter__ += recursive_f([])

        def recursive_f(A):
            if len(A) == k:     # Aはリスト[7,7,7]
                A_ = int("".join(map(str,A)))    # A_はint 777
                counter = 0
                # print(A_)
                if len(set(A)) == 3 and A_ <= n_int:
                    counter += 1
                return counter

            counter_ = 0

            for i in [3,5,7]:
                A.append(i)
                counter_ += recursive_f(A)
                A.pop()

            return counter_
        
print(counter__)

Submission status: Runtime Error

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

if n_int<357:
  print(0)
else:
  counter__ = 0
  for k in range(3 ,len(n)+1):
    counter__ += recursive_f([])

    def recursive_f(A):
      if len(A) == k:     # Aはリスト[7,7,7]
        A_ = int("".join(map(str,A)))    # A_はint 777
        counter = 0
        # print(A_)
        if len(set(A)) == 3 and A_ <= n_int:
          counter += 1
          return counter

        counter_ = 0

        for i in [3,5,7]:
          A.append(i)
          counter_ += recursive_f(A)
          A.pop()

          return counter_
        
print(counter__)

Submission status: Runtime Error

Solution code:
N = int(input())

def f(x):
    if int(x) > N:
        return 0
    else:
        if all(x.count(j) >= 1 for j in [3, 5, 7]):
            ans = 1
        for i in [3, 5, 7]:
            ans += f(x+i)    
        return ans        

print(f("0"))

Submission status: Runtime Error

Solution code:
import itertools
import math


def main():
  n = int(input())
  
  count_753 = 0
  max_digits = math.ceil(math.log10(n))
  cand_753 = (3, 5, 7)
  
  for digits in range(3, max_digits):
    for dig_753 in itertools.product(cand_753, repeat=digits):
      number_str = "".join(dig_753)
      
      if "7" in number_str and "5" in number_str and "3" in number_str and int(number_str) <= n:
        count_753 += 1
  
  print(count_753)

if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
n = int(input())
A = set()
for x in product('753_', repeat=9):
    s = ''.join(x)
    s = s.replace('_', '')
    if '7' in s and '5' in s and '3' in s and int(s) <= n:
        A.add(s)
print(len(A))

Submission status: Runtime Error

Solution code:
N = int(input())

def dfs(s, res):
  if int(s) > N:
    return
  res = +all((t in s)for t in '753')
  for i in '753':
    res += dfs(s+i, res)
  return res

print(dfs('0', 0))

Submission status: Runtime Error

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 行目でのエラーを防ぐため仕方なく

#文字列をどんどん分岐しながら延ばすときにもdfsは使える
#準七五三数を全列挙し、それぞれについて判定

Submission status: Runtime Error

Solution code:
n = int(input())
nums = [3, 5, 7]

d = deque([0])

count = 0
while True:
    if len(d) == 0:
        break
    x = d.popleft()
    if x > n:
        continue
    else:
        if '3' in str(x) and '5' in str(x) and '7' in str(x):
            count += 1
        for num in nums:
            d.append(x * 10 + num)
print(count)

Submission status: Runtime Error

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: Runtime Error

Solution code:
ans = 0
n = int(input())
if n < 357:
  print(0)
else:
  for i in range(n):
    s = str(i)
    if s.count('7')+s.count('5')+s.count('3') == len(s):
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(n+1):
  s = str(i)
  if s.count('7')+s.count('5')+s.count('3') == int(s):
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(n+1):
  s = str(input())
  if s.count('7')+s.count('5')+s.count('3') == int(s):
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(n+1):
  s = list(str(input()))
  if s.count('7')+s.count('5')+s.count('3') == int(s):
    ans += 1
print(ans)

Submission status: Runtime Error

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'))

Submission status: Runtime Error

Solution code:
N=int(input())
cnt=0
 
for i in range(1, N+1):
    i=str(i)
    if "1" in i or "2" in i or "4" in i or "6" in i or "8" in i or "9" in i or "0" in i:
        continue
    elif "3" in i and "5" in i and "7" in i:
        cnt+=1
 
print(cnt

Submission status: Runtime Error

Solution code:
 n=int(input())
def des(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: Runtime Error

Solution code:
n = int(input())
from itertools import product
ans = 0
for i in range(1, 11):
  for p in product("357", repeat=i):
    v = "".join(p)
    if "3" in v and "5" in v and "7" in v and int("".join(p)) <= N:
      ans += 1
print(ans)