Problem:


Score : 300 points

Problem Statement

You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?

Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:

When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

Sample Input 1

575

Sample Output 1

4

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

Sample Input 2

3600

Sample Output 2

13

There are 13 Shichi-Go-San numbers not greater than 3600: the above four numbers, 735, 753, 3357, 3375, 3537, 3557, 3573, 3575 and 3577.

Sample Input 3

999999999

Sample Output 3

26484



Sample input:
575


Sample output:
4

Submission status: Accepted

Solution code:
n=int(input())
def f(s):
  if int(s)>n:
    return 0
  t=0
  if s.count("3")>0 and s.count("5")>0 and s.count("7")>0:
    t=1
  return f(s+"7")+f(s+"5")+f(s+"3")+t
print(f("0"))

Submission status: Accepted

Solution code:
#解説AC,9割写経
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 Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = []
for i in range(10):
    for p in itertools.product(['3','5','7'],repeat=i):
        if '3' in p and '5' in p and '7' in p:
            s.append(int(''.join(p)))
res = 0
for i,t in enumerate(s):
    if t <= n:
        res += 1
print(res)

Submission status: Accepted

Solution code:
import itertools
import bisect
n=int(input())
s=[]
for i in range(3,10):
  for p in itertools.product(['3','5','7'],repeat=i):
    if '3' in p and '5' in p and '7' in p:
      s.append(int(''.join(p)))
x=bisect.bisect_right(s,n)
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def STR(): return input()

def func(a, b):
    if a > b:
        return 0
    else:
        return 1

def solve_dp(arr, ii):
    dp = [[0, 0] for _ in range(ii)]
    lenarr = len(arr)
    n0 = int(n[0])
    a = lenarr
    for j in range(lenarr):
        a -= func(n0, arr[j])
    dp[0][0] = a
    dp[0][1] = 1 if n0 in arr else 0
    for i in range(1, ii):
        ni = int(n[i])
        a = lenarr
        for j in range(lenarr):
            a -= func(ni, arr[j])
        dp[i][0] = dp[i-1][0] * lenarr + dp[i-1][1] * a
        dp[i][1] = dp[i-1][1] if ni in arr else 0
    return sum(dp[ii-1])

n = STR()
l = len(n)
ans = 0

arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]
ans = solve_dp(arr[6], l)
for i in range(3):
    ans += solve_dp(arr[i], l)
for i in range(3, 6):
    ans -= solve_dp(arr[i], l)
for i in range(1, l):
    ans += pow(3, i) + 3 - 3 * pow(2, i)
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def func(a, b):
    if a > b:
        return 0
    else:
        return 1

def solvedp(arr, ii):
    dp = [[0, 0] for _ in range(ii)]
    lenarr = len(arr)
    if ii == l:
        n0 = int(n[0])
        a = lenarr
        for j in range(lenarr):
            a -= func(n0, arr[j])
        dp[0][0] = a
        dp[0][1] = 1 if n0 in arr else 0
    else:
        dp[0][0] = lenarr
    for i in range(1, ii):
        if ii == l:
            ni = int(n[i])
            a = lenarr
            for j in range(lenarr):
                a -= func(ni, arr[j])
            dp[i][0] = dp[i-1][0] * lenarr + dp[i-1][1] * a
            dp[i][1] = dp[i-1][1] if ni in arr else 0
        else:
            dp[i][0] = dp[i-1][0] * lenarr
    return dp

n = STR()
l = len(n)
ans = 0

arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]
for ii in range(1, l + 1):
    dp = [[[0, 0]for _ in range(ii)]for _ in range(7)]
    for i in range(7):
        dp[i] = solvedp(arr[i], ii)

    res = sum(dp[6][ii-1])
    for i in range(3, 6):
        res -= sum(dp[i][ii-1])
    for i in range(3):
        res += sum(dp[i][ii-1])
    ans += res
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
def dfs(s):
    if int(s) > N:
        return 0
    else:
        if '7' in s and '5' in s and '3' in s:
            ret = 1
        else:
            ret = 0
        for i in '357':
            ret += dfs(s + i)
        return ret
print(dfs("0"))

Submission status: Accepted

