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 = input()
m = len(n)
ans = 0

for k in range(m+1):
    for i in range(3 ** k):
        li = [] 
        for j in range(k):
            li.insert(0,int((i%(3**(j+1)))/(3**j)))                
        for j in range(k):
            if li[j] == 0:
                li[j] = '3'
            if li[j] == 1:
                li[j] = '5'
            if li[j] == 2:
                li[j] = '7'
        if li != []:
            if int(''.join(li)) <= int(n) and len(set(li)) == 3:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
def dfs(a,n):
    if int(a)>n:
        return 0
    if a.count('7')>0 and a.count('5')>0 and a.count('3')>0:
        ans=1
    else:
        ans=0
    for i in '753':
        ans+=dfs(a+i,n)
    return ans

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

Submission status: Accepted

Solution code:
import itertools
n=int(input())
keta=len(str(n))
ans=0
for k in range(1,keta+1):
  for c in itertools.product(range(3),repeat=k):
    nn=""
    flag3,flag5,flag7=0,0,0
    for i in range(k):
      if c[i]==0:
        nn+="3"
        flag3=1
      elif c[i]==1:
        nn+="5"
        flag5=1
      else:
        nn+="7"
        flag7=1
    if flag3*flag5*flag7==1 and int(nn)<=n:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

# 10 ** 9
l753 = []
for i in range(3, 10):
    l = ['753'] * i
    for s in product(*l):
        if '7' in s and '3' in s and '5' in s:
            l753.append(int("".join(s)))
l753 = sorted(l753)
N = int(input())
count = 0
for i in l753:
    if i > N:
        break
    count += 1
print(count)

Submission status: Accepted

Solution code:
n=int(input())
def f(s):
    if int(s)>n:
        return 0
    p=0
    if '7' in s and '5' in s and '3' in s:
        p=1
    return f(s+'7')+f(s+'5')+f(s+'3')+p
print(f('0'))

Submission status: Accepted

Solution code:
from itertools import product
N=input()
ans=0
for i in range(3,len(N)+1):
    A=list(product(['7','5','3'],repeat=i))
    for a in A:
        if int(''.join(a))<=int(N) and set(a)>={'7','5','3'}:
            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(num):
    if num and int(num) > N:
        return 0

    count = 1 if '3' in num and '5' in num and '7' in num else 0

    for s in '357':
        count += dfs(num + s)
    return count

print(dfs(''))

Submission status: Accepted

Solution code:
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) 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()
Nlen = len(N)
N = int(N)

def f(i, n, T, F, S):
  if i >= Nlen:
    return 1 if n <= N and T > 0 and F > 0 and S > 0 else 0
  n *= 10
  cnt = 0
  if n == 0:
    cnt += f(i+1, n, T  , F  , S  )
  cnt += f(i+1, n+3, T+1, F  , S  )
  cnt += f(i+1, n+5, T  , F+1, S  )
  cnt += f(i+1, n+7, T  , F  , S+1)
  return cnt

print(f(0, 0, 0, 0, 0))

Submission status: Accepted

Solution code:
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all([s.count(w) > 0 for w in '753']) else 0

    for x in '753':
        ret += dfs(s + x)
    return ret


