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:
def p_c():
    import sys
    sys.setrecursionlimit(10 ** 9)
    n = int(input())
    ans = 0

    def dfs(s):
        """
        :type s: str
        """
        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"))
    
p_c()

Submission status: Accepted

Solution code:
n=int(input())
option=[3,5,7]
completed=[]
a=[3,5,7]
ans=0
while option:
    number=option.pop()
    completed.append(number)
    for add_number in a:
        new_number=number*10+add_number
        if new_number<=n:
            option.append(new_number)
for i in completed:
    i=list(str(i))
    i=set(i)
    if len(set(i))==3:
        ans+=1
print(ans)

Submission status: Accepted

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

from functools import lru_cache
@lru_cache(maxsize=10**6)
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:
import sys
sys.setrecursionlimit(10**6)

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
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
#https://atcoder.jp/contests/arc084/tasks/arc084_a
#C - Snuke Festival
"""
need to consider the case that ticket is not enough to lower everything
"""


def bt():
    global prefix, ans
    prefix *= 10

    for i in range(3):
        prefix += ds[i]
        cnt[i] += 1

        if prefix <= N:
            if all(cnt):
                ans += 1
            bt()
        cnt[i] -= 1
        prefix -= ds[i]
    prefix /= 10


N = gi()
prefix = 0
ds = [3, 5, 7]
cnt = [0] * 3
ans = 0

bt()
print(ans)

Submission status: Accepted

Solution code:
#abc114 c-755
k=input()
n=int(k)

x=['7','5','3']
m=0
def dfs(i,s):
    ans=0
    if i==m:
        if int(s)<=n and x[0] in s and x[1] in s and x[2] in s:
            return 1
        else:
            return 0
    ans+=dfs(i+1,s+x[0])
    ans+=dfs(i+1,s+x[1])
    ans+=dfs(i+1,s+x[2])
    return ans
ans=0
for l in range(3,len(k)+1):
    m=l
    ans+=dfs(0,'')
print(ans)

Submission status: Accepted

Solution code:
import itertools
print(sum([sum([sum([N>=int("".join(i)) for i in itertools.product("357",repeat=n) if "3" in i and "5" in i and "7" in i]) for n in range(3,10)]) for N in [int(input())]]))

Submission status: Accepted

Solution code:
from fractions import Fraction ,gcd
import itertools
N=int(input())

count=0
for n in range(3,10):
    for i in itertools.product("357",repeat=n):
        if "3" in i and "5" in i and "7" in i:
            count+=N>=int("".join(i))
print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
counter = 0
def dfs(num):
    global counter
  
    if num != "" and int(num)>n:return
    if "3"in num and "5" in num and "7" in num :counter+=1
    dfs(num+"7")
    dfs(num+"5")
    dfs(num+"3")
    
    

    


    
    
  

dfs("")  
print(counter)

Submission status: Accepted

Solution code:
N = int(input())


def f(s, cnt):
    if s and int(s) > N:
        return 0
    res = 0
    if all(a in s for a in "753"):
        res += 1
    for a in "753":
        res += f(s + a, cnt)
    return res


print(f("", 0))

Submission status: Accepted

Solution code:
import sys
from itertools import product
from bisect import bisect_right as bi_r

shichigosan = set('357')

cand = []
for i in range(3, 10):
    for x in product('357', repeat=i):
        x = ''.join(x)
        if set(x) == shichigosan:
            cand.append(int(''.join(x)))

n = int(sys.stdin.readline().rstrip())

def main():
    return bi_r(cand, n)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
m=len(str(n))
r=0

def dfs(i,s):
    global r
    if len(set(s))==3 and int(s)<=n:
        r+=1
    if i==m:
        return
    dfs(i+1,'3'+s)
    dfs(i+1,'5'+s)
    dfs(i+1,'7'+s)

dfs(0,'')
print(r)

Submission status: Accepted

Solution code:
S="753"
ans = 0

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

