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: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()

a = [3,5,7]

cnt = 0

for i in range(3, len(N)):
	for x in product(a, repeat=i):
		##print(x, len(set(x)))
		if len(set(x)) == 3:
			cnt += 1
			#print(x)

for x in product(a, repeat=len(N)):
	##print(x, len(set(x)))
	if len(set(x)) == 3:
		#print(x)
		p = 0
		for i in range(len(N)):
			p += x[-(i+1)]*10**i
		if int(N) < p:
			#print(cnt)
			break
		cnt += 1
else:
	print(cnt)

Submission status: Wrong Answer

Solution code:
s = input()
l = len(s)
n = int(s)
ans = 0
import itertools
for li in range(3, l+1):
    for i in itertools.product([7, 5, 3], repeat=li):
        if len(set(i)) == 3:
            ans += 1
        num = int(''.join(map(str, i)))
        if num > n:
            continue
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = int(s)
l = len(s)

dp = [[] for _ in range(l+1)]
dp[0].append('')

for i in range(l):
  for e in dp[i]:
    dp[i+1].append(e+'3')
    dp[i+1].append(e+'5')
    dp[i+1].append(e+'7')
ans = 0
for i in range(min(3,l),l):
  for e in dp[i]:
    if '3' in e and '5' in e and '7' in e and int(e) <= n:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# a, b, c, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
n = int(input())
# n, m = list(map(int, input().split()))
# n, m = list(map(int, input().split()))
# x = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
# n = int(input())
# n, m = list(map(int, input().split()))
if n < 357:
    print(0)
