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 bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n = list(map(lambda c: ord(c) - ord('0'), input()))



def solve(pos, leading_zero, is_small, i3, i5, i7):

    # print(pos, is_small, i3, i5, i7)

    if pos == len(n):
        if i3 and i5 and i7:
            return 1
        return 0

    res = 0

    for d in [0,3,5,7]:
        if leading_zero == False and d == 0:
            continue
        if not is_small and d > n[pos]:
            continue
        new_is_small = True
        if d == n[pos] and not is_small: new_is_small = False
        new_leading_zero = False
        if leading_zero and d == 0:
            new_leading_zero = True
        res += solve(pos + 1, new_leading_zero, new_is_small,
                     i3 or (d == 3), i5 or (d == 5), i7 or (d == 7))

    return res


print(solve(0, True, False, False, False, False))

Submission status: Accepted

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


def dfs(x: str):
    if int(x) > n:
        return
    if x.count('3') >= 1 and x.count('5') >= 1 and x.count('7') >= 1:
        global ans
        ans += 1

    dfs(x+'3')
    dfs(x+'5')
    dfs(x+'7')


dfs('0')
print(ans)

Submission status: Accepted

Solution code:
nums = ['7','5','3']
N = input()
Max_digit = len(N)

def generator(n, nums):
    """
    return n-digit number in strings that are made out of numbers in nums and each one use precisely once
    """
    ans = [x for x in nums]
    
    for idx in range(1,n):
        new_ans = []
        for n1 in ans:
            for n2 in nums:
                new_ans.append(n1 + n2)
        ans = new_ans.copy()
    
    return [x for x in ans if all(num in x for num in nums)]

if Max_digit < 3:
    print(0)
if Max_digit == 3:
    ans = generator(3,nums)
    print(len([x for x in ans if int(x) <= int(N)]))
if Max_digit > 3:
    # count the number of eligible numbers which has less digits than N
    counter = 0
    for d in range(3, Max_digit):
        counter += len(generator(d,nums))
    # count the number of eligible numbers of the same digits as N and equal or less than N
    ans = generator(Max_digit, nums)
    counter += len([x for x in ans if int(x) <= int(N)])
    print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()

d_len = len(n)


def dfs(d):
    ret = 0
    if int(d) > int(n):
        return 0
    if all(i in d for i in ('357')):
        ret += 1
    for j in '357':
        ret += dfs(d + j)
    return ret


print(dfs('0'))

Submission status: Accepted

Solution code:
from itertools import product
N = input()
ans = 0
for i in range(3,len(N)+1):
    for k in product(["3","5","7"],repeat=i):
        if k.count("3") > 0 and k.count("5") > 0 and k.count("7") > 0:
            if int(''.join(k)) <= int(N):
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

def dfs(s):
    if int(s) > N:
        return 0
    r = 1 if s.count("3")>0 and s.count("5")>0 and s.count("7")>0 else 0
    for x in ["3","5","7"]:
        r += dfs(s+x)
    return r

print(dfs("0"))

Submission status: Accepted

Solution code:
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""


if __name__ == "__main__":
    N = int(sys.stdin.readline())
    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 = input()

l = len(N)
ans = 0
#各桁を「数字無し（０）」「７（１）」「５（２）」「３（３）」で記述するような4進数を作る
for n in range(1, 4**l):
  n4 = ""
  while n > 0:
    mod = n % 4
    n4 = str(mod) + n4
    n //= 4
  
  if "0" in n4:
    continue
  
  if ("1" in n4) and ("2" in n4) and ("3" in n4):
    n4_10 = ""
    for i in range(len(n4)):
      if n4[i] == "1":
        n4_10 = n4_10 + "7"
      elif n4[i] == "2":
        n4_10 = n4_10 + "5"
      else:
        n4_10 = n4_10 + "3"
    if int(n4_10) <= int(N):
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
n = input()
lst = list("357")
cnt = 0
for i in range(3, len(n) + 1):
    for j in itertools.product(lst, repeat=i):
        if int("".join(j)) <= int(n) and "3" in j and "5" in j and "7" in j:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = input()
count = 0
def f(s):
    if s == "":
        ns = 0
    else:
        ns = int(s)
    
    if ns <= int(n):
        s3 = s.count("3")
        s5 = s.count("5")
        s7 = s.count("7")
        if s3>0 and s5>0 and s7>0 and s3+s5+s7 == len(s):
            global count
            count += 1
        f(s+"3")
        f(s+"5")
        f(s+"7")