def dfs(s):
  global ans
  if len(s) == keta:
    if int(s) <= N and ('7' in s and '5' in s and '3' in s):
      ans += 1
    return
  elif len(s) < keta:
    if int(s) <= N and ('7' in s and '5' in s and '3' in s):
      ans += 1
  for c in S:
    dfs(s+c)

dfs('3')
dfs('5')
dfs('7')

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
l = [0]
def dfs(v, N):
    if int(v)<= N:
        flag = True
        if v.count("3") <= 0:
            flag = False
        if v.count("5") <= 0:
            flag = False
        if v.count("7") <= 0:
            flag = False
        if flag:
            l[0] += 1
    else:
        return
    dfs(v + "7", N)
    dfs(v + "5", N)
    dfs(v + "3", N)
dfs("0", N)
print(l[0])

Submission status: Accepted

Solution code:
N=int(input())
a=len(str(N))

import itertools
ans=0
A=['7','5','3']
for i in range(3,a+1):
  for j in list(itertools.product(A,repeat=i)):
    if '7' in j and '5' in j and '3' in j:
      if int(''.join(j))<=N:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
l = []
def dfs(v, N):
    if int(v)<= N:
        flag = True
        if v.count("3") <= 0:
            flag = False
        if v.count("5") <= 0:
            flag = False
        if v.count("7") <= 0:
            flag = False
        if flag:
            l.append(1)
    else:
        return
    dfs(v + "7", N)
    dfs(v + "5", N)
    dfs(v + "3", N)
dfs("0", N)
print(sum(l))

Submission status: Accepted

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


def main():
    N = int(input())

    a = 0
    for i in range(3, len(str(N)) + 1):
        for j in itertools.product("357", repeat=i):
            if len(collections.Counter(j)) >= 3:
                if int("".join(j)) <= N:
                    a += 1

    print(a)












if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
if N <= 356:
  print(0)
else:
  L = ['3','5','7']
  for i in range(len(str(N))-1):
    for j in range(len(L)):
      L.append(L[j]+'3')     #L[j]に"3"を加えた数をLに追加
      L.append(L[j]+'5')
      L.append(L[j]+'7')
  K=list(set(L))
  for i in range(len(K)):
    if K[i].count('3') > 0:
      if K[i].count('5') > 0:
        if K[i].count('7') > 0:
          if int(K[i]) <= N:
            ans += 1
  print(ans)

Submission status: Accepted

Solution code:
N=int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:


N = int(input())
from itertools import product
S = ["3", "5", "7"]

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
ans = 0
for k in range(3, 10):
    for prod in product("357", repeat=k):
        if all(s in prod for s in "357") and int("".join(prod)) <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

def dfs(x):
    if x>n:
        return 0
    cnt = 1 if all(str(x).count(a) > 0 for a in '753') else 0
    for a in '753':
        cnt += dfs( int(str(x)+a) )
    return cnt
print(dfs(0))

Submission status: Accepted

Solution code:
import itertools
if __name__ == '__main__':
  
  N = input()
  n = int(N)
  count = 0
  for i in range(0, len(N)):

    temp = itertools.product(["3", "5", "7"], repeat=i+1)
    for j in temp:
      s = "".join(j)
      
      if ("3" in s and "5" in s and "7" in s and int(s) <= n):
        count += 1
  
  print(count)

Submission status: Accepted

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

ans=0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
sitigosan = []

def dfs(i,siti):
  if i == 9:
    pass
  else:
    dfs(i+1,siti*10+3)
    dfs(i+1,siti*10+5)
    dfs(i+1,siti*10+7)
    sitigosan.extend([siti*10+3,siti*10+5,siti*10+7])
    
dfs(0,0)
ans = 0
for i in sitigosan:
  if i <= n and set(str(i)) == {"3","5","7"}:
    ans += 1
  
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
ans = 0
for i in range(3,len(str(n))+1):
    for tuple357 in itertools.product([3,5,7], repeat=i):
        if len(set(tuple357)) < 3:
            continue
        number = int(''.join(map(str,tuple357)))
        if number <= n:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
L = ["3","5","7"]

l = len(str(n))