else:
    l = len(str(n))
    num = [3, 5, 7]*l
    print(num)
    data = []
    for j in range(3, l+1):
        for v in itertools.permutations(num, j):
            a = ""
            for i in range(j):
                a += str(v[i])

            if int(a) <= n:
                if "3" in a and "5" in a and "7" in a:
                    data.append(a)
            # print(v)
    # print(data)
    ans = set(list(data))
    print(len(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# a, b, c, k = list(map(int, input().split()))
# a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
n = int(input())
# n, m = list(map(int, input().split()))
# n, m = list(map(int, input().split()))
# x = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
# n = int(input())
# n, m = list(map(int, input().split()))
if n < 357:
    print(0)
else:
    l = len(str(n))
    num = [3, 5, 7]*l
    print(num)
    data = []
    for j in range(3, l+1):
        for v in itertools.permutations(num, j):
            a = ""
            for i in range(j):
                a += str(v[i])

            if int(a) <= n:
                if "3" in a and "5" in a and "7" in a:
                    data.append(a)
            # print(v)
    # print(data)
    ans = set(list(data))
    print(len(data))
    print(ans)
    print(l)
    print(len(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
from collections import deque
d = deque([0])
cnt = 0
while d[-1] < n:
    x = d.popleft()
    for i in range(3,8,2):
        d.append(x * 10 + i)
        cnt += 1 if all(str(x * 10 + i).count(c)>0 for c in "753") else 0
ans=0
if d[-3] > n:
    for i in range(1,4):
        ans += 1 if all(str(d[-i]).count(c) > 0 for c in "753") else 0
    print(cnt - ans)
elif d[-2] > n:
    for i in range(1,2):
        ans += 1 if all(str(d[-i]).count(c) > 0 for c in "753") else 0
    print(cnt - ans)
elif d[-1] > n:
    if all (str(d[-1]).count(c) > 0 for c in "753"):
        print(cnt - 1)
    else:
        print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())

def dfs(cur,use,counter):
    if cur>N:
        return 0
    
    elif use==0b111:
        counter=1

    counter+=dfs(cur*10+7,use | 0b001, counter)
    counter+=dfs(cur*10+5,use | 0b010, counter)
    counter+=dfs(cur*10+3,use | 0b100, counter)

    return counter

print(dfs(0,0,0))

Submission status: Wrong Answer

Solution code:
N=int(input())

def dfs(cur,use,counter):
    if cur>N:
        return 0
    
    if use==0b111:
        counter=1

    counter+=dfs(cur*10+7,use | 0b001, counter)
    counter+=dfs(cur*10+5,use | 0b010, counter)
    counter+=dfs(cur*10+3,use | 0b100, counter)

    return counter

print(dfs(0,0,0))

Submission status: Wrong Answer

Solution code:
import itertools
n = input()
ans = 0

if int(n) < 357:
  print(ans)
else:
  num = "753"
  for x in range(3,len(n)+1):
    for y in itertools.product(num, repeat=x):
      if "7" in y and "5" in y and "3" in y:
        if int("".join(y)) <= int(n):
          ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def Base_10_to_n(x,n):
	if (int(x/n)):
		return Base_10_to_n(int(x/n),n)+str(x%n)
	return str(x%n)
	
n=int(input())
l=len(str(n))

res=0

for i in range(4**l):
	x=Base_10_to_n(i,4)
	cnt=0
	if not "0" in x: 
		if ("3" in x) and ("2" in x) and ("1" in x):
			for j in range(len(x)):
				if x[j]=="1":
					cnt+=3*(10**j)
				elif x[j]=="2":
					cnt+=5*(10**j)
				elif x[j]=="3":
					cnt+=7*(10**j)
			if cnt<n:
				res+=1
			
print(res)

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())


s = []
def dfs(A):
    if len(A) == len(str(n)):
        return
    for i in ['7', '5', '3']:
        A.append(i)
        if len(set(A)) == 3 and int(''.join(A)) <= n:
            s.append(int(''.join(A)))
        dfs(A)
        A.pop()

dfs([])

print(s)
print(len(s))

Submission status: Wrong Answer

Solution code:
n=int(input())
a1=["7","5","3"]
a2=[]
a3=[]
a4=[]
for i in range(len(str(n))-1):
    for j in range(len(a3)):
        a4.append(a3[j]+"3")
        a4.append(a3[j]+"5")
        a4.append(a3[j]+"7")
    a3=[]
    for j in range(len(a2)):
        if a2[j][1]=="3":
            a3.append(a2[j][0]+"3")
            a4.append(a2[j][0]+"3")
            a2.append([a2[j][0]+"5","3"])
            a2[j][0]=a2[j][0]+"7"
        if a2[j][1]=="5":
            a3.append(a2[j][0]+"5")
            a4.append(a2[j][0]+"5")
            a2.append([a2[j][0]+"7","5"])
            a2[j][0]=a2[j][0]+"3"
        if a2[j][1]=="7":
            a3.append(a2[j][0]+"7")
            a4.append(a2[j][0]+"7")
            a2.append([a2[j][0]+"5","7"])
            a2[j][0]=a2[j][0]+"3"
    for j in range(len(a1)):
        if a1[j][0]=="7":
            a2.append([a1[j]+"5","3"])
            a2.append([a1[j]+"3","5"])
            a1[j]=a1[j]+"7"
        if a1[j][0]=="5":
            
            a2.append([a1[j]+"7","3"])
            a2.append([a1[j]+"3","7"])
            a1[j]=a1[j]+"5"
        if a1[j][0]=="3":
            a2.append([a1[j]+"5","7"])
            a2.append([a1[j]+"7","5"])
            a1[j]=a1[j]+"3"
count=0
for i in reversed(range(0,len(a4))):
    if len(a4[i])<len(str(n)):
        break
    if int(a4[i])>n:
        count+=1
print(len(a4)-count)

Submission status: Wrong Answer

Solution code:
def dfs(s):
    if s != "":
        if int(s) > n:
            return 0
    if len(set(s)) == 3:
        return 1
    cnt = 0
    for i in "753":
        cnt += dfs(s + i)
    return cnt


n = int(input())
print(dfs(""))

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
ans = 0
for i in range(1, 10):
  for x in itertools.product("753", repeat=i):
    s= ''.join(x)
    if int(s) > N: continue
    if '3' not in s: continue
    if '5' not in s: continue
    if '7' not in s: continue
    print(s)
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
def dfs(cur,use):
    global ans
    if cur>N: return
    if use==0b111:ans+=1
    dfs(cur*10+7,use | 0b001)
    dfs(cur*10+5,use | 0b010)
    dfs(cur*10+3,use | 0b100)
    return print(cur)

dfs(0,0)
print(ans)

Submission status: Wrong Answer

Solution code:
import queue
q = queue.Queue()
n = int(input())
cnt = 0
q.put(3)
q.put(5)
q.put(7)
while not q.empty():
    tmp = q.get()
    if tmp < n:
        if ('3' in str(tmp)) and ('7' in str(tmp)) and ('5' in str(tmp)):
            cnt += 1
        q.put(tmp*10 + 3)
        q.put(tmp*10 + 5)
        q.put(tmp*10 + 7)
    else:
        continue
print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import product
from bisect import bisect_left
n = int(input())
ns = []
for i in range(9):
    for j in product(["7", "5", "3"], repeat=i + 1):
        ns.append(''.join(j))
ns = sorted([int(i) for i in ns if len(set(i)) == 3])
print(bisect_left(ns, n))

Submission status: Wrong Answer

Solution code:
def nyu():
    N = int(input())

    return N

def kansu(N):

    cnt = 0

    for n in range(N):
        str_n = str(n)
        if  '0' not in str_n and '1' not in str_n and '2' not in str_n and '4' not in str_n and '6' not in str_n and '8' not in str_n and '9' not in str_n:
            if '7' in str_n  and '5' in str_n  and '3' in str_n:
                cnt += 1
        #       print("str_n",str_n)
    print(cnt)





N = nyu()
kansu(N)

Submission status: Wrong Answer

Solution code:
N = int(input())

count = 0
for number in range(0, N + 1):
    number_str = str(number)

    if '7' in number_str and '5' in number_str and '3' in number_str:
        count += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
def dfs(now_s,digit,n,ans_sum):
    ans = 0
    if len(now_s)<digit:
        for i in ["3","5","7"]:
            now_s.append(i)
            if "3" in now_s and "5" in now_s and "7" in now_s and eval("".join(now_s)) <= n:
                ans = 1
                print(now_s)
            return(ans+dfs(now_s,digit,n,ans_sum))
    return ans_sum

now_s = []
ls_753 = [0,0,0]
digit = len(str(n))
ans = 0
print(dfs(now_s,digit,n,ans))

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())

lis = set()
def dfs():
    d = ['3','5','7']
    que = deque(['3','5','7'])
    while len(que) != 0:
        val = que.pop()
        #print(val)
        if len(val) < 11:
            #print(len(str(val)))
            for i in range(3):
                val2 = val + d[i]
                #print(val3[-1])
                l = list(val2)
                if '3' in l and '5' in l and '7' in l:
                    lis.add(int(val2))
                que.append(val2)

    return lis
lis = dfs()
ans = 0
for i in lis:
    if int(i) < n:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())