print(dfs('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:
n = int(input())

def f(s):
	if int(s) > n: return 0
	p = 0
	if '7' in s and '5' in s and '3' in s:
		#print(s)
		p = 1
	return f(s + '3') + f(s + '5') + f(s + '7') + p

print(f('0'))

Submission status: Accepted

Solution code:
N = int(input())


def dfs(s):
    if s != '' and int(s) > N:
        return 0
    ans = int(all([s.count(c) > 0 for c in '753']))
    for c in '753':
        ans += dfs(s + c)
    return ans


print(dfs(''))

Submission status: Accepted

Solution code:
n = int(input())
sevenfivethree = []
judge = 0

def dfs(num: str):
    if int(num) > n or len(num) > 8:
        return
    else:
        if int(num+"3") <= n:
            sevenfivethree.append(num + "3")
        if int(num+"5") <= n:
            sevenfivethree.append(num + "5")
        if int(num+"7") <= n:
            sevenfivethree.append(num + "7")

        dfs(num + "3")
        dfs(num + "5")
        dfs(num + "7")

        return

dfs("3")
dfs("5")
dfs("7")

for i in range(len(sevenfivethree)):
    if sevenfivethree[i].count("3") ==0 or sevenfivethree[i].count("5") ==0 or sevenfivethree[i].count("7") ==0:
        sevenfivethree[i] = 0 #条件に合わないやつを0に書き換え
        judge = 1
print(len(set(sevenfivethree)) - (judge == 1)) #0があれば、setの数が1こ余分なので引く。

Submission status: Accepted

Solution code:
import itertools
n = input()
m = len(n)

cn = 0
for i in range(3,m+1):
    for l in itertools.product(["5","7","3"],repeat = i):
        l = "".join(l)
        if int(l) > int(n): continue
        cn += 1 if "3" in l and "5" in l and "7" in l else 0
print(cn)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())

def dfs(num):
    if int(num) > N:
        return 0

    # numが753数ならcntを1にセット
    cnt = 0
    flag = 1
    for i in "753":
        if not num.count(i):
            flag = 0
            break
    if flag:
        cnt += 1

    for i in "753":
        cnt += dfs(num + i)

    return cnt

print(dfs("0"))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

            

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

    return ret
            




def solve(N: str):
    print(dfs("0",int(N)))


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def ls_ternary(n, limit):
  ls = ["3"*n]
  while int(ls[-1]) <= limit and len(ls) < 3**n:
    ls.append(ternary_plus(ls[-1], 1))
    
  return ls[:-1]

def ternary_plus(chars, d):
  n = len(chars)
  tg = chars[n-d]
  if tg=='7':
    return ternary_plus(chars[:n-d]+'3'+chars[n-d+1:], d+1)
  else:
    if tg=='3':
      nxt = '5'
    else:
      nxt = '7'
    return chars[:n-d] + nxt + chars[n-d+1:]

s = input()
l = len(s)
hs = []
for i in range(l):
  if i+1<3:
    hs.append(0)
  else:
    hs.append(3**(i+1)-3*(2**(i+1))+3)

if l<3:
  print(0)
elif l==3:
  print(len(list(filter(lambda x: '3' in x and '5' in x and '7' in x, ls_ternary(l, int(s))))))
else:
  a = len(list(filter(lambda x: '3' in x and '5' in x and '7' in x, ls_ternary(l, int(s)))))
  print(a+sum(hs[:l-1]))

Submission status: Accepted

Solution code:
n= int(input())

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

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

print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())

import itertools
ans = 0
candidate = [3,5,7]

for j in range(3,len(str(N))+1):
    for i in itertools.product(candidate, repeat=j):
        if int("".join(map(str, list(i)))) <= N:
            if 3 in list(i) and 5 in list(i) and 7 in list(i):
                ans += 1


print(ans)

Submission status: Accepted

Solution code:
N = input()
k = len(N)
N = int(N)

nums = ['3', '5', '7']
add3 = lambda x: x + '3'
add5 = lambda x: x + '5'
add7 = lambda x: x + '7'

cnt = 0
for _ in range(k-1):
    num_tmp = []
    num_tmp.append(list(map(add3, nums)))
    num_tmp.append(list(map(add5, nums)))
    num_tmp.append(list(map(add7, nums)))
    nums = sum(num_tmp, [])

    for i in range(len(nums)):
        if '3' in nums[i] and '5' in nums[i] and '7' in nums[i] and int(nums[i]) <= N:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = input()

def f(s):
    if int(s) > int(n):
        return 0
    if all(['3' in s,'5' in s,'7' in s]):
        ans.append(1)
    for t in '3','5','7':
        f(s+t)

ans=[]
f('0')
print(sum(ans))

Submission status: Accepted

Solution code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
from itertools import permutations
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

l=[3,5,7]
# eprint(type(l))
# for xxx in itertools.permutations(l,9):
#     print(xxx)
nnn=10
cnt=0
inputx=int(input())
endflag=0
for n in range(3,nnn):
    for xxx in itertools.product(l,repeat=n):
        num = int("".join([str(e) for e in xxx]))
        if num>inputx:
            endflag=1
            break
        else:
            res=sorted(set(xxx))
            # print(res)
            if res==[3,5,7]:
                # print(xxx)
                cnt+=1
            else:
                continue
    if endflag==1:
        print(cnt)
        break
if endflag==0:
    print(cnt)

    # eprint(str(n)+": "+str(cnt))

# for xxx in itertools.product(l,repeat=8):
#     res=sorted(set(xxx))
#     if res==[3,5,7]:
#         print(xxx)
#         cnt+=1
#     else:
#         continue