Solution code:
def f(a,b):
#a=7,5,3  b=0-7
#no=0, 3=1, 5=2, 7=4, all=7
    if a==7 and b>=4: return b
    if a==7 and b<4: return b+4
    if a==5 and b in (2,3,6,7): return b
    if a==5 and b not in (2,3,6,7): return b+2
    if a==3 and b in (1,3,5,7): return b
    if a==3 and b not in (1,3,5,7): return b+1

n=input()

#a,b=map(int, input().split())
#print(f(a,b))
l=[int(i) for i in "0"+n]
dp=[[[0]*9,[0]*9] for _ in "ww"]
dp[0][0][0]=1

chk=(7,5,3)
for i,j in enumerate(l):
    if i==0: continue
    elif i==1:
        if j in chk: dp[i%2][0][f(j,0)]=1
        if j not in chk: dp[i%2][0][0]=1
        if j>7: dp[i%2][1][4]+=1
        if j>5: dp[i%2][1][2]+=1
        if j>3: dp[i%2][1][1]+=1
        dp[i%2][1][0]=1
    else:
        dp[i%2][1][0]=1
        dp[i%2][1][4]+=1
        dp[i%2][1][2]+=1
        dp[i%2][1][1]+=1
        for k in range(8):
            if dp[i%2-1][0][k] and (k==0 or j not in chk): dp[i%2][0][0]=1
            elif dp[i%2-1][0][k] and j in chk: dp[i%2][0][f(j,k)]=1

            if dp[i%2-1][0][k] and k!=0:
                if j>7: dp[i%2][1][f(7,k)]+=1
                if j>5: dp[i%2][1][f(5,k)]+=1
                if j>3: dp[i%2][1][f(3,k)]+=1
            if dp[i%2-1][1][k] and k!=0:
                dp[i%2][1][f(7,k)]+=dp[i%2-1][1][k]
                dp[i%2][1][f(5,k)]+=dp[i%2-1][1][k]
                dp[i%2][1][f(3,k)]+=dp[i%2-1][1][k]
    for k in range(9):
        dp[i%2-1][0][k]=0
        dp[i%2-1][1][k]=0

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

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if '7' in s and '5' in s and '3' in s 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**8)

N = int(input())

def sft(p) :
    if int(p) > N :
        return 0
    co = 0
    if "7" in p and "5" in p and "3" in p :
        co = 1
    co += sft(p+"7") + sft(p+"5") + sft(p+"3")
    return co

print(sft("0"))

Submission status: Accepted

Solution code:
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n = int(input())

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

        for c in '753':
            res += dfs(s + c)
        return res

    print(dfs('0'))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n = int(input())
    str_n = str(n)
    #print(str_n)
    ngs = ['3','5','7']
    #a = list(product(ngs, repeat=len(str_n)))
    #print(a)
    ans = ''
    count = 0
    for i in range(1,len(str_n)+1):
        for j in list(product(ngs, repeat=i)):
            #print(j)
            for k in j:
                ans += k
            #print(ans)
            ngs_and_ans = set(ngs) & set(ans)
            if int(ans) <= n and len(ngs_and_ans) == 3:
                count += 1
            ans = ''
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#abc 114 c

n=input()
n_len=len(n)
nana=["7","5","3"]

def dfs(s):
    #print(s,n)
    if int(s)>int(n):
        return 0
    d=1 if all(s.count(nana[i])>=1 for i in range(3) ) else 0
    for j in range(3):
        d+=dfs(s+nana[j])
    return d

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

Submission status: Accepted

Solution code:
N = int(input())
def dfs(S):
    if int(S) > N:
        return 0
    res = 1 if all(S.count(x) > 0 for x in '753') else 0
    for x in '753':
        res += dfs(S+x)
    return res

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())
s = "357"
cnt = 0
for i in range(1,10):
    for j in range(3**i):
        n = j
        t = ""
        for k in range(i):
            t+=s[n%3]
            n//=3
        if len(set(t))!=3:continue
        if int(t)<=N:cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0

    ans = 1 if sorted(list(set(str(s)))) == ['0', '3', '5', '7'] else 0
    for i in '753':
        ans += dfs(s + i)

    return ans


print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(x):
    if int('0'+x) > N:
        return 0

    retval = 1 if len(set(x)) == 3 else 0
    for c in '753':
        retval += dfs(x + c)
    return retval


print(dfs(''))

Submission status: Accepted

Solution code:
n = int(input())

def squ(x):
    if x == 0:
        return '0'
    a = ""
    while x != 0:
        x, mod = divmod(x, 4)
        a += str(mod)
    return a[::-1]