cnt = 0
for i in range(1,l+1):
    p = product(L,repeat = i)
    for j in p:
        d = "".join(j)
        if ("3" in d) and ("5" in d) and ("7" in d) and int(d) <= n:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc114/tasks/abc114_c

# 7,5,3がそれぞれ1回以上現れる数
# 3進数を自分で作ってしまうのは？→3,5,7の順にiterateするのは十分間に合う
# 10進数で10**9は3進数だけ考慮するなら10**4.5ぐらいですむ


from itertools import product
N = int(input())
number = ['0'] * 9
nums = ['0', '3', '5', '7']
arg = [nums] * 9


ans = 0
for iters in product(*arg):  # 頭がわるいので
    tmp = int(''.join(iters))
    if tmp > N:
        break
    tmp = str(tmp)
    if tmp.count('0') > 0 or tmp.count('3') == 0 or tmp.count('5') == 0 or tmp.count('7') == 0:
        continue
    else:
        ans += 1


print(ans)

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())

cnt = 0
for n in range(1, len(str(N)) + 1):
    for c in itertools.product('753', repeat=n):
        c = ''.join(c)
        if '7' in c and '5' in c and '3' in c and int(c) <= N:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())


def dfs(ret, cur, f1, f2, f3):
    if N < cur:
        return ret
    ret += 1 if f1 and f2 and f3 else 0
    ret = dfs(ret, cur * 10 + 7, True, f2, f3)
    ret = dfs(ret, cur * 10 + 5, f1, True, f3)
    ret = dfs(ret, cur * 10 + 3, f1, f2, True)
    return ret


def main():
    print(dfs(0, 0, False, False, False))
    return


main()

Submission status: Accepted

Solution code:
N = int(input())


def dfs(ret, cur, f1, f2, f3):
    if N < cur:
        return ret

    ret += 1 if f1 and f2 and f3 else 0

    ret = dfs(ret, cur * 10 + 7, True, f2, f3)
    ret = dfs(ret, cur * 10 + 5, f1, True, f3)
    ret = dfs(ret, cur * 10 + 3, f1, f2, True)

    return ret


def main():
    print(dfs(0, 0, False, False, False))
    return


main()

Submission status: Accepted

Solution code:
N = input()


def f(d, used, cur):
    num = len(used | set(cur))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 1:
        return 3 ** d - 2 * (2 ** d) + 1
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d


def high(N, used, ret):
    if N:
        if N[0] > "3":
            ret += f(len(N) - 1, used, "3")
        if N[0] > "5":
            ret += f(len(N) - 1, used, "5")
        if N[0] > "7":
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in "357":
        ret = high(N[1:], used | set(N[0]), ret)
    return ret


def low():
    ret = 0
    for d in range(len(N) - 1):
        ret += 3 * (3 ** d - 2 ** (d + 1) + 1)
    return ret


def main():
    print(high(N, set(), low()))
    return


main()

Submission status: Accepted

Solution code:
N = input()


def f(d, used, cur):
    num = len(used | set(cur))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3 ** d
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d - 2 * (2 ** d) + 1


def high(N, used, ret):
    if N:
        if N[0] > "3":
            ret += f(len(N) - 1, used, "3")
        if N[0] > "5":
            ret += f(len(N) - 1, used, "5")
        if N[0] > "7":
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in "357":
        ret = high(N[1:], used | set(N[0]), ret)
    return ret


def low():
    ret = 0
    for d in range(len(N) - 1):
        ret += 3 * (3 ** d - 2 ** (d + 1) + 1)
    return ret


def main():
    print(high(N, set(), low()))
    return


main()

Submission status: Accepted

Solution code:

n = int(input())
l = len(str(n))

from itertools import product

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

count = 0
for i in range(3, l+1):
  for j in list(product(*[a for _ in range(i)])):
    if "3" in j and "5" in j and "7" in j:
      num = int("".join(j))
      if num <= n:
        count += 1

print(count)

Submission status: Accepted

Solution code:
N = input()


def f(d, used, next):
    num = len(used | set(next))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3 ** d
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d - 2 * (2 ** d) + 1