Submission status: Accepted

Solution code:
n = input()
ans = 0
num753 = [[]for _ in range(len(n)+1)]

def create753(n): #357いずれかの数字からなるn桁の数をnum753に格納
  num753[0].append('0')
  num753[1].append('3')
  num753[1].append('5')
  num753[1].append('7')
  
  for i in range(1,n):
    for j in num753[i]:
      for k in '357':
        num_next = j + k
        num753[i+1].append(num_next)
  
create753(len(n))

for i in num753:
  for j in i:
    if all(j.count(c) > 0 for c in '753') and (1 <= int(j) <=int(n)):
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
import bisect
n=input()
l=[]
for i in range(3,len(n)+1):
    for j in itertools.product([3,5,7],repeat=i):
        if len(set(j))==3:
            l.append(int(''.join(map(str,j))))
l.sort()
print(bisect.bisect_right(l,int(n)))

Submission status: Accepted

Solution code:
N = int(input())
def n_ary(l,d): # リストl中の文字でd桁までを全列挙(sorted)
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i for i in n_ary(['3','5','7'],9)] # 制約が10**9なので9
print(len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)]))

Submission status: Accepted

Solution code:
N = int(input())
def n_ary(l,d): # リストl中の文字でd桁までを全列挙(sorted)
    if d == 1:
        return(l)
    n = len(l)
    ll = n_ary(l,d-1)
    lll = []
    for i in l:
        for j in ll[n*(n**(d-2)-1)//(n-1):]:
            lll.append(i+j)
    return(ll+lll)
possible = [i.replace('0','3').replace('1', '5').replace('2','7') for i in n_ary(['0','1','2'],9)] # 制約が10^9なので9
print(len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)]))

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


print(dfs('0'))

Submission status: Accepted

Solution code:
N = input()

def search(i):
        if int(i) > int(N):
                return 0

        nums = [3, 5, 7]
        count = 0
        if all(i.count(str(n)) > 0 for n in nums):
                count = 1
        else:
                count = 0
        
        for n in nums:
                count += search(i + str(n))
        
        return count

print(search(str(0)))

Submission status: Accepted

Solution code:
def make(num):
  if num==1 or num==2:
    return []
  l3=['357','375','537','573','735','753']
  if num==3:
    return l3
  l4=set()
  for i in range(len(l3)):
    l4.add('3'+l3[i])
    l4.add('5'+l3[i])
    l4.add('7'+l3[i])
    for j in range(1,3):
      l4.add(l3[i][:j]+'3'+l3[i][j:])
      l4.add(l3[i][:j]+'5'+l3[i][j:])
      l4.add(l3[i][:j]+'7'+l3[i][j:])
    l4.add(l3[i]+'3')
    l4.add(l3[i]+'5')
    l4.add(l3[i]+'7')
  l4=list(l4)
  if num==4:
    return l4+l3
  l5=set()
  for i in range(len(l4)):
    l5.add('3'+l4[i])
    l5.add('5'+l4[i])
    l5.add('7'+l4[i])
    for j in range(1,4):
      l5.add(l4[i][:j]+'3'+l4[i][j:])
      l5.add(l4[i][:j]+'5'+l4[i][j:])
      l5.add(l4[i][:j]+'7'+l4[i][j:])
    l5.add(l4[i]+'3')
    l5.add(l4[i]+'5')
    l5.add(l4[i]+'7')
  l5=list(l5)
  if num==5:
    return l5+l4+l3
  l6=set()
  for i in range(len(l5)):
    l6.add('3'+l5[i])
    l6.add('5'+l5[i])
    l6.add('7'+l5[i])
    for j in range(1,5):
      l6.add(l5[i][:j]+'3'+l5[i][j:])
      l6.add(l5[i][:j]+'5'+l5[i][j:])
      l6.add(l5[i][:j]+'7'+l5[i][j:])
    l6.add(l5[i]+'3')
    l6.add(l5[i]+'5')
    l6.add(l5[i]+'7')
  l6=list(l6)
  if num==6:
    return l6+l5+l4+l3
  l7=set()
  for i in range(len(l6)):
    l7.add('3'+l6[i])
    l7.add('5'+l6[i])
    l7.add('7'+l6[i])
    for j in range(1,6):
      l7.add(l6[i][:j]+'3'+l6[i][j:])
      l7.add(l6[i][:j]+'5'+l6[i][j:])
      l7.add(l6[i][:j]+'7'+l6[i][j:])
    l7.add(l6[i]+'3')
    l7.add(l6[i]+'5')
    l7.add(l6[i]+'7')
  l7=list(l7)
  if num==7:
    return l7+l6+l5+l4+l3
  l8=set()
  for i in range(len(l7)):
    l8.add('3'+l7[i])
    l8.add('5'+l7[i])
    l8.add('7'+l7[i])
    for j in range(1,7):
      l8.add(l7[i][:j]+'3'+l7[i][j:])
      l8.add(l7[i][:j]+'5'+l7[i][j:])
      l8.add(l7[i][:j]+'7'+l7[i][j:])
    l8.add(l7[i]+'3')
    l8.add(l7[i]+'5')
    l8.add(l7[i]+'7')
  l8=list(l8)
  if num==8:
    return l8+l7+l6+l5+l4+l3
  l9=set()
  for i in range(len(l8)):
    l9.add('3'+l8[i])
    l9.add('5'+l8[i])
    l9.add('7'+l8[i])
    for j in range(1,8):
      l9.add(l8[i][:j]+'3'+l8[i][j:])
      l9.add(l8[i][:j]+'5'+l8[i][j:])
      l9.add(l8[i][:j]+'7'+l8[i][j:])
    l9.add(l8[i]+'3')
    l9.add(l8[i]+'5')
    l9.add(l8[i]+'7')
  l9=list(l9)
  if num==9 or num==19:
    return l9+l8+l7+l6+l5+l4+l3