lis = set()
def dfs():
    d = ['3','5','7']
    que = deque(['3','5','7'])
    while len(que) != 0:
        val = que.pop()
        #print(val)
        if len(val) < 10:
            #print(len(str(val)))
            for i in range(3):
                val2 = val + d[i]
                #print(val3[-1])
                l = list(val2)
                if '3' in l and '5' in l and '7' in l:
                    lis.add(int(val2))
                que.append(val2)

    return lis
lis = dfs()
ans = 0
for i in lis:
    if i < n:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
a = [3, 5, 7]
i = 0
while ans == 0:
    if a[i] > N:
        for j in range(i+1):
            s = str(a[j])
            if "3" in s and "5" in s and "7" in s:
                ans += 1
    else:
        x10 = a[i] * 10
        a.append(x10+3)
        a.append(x10+5)
        a.append(x10+7)
        i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

N = input()
digits = len(N)
if digits <= 2 or int(N[0]) <= 2:
    print(0)
    sys.exit()

ans = 0

queue = deque([("3", 1, 0, 0), ("5", 0, 1, 0),  ("7", 0, 0, 1)])

while queue:

    current, flg3, flg5, flg7 = queue.popleft()

    if len(current) > digits:
        continue    
    if flg3 and flg5 and flg7 and int(current) <= int(N):
        print(current)
        ans += 1

    queue.append((current+"3", 1, flg5, flg7))
    queue.append((current+"5", flg3, 1, flg7))    
    queue.append((current+"7", flg3, flg5, 1))
    
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
l = [3,7,5]
c = 0
for i in range(3,10):
    for j in itertools.product(l, repeat=i):
        if set(j) == 3 and int(''.join(map(str,j))) <= n:
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
s=input()
n=[int(i) for i in s]
l=len(s)
dp=[[[0]*8,[0]*8] for i in range(l+1)]
for i in range(l):
    dp[i][0][0]=1