ans = 0

for x in range(10**6):
    x_squ = squ(x)
    x_str = x_squ.replace('3', '7').replace('2', '5').replace('1', '3')

    if "0" in x_str:
        continue

    if int(x_str) > n:
        break

    if len(set(x_str)) != 3:
        continue

    ans += 1

print(ans)

Submission status: Accepted

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

N = int(input())

dfs(0, 0, 0, 0)
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 f(s):
    if int(s) > N:
        return 0
    res=1 if all(s.count(c)>0 for c in "357") else 0    
    for c in "357":
        res += f(s+c)
    return res    
print(f("0"))

Submission status: Accepted

Solution code:
n=int(input())
A=[3,5,7]
past=int(0)
head=int(2)
for i in range(9):
    for j in range(past,head+1):
        A.append(10*A[j]+3)
        A.append(10*A[j]+5)
        A.append(10*A[j]+7)
    past=head+1
    head=len(A)

ans=int(0)
for i in range(len(A)):
    t=0
    f=0
    s=0
    now=A[i]
    while(now>0):
        if now%10==3:
            t=1
        if now%10==5:
            f=1
        if now%10==7:
            s=1
        now=int(now/10)
    
    if t and f and s and A[i]<=n:
        ans+=1
        
print(ans)

Submission status: Accepted

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

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs("0",N))

Submission status: Accepted

Solution code:
n = input()
l = len(n)
ans = 0
stack = ["7", "3", "5"]

def check753(s):
  if "7" in s and "3" in s and "5" in s:
    return True
  else:
    return False


while stack:
  s = stack.pop()
  if int(n) >= int(s) and len(s) >= 3 and check753(s):
    ans+=1
  if len(s) < l:
    for i in ["7", "5", "3"]:
      stack.append(i+s)
      
print(ans)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
l=len(str(N))
s=set()
S='753'
for i in range(1,l+1):
    for j in itertools.product(S,repeat=i):
        s.add(int(''.join(j)))
li=sorted(s)
cnt=0
for i in range(len(li)):
    if(li[i]>N):
        break
    if('7' in str(li[i]) and '5' in str(li[i]) and '3' in str(li[i])):
        cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

cnt = 0

def dfs(s):    
    global cnt
    
    if int(s) > n:
        return None
    
    else:
        if s.count('3') >= 1 and s.count('5') >= 1 and s.count('7') >= 1:
            cnt += 1
            
        dfs(s+'3')
        dfs(s+'5')
        dfs(s+'7')


dfs('0')
print(cnt)

Submission status: Accepted

Solution code:

"""

4進法で表す
各桁が
0→0
1→3
2→5
3→7で変換

"""