n=int(input())
l=len(str(n))
arr=make(l)
if len(arr)==0:
  print(0)
else:
  cnt=0
  for i in range(len(arr)):
    if int(arr[i])<=n:
      cnt+=1
  print(cnt)

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:
from collections import deque
def dfs(N):
    stack=deque(["3","5","7"])
    cnt=0
    while stack:
        cand=stack.pop()
        if all(cand.count(c)>0 for c in "357"):
            cnt+=1
        for c in "357":
            if int(cand+c)<=N:
                stack.append(cand+c)
    return cnt
if __name__=="__main__":
    N=int(input())
    print(dfs(N))

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
from math import factorial
from sys import exit, stdin
N = int(stdin.readline().rstrip())
def dfs(s):
    #print(s)
    if int(s) > N:
        #print('exit')
        return 0
    if all(s.count(c) > 0 for c in '753'):
        #print('yay!')
        ret = 1
    else:
        ret = 0
    #print('before for %d' % ret)
    for c in '753':
        #print('c in for %s' % c)
        ret += dfs(s+c)
    #print('return is %s' % ret)
    return ret

print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())

a = [3, 5, 7]

for i in range(1, 9):
    added_a = []
    for _a in a:
        added_a.append(3*(10**i)+_a)
        added_a.append(5*(10**i)+_a)
        added_a.append(7*(10**i)+_a)
    a.extend(added_a)

b = []
for _a in a:
    if _a <= N:
        b.append(_a)

c = []
for _b in b:
    _s = str(_b)
    if "3" in _s and "5" in _s and "7" in _s and "0" not in _s:
        c.append(_b)

print(len(c))

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('') と書きたいが if int(s) > N のエラー回避のために

Submission status: Accepted

Solution code:
n_str = input()
n = int(n_str)
digit = len(n_str)
top = int(n_str[0])

def calc_add(digit):
    return (3 ** (digit) - ((2 ** (digit)) * 2) + 1) if digit >= 2 else 0 
# 前項
answer = 0
if(digit > 3):
    for(pre_digit) in range(3, digit):
        answer += calc_add(pre_digit - 1) * 3
# 最大桁に3,5,7が含まれる場合
add = calc_add(digit - 1)
if(top > 3):
    # 1パターン追加
    answer += add
if(top > 5):
    # 2パターン追加
    answer += add
if(top > 7):
    # 3パターン追加
    answer += add