for i in range(l):
    for smaller in range(2):
        if 3<=n[i] or smaller:
            dp[i+1][smaller or 3<n[i]][1]+=dp[i][smaller][0]
        if 5<=n[i] or smaller:
            dp[i+1][smaller or 5<n[i]][2]+=dp[i][smaller][0]
        if 7<=n[i] or smaller:
            dp[i+1][smaller or 7<n[i]][4]+=dp[i][smaller][0]

        if 3<=n[i] or smaller:
            dp[i+1][smaller or 3<n[i]][1]+=dp[i][smaller][1]
        if 5<=n[i] or smaller:
            dp[i+1][smaller or 5<n[i]][3]+=dp[i][smaller][1]
        if 7<=n[i] or smaller:
            dp[i+1][smaller or 7<n[i]][5]+=dp[i][smaller][1]

        if 3<=n[i] or smaller:
            dp[i+1][smaller or 5<n[i]][2]+=dp[i][smaller][2]
        if 5<=n[i] or smaller:
            dp[i+1][smaller or 3<n[i]][3]+=dp[i][smaller][2]
        if 7<=n[i] or smaller:
            dp[i+1][smaller or 7<n[i]][6]+=dp[i][smaller][2]

        if 3<=n[i] or smaller:
            dp[i+1][smaller or 3<n[i]][3]+=dp[i][smaller][3]
        if 5<=n[i] or smaller:
            dp[i+1][smaller or 5<n[i]][3]+=dp[i][smaller][3]
        if 7<=n[i] or smaller:
            dp[i+1][smaller or 7<n[i]][7]+=dp[i][smaller][3]
        if 3<=n[i] or smaller:
            dp[i+1][smaller or 3<n[i]][5]+=dp[i][smaller][4]
        if 5<=n[i] or smaller:
            dp[i+1][smaller or 5<n[i]][6]+=dp[i][smaller][4]
        if 7<=n[i] or smaller:
            dp[i+1][smaller or 7<n[i]][4]+=dp[i][smaller][4]

        if 3<=n[i] or smaller:
            dp[i+1][smaller or 3<n[i]][5]+=dp[i][smaller][5]
        if 5<=n[i] or smaller:
            dp[i+1][smaller or 5<n[i]][7]+=dp[i][smaller][5]
        if 7<=n[i] or smaller:
            dp[i+1][smaller or 7<n[i]][5]+=dp[i][smaller][5]

        if 3<=n[i] or smaller:
            dp[i+1][smaller or 3<n[i]][7]+=dp[i][smaller][6]
        if 5<=n[i] or smaller:
            dp[i+1][smaller or 5<n[i]][6]+=dp[i][smaller][6]
        if 7<=n[i] or smaller:
            dp[i+1][smaller or 7<n[i]][6]+=dp[i][smaller][6]

        if 3<=n[i] or smaller:
            dp[i+1][smaller or 3<n[i]][7]+=dp[i][smaller][7]
        if 5<=n[i] or smaller:
            dp[i+1][smaller or 5<n[i]][7]+=dp[i][smaller][7]
        if 7<=n[i] or smaller:
            dp[i+1][smaller or 7<n[i]][7]+=dp[i][smaller][7]
# print([[i for i in range(8)],[i for i in range(8)]])
# for i in dp:
#     print(i)
print(dp[-1][0][7]+dp[-1][1][7])

Submission status: Wrong Answer

Solution code:
def generate(x):
    yield x * 10 + 3
    yield x * 10 + 5
    yield x * 10 + 7