f("")
print(count)

Submission status: Accepted

Solution code:
n = int(input())
def check(s):
    if int(s) > n:
        return 0
    if all(s.count(i)>0 for i in '753'):
        count = 1
    else:
        count = 0
    for i in '753':
        count += check(s+i)
    return count
print(check('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:
n = int(input())
ans = 0
def dfs(s):
    global ans
    if int(s) > n:
        return
    seven = 0
    five = 0
    three = 0
    for i in range(len(s)):
        if s[i] == "7":
            seven = 1
        elif s[i] == "5":
            five = 1
        elif s[i] == "3":
            three = 1
    if seven == 1 and five == 1 and three == 1:
        ans += 1

    dfs(s + "7")
    dfs(s + "5")
    dfs(s + "3")
    return
dfs("7")
dfs("5")
dfs("3")
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
  ret = 0
  if int(s) > n:
    return 0
  if all(s.count(c) > 0 for c in '753'):
    ret = 1
  for c in '753':
    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:
    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: Accepted

Solution code:
import bisect
n=input()
N=int(n)


tmp=["3", "5", "7"]
for i in range(1, len(n)):
    next=[]
    for j in tmp:
        for k in ["3", "5", "7"]:
            next.append(j+k)
    tmp=tmp+next

tmp=list(set(tmp))
N_753=[]
for i in tmp:
    if "3" in i and "5" in i and "7" in i:
        N_753.append(int(i))


N_753.sort()

print(bisect.bisect_right(N_753, N))

Submission status: Accepted

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


def dfs(num, add_num):
    num *= 10
    num += add_num

    if num > N:
        return

    num_list.append(num)

    dfs(num, 7)
    dfs(num, 5)
    dfs(num, 3)

    return num_list


dfs(3, 3)
dfs(3, 5)
dfs(3, 7)
dfs(5, 3)
dfs(5, 5)
dfs(5, 7)
dfs(7, 3)
dfs(7, 5)
dfs(7, 7)


ans = 0
tmp = 0
target = set(['7', '5', '3'])
# print(num_list)
for n in num_list:
    tmp = 0
    for t in target:
        if t in str(n):
            tmp += 1
    if tmp == 3:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
ans = 0
arr = ['3','5','7']
for repeat in range(3,11):
    ite = itertools.product(arr, repeat=repeat)
    for l in ite:
        if '3' in l and '5' in l and '7' in l:
            num = int(''.join(l))
            if num > N:
                break
            else:
                ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
n = input()
digit = len(n)
a753 = 0
a75 = 0
a73 = 0
a53 = 0
now = 0
i = digit - 1
# now + i = digit - 1
while now < digit:
  tmp = int(n[i])
  add = 3 ** now
  sun = (3 ** (now+1) - 3) // 2
  add2 = 2 ** now
  sun2 = 2 ** (now+1) - 2
  if tmp == 8 or tmp == 9:
    a753 = sun + 3 * add
    a75 = sun2 + 2 * add2
    a73 = sun2 + 2 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 7:
    a753 += 3 * add
    a75 += 2 * add2
    a73 += 2 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 6:
    a753 = sun + 2 * add
    a75 = sun2 + 1 * add2
    a73 = sun2 + 1 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 5:
    a753 += 2 * add
    a75 += 1 * add2
    a73 = sun2 + 1 * add2
    a53 += 2 * add2
  elif tmp == 4:
    a753 = sun + 1 * add
    a75 = sun2 + 0 * add2
    a73 = sun2 + 1 * add2
    a53 = sun2 + 1 * add2
  elif tmp == 3:
    a753 += 1 * add
    a75 = sun2 + 0 * add2
    a73 += 1 * add2
    a53 += 1 * add2
  else:
    a753 = sun + 0 * add
    a75 = sun2 + 0 * add2
    a73 = sun2 + 0 * add2
    a53 = sun2 + 0 * add2
    a = 3 * now - 3
  now += 1
  i -= 1
all1 = (10 ** digit - 1) // 9
a = 3 * digit
if int(n) < 7 * all1:
  a -= 1
if int(n) < 5 * all1:
  a -= 1
if int(n) < 3 * all1:
  a -= 1
#print(a753,a75,a73,a53,a)
print(a753 - a75 - a73 - a53 +a)

Submission status: Accepted

Solution code:
n = int(input())

a = []


def func(s):
    if s:
        a.append(int(s))
    if len(s) == len(str(n)):
        return
    func(s + '3')
    func(s + '5')
    func(s + '7')


func('')

print(len([x for x in a if x <= n and len(set(str(x))) == 3]))

Submission status: Accepted

Solution code:
import itertools
a = input()
b = list("357")
c = 0
for j in range(3, len(a) + 1):
    for i in itertools.product(b, repeat=j):
        if int("".join(i)) <= int(a) and "3" in i and "5" in i and "7" in i:
            c += 1
print(c)

Submission status: Accepted

Solution code:
#%%
import copy
N = int(input())
# 桁数を取得
keta = len(str(N))
# 桁数以内で3,5,7で構成される数を生成
l = ['3', '5', '7']
kotae = set()
kotae.add('0')

for i in range(keta):
    kari = copy.copy(kotae)
    for m in kari:
        for n in l:
            k = m + n
            if int(k) <= N:
                kotae.add(k)

count = 0
for s in kotae:
    count += 1 if all(s.count(c) > 0 for c in '753') else 0

print(count)

Submission status: Accepted

Solution code:
import itertools
import math
n = input()

chars = ["3", "5", "7"]
ndigits = int(math.log10(n)) + 1

count = 0
for digit in range(3, ndigits + 1):
    for string in itertools.product(chars, repeat=digit):
        if(string.count("3") == 0):
            continue
        if(string.count("5") == 0):
            continue
        if(string.count("7") == 0):
            continue
        if n >= int("".join(string)):
            count += 1

print(count)

Submission status: Accepted

Solution code:
#%%
N = int(input())
#import time
#s = time.time()

def ternary (n):
    if n == 0:
        return '0'
    nums = []
    while n:
        n, r = divmod(n, 3)
        nums.append(str(r))
    return ''.join(reversed(nums))

l = []

for i in range(3**9):
    tmp = ternary(i)
    tmp_list = list(tmp)
    tmp2 = ''
#    if tmp_list[0] != '0' and len(tmp_list)<9:
#        tmp = '0' + tmp 
    if '0' in tmp_list and '1' in tmp_list and '2' in tmp_list :
        for j in range(len(tmp)):
            if tmp[j] == '0':
                tmp2 += '3'
            elif tmp[j] ==  '1':
                tmp2 += '5'
            elif tmp[j] == '2':
                tmp2 += '7'
        tmp2 = int(tmp2)
        l.append(tmp2)

for i in range(3**9):
    tmp = ternary(i)
    tmp_list = list(tmp)
    tmp2 = ''
#    if tmp_list[0] != '0' and len(tmp_list)<9:
#        tmp = '0' + tmp 
    if '0' in tmp_list and '1' in tmp_list and '2' in tmp_list :
        for j in range(len(tmp)):
            if tmp[j] == '1':
                tmp2 += '3'
            elif tmp[j] ==  '2':
                tmp2 += '5'
            elif tmp[j] == '0':
                tmp2 += '7'
        tmp2 = int(tmp2)
        l.append(tmp2)

ans = 0

l = list(set(l))

#print(len(l))
#print(l[:100])

for i in range(len(l)):
    if l[i] <= N :
        ans += 1

print(ans)

#e = time.time() - s
#print(e)


#%%

Submission status: Accepted

Solution code:
N = int(input())
lst = ["3", "5", "7"]
ans = 0
while lst:
    a = lst.pop(0)
    if int(a) <= N:
        for c in ["3", "5", "7"]:
            if int(a + c) <= N:
                lst.append(a + c)
        if all(a.count(c) > 0 for c in ["3", "5", "7"]):
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
num = []
for i in range(3, 10):
    for j in itertools.product("357", repeat = i):
        if "3" in j and "5" in j and "7" in j:
            num.append("".join(j))
count = 0
for i in num:
    if int(i) <= n:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import math
import itertools


def solve():
    n = read()
    result = think(n)
    write(result)


def read():
    return read_int(1)[0]


def read_int(n):
    return list(map(int, input().rstrip().split()[:n]))


def think(n):
    if n < 357:
        return 0
    digits = math.ceil(math.log10(n))
    if digits % 10 == 0:
        digits += 1

    count = 0
    dictionary = ['3', '5', '7']
    for d in range(3, digits + 1):
        for list_of_012 in itertools.product([0, 1, 2], repeat=d):
            buf = ''
            for elem in list_of_012:
                buf += str(dictionary[elem])
            if int(buf) <= n and buf.count('3') >= 1 and buf.count('5') >= 1 and buf.count('7') >= 1:
                # print(buf)
                count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

nums_753 = []
list_357 = ["3","5","7"]
upper_limit = N
def create_nums_of_357(s):
#     print(s)
    for i in list_357:
        news = s + i
        if int(news) > upper_limit:
            continue
        save_bool = True
        for j in list_357:
            if j not in news:
                save_bool=False
                break
        if save_bool:
            nums_753.append(news)
        create_nums_of_357(news)


create_nums_of_357("")

print(len(nums_753))

Submission status: Accepted

Solution code:
import itertools
N = int(input().strip())

ns = '753'

def dfs(s):
  cnt = 0
  if int(s) > N:
    return cnt
  cnt += all(c in s for c in ns) 
  cnt += sum(dfs(s + c) for c in ns)
  return cnt


ans = 0
for s in itertools.product('753', repeat=3):
  ans += dfs("".join(s))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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: 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 shichigosan(n):
    if n < 10:
        s = {3, 5, 7}
    else:
        s = shichigosan(n//10)
        ss = shichigosan(n//10)
        for i in ss:
            s.add(i*10+3)
            s.add(i*10+5)
            s.add(i*10+7)
    return s

ans = 0
for s in shichigosan(N):
    if s <= N:
        for c in '753':
            if str(s).count(c) == 0:
                break
        else:
            ans += 1
#print(shichigosan(N))
print(ans)

Submission status: Accepted

Solution code:
S = int(input())

def solve() :
    ret = 0
    lst = [0]
    pre, cur = 0, len(lst)
    for _ in range(10) :
        for i in range(pre, cur) :
            for j in [3, 5, 7] :
                s = lst[i]*10+j
                if s > S :
                    return ret
                lst.append(s)
                s = str(s)
                if '3' in s and '5' in s and '7' in s :
                    ret += 1
        pre, cur = cur, len(lst)

print(solve())

Submission status: Accepted

Solution code:
def dfs(s):
    if int(s) > n:
        return 0
    return all([c in s for c in '753']) + sum([dfs(s + c) for c in '753'])


n = int(input())
print(dfs('0'))

Submission status: Accepted

Solution code:
def dfs(s):
    if int(s) > n:
        return 0
    return ('7' in s and '5' in s and '3' in s) + dfs(s + '7') + dfs(s + '5') + dfs(s + '3')


n = int(input())
print(dfs('0'))

Submission status: Accepted

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

# dp[i番目まで][N未満かどうか][0以外を含んだかどうか][7][5][3]
dp = [[[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(digit+2)]
dp[0][0][0][0][0][0] = 1

for i in range(digit):
  num = int(N[i])
  for j in range(2):
    for nonzero in range(2):
      for seven in range(2):
        for five in range(2):
          for three in range(2):
            for n in [0,3,5,7]:
              if (nonzero and (n == 0)) or ((j == 0) and (n > num)):
                continue
              else:
                dp[i+1][j or (n < num)][nonzero or (n != 0)]\
                [seven or (n == 7)][five or (n == 5)][three or (n == 3)]\
                += dp[i][j][nonzero][seven][five][three]

print(dp[digit][0][1][1][1][1] + dp[digit][1][1][1][1][1])

Submission status: Accepted

Solution code:
N = int(input())


List = []
n = len(str(N))
ans = 0
if n >= 3:
    if n > 3:
        for i in range(2,n-1):
            ans += (3**(i+1)-3*2**(i+1)+3)
    for j in range(n):
        if j == 0:
            List = [3*10**(n-1),5*10**(n-1),7*10**(n-1)]
        else:
            for k in range(3**j):
                num = List.pop(0)
                List.append(num+3*10**(n-j-1))
                List.append(num+5*10**(n-j-1))
                List.append(num+7*10**(n-j-1))
    for l in range(len(List)):
        if List[l] <= N:
            s = str(List[l])
            if "3" in s and "5" in s and "7" in s:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
n = input()
keta = len(list(n))
cnt=0
l = [3,5,7]
for k in range(3,keta+1):
  for i in itertools.product(l, repeat=k):
    if 3 in i and 5 in i and 7 in i:
      tmp=""
      for j in i:
        tmp+=str(j)
      if int(tmp)<=int(n):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

num = 4**9
ans = 0

for i in range(num):
    num_0 = 0
    num_3 = 0
    num_5 = 0
    num_7 = 0

    s = i
    for m in range(9):
        num_0 += 0 * int(s % 4 == 0) * 10 ** m
        num_3 += 3 * int(s % 4 == 1) * 10 ** m
        num_5 += 5 * int(s % 4 == 2) * 10 ** m
        num_7 += 7 * int(s % 4 == 3) * 10 ** m
        s = s // 4
    
    tmp = num_0 + num_3 + num_5 + num_7
        
    if tmp > n:
        break
    
    tmp = str(tmp)
    
    if num_3 > 0 and num_5 > 0 and num_7 > 0 and tmp.count('0') == 0:
        #print(tmp)
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools as it
N=int(input())
d=0
for i in range(3,10):
    for c in sorted(list(it.product('753',repeat=i))):
        if int(''.join(c))>N:
            print(d)
            exit(0)
        if len(set(c))==3:d+=1
print(d)

Submission status: Accepted

Solution code:
# ABC 114 C

import itertools

def get_list(N, rep):
    count = 0
    a = list(itertools.product([3, 5, 7], repeat=rep))
    delList = []
    for e in a:
        if 3 not in e or 5 not in e or 7 not in e:
            delList.append(e)
    for e in delList:
        a.remove(e)
    for e in a:
        val = 0
        for i in range(rep):
            val += e[i] * 10**(rep-i-1)
        if val <= N:
            count += 1
    return count

def resolve():
    N = int(input())
    ans = 0
    for i in range(9):
        ans += get_list(N, i+1)
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())

def count_753(s):
    if int(s) > n:
        return 0
    ret = all((c in s for c in '753'))
    for c in '753':
        ret += count_753(s + c)
    return ret

print(count_753('0'))

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    N_STR = inputs[0]
    N = int(N_STR)

    if len(N_STR) <= 2:
        return 0

    def check_over(string):
        if int(string) > N:
            return False
        return True

    def check_all_appered(string):
        does_appered = {
            '3': False,
            '5': False,
            '7': False
        }

        for s in string:
            if s in does_appered:
                does_appered[s] = True
        are_all_true = True
        for d in does_appered.values():
            are_all_true = are_all_true and d
        return are_all_true

    def create_s(origin, until_len):
        if len(origin) == until_len:
            return [origin]

        ret = []
        ret += create_s(origin+'3', until_len)
        ret += create_s(origin+'5', until_len)
        ret += create_s(origin+'7', until_len)

        pop_items = []
        for i in range(0, len(ret)):
            if ret[i] is None \
                    or not check_all_appered(ret[i]) \
                    or not check_over(ret[i]):
                pop_items.append(i)
        for p in reversed(pop_items):
            ret.pop(p)

        return ret

    ret = []
    for i in range(3, len(N_STR)+1):
        ret += create_s('', i)
    return len(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

Solution code:
N = int(input())

def dp(now) :
    if int(now) > N :
        return 0
    count = 0
    if all(x in now for x in ['7', '5', '3']) :
        count += 1
    for x in ['7', '5', '3'] :
        count += dp(now + x)
    return count

ans = dp('0')
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = [7,5,3]
    if n in a:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    s = S()
    ans = inf
    for i in range(len(s) - 2):
        ans = min(ans, abs(753-int("".join(s[i:i + 3]))))
    print(ans)
    return

#C
def C():
    s = II()
    n = len(str(s))
    ans = 0
    for i in range(3,n+1):
        c = itertools.product(["3", "5", "7"], repeat=i)
        for ci in c:
            if len(set(ci)) < 3:
                continue
            if int("".join(ci)) <= s:
                ans += 1
    print(ans)

        
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
n = int(input())

def f(s):

    if int(s) > n:
        return 0

    if set(list(s)) == {"0", "3", "5", "7"}:
        ans = 1
    else:
        ans = 0

    for c in list("753"):
        ans += f(s + c)

    return ans

print(f("0"))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):

    if int(s) > N:
        return 0
        
    if set(list(s)) == {"7", "5", "3", "0"}:
        ret = 1
    else:
        ret = 0

    for c in "753":
        ret += dfs(s + c)

    return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
def f(N, D, b=False):
    if len(N)==0: return 0 if b else 1

    n0 = int(N[0])
    m = 0
    for d in D:
        if d==n0:
            m += f(N[1:], D)
        if d<n0:
            m += len(D)**len(N[1:])
    return m + f('9'*len(N[1:]), D, True) if b else m

N = input()
print(( f(N,[3,5,7],True)
       -f(N,[3,5  ],True)
       -f(N,[  5,7],True)
       -f(N,[3,  7],True)
       +f(N,[3    ],True)
       +f(N,[  5  ],True)
       +f(N,[    7],True)))

Submission status: Accepted

Solution code:
from math import log10, floor
import bisect


N = int(input())

M = []


def rec(s):
    for x in "357":
        xx = s + x
        if int(xx) >= 2e9:
            break
        if "3" in xx and "5" in xx and "7" in xx:
            M.append(int(xx))
        rec(xx)


rec("")
M.sort()
ans = bisect.bisect_right(M, N)
print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())

c = ["!", "3", "5", "7"]
def shichigosan_numbers():
    x = 0
    while True:
        x += 1
        s = ""
        y = x
        while y > 0:
            s = c[y%4] + s
            y = y // 4
        if "!" not in s and "3" in s and "5" in s and "7" in s: 
            yield int(s)

ans = 0
for x in shichigosan_numbers():
    if x <= n:
        ans += 1
    else: 
        print(ans)
        exit()

Submission status: Accepted

Solution code:
N = int(input())

def shitigosan(x):
  if int(x) > N:
    return 0
  cnt = 1 if all(x.count(c) > 0 for c in '753') else 0
  for i in "753":
    cnt += shitigosan(x+i)
  return cnt
  
print(shitigosan("0"))

Submission status: Accepted

Solution code:
def generate357(num_str,n):  
  if len(num_str) < 3:
    pass
  elif int(num_str) > n:    
    return 0
  
  count = sum([generate357(str(i) + num_str, n) for i in '357'])      
  
  if all((s in num_str)  for s in '357'):
    count +=1
  return count   

n = int(input())
print(generate357('',n))

Submission status: Accepted

Solution code:
n = int(input())
m = ["3","5","7"]
m1 = m.copy()
for i in range(2,10):
    mi = []
    for x in m1:
        mi.append(x+"3")
        mi.append(x+"5")
        mi.append(x+"7")
    m += mi
    m1 = mi
count = 0
for x in m:
    if int(x)<= n and x.count("3")*x.count("5")*x.count("7") != 0:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import math
n = input()
ans = 0
li=[]
global num_li
num_li = []
def create_num(n, length):
    global num_li
    if len(n) == length:
        num_li.append(n)
    else:
        create_num(n+"3", length)
        create_num(n+"5", length)
        create_num(n+"7", length)
for i in range(1, len(n)+1):
    if i == len(n):
        create_num("", i)
        for j in num_li:
            if "3" in j and "5" in j and "7" in j and int(j) <= int(n):
                ans+= 1       
    elif i > 2:
        ans += 3**i - (2**i -2) * 3 - 3 
print(ans)

Submission status: Accepted

Solution code:
x=input()
n=len(x)

res=[]

import numpy as np
import itertools

x753=[3,5,7]

pt=list(itertools.product(x753, repeat=n))

pt_n=len(pt)

for i in range(pt_n):
	y="".join(map(str, pt[i]))
	for j in range(n):
		z=y[j:]
		if int(z)<=int(x) and ('3' in z) and ('5' in z) and ('7' in z):
			res.append(z)
            
print(len(set(res)))

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:
from itertools import product
N = int(input())
ans = 0
for l in range(1, 11):
    for p in product("357", repeat=l):#product関数はlistを返す
        v = "".join(p)
        if "3" in v and "5" in v and "7" in v and int(v) <= N:#文字列のリストをjoinで結合
            ans += 1
print(ans)

#直積集合，集合の集まり（集合族）に対して各集合から1つずつ元を取り出して組にしたものを元としてもつ新たな集合

Submission status: Accepted

Solution code:
n = input()
def dfs(s):
    if int(s) > int(n):
        return 0
    ret = 1 if all(c in s for c in ['7', '5', '3']) else 0
    for c in ['7', '5', '3']:
        ret += dfs(s + c)
    return ret
print(dfs('0'))

Submission status: Accepted

Solution code:
from itertools import *

N = int(input())

A = ["3", "5", "7"]

ans = 0

length = len(str(N))

for i in range(3, length+1) :
    for prod in product(A, repeat=i) :
        if prod.count("3") == 0 or prod.count("5") == 0 or prod.count("7") == 0 :
            continue
        
        num = int("".join(prod))
        if num > N :
            break
        
        ans += 1
        
print(ans)