if (top == 3 or top == 5 or top == 7):
    # ややこなのでforチェックする.
    # チェックするリストを作成
    chk_list = []
    char_list = ["3", "5", "7"]
    counter = 0
    while True:
        string = str(top)
        cp_counter = counter
        for index in reversed(range(0, (digit - 1))):
            string += char_list[(cp_counter // (3 ** (index)))]
            cp_counter -=  (3 ** (index)) * (cp_counter // (3 ** (index)))
        if int(string) <= n:
           chk_list.append(tuple(string))
        counter += 1
        if counter >= 3 ** (digit - 1):
            break
    # チェック
    for string_number in chk_list:
        count3 = 0
        count5 = 0
        count7 = 0
        for num in string_number:
            if(int(num) == 3):
                count3 += 1
            elif(int(num) == 5):
                count5 += 1
            elif(int(num) == 7):
                count7 += 1 
            else:
                break
        else:
            if(count3 != 0 and count5 != 0 and count7 != 0):
                answer += 1
print (answer)

Submission status: Accepted

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


def dfs(k, a, b, c):
    global num
    if min(a, b, c) > 0 and int(k) <= int(N):
        num += 1
    elif int(k) > int(N):
        return

    dfs(k + '3', 1, b, c)
    dfs(k + '5', a, 1, c)
    dfs(k + '7', a, b, 1)


dfs('3', 1, 0, 0)
dfs('5', 0, 1, 0)
dfs('7', 0, 0, 1)
print(num)

Submission status: Accepted

Solution code:
N = int(input())

def f(s):
    if int(s) > N:
        return False
    ret = 1 if all(s.count(c) > 0 for c in '753') else 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, n):
    if  int(s) > n:
        return 0
    ret = 0
    if all([c in s for c in '753']):
        ret = 1
    for c in '753':
        ret += dfs(s + c, n)
    return ret 

print(dfs('0', n))

Submission status: Accepted

Solution code:
S = input()
N = len(S)
K = int(S)
num = 0


def dfs(k, a, b, c):
    global num
    if min(a, b, c) > 0 and int(k) <= K:
        num += 1
    if int(k) > K:
        return

    dfs(k + '3', 1, b, c)
    dfs(k + '5', a, 1, c)
    dfs(k + '7', a, b, 1)


dfs('3', 1, 0, 0)
dfs('5', 0, 1, 0)
dfs('7', 0, 0, 1)
print(num)

Submission status: Accepted

Solution code:
N = int(input())



def check(num):

    if num > N:
        return 0

    # check 753
    str_num =  str(num)

    count = 0

    if "7" in str_num and "5" in str_num and "3" in str_num:
        count += 1

    count += check(num*10 + 7)
    count += check(num*10 + 5)
    count += check(num*10 + 3)
    return count

    
ret = 0
ret += check(7)
ret += check(5)
ret += check(3)
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
stack = [(0, 0)]
ans = 0
while stack:
  s = stack.pop()
  if s[0] > N:
    continue
  if s[1] == 7:
    ans += 1
  stack.append((s[0] * 10 + 3, s[1] | 1))
  stack.append((s[0] * 10 + 5, s[1] | 2))
  stack.append((s[0] * 10 + 7, s[1] | 4))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
#  print("1, s:{}".format(s))
  if int(s) > N:
#    print("4, s:{}".format(s))
    return 0
  ret = 1 if all(s.count(c) > 0 for c in "753") else 0
  for c in "753":
    ret += dfs(s+c)
#    print("2, s:{}, ret:{}".format(s, ret))
#  print("3, s:{}, ret:{}".format(s, ret))
  return ret
  
print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())


def dfs(acc):
    if int(acc) > N:
        return 0
    is_hichigosan_num = False
    if '7' in acc and '5' in acc and '3' in acc:
        is_hichigosan_num = True

    return sum([
        1 if is_hichigosan_num else 0,
        dfs(acc + '7'),
        dfs(acc + '5'),
        dfs(acc + '3')
    ])


print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())


def dfs(acc, sevens, fives, threes):
    if int(acc) > N:
        return 0
    is_hichigosan_num = False
    if sevens >= 1 and fives >= 1 and threes >= 1:
        is_hichigosan_num = True

    return sum([
        1 if is_hichigosan_num else 0,
        dfs(acc + '7', sevens+1, fives, threes),
        dfs(acc + '5', sevens, fives+1, threes),
        dfs(acc + '3', sevens, fives, threes+1)
    ])


print(dfs('0', 0, 0, 0))

Submission status: Accepted