n = int(input())
nums = [3, 5, 7]
ans = 0
while nums:
    x = nums.pop(0)
    for res in generate(x):
        if res < n:
            nums.append(res)
            if len(set(list(str(res)))) == 3:
                ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1=str(lint)+"3"
    lint1int=int(lint1)
    if lint1int<lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2=str(lint)+"5"
    lint2int=int(lint2)
    if lint2int<lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3=str(lint)+"7"
    lint3int=int(lint3)
    if lint3int<lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 
    lint4="3"+str(lint)
    lint4int=int(lint4)
    if lint4int<lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int,lim)
    lint5="5"+str(lint)
    lint5int=int(lint5)
    if lint5int<lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int,lim)
    lint6="7"+str(lint)
    lint6int=int(lint6)
    if lint6int<lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int,lim)
def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
count=0
for b in list753:
    cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print(len(list333))

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
Q = deque(["357"])
count = 0
for q in range(357,N):
  q = str(q)
  if "0" not in q and "1" not in q and "2" not in q and "4" not in q and "6" not in q and "8" not in q and "9" not in q and "7" in q and "5" in q and "3" in q:
    count += 1
print(count)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
L = []
num = ["3", "5", "7"]
peak = 1
for i in range(10):
  for j in range(peak):
    T = ""
    S = [0, 0, 0]
    tmp = j
    for k in range(i):
      T = T[:] + num[tmp%3]
      S[tmp%3] += 1
      tmp //= 3
    if S[0] * S[1] * S[2] > 0:
      L.append(int(T))
  peak *= 3
L.sort()
N = int(input())
n = len(L)
l, c, r = 0, n // 2, n
pnt = 0
m = max(L)
if m <= N:
  print(n)
else:
  while L[pnt] < N:
    pnt += 1
  print(pnt)

Submission status: Wrong Answer

Solution code:
L = []
num = ["3", "5", "7"]
peak = 1
for i in range(10):
  for j in range(peak):
    T = ""
    S = [0, 0, 0]
    tmp = j
    for k in range(i):
      T = T[:] + num[tmp%3]
      S[tmp%3] += 1
      tmp //= 3
    if S[0] * S[1] * S[2] > 0:
      L.append(int(T))
  peak *= 3
L.sort()
N = int(input())
n = len(L)
l, c, r = 0, n // 2, n
flg = True
for _ in range(16):
  if L[c] >= N:
    r = c
    c = (r + l) // 2
  else:
    l = c
    c = (r + l) // 2
print(c+1)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
nagoya = [3,5,7]
i = 1
if n < 357:
    print(0)
    exit()