def high(N, used, ret):
    if N:
        if N[0] > "3":
            ret += f(len(N) - 1, used, "3")
        if N[0] > "5":
            ret += f(len(N) - 1, used, "5")
        if N[0] > "7":
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in "357":
        ret = high(N[1:], used | set(N[0]), ret)
    return ret


def low():
    ret = 0
    for i in range(len(N) - 1):
        ret += 3 * (3 ** i - 2 ** (i + 1) + 1)
    return ret


def main():
    print(high(N, set(), low()))
    return


main()

Submission status: Accepted

Solution code:
N = input()


def f(d, used, next):
    num = len(used | set(next))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3 ** d
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d - 2 * (2 ** d) + 1


def high(N, used, ret):
    if N:
        if N[0] > "3":
            ret += f(len(N) - 1, used, "3")
        if N[0] > "5":
            ret += f(len(N) - 1, used, "5")
        if N[0] > "7":
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in ["3", "5", "7"]:
        ret = high(N[1:], used | set(N[0]), ret)
    return ret


def low():
    ret = 0
    for i in range(len(N) - 1):
        ret += 3 * (3 ** i - 2 ** (i + 1) + 1)
    return ret


def main():
    print(high(N, set(), low()))
    return


main()

Submission status: Accepted

Solution code:
N = input()


def f(d, used, next):
    num = len(used | set(next))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3 ** d
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d - 2 * (2 ** d) + 1


def high(N, used, ret):
    if N:
        if int(N[0]) > 3:
            ret += f(len(N) - 1, used, "3")
        if int(N[0]) > 5:
            ret += f(len(N) - 1, used, "5")
        if int(N[0]) > 7:
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret
    if N[0] in ["3", "5", "7"]:
        ret = high(N[1:], used | set(N[0]), ret)
    return ret


def low():
    d = 0
    ret = 0
    for i in range(len(N) - 1):
        ret += 3 * (3 ** d - 2 ** (d + 1) + 1)
        d += 1
    return ret


def main():
    print(high(N, set(), low()))
    return


main()

Submission status: Accepted

Solution code:
N = input()


def f(d, used, next):
    num = len(used | set(next))
    if d == 0:
        if num == 3:
            return 1
        else:
            return 0
    elif num == 3:
        return 3 ** d
    elif num == 2:
        return 3 ** d - 2 ** d
    else:
        return 3 ** d - 2 * (2 ** d) + 1


def high(N, used, ret):
    if N:
        if int(N[0]) > 3:
            ret += f(len(N) - 1, used, "3")
        if int(N[0]) > 5:
            ret += f(len(N) - 1, used, "5")
        if int(N[0]) > 7:
            ret += f(len(N) - 1, used, "7")
    else:
        if len(used) == 3:
            ret += 1
        return ret

    if N[0] in ["3", "5", "7"]:
        ret = high(N[1:], used | set(N[0]), ret)

    return ret


def low():
    d = 0
    ret = 0
    for i in range(len(N) - 1):
        ret += 3 * (3 ** d - 2 ** (d + 1) + 1)
        d += 1
    return ret


def main():
    print(high(N, set(), low()))
    return


main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N=int(input().rstrip())
count=0

def resolve():
    global count
    dfs("")
    print(count)