Solution code:
import itertools

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

    answer = 0

    for i_repeat in range(1, len(str(N))+1):
        for i in itertools.product([7, 5, 3], repeat=i_repeat):
            i_list = list(i)
            str_i_list = str(i_list)
            cnt_7 = str_i_list.count('7')
            cnt_5 = str_i_list.count('5')
            cnt_3 = str_i_list.count('3')
            if cnt_7 >= 1 and cnt_5 >= 1 and cnt_3 >= 1:
                num = 0
                for j, e in enumerate(i_list):
                    num += int(e) * pow(10, len(i_list)-j-1)
                if num <= N:
                    answer += 1
    print(answer)

Submission status: Accepted

Solution code:
N = int(input())

cnt = 0
def dfs(n):
    global cnt
    if len(n) >= 11:
        return 0
    for s in '357':
        dfs(n+s)
    if int(n) <= N and '3' in n and '5' in n and '7' in n:
        cnt += 1
    return cnt

print(dfs('0'))

Submission status: Accepted

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

cnt = 0


def f(s):
    if s > n:
        return False

    str_s = str(s)
    return sum(f(s*10 + i) for i in L) + ("7" in str_s and "5" in str_s and "3" in str_s)


print(f(0))

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
stack = deque(["0"])
cnt = 0
while len(stack)>0:
    c = stack.pop()
    for s in "357":
        cs = c + s
        # print(cs)
        if int(cs)<=N:
            stack.append(cs)
            if cs.count("3")*cs.count("5")*cs.count("7")>0:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
stack = deque(["0"])
cnt = 0
while len(stack)>0:
    c = stack.pop()
    for s in "753":
        cs = c + s
        # print(cs)
        if int(cs)<=N:
            stack.append(cs)
            if cs.count("3")*cs.count("5")*cs.count("7")>0:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
def dfs(s): # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        # print("invalid  ",s)
        return 0
    # print("valid    ",s)
    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: Accepted

Solution code:
N = int(input())
cnt = 0
def dfs(n, cnt):
    if int(n) > N:
        return cnt
    if n.count("3") >= 1 and n.count("5") >= 1 and n.count("7") >= 1:
        cnt += 1

    for i in ("3","5","7"):
        cnt = max(cnt, dfs(n+i, cnt))
    return cnt