def change4(x):
    ret = []

    for i in range(10,-1,-1):
        ret.append(x // (4**i))
        x %= (4**i)
    ret.reverse()
    return ret

N = input()
ni = int(N)
ch = [0,3,5,7]
ans = 0

for i in range(4 ** len(N)):

    now = change4(i)

    if 1 not in now or 2 not in now or 3 not in now:
        continue

    zf = False
    flag = True
    nsum = 0
    for j in range(11):
        if now[j] == 0:
            zf = True
        elif zf:
            flag = False
            break
        else:
            nsum += (10**j) * ch[now[j]]
            #print (nsum)

    if flag and nsum <= ni:
        ans += 1
    
    #print (nsum)

print (ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    print(dfs("0",n))



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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
n = int(input())
target = ["7","5","3"]
c = 0
for i in range(1,len(str(n))+1):
  for p in list(itertools.product(target,repeat=i)):
    if int("".join(list(p))) <= n and len(set(p))==3: c += 1
print(c)

Submission status: Accepted

Solution code:
from bisect import bisect_right

def sft(n, s):
    d = len(s[0])
    if s and d == n:
        return sorted([int(i) for i in s])
    a = []
    for i, si in enumerate(s):
        for k in range(3):
            ai = si + "357"[k]
            da = len(set(list(ai)))
            if d == n - 2 and da < 2:
                continue
            if d == n - 1 and da < 3:
                continue
            a.append(ai)
    return sft(n, a)

def main():
    n = input()
    d = len(n)
    s = []
    l = list("357")
    for i in range(3, d + 1):
        s += sft(i, l)
    print(bisect_right(s, int(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:
import itertools

s=input()

keta = len(s)

risuto = ['3','5','7']

ans = 0

for i in range(3,keta+1):
    for j in itertools.product(risuto, repeat=i):
        #print(j)
        if '3' in j and '5' in j and '7' in j:
            if int(''.join(j)) <= int(s):
                   ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())
S = len(str(N))
T = ["7","5","3"]
ans = 0
for s in range(3,S+1):
    for i in range(3**s):
        A = []
        n = i
        for j in range(s):
            A.append(n%3)
            n//=3
        if len(set(A))<3:continue
        k = "".join([T[a] for a in A])
        if int(k)<=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())

cnt = 0

def cn(n,N):
    global cnt
    
    if n == 0:
        return 0
    a = int("3"+n) 
    b = int("5"+n) 
    c = int("7"+n)
    if a <= N and "5" in n and "7" in n:
        cnt += 1
    if b <= N and "3" in n and "7" in n:
        cnt += 1
    if c <= N and "3" in n and "5" in n:
        cnt += 1
      
    if a > N:
        cn(0,N)
    else:
        cn(str(a),N)
    if b > N:
        cn(0,N)
    else:
        cn(str(b),N)
    if c > N:
        cn(0,N)
    else:
        cn(str(c),N)

cn("",N)
print(cnt)

Submission status: Accepted

Solution code:
def main():
  n=[int(i) for i in list(input())]
  l=len(n)
  
  def abc_num(n,a,b,c):
    dp=[[0]*2 for i in range(l+1)]
    dp[0][0]=1
    for i in range(l):
      if n[i]<a:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][1]*3
      elif n[i]==a:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][1]*3
      elif n[i]<b:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]+dp[i][1]*3
      elif n[i]==b:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]+dp[i][1]*3
      elif n[i]<c:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*3
      elif n[i]==c:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*3
      else:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*3+dp[i][1]*3
    return sum(dp[-1])
    
        
  def ab_num(n,a,b):
    dp=[[0]*2 for i in range(l+1)]
    dp[0][0]=1
    for i in range(l):
      if n[i]<a:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][1]*2
      elif n[i]==a:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][1]*2
      elif n[i]<b:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]+dp[i][1]*2
      elif n[i]==b:
        dp[i+1][0]=dp[i][0]
        dp[i+1][1]=dp[i][0]+dp[i][1]*2
      else:
        dp[i+1][0]=0
        dp[i+1][1]=dp[i][0]*2+dp[i][1]*2
    return sum(dp[-1])
  
  def a_num(x):
    x=int(''.join([str(i) for i in x]))
    three=int(''.join(['3']*l))
    five=int(''.join(['5']*l))
    seven=int(''.join(['7']*l))
    if x<three:
      return 0
    elif three<=x<five:
      return 1
    elif five<=x<seven:
      return 2
    else:
      return 3  

  ans=abc_num(n,3,5,7)
  ans-=(ab_num(n,3,5)+ab_num(n,3,7)+ab_num(n,5,7))
  ans+=a_num(n)
  for i in range(3,l):
    ans+=3**i-3*(2**i)+3
  print(ans)  
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0
    if s.count('7') > 0 and s.count('5') > 0 and s.count('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:
n = int(input())
 
def dfs(s):
    if int(s) > n:
        return 0
    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt = 1
    else:
        cnt = 0
    cnt += dfs(s + '3')
    cnt += dfs(s + '5')
    cnt += dfs(s + '7')
    return cnt
 
 
print(dfs('0'))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#114_C
#桁dp
N=int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())


def dfs(x):
    if x > N:
        return 0
    s = str(x)
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
        # print(x)
    else:
        ret = 0
    ret += dfs(10 * x + 7)
    ret += dfs(10 * x + 5)
    ret += dfs(10 * x + 3)
    return ret


print(dfs(0))

Submission status: Accepted

Solution code:
N = int(input())


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


print(dfs("0"))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    N_len = len(str(N))
    from itertools import product
    s = set()
    for k in range(3, N_len + 1):
        s = s | {t for t in product("753", repeat=k)
                 if int("".join(t)) <= N and len(set(t) & set("753")) == 3}
    print(len(s))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy,copy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    candidate = set(["3","5","7"])
    for i in range(9):
        for c in copy(candidate):
            candidate.add(c+"3")
            candidate.add(c+"5")
            candidate.add(c+"7")
    
    ans = 0
    for c in candidate:
        if int(c)<=N and 0 not in (c.count("3"),c.count("5"),c.count("7")):
            ans += 1
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
from itertools import product
ans = 0
for n in range(3,10):
    for ptn in product('753', repeat=n):
        if '7' not in ptn: continue
        if '5' not in ptn: continue
        if '3' not in ptn: continue
        v = int(''.join(ptn))
        if v <= N:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools


n = int(input())

def calculate(n,length):
    count = 0
    for i in itertools.product([3,5,7],repeat=length):
        if isValid(i) == False:
            continue
        sum = 0
        for j in range(length):
            sum = sum + i[j] * 10 ** j
        if sum <= n:
            count = count + 1

    return count

def isValid(n):
    dict = {}
    for s in n:
        if dict.get(s) == None:
            dict.__setitem__(s,1)
        else:
            dict.__setitem__(s,dict.get(s) + 1)

    s1 = dict.get(3) != None and dict.get(3) > 0
    s2 = dict.get(5) != None and dict.get(5) > 0
    s3 = dict.get(7) != None and dict.get(7) > 0

    return s1 and s2 and s3

length = len(str(n))

result = 0
for i in range(3,length+1):
    result = result + calculate(n,i)

print(result)

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


ans = dfs("0")

print(ans)

Submission status: Accepted

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

x =[]
for i in range(3,11):
    x += list(product(a, repeat = i))
y = []
for j in x:
    if '7' in j and '5' in j and '3' in j:
        y.append(j)
z = []
for k in range(len(y)):
    z.append(''.join(y[k]))
z = [int(_) for _ in z]

b = 0
for p in z:
    if p <= n:
        b += 1

print(b)

Submission status: Accepted

Solution code:
def function(n):
    digit=len(str(n))
    N=str(n)
    if digit<3:
        return 0
    else:
        k=int(N[0])
        m=int(N[1])
        if k<3:
            return function(10**(digit-1)-1)
        elif k==3 and m>0:
            return function(10**(digit-1)-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(5,7,n%(10**(digit-1)))
        elif k==3 and m==0:
            return function(10**(digit-1)-1)
        elif k==4:
            return function(4*(10**(digit-1))-1)
        elif k==5 and m>0:
            return function(4*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,7,n%(10**(digit-1)))
        elif k==5 and m==0:
            return function(4*(10**(digit-1))-1)
        elif k==6:
            return function(6*(10**(digit-1))-1)
        elif k==7 and m>0:
            return function(6*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,5,n%(10**(digit-1)))
        elif k==7 and m==0:
            return function(6*(10**(digit-1))-1)
        else:
            return function(8*(10**(digit-1))-1)

def subfunction(a,b,n):
    digit=len(str(n))
    N=str(n)
    k=int(N[0])
    if digit<2:
        return 0
    else:
        if k<a:
            return 0
        elif k==a:
            if n%(10**(digit-1))<b*(10**(digit-1)-1)//9:
                s=0
            else:
                s=1
            return subfunction(a,b,n%(10**(digit-1)))+s
        elif a<k<b:
            return subfunction(a,b,(a+1)*(10**(digit-1))-1)
        elif k==b:
            if n%(10**(digit-1))<a*(10**(digit-1)-1)//9:
                s=0
            else:
                s=1
            return subfunction(a,b,(a+1)*(10**(digit-1))-1)+subfunction(a,b,n%(10**(digit-1)))+s
        else:
            return subfunction(a,b,(b+1)*(10**(digit-1))-1)

N=int(input())
print(function(N))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
def bfs(x):
    global ans
    if x>n: return 0
    else:
        if set(list(str(x)))=={'7','5','3'}:
            ans+=1
        bfs(x*10+3)
        bfs(x*10+5)
        bfs(x*10+7)
bfs(0)
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = input()
    n_len = len(N)

    def dfs(val, is357):
        c = 0

        if (not is357
            and val.count('3') > 0
            and val.count('5') > 0
            and val.count('7') > 0):
            is357 = True

        if len(val) == n_len:
            if is357 and int(val) <= int(N):
                return 1
            else:
                return 0

        if is357:
            c+= 1

        c += dfs(val + '3', is357)
        c += dfs(val + '5', is357)
        c += dfs(val + '7', is357)
        return c

    print(dfs('', False))

if __name__ == '__main__':
    main()