def dfs(s):
    global count
    
    if s!="":
        if int(s)>N:
            return

    if s.find("3")!=-1 and s.find("5")!=-1 and s.find("7")!=-1:
        count+=1
    
    s3=str(s)+str(3) if s!="" else str(3)
    s5=str(s)+str(5) if s!="" else str(5)
    s7=str(s)+str(7) if s!="" else str(7)

    dfs(s3)
    dfs(s5)
    dfs(s7)



    """
    s3=str(s)+str(3) if s!="" else str(3)
    s5=str(s)+str(5) if s!="" else str(5)
    s7=str(s)+str(7) if s!="" else str(7)

    if s3.find("3")!=-1 and s3.find("5")!=-1 and s3.find("7")!=-1 and int(s3)<=N:
        count+=1
    if int(s3)>N:
        return
    dfs(s3)

    if s5.find("3")!=-1 and s5.find("5")!=-1 and s5.find("7")!=-1 and int(s5)<=N:
        count+=1
    if int(s5)>N:
        return
    dfs(s5)

    if s7.find("3")!=-1 and s7.find("5")!=-1 and s7.find("7")!=-1 and int(s7)<=N:
        count+=1
    if int(s7)>N:
        return
    dfs(s7)
    """

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """575"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3600"""
        output = """13"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """999999999"""
        output = """26484"""
        self.assertIO(input, output)

if __name__ == "__main__":
#    unittest.main()
    resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N=int(input().rstrip())
count=0

def resolve():
    global count
    dfs("")
    print(count)

def dfs(s):
    global count
    

    s3=str(s)+str(3) if s!="" else str(3)
    s5=str(s)+str(5) if s!="" else str(5)
    s7=str(s)+str(7) if s!="" else str(7)

    if s3.find("3")!=-1 and s3.find("5")!=-1 and s3.find("7")!=-1 and int(s3)<=N:
        count+=1
    if int(s3)>N:
        return
    dfs(s3)

    if s5.find("3")!=-1 and s5.find("5")!=-1 and s5.find("7")!=-1 and int(s5)<=N:
        count+=1
    if int(s5)>N:
        return
    dfs(s5)

    if s7.find("3")!=-1 and s7.find("5")!=-1 and s7.find("7")!=-1 and int(s7)<=N:
        count+=1
    if int(s7)>N:
        return
    dfs(s7)


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """575"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3600"""
        output = """13"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """999999999"""
        output = """26484"""
        self.assertIO(input, output)

if __name__ == "__main__":
#    unittest.main()
    resolve()

Submission status: Accepted

Solution code:
Table=[0,0,0,6,42,192,732,2538,8334,26484]
N=int(input())
K=len(str(N))
ans=Table[K-1]

import itertools
U=['3','5','7']
PRD = list(itertools.product(U, repeat=K))
for i in PRD:
    T=''.join(i)
    if int(T)>N:
        break
    if '3' in T and '5' in T and '7' in T:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
from collections import deque


def solve():
    N = int(input())
    
    nums = []
    que = deque([0])
    while que:
        num = que.pop()
        for c in '357':
            n_num = num*10 + int(c)
            if n_num <= N:
                if '3' in str(n_num) and '5' in str(n_num) and '7' in str(n_num):
                    nums.append(n_num)
                que.append(n_num)
    
    print(len(nums))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import itertools

n = int(input())

l = len(str(n))
P = [3,5,7]
count = 0

for l_i in range(3, l+1):
  comb = list(itertools.product(P, repeat = l_i))
  for comb_i in comb:
    check_num = int(''.join(map(str, comb_i)))
    if check_num <= n and len(set(comb_i)) == 3:
      count += 1
      
print(count)

Submission status: Accepted

Solution code:
N = input().strip()
n = len(N)
dp = [[[[[[0 for _ in range(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 in range(1,n+1):
    for lead in range(2):
        for small in range(2):
            for a in range(2):
                for b in range(2):
                    for c in range(2):
                        if lead ==0:
                            dp[i][0][small or (0<int(N[i-1]))][a][b][c] += dp[i-1][0][small][a][b][c]
                        for j in range(3,min(int(N[i-1]),7)+1 if small==0 else 8, 2):
                            dp[i][1][small or (j<int(N[i-1]))][a or (j==3)][b or (j==5)][c or (j==7)] += dp[i-1][lead][small][a][b][c]
print(dp[n][1][0][1][1][1]+dp[n][1][1][1][1][1])

Submission status: Accepted

Solution code:
import itertools

N = int(input())

l = len(str(N))

ans = 0
for i in range(1,l+1):
    for v in itertools.product(['3','5','7'],repeat=i):
        if '3' in v and '5' in v and '7' in v:
            n = int(''.join(list(v)))
            if n <= N:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

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

Submission status: Accepted

Solution code:
def recursive(num, n):
    if int(num) > n:
        return 0
    if all(num.count(val) for val in '357'):
        count = 1
    else:
        count = 0
    for val in '357':
        count += recursive(num+val, n)
    return count


def main():
    n = int(input())
    num = '0'
    count = recursive(num, n)
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)

n=int(input())
cnt=0
#curは今の数字
def dfs(cur,f3,f5,f7):
		global cnt
		#print(cur,f3,f5,f7,cnt)
		if cur>n:
			return
		elif f3&f5&f7:
			cnt+=1
		dfs(cur*10+3,True,f5,f7)
		dfs(cur*10+5,f3,True,f7)
		dfs(cur*10+7,f3,f5,True)

dfs(0,False,False,False)
print(cnt)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
sgs = {"3", "5", "7"}
ans = {""}
for i in range(len(str(N))):
  res = set()
  for x in ans:
    for i in sgs:
      if int(i+x) <= N:
        res.add(i+x)
  ans |= res
print(len([x for x in ans if set(list(x)) == sgs]))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
STR = ['3','5','7']
cnt = 0
for i in range(10):
    if N<10**i-1:
        break
    else:
        A=list(product(STR,repeat = i+1))
        # Aにiけた未満の３５７の組み合わせを入れる
        for j in A:
            # ３桁かつ３、５、７が一個以上入るかつNより小さい数
            if j.count('3')>=1 and j.count('5')>=1 and j.count('7')>=1 and int(''.join(j))<=N:
                cnt +=1
print(cnt)

Submission status: Accepted

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

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

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

            if num.count('3') >= 1 and num.count('5')>=1 and num.count('7') >=1 and int(''.join(num))<=N:
                answer +=1

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

def getNum(s):
    if int(s) >N:
        return 0
    ret = 0
    if all(s.count(c) > 0 for c in '357'):
        ret = 1
    for c in '357':
        ret += getNum(s+c)
    return(ret)

print(getNum('0'))

Submission status: Accepted

Solution code:
n = int(input())

def dfs(count, s):
	if int(s) > n:
		return count
	if '3' in s and '5' in s and '7' in s:
		count += 1
	for c in '357':
		count = dfs(count, s+c)
	return count

print(dfs(0, '0'))

Submission status: Accepted

Solution code:
n = int(input())

def dfs(count, s):
    if int(s) > n:
        return count
    if '3' in s and '5' in s and '7' in s:
        count += 1
    for c in '357':
        count = dfs(count, s+c)
    return count

print(dfs(0, '0'))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
STR = ['3','5','7']
cnt = 0
for i in range(10):
  if N < 10 ** i-1:
    break
  else:
    A=list(product(STR,repeat = i+1))
    for j in A:
      if j.count('3')>=1 and j.count('5')>=1 and j.count('7')>=1 and int(''.join(j))<=N:
        cnt +=1
print(cnt)

Submission status: Accepted

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

def solve(N: int):
    n = len(str(N))
    ans = 0
    candidate = ["3", "5", "7"]
    break_flag = False
    for i in range(1, n + 1):
        combi_int = []
        for tmp in itertools.product(candidate, repeat=i):
            combi_int.append(int("".join(tmp)))
        combi_int = sorted(combi_int)
        if break_flag:
            break
        for tmp in combi_int:
            if N < tmp:
                break_flag = True
                break
            else:
                if "3" in str(tmp) and "5" in str(tmp) and "7" in str(tmp):
                    #print(tmp)
                    ans += 1
    print(ans)

# Generated by 1.1.6 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 = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

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())
cnt=0
def rei(a,f3,f5,f7):
    global cnt
    #print(a,cnt)
    if a>n:
        return
    elif f3&f5&f7:
        cnt+=1
    rei(a*10+3,True,f5,f7)
    rei(a*10+5,f3,True,f7)
    rei(a*10+7,f3,f5,True)

rei(0,False,False,False)
print(cnt)

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())
ans = 0
def dfs(s):
    if int(s) <= N and len(set(s)) >= 3:
        global ans
        ans += 1

    if len(s) == 9:
        return
    dfs(s + "7")
    dfs(s + "5")
    dfs(s + "3")

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

print(ans)