print(dfs("0", 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:
N = int(input())
ans = 0
def chr(i,a):
    global ans
    if i <= 9:
        chr(i+1,a+"7")
        chr(i+1,a+"5")
        chr(i+1,a+"3")
    if i >= 3:
        if a.count("7"):
            if a.count("5"):
                if a.count("3"):
                    if int(a) <= N:    
                        ans += 1
chr(0,"")
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(s):
    if int(s) > n:
        return 0
    sum = all(s.count(c) > 0 for c in '753')
    for c in '753':
        sum += dfs(s + c)
    return sum
print(dfs('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:
S = input()

'''
357 375 537 573 735 753 
3357 3375 3537 3573 3735 3753 
5357 5375 5537 5573 5735 5753 
3357,3375,3537,

3けた　、4けた 5 ,6, 7, 8
6,18,54,162,486, 8
sum = [2 * 3,2 * 3 * 3,]
'''

N = len(S)
list375 =['3','5','7']
if N <  3:
    print(0)
    exit(0)

for i in range(N + 1):
    if i ==0:
        continue
    else:
        targetList = list375[:]
        for l in targetList:
            #print(l)
            list375.append(l + '3')
            list375.append(l + '5')
            list375.append(l + '7')

result = [i for i in list(set(list375)) if int(i) <= int(S) and (i.count('3') >0 and i.count('5') >0 and i.count('7') >0)]
#print(result)
print(len(result))


'''
def judge753():
    if keta[0] < 3:
        return 0
    if keta[0] < 5:
        if keta[1] < 3:
            return 0
        if keta[1] < 5:
            if keta[2] < 5:
                return 0
            if keta[2] < 7:
                return 1
            return 2
        if keta[1] < 7:
            
        return sum[len(S)-1]
    if keta[0] < 7:
        if keta[1] < 3:
            return sum[len(S)-1] + sum[len(S)-2]
        if keta[1] < 5:
            if keta[2] < 5:
        
        return sum[len(S)-1]
        
print(min(absList))
'''

Submission status: Accepted

Solution code:
from math import log10
N = int(input())
ndig = int(log10(N))+1
def dfs(n, s):
    if n==0:
        return 1 if int(s)<=N and "7" in s and "5" in s and "3" in s else 0
    return sum([dfs(n-1,i+s) for i in ["7","5","3"]])
ans = 0
for i in range(3,ndig+1):
    ans += dfs(i, "")
print(ans)

Submission status: Accepted

Solution code:
N = input()

def f(s):
    if int(s) > int(N):
        return 0

    if "3" in s and "5" in s and "7" in s:
        cnt = 1
    else:
        cnt = 0

    for t in "3","5","7":
        cnt += f(s + t)

    return cnt

ans = f("0")
print(ans)

Submission status: Accepted

Solution code:
N =int(input())

def dfs(s):
  # s < N　か確認。満たさなければ、これ以上先の深さを探索しない
  if int(s) > N:
    return 0
  
  # sが753数か確認
  # もしcntを下のfor内部で作ってしまうと、毎回書き換わるので7以外がカウントできないし、元のコールスタックに戻る際にもcntのスコープによっては消える
  if s.count("3") >= 1 and s.count("5") >= 1 and s.count("7") >= 1:
    cnt = 1
  else:
    cnt = 0
    
  for num in ["3", "5", "7"]:
    # ここで連結した値がNを超えても、次のdfsが呼ばれた時に初めにはじかれるから問題ない
    cnt += dfs(s + num)
    
  return cnt

ans = dfs("0")
print(ans)

Submission status: Accepted

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

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

counter = 0

for l in range(3, len(s) + 1):
    for v in itertools.product([3, 5, 7], repeat = l):
        if 3 in v and 5 in v and 7 in v:
            p = [str(p) for p in v]
            p = int("".join(p))
            
            if p <= n:
                counter += 1
                
print(counter)

Submission status: Accepted

Solution code:
N = input()

def f(s):
    if int(s) > int(N):
        return 0
    for t in '3','5','7':
        if all(['3' in s,'5' in s,'7' in s]):
            ans.append(1)
        f(s+t)

ans=[]
f('0')
print(sum(ans)//3)

Submission status: Accepted

Solution code:
N = input()
n_dig = len(N)
N = int(N)

def dfs(cur_n, n_3, n_5, n_7, cur_dig) : 
    if cur_dig == n_dig : 
        if cur_n <= N and n_3 >= 1 and n_5 >= 1 and n_7 >= 1 : 
#            print(cur_n, n_3, n_5, n_7, cur_dig)
            return 1
        else : 
            return 0

    a = dfs(cur_n*10 +3, n_3 +1, n_5, n_7, cur_dig +1)
    b = dfs(cur_n*10 +5, n_3, n_5 +1, n_7, cur_dig +1)
    c = dfs(cur_n*10 +7, n_3, n_5, n_7 +1, cur_dig +1)
    d = 0
    
    if (n_dig -3) > cur_dig and n_3 == 0 and n_5 == 0 and n_7 == 0 : 
        d = dfs(cur_n, n_3, n_5, n_7, cur_dig +1)
    
    return(a + b + c + d)

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

Submission status: Accepted

Solution code:
N = int(input())

def joinnum(N, keta, anscount, aaa):
    if aaa.count('3') > 0 and aaa.count('5') > 0 and aaa.count('7') > 0 and int(aaa) <= N:
        anscount += 1

    if keta == len(str(N)):
        return anscount
    else:
        for i in ['3', '5', '7']:
            anscount = joinnum(N, keta + 1, anscount, i + aaa)

        return anscount

print(joinnum(N, 0, 0, ''))

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())

S = [int(x) for x in str(N)]
n = len(S)

# dp[pos][smaller?][started?][3?][5?][7?]
dp = [[[[[[0] * 2 for _ in range(2)] for _ in range(2)]
        for _ in range(2)] for _ in range(2)] for _ in range(n + 1)]
dp[0][0][0][0][0][0] = 1

for i, j, k, c3, c5, c7 in product(range(n), [0, 1], [0, 1], [0, 1], [0, 1],
                                   [0, 1]):
    num = [0, 3, 5, 7]
    if not j:
        num = [x for x in num if x <= S[i]]
    if k:
        num = [x for x in num if x != 0]
    for x in num:
        f0 = k or x != 0
        f3 = c3 or x == 3
        f5 = c5 or x == 5
        f7 = c7 or x == 7
        dp[i + 1][j or x < S[i]][f0][f3][f5][f7] += dp[i][j][k][c3][c5][c7]

ans = sum([dp[n][j][1][1][1][1] for j in [0, 1]])
print(ans)