ans = 0
while(i < 99):
    current = list(itertools.product(nagoya,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if len(set(str(h))) == 3:
            if n <= h:
                print(ans)
                exit()
            else:
                ans += 1
    i += 1

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
f = [3,5,7]
i = 1
if n < 357:
    print(0)
    exit()
ans = 0
while(i < 11):
    current = list(itertools.product(f,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if len(set(str(h))) == 3:
            if n <= h:
                print(ans)
                exit()
            else:
                ans += 1
    i += 1

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
nagoya = [3,5,7]
i = 3
if n < 357:
    print(0)
    exit()
ans = 0
while(i < 10):
    current = list(itertools.product(nagoya,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if len(set(str(h))) == 3:
            if n <= h:
                print(ans)
                exit()
            ans += 1
    i += 1

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
nagoya = [3,5,7]
i = 3
if n < 357:
    print(0)
    exit()
ans = 0
while(i < 10):
    current = list(itertools.product(nagoya,repeat=i))
    for j in range(len(current)):
        h = int("".join(map(str,(list(current[j])))))
        if len(set(str(h))) == 3:
            if n <= h:
                print(ans)
                exit()
            ans += 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

if __name__ == "__main__":
    n = input()

    if len(n) < 3:
        print(0)
        exit()

    ans = 0
    seq = ['0', '3', '5', '7']

    tmp = list(itertools.product(seq, repeat=len(n)))

    for t in tmp:
        if int(''.join(t)) < int(n):
            a = str(int(''.join(t)))
            if '0' not in a and len(set(a)) == 3:
                ans += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
import math
import collections
from operator import mul
from functools import reduce
import bisect

b=[]
def test(a):
    if len(a)>=8:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
    else:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
        test(a+"3")
        test(a+"5")
        test(a+"7")

#n,m=map(int,input().split())

n=int(input())
test("")
c=[]
b=set(b)
for bi in b:
    if bi.count("3")>0 and  bi.count("5")>0 and bi.count("7")>0 :
        c.append(bi)

c=sorted(list(map(int,c)))
d=bisect.bisect_left(c,n)
print(d)

Submission status: Wrong Answer

Solution code:
import math
import collections
from operator import mul
from functools import reduce
import bisect

b=[]
def test(a):
    if len(a)>=8:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
    else:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
        test(a+"3")
        test(a+"5")
        test(a+"7")

#n,m=map(int,input().split())

n=int(input())
test("")
c=[]
for bi in b:
    if bi.count("3")>0 and  bi.count("5")>0 and bi.count("7")>0 :
        c.append(bi)

c=sorted(list(map(int,c)))
d=bisect.bisect_left(c,n)
print(d)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
num = 4**6
ans = 0
for i in range(num):
    a = 0
    b = 0
    c = 0
    d = 0
    s = i
    for j in range(9):
        a += 0 * int(s % 4 == 0) * 10 ** j
        b += 3 * int(s % 4 == 1) * 10 ** j
        c += 5 * int(s % 4 == 2) * 10 ** j
        d += 7 * int(s % 4 == 3) * 10 ** j
        s = s // 4
    tmp = a + b + c + d
    if tmp > n:
        break
    tmp = str(tmp)
    if b > 0 and c > 0 and d > 0 and tmp.count('0') == 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N= int(input())
def f(x):
    if int(x) >N:
        return 0
    if x.count('3')>0 and x.count('5')>0 and x.count('7')>0:
        z = 1
    z=0
    z +=f(x+'3')
    z +=f(x+'5')
    z +=f(x+'7')
    return z
print(f('0'))

Submission status: Wrong Answer

Solution code:
from itertools import product

N = int(input())
ans = 0
for i in product("357", repeat=len(str(N))):
    x = "".join(i)
    if 357 <= int(x) <= N and len(set(x)) == 3:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
A=[0,1,2,3,4,5,6,7,8,9]
B=[0,0,0,1,1,2,2,3,3,3]
N=[]
for i in range(len(n)):
  N.append(B[int(n[i])])
NN=0
for i in range(len(N)):
  NN=NN+N[-1-i]*4**i
ans=0
for i in range(NN+1):
  S=[]
  j=i
  while j>0:
    k=j%4
    S.append(k)
    j=j//4
  s=set(S)
  if s=={1,2,3}:
    ans=ans+1
print(ans)

Submission status: Wrong Answer

Solution code:
def search(s, n):
  if int(s) > n:
    return 0
  ans = 0 if s == '0' else 1
  for c in '753':
    ans += search(s+c,n)
  return ans

N = int(input())
print(search('0',N))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dic

n = int(input())

ans = 0
for i in range(n):
    flag = dic(int)
    s = str(i)
    judge = 1
    for j in range(len(s)):
        if s[j] != '3' and s[j] != '5' and s[j] != '7':
            judge = 0
            break
        else:
            flag[int(s[j])] = 1
    
    if judge == 1 and flag[3] == 1 and flag[5] == 1 and flag[7] == 1:
        ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
 
def dfs(s):
    print(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: Wrong Answer

Solution code:
def f(n, k):
  num_bit = 3 - bin(k).count('1')
  c = [0, 0, 1, 3]
  return 3**n - num_bit*2**n + c[num_bit]

# k = 0:(), 1:(3), 2(5), 3:(3, 5), 4:(7), 5:(3, 7), 6:(5, 7), 7:(3, 5, 7)
def solve(N, k=0):
  n = len(N)
  num_used = bin(k).count('1')
  if n==0 or n+num_used<3:
    return 0
  else:
    a = int(N[0])
    base = sum([f(i, 0) for i in range(3, n)])
    if a > 7:
      return sum([f(i, 0) for i in range(3, n+1)])
    elif a == 7:
      return base + f(n-1, k|2) + f(n-1, k|1) + solve(N[1:], k|4)
    elif a > 5:
      return base + f(n-1, k|2) + f(n-1, k|1)
    elif a == 5:
      return base + f(n-1, k|1) + solve(N[1:], k|2)
    elif a > 3:
      return base + f(n-1, k|1)
    elif a == 3:
      return base + solve(N[1:], k|1)
    elif a > 0:
      return base
    else: # a == 0
      return solve(N[1:])

print(solve(input()))

Submission status: Wrong Answer

Solution code:
def f(n, k):
  num_bit = 3 - bin(k).count('1')
  c = [0, 0, 1, 3]
  return 3**n - num_bit*2**n + c[num_bit]

# k = 0:(), 1:(3), 2(5), 3:(3, 5), 4:(7), 5:(3, 7), 6:(5, 7), 7:(3, 5, 7)
def solve(N, k=0):
  n = len(N)
  num_used = bin(k).count('1')
  if n==0 or n+num_used<3:
    return 0
  else:
    a = int(N[0])
    base = sum([f(i, 0) for i in range(3, n)])
    if a > 7:
      return sum([f(i, k) for i in range(3, n+1)])
    elif a == 7:
      return base + f(n-1, k|2) + f(n-1, k|1) + solve(N[1:], k|4)
    elif a > 5:
      return base + f(n-1, k|2) + f(n-1, k|1)
    elif a == 5:
      return base + f(n-1, k|1) + solve(N[1:], k|2)
    elif a > 3:
      return base + f(n-1, k|1)
    elif a == 3:
      return base + solve(N[1:], k|1)
    elif a > 0:
      return base
    else: # a == 0
      return solve(N[1:])

print(solve(input()))

Submission status: Wrong Answer

Solution code:
def f(n, k):
  num_bit = 3 - bin(k).count('1')
  c = [0, 0, 1, 3]
  return 3**n - num_bit*2**n + c[num_bit]

# k = 0:(), 1:(3), 2(5), 3:(3, 5), 4:(7), 5:(3, 7), 6:(5, 7), 7:(3, 5, 7)
def solve(N, k=0):
  n = len(N)
  num_used = bin(k).count('1')
  if n==0 or n+num_used<3:
    return 0
  else:
    a = int(N[0])
    base = sum([f(i, k) for i in range(3, n)])
    if a > 7:
      return sum([f(i, k) for i in range(3, n+1)])
    elif a == 7:
      return base + f(n-1, k|2) + f(n-1, k|1) + solve(N[1:], k|4)
    elif a > 5:
      return base + f(n-1, k|2) + f(n-1, k|1)
    elif a == 5:
      return base + f(n-1, k|1) + solve(N[1:], k|2)
    elif a > 3:
      return base + f(n-1, k|1)
    elif a == 3:
      return base + solve(N[1:], k|1)
    elif a > 0:
      return base
    else: # a == 0
      return solve(N[1:])

print(solve(input()))

Submission status: Wrong Answer

Solution code:
def number_lst(x): #x桁での753
    lst = ['3', '5', '7']
    flag = False
    while True:
        for i in range(len(lst)):
            if len(lst[0])==x:
                flag = True
                break

            number = lst[i]
            y1 = number + '3'
            y2 = number + '5'
            y3 = number + '7'
            lst.append(y1)
            lst.append(y2)
            lst.append(y3)

        if flag:
            break

        min_lst = len(lst[0])
        new_lst = []
        for i in range(len(lst)):
            if len(lst[i])!=min_lst:
                new_lst.append(lst[i])
        lst = new_lst.copy()

    new_lst = []
    for i in range(len(lst)):
        number = lst[i]
        tmp_lst = [number.count('3'), number.count('5'), number.count('7')]
        if 0 not in tmp_lst:
            new_lst.append(number)

    return new_lst

n = str(input())
digit = len(n)

if digit<3:
    answer = 0
else:
    tmp1 = 3**(digit-1) - 3*2**(digit-1) + 3 #一個くらいを消去した時の個数
    tmp2 = 0

    lst_1 = number_lst(digit).copy()

    for i in range(len(lst_1)):
        number = int(lst_1[i])

        if number<=int(n):
            tmp2 += 1

    answer = tmp1 + tmp2

print(answer)