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:
N = int(input())

num = ["7", "5", "3"]
l = []


def make_num(s): # s is str
    if int(s) >= N:
        return
    l.append(s)
    for i in num:
        ns = s + i
        make_num(ns)


for j in num:
    make_num(j)

count = 0
for k in l:
    if "3" in k and "5" in k and "7" in k:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
num = int(input())
count = 0
n = num;
while n >= 357:
  ck = True
  is3 = False
  is5 = False
  is7 = False
  nStr = str(n)
  length = len(nStr)
  for i in range(length):
    if nStr[i] == '3':
      is3 = True
    elif nStr[i] == '5':
      is5 = True
    elif nStr[i] == '7':
      is7 = True
    else:
      ck = False
      n -= 10 ** (length - (i+1))
      break
  if ck:
    if is3 and is5 and is7:
      count += 1
    n -= 1
print(str(count))

Submission status: Wrong Answer

Solution code:
import itertools

N = input()

element= [3,5,7]

nums = []

for i in range(3,len(N) + 1):
  num = itertools.product(element, repeat = i)
  for j in num:
    if len(set(j)) == 3:
      nums.append(j)

con = 0

numlist = []

for i in range(0,len(nums)):
  S = ""
  for j in range(0,len(nums[i])):
    S += str(nums[i][j])
  S = int(S)
  numlist.append(S)
  
print(len([i for i in numlist if i < int(N)]))

Submission status: Wrong Answer

Solution code:
n=int(input())
cnt=0 
dp=[[[0 for j in range(10)]for i in range(10)]for k in range(10)]
ans=[0]
arr=[0]
vis=set()
vis.add(0)
while arr: 
    t=arr.pop(0)
    a=t*10+3 
    b=t*10+5 
    c=t*10+7 
    def ok(x):
        return x<n and x not in vis 
    for i in [a,b,c]:
        if ok(i):
            vis.add(i)
            ans.append(i)
            arr.append(i)
ans.sort()
from bisect import bisect_left as bl 
c=0 
def valid(a):
    one=0 
    two=0 
    three=0 
    while a: 
        if a%10==3:
            one+=1 
        if a%10==5:
            two+=1 
        if a%10==7:
            three+=1 
        a//=10 
    if one==0 or two==0 or three==0:
        return 0 
    return 1 
for i in ans: 
    if valid(i):
        c+=1 
    if i>n:
        break 
print(c)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
sys.setrecursionlimit(10**6) 
import bisect

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

li = [7,5,3]

if n < 357:
    print(0)
    exit()

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)

kazu = 0
point = 0
k = "0"
while int(k) <= n:
    k = Base_10_to_n(kazu,4)
    k = k.replace("3","7").replace("1","3").replace("2","5")
    if all(k.count(c)>0 for c in "753")and k.count("0") == 0:
        point += 1
    kazu += 1
print(point)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
sys.setrecursionlimit(10**6) 
import bisect

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

li = [7,5,3]

if n < 357:
    print(0)

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)

kazu = 0
point = 0
k = "0"
while int(k) <= n:
    k = Base_10_to_n(kazu,4)
    k = k.replace("3","7").replace("1","3").replace("2","5")
    if all(k.count(c)>0 for c in "753")and k.count("0") == 0:
        point += 1
    kazu += 1
print(point)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
sys.setrecursionlimit(10**6) 
import bisect

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

li = [7,5,3]

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)

kazu = 0
point = 0
k = "0"
while int(k) <= n:
    k = Base_10_to_n(kazu,4)
    k = k.replace("3","7").replace("1","3").replace("2","5")
    if all(k.count(c)>0 for c in "753")and k.count("0") == 0:
        point += 1
    kazu += 1
print(point)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect


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

li = [7,5,3]
point = 0

for i in range(n+1):
    s = str(i)
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        point += 1

print(point)

Submission status: Wrong Answer

Solution code:
n=input()
h=0
k=0
if int(n[0])>=7:
  for i in range(1,len(n)+1):
    h+=3**i-2**i*3+3
    
elif int(n[0])>=5:
  for i in range(1,len(n)+1):
    h+=3**i-2**i*3+3
    k-=3**(len(n)-1)-2**(len(n)+1)
elif int(n[0])>=3:
  for i in range(1,len(n)+1):
    h+=3**i-2**i*3+3
    k-=2*(3**(len(n)-1)-2**(len(n)+1))
  
else:
  for i in range(1,len(n)):
    h+=3**i-2**i*3+3
    
       
print(h-k)

Submission status: Wrong Answer

Solution code:
n=int(input())

import itertools

li=[]

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

Submission status: Wrong Answer

Solution code:
limit = int(input())
seed = [3,5,7]
def valid(n):
    strn = str(n)
    return (len(strn) == strn.count('3') + strn.count('5') + strn.count('7')) and '3' in strn and '5' in strn and '7' in strn
def f(current):
    ans = valid(current)
    for s in seed:
        temp = (current * 10) + s
        if temp <= limit:
            ans += f(temp)
    return ans

print(f(0))

Submission status: Wrong Answer

Solution code:
limit = int(input())
seed = [3,5,7]
set357 = set(seed)
def valid(n):
    x_set = set()
    while(n > 0):
        x_set.add(n % 10)
        n //= 10
    return x_set == set357
def f(current):
    ans = valid(current)
    for s in seed:
        temp = (current * 10) + s
        if temp > limit:
            continue
        ans += f(temp)
    return ans

print(f(0))

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
num=0
l=["3","5","7"]
q=deque(["3","5","7"])
l1=["3","5","7"]
count=0
while q:
  a=q.popleft()
  for i in l:
    if int(i+a)<n:
      q.append(i+a)
      l1.append(i+a)
for i in l1:
  if ("3" in i) and ("5" in i) and ("7" in i):
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools

N = input()

A = []
nums = [3,5,7]
con = 0

for i in range(3,len(N) + 1):
  A += list(itertools.product(nums,repeat = i))

L = []

for i in range(0,len(A)):
  a = set(list(A[i]))
  if len(a) == 3:
    L.append(A[i])

Slist = []
    
for i in range(0,len(L)):
  S = ""
  for j in range(0,len(L[i])):
    S += str(L[i][j])
  S = int(S)
  Slist.append(S)

print(len([c for c in Slist if c < int(N)]))

Submission status: Wrong Answer

Solution code:
N = int(input())

con = 0

NG = ["0","1","2","4","6","8","9"]

for i in range(357,N):
  num = str(set(str(i)))
  if "3" in num and "5" in num and "7" in num:
    for j in range(0,len(num)):
      if num[j] in NG:
        break
    else:con += 1
    
print(con)

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = ["3", "5", "7"]
digit = len(str(n))
ans = 0

def rec(d, snum):
    if len(snum) >= d:
        global ans
        num = int(snum)
        if num >= n:
            print(ans)
            exit()
        if nums[0] in snum and nums[1] in snum and nums[2] in snum:
            ans += 1
        return
    for i in nums:
        rec(d, snum + i)

for d in range(1, digit+1):
    rec(d, "")

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
ans=0
start=["357","375","537","573","735","753"]
start=deque(start)
while start:
  s=start.popleft()
  if int(s)<=n:ans+=1
  else:continue
  for i in ["3","5","7"]:
    start.append(s+i)
print(ans)

Submission status: Wrong Answer

Solution code:
def appendedList(arr, val):
    ret = arr.copy()
    ret.append(val)
    return ret

def dfs(cur, target, ret):
    if 0 < len(cur):
        if target <= int(''.join(map(str, cur))):
            return 0
    const = 1 if (3 in cur and 5 in cur and 7 in cur) else 0
    ret3 = dfs(appendedList(cur, 3), target, ret)
    ret5 = dfs(appendedList(cur, 5), target, ret)
    ret7 = dfs(appendedList(cur, 7), target, ret)
    return ret + const + ret3 + ret5 + ret7

if __name__ == '__main__':
    N = int(input())
    print(dfs([], N, 0))

Submission status: Wrong Answer

Solution code:


import itertools

cnt = 0

N = input()

if int(N)<357:
    cnt = 0
elif int(N)<3357:
    cnt = 0
    for i in range(100, 3357):
        ans = list(str(i))
        if "3" in ans and "5" in ans and "7" in ans \
            and "0" not in ans and "1" not in ans and "2" not in ans \
            and "4" not in ans and "6" not in ans and "8" not in ans \
            and "9" not in ans:
            if int("".join(ans))<=int(N):
                cnt += 1
else:
    cnt = 6
    data = ('3','5','7')
    orig = []
    for i in range(4, len(N)+1):
        dgt = len(N) - 3
        for sft in list(itertools.combinations_with_replacement(data, dgt)):
            data_list = list(data)
            sft_list = list(sft)
            data_list[len(data_list):len(data_list)] = sft_list
            data2 = tuple(data_list)
            for temp in list(itertools.permutations(data2)):
                temp_int = int("".join(temp))
                if temp_int<=int(N) and temp_int not in orig:
                    cnt += 1
                    orig.append(temp_int)

print(cnt)

Submission status: Wrong Answer

Solution code:
import copy

n = input()
a = {'7','5','3'}
for _ in range(len(n)-1):
    b = copy.copy(a)
    for s in a:
        for i in (7,5,3):
            b.add(s + str(i))
    a = b
a = {i for i in a if not ('3' not in i or '5' not in i or '7' not in i)}

n = int(n)
a = {i for i in a if int(i)<n}
print(len(a))

Submission status: Wrong Answer

Solution code:
n=int(input())

def ju(n):
    l=list(str(n))
    j=[0]*3
    for i in range(len(l)):
        if l[i]=='3':
            j[0]=1
        elif l[i]=='5':
            j[1]=1
        elif l[i]=='7':
            j[2]=1
    if sum(j)==3:
        return 1
    else:
        return 0

zenbu=[3,5,7]

for i in range(10):
    tmp=[]
    for j in zenbu:
        tmp.append(j*10+3)
        tmp.append(j*10+5)
        tmp.append(j*10+7)
  
ans=0
for i in zenbu:
    if i<=n and ju(i)==1:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
keta = int(math.log10(n))+1

shichigosan = [
        357,
        375,
        537,
        573,
        735,
        753
    ]


num_list = []

def append_number(n):
    nums = []
    for s in [3,5,7]:
        nums.append(str(n)+str(s))
        nums.append(str(s)+str(n))
    return nums

def make_numbers(n_list,keta):
    if keta >= 3:
        append_numbers = []
        for n in n_list:
            num_list.append(n)
            for s in append_number(n):
                append_numbers.append(s)
        return(make_numbers(append_numbers,keta-1))

make_numbers(shichigosan,keta)

ans = 0
for i in map(int,num_list):
    if i <= n:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def is_753(n):
    dic753 = {}
    for i in str(n):
        if i == "7":
            dic753[7] = True
        elif i == "5":
            dic753[5] = True
        elif i == "3":
            dic753[3] = True
        else:
            return False
    if len(dic753) >= 3:
        return True
    else:
        return False


N = int(input())
ans = 0
for i in range(100, N):
    if is_753(i):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict
s = input()
L = len(s)
N = int(s)
ls = [3, 5, 7]
dic = defaultdict(int)
def dfs(s):
  if len(s)<L:
    return dfs(s+'3')+dfs(s+'5')+dfs(s+'7')+dfs('0'+s)
  if (not '3' in s) or(not '5' in s) or(not '7' in s):
    return 0
  if int(s)<N and dic[s]==0:
    dic[s]=1
    return 1
  else:
    return 0
print(dfs(''))

Submission status: Wrong Answer

Solution code:
N=int(input())
def f(s):
    t=s
    num=0
    ten=1
    L=[0,0,0,1]
    while t!=0:
        a=t%3
        if a==0:
            num+=3*ten
            L[0]=1
        elif a==1:
            num+=5*ten
            L[1]=1
        elif a==2:
            num+=7*ten
            L[2]=1
        ten*=10
        t=t//3
    return num,L
ans=0
for i in range(1,3**9):
    num,L=f(i)
    if num<=N and L==[1,1,1,1]:
        ans+=1
        #print(num)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans =0
for i in range(n):
    if set('753') == set(str(i)):
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(input())

def dfs(X, bit, count):
    if X >= N:
        return count

    if bit == 7:
        count += 1

    count = dfs(X*10+7, bit|4, count)
    count = dfs(X*10+5, bit|2, count)
    count = dfs(X*10+3, bit|1, count)

    return count


count = dfs(0, 0, 0)
print(count)

Submission status: Wrong Answer

Solution code:
import itertools as it
import collections as col
import heapq
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N=input()

D=set()
for n in range(3,11):
    for d in it.product(['3','5','7'],repeat=n):
        if '3' in d and '5' in d and '7' in d:
            x=0
            for i in range(n):
                x += (10**i)*int(d[n-i-1])
            if x < int(N):
                D.add(x)
#print(N)
print(len(D))

Submission status: Wrong Answer

Solution code:
import itertools as it
import collections as col
import heapq
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N=input()

D=set()
for n in range(3,10):
    for d in it.product(['3','5','7'],repeat=n):
        if '3' in d and '5' in d and '7' in d:
            x=0
            for i in range(n):
                x += (10**i)*int(d[n-i-1])
            if x < int(N):
                D.add(x)
#print(N)
print(len(D))

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
sys.setrecursionlimit(10**6)

def check(n,a,b,c,t,l):
    tmp = 0
    if len(n) > l:
        return 0
    if n == "":
        return check(n+"3",a+1,b,c,t,l) + check(n+"5",a,b+1,c,t,l) + check(n+"7",a,b,c+1,t,l) + tmp
    if a and b and c and int(n) < t:
        tmp = 1
    return check(n+"3",a+1,b,c,t,l) + check(n+"5",a,b+1,c,t,l) + check(n+"7",a,b,c+1,t,l) + tmp

def main():
    N = int(input())
    l = len(str(N))
    print(check("",0,0,0,N,l))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def fn(x):
    if x >= N:
        return
    X.append(str(x))
    for i in [7, 5, 3]:
        fn(int(str(x) + str(i)))


fn(0)
ans = 0
for x in X:
    if x.count('7') > 0 and x.count('5') > 0 and x.count('3') > 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

N=int(input())

tmp0=[]
tmp1=[3,5,7]
res=[3,5,7]
for i in range(1,8):
  for j in tmp1:
    for k in [3,5,7]:
      res.append(j*10+k)
      tmp0.append(j*10+k)
  tmp1=copy.deepcopy(tmp0)
  tmp0=[]

res2=[]
for i in res:
  if len(set(str(i)))==3:
    res2.append(i)
#print(res2)

ans=0
for i in res2:
  if i<=N:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

def dfs(s):
    print(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:
N = int(input())
ans = 0

def f(target):
    for i in '753':
        targetJoin = str(target) + str(i)
        
        if int(targetJoin) >= N:
            continue

        if  '7' in targetJoin and '5' in targetJoin and '3' in targetJoin :
            
            flag = True
            if '0' in targetJoin:
                flag = False
            if '1' in targetJoin:
                flag = False
            if '2' in targetJoin:
                flag = False
            if '4' in targetJoin:
                flag = False
            if '6' in targetJoin:
                flag = False
            if '8' in targetJoin:
                flag = False
            if '9' in targetJoin:
                flag = False
            
            if flag :
                global ans
                ans+=1
                
        f(targetJoin)
        
f(3)
f(5)
f(7)
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
No753 = ['3','5','7']
for i in range(len(n)-1):
    No753_plus = []
    for no753 in No753:
        No753_plus += ['3' + no753]
        No753_plus += ['5' + no753]
        No753_plus += ['7' + no753]
    No753 += No753_plus
No75 = ['5','7']
for i in range(len(n)-1):
    No75_plus = []
    for no75 in No75:
        No75_plus += ['5' + no75]
        No75_plus += ['7' + no75]
    No75 += No75_plus
No53 = ['3','5']
for i in range(len(n)-1):
    No53_plus = []
    for no53 in No53:
        No53_plus += ['3' + no53]
        No53_plus += ['5' + no53]
    No53 += No53_plus
No37 = ['3','7']
for i in range(len(n)-1):
    No37_plus = []
    for no37 in No37:
        No37_plus += ['3' + no37]
        No37_plus += ['7' + no37]
    No37 += No37_plus
No753 = set(No753)-(set(No75)|set(No53)|set(No37))
count = 0
for no753 in No753:
    if no753 <= n:
        count += 1
print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# WIP
from itertools import product

N_str = input()
len_N = len(N_str)
N = int(N_str)

# DP Initialization
dp = [[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
      for _ in range(len_N)]
# dp[digit][is_max][is_3][is_5][is_7]

"""
for l in range(len_N):
    dp[l][0][0][0][0] = 1
"""

# DP at 0 digit
for m in range(10):
    digit_0 = int(N_str[0])
    if m > digit_0:
        continue
    if m in [3, 5, 7]:
        dp[0][digit_0 == m][m == 3][m == 5][m == 7] = 1

for l, m, n, o, p in product(range(len_N - 1), range(10), range(2), range(2),
                             range(2)):
    if m in [3, 5, 7]:
        digit_lp1 = int(N_str[l + 1])
        dp[l+1][0][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][0][n][o][p]

        if digit_lp1 < m:
            continue

        dp[l+1][digit_lp1 == m][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][1][n][o][p]

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    import itertools
    from bisect import bisect_left,bisect
    L=[]

    S = "753"
    m = 6
    for i in range(3,10):
        for j in itertools.product(S, repeat=i):
            flag7 = 0
            flag5 = 0
            flag3 = 0
            tmp = ""
            for s in j:
                if s == "7":
                    flag7 = 1
                elif s == "5":
                    flag5 = 1
                elif s == "3":
                    flag3 = 1
                tmp += s
            if flag3 == flag5 == flag7 == 1:
                tmp = int(tmp)
                L.insert(bisect_left(L,tmp), tmp)
    ans = bisect_left(L,N)
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
n=int(input())
cnt=0
l=['3','5','7']
def sol(x,c):
    global cnt
    if int(x)<n and all(y in x for y in l):
        cnt+=1
    if c<9:
        for y in l:
            sol(x+y,c+1)
sol('0',0)
print(cnt)

Submission status: Wrong Answer

Solution code:
# WIP
from itertools import product

N_str = input()
len_N = len(N_str)
N = int(N_str)

# DP Initialization
dp = [[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
      for _ in range(len_N)]
# dp[digit][is_max][is_3][is_5][is_7]

for l in range(len_N):
    dp[l][0][0][0][0] = 1


# DP at 0 digit
for m in range(10):
    digit_0 = int(N_str[0])
    if m > digit_0:
        continue
    if digit_0 in [3, 5, 7]:
        dp[0][digit_0 == m][m == 3][m == 5][m == 7] = 1

for l, m, n, o, p in product(range(len_N - 1), range(10), range(2), range(2),
                             range(2)):
    if m in [3, 5, 7]:
        digit_lp1 = int(N_str[l + 1])
        dp[l+1][0][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][0][n][o][p]

        if digit_lp1 < m:
            continue

        dp[l+1][digit_lp1 == m][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][1][n][o][p]

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

Submission status: Wrong Answer

Solution code:
# WIP
from itertools import product

N_str = input()
len_N = len(N_str)
N = int(N_str)

# DP Initialization
dp = [[[[[0] * 2 for _ in range(2)] for _ in range(2)] for _ in range(2)]
      for _ in range(len_N)]
# dp[digit][is_max][is_3][is_5][is_7]
"""
for l in range(len_N):
    dp[l][0][0][0][0] = 1
"""

# DP at 0 digit
for m in range(10):
    digit_0 = int(N_str[0])
    if m > digit_0:
        continue
    if digit_0 in [3, 5, 7]:
        dp[0][digit_0 == m][m == 3][m == 5][m == 7] = 1

for l, m, n, o, p in product(range(len_N - 1), range(10), range(2), range(2),
                             range(2)):
    if m in [3, 5, 7]:
        digit_lp1 = int(N_str[l + 1])
        dp[l+1][0][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][0][n][o][p]

        if digit_lp1 < m:
            continue

        dp[l+1][digit_lp1 == m][n or m == 3][o or m == 5][p or m == 7] += \
            dp[l][1][n][o][p]

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

Submission status: Wrong Answer

Solution code:
# ABC114 C - 755
N = int(input())
ans = 0
for i in range(1,N,2):
    c7,c5,c3,c753= 0,0,0,0
    i = str(i)
    for j in range(len(str(i))):
        if i[j] == "7":
            c7 += 1
            c753 += 1
        elif i[j] == "5":
            c5 += 1
            c753 += 1
        elif i[j] == "3":
            c3 += 1
            c753 += 1
        else:
            break
    if c753 == len(str(i)) and c7 >= 1 and c5 >= 1 and c3 >= 1:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
scg = ["3", "5", "7"]
s = []
res = []
s += scg
while len(s) > 0:
  p = s.pop()
  for i in range(3):
    q = p + scg[i]
    if int(q) < N:
      s.append(q)
      tfs = [0, 0, 0]
      for i in range(len(q)):
        if q[i] == "3":
          tfs[0] = 1
        elif q[i] == "5":
          tfs[1] = 1
        elif q[i] == "7":
          tfs[2] = 1
      if min(tfs) != 0:
        res.append(q)
print(len(res))

Submission status: Wrong Answer

Solution code:

ans=0
n=int(input())
def tri(x):
	p=""
	while x>0:
		p+=str(x%4)
		x//=4
	return p[::-1]
if n>=50000000:
	ans=4470
	k=51111113
	i=32768
else:
	i=16
	k=357
while k<=n:
	c0=0
	c1=0
	c2=0
	for j in range(len(tri(i))):
		if tri(i)[j]=="1":
			c0+=1
		elif tri(i)[j]=="2":
			c1+=1
		elif tri(i)[j]=="3":
			c2+=1
		else:
			c0=0
			break
	if c0!=0 and c1!=0 and c2!=0:
		ans+=1
	i+=1
	k=0
	for j in range(len(tri(i))):
		k+=(int(tri(i)[-j-1])*2+1)*(10**j)
	print(k)
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
cnt = 0

if int(N) < 375:
    print(0)
    exit()

def solve(s):

    global cnt
    

    if len(s) >= 3:


        if int(s) > int(N):
            return

        n7 = s.count("7")
        n5 = s.count("5")
        n3 = s.count("3")
        if n7 >= 1 and n5 >= 1 and n3 >= 1 and n7+n5+n3 == len(s) and int(s) <= int(N):
            cnt += 1
        
    solve(s+"7")
    solve(s+"5")
    solve(s+"3")

solve("")
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = input()
num = int(n)
l = len(n)
li = ['3', '5', '7']
keta = [[] for i in range(l)]
keta[0] = li
for i in range(1, l):
    for kazu in keta[i-1]:
        for n in li:
            keta[i].append(kazu + n)
ct = 0
if l < 3:
    print(0)
else:
    for i in range(2, l):
        for n in keta[i]:
            if '3' in n and '5' in n and '7' in n and int(n) < num:
                ct += 1
    print(ct)

Submission status: Wrong Answer

Solution code:
import itertools

N = input()
l = ['3', '5', '7']
d = len(N)
N = int(N)
aa = 0

if N - 357 < 0:
    print(0)
    exit()
if N > 777777777:
    for i in range(3, d + 1):
        aa += 3 ** i - 3 * (2 ** i - 2) - 3
    print(aa)
    exit()

#d-1桁以下の753数
for i in range(3, d):
    aa += 3 ** i - 3 * (2 ** i - 2) - 3

#N以下のd桁の753数
a = [i for i in itertools.combinations_with_replacement(l, d)]
b = [i for i in a if len(set(i)) == 3]
c = []
count = 0
for k in b:
    temp = list(set([i for i in itertools.permutations(k)]))
    print('here')
    for j in temp:
        if int(''.join(j)) <= N:
            count += 1

print(aa + count)

Submission status: Wrong Answer

Solution code:
import itertools

N = input()
l = ['3', '5', '7']
d = len(N)
N = int(N)

if N - 357 < 0:
    print(0)
    exit()

#d-1桁以下の753数
aa = 0
for i in range(3, d):
    aa += 3 ** (d - 1) - 3 * (2 ** (d - 1) - 2) - 3

#d桁の753数を全て生成
a = [i for i in itertools.combinations_with_replacement(l, d)]
b = [i for i in a if len(set(i)) == 3]
c = []
for k in b:
    temp = [i for i in itertools.permutations(k)]
    temp = list(set(temp))
    for j in temp:
        c.append(''.join(j))

count = 0
for i in c:
    if int(i) <= N:
        count += 1
print(aa + count)

Submission status: Wrong Answer

Solution code:
import itertools

N = input()
l = ['3', '5', '7']
d = len(N)
N = int(N)

if N - 357 < 0:
    print(0)
    exit()

#d-1桁以下の753数
aa = 0
for i in range(3, d):
    aa += 3 ** (d - 1) - 3 * (2 ** (d - 1) - 2) - 3

#d桁の753数を全て生成
a = [i for i in itertools.combinations_with_replacement(l, d)]
b = [i for i in a if len(set(i)) == 3]
c = []
for k in b:
    temp = [i for i in itertools.permutations(k)]
    temp = list(set(temp))
    for j in temp:
        c.append(''.join(j))

count = 0
for i in c:
    if int(i) <= N:
        count += 1
        print(i)
print(aa + count)

Submission status: Wrong Answer

Solution code:
N = int(input())

def search(i,j,k,val) :
    ret = 0 
    if val > N :
        return 0
    elif i > 0 and j > 0 and k > 0 and val<=N:
        return 1 
    else :
        ret += search(i+1,j,k,val*10+3)
        ret += search(i,j+1,k,val*10+5)
        ret += search(i,j,k+1,val*10+7)
    return ret
print(search(0,0,0,0))

Submission status: Wrong Answer

Solution code:
text=input()
N=len(text)
high=int(text[0])
ans=0
if high>6:
  ans=3**N-3*(2**N)+3
elif high>4:
  ans=2*(3**(N-1))+2**(N+1)+2
elif high>2:
  ans=3**(N-1)-2**N+1
else:
  ans=3**(N-1)-3*(2**(N-1))+3
for i in range(1,N):
  ans+=3**i-3*(2**i)+3
print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())

ketalis = list(str(N))
ketalis.reverse()

dp = []

for i in range(10):

    a = []

    for i2 in range(2):
        b = []

        for i3 in range(2):
            c = []

            for i4 in range(2):
                d = []

                for i5 in range(2):
                    e = []

                    for i6 in range(2):

                        e.append(-1)

                    d.append(e)

                c.append(d)

            b.append(c)
            
        a.append(b)

    dp.append(a)

dp[0][0][0][0][0][0] = 1

#print (dp[4][0][0][0][0][0])


for i in range(10):

    if i == 0:
        continue;

    keta = 10 - i

    nowketa = 0

    if len(ketalis) >= keta:

        nowketa = int(ketalis[keta-1])


    for sf in range(2):

        for ff in range(2):

            for tf in range(2):

                for mnf in range(2):

                    for mxf in range(2):

                        for x in [0,3,5,7]:

                            if dp[i-1][sf][ff][tf][mnf][mxf] == -1:
                                continue;


                            nsf = sf
                            nff = ff
                            ntf = tf
                            nmnf = mnf
                            nmxf = mxf


                            if x == 0 and mxf == 1: #最上位ビットが出た後だと0はたせない
                                continue;

                            if x != 0 and mxf == 0: #最上位ビットが出た時の処理
                                nmxf = 1

                            if mnf == 0:

                                if x > nowketa:
                                    continue;

                                if x < nowketa:
                                    nmnf = 1

                            if x == 7:
                                nsf = 1
                            if x == 5:
                                nff = 1
                            if x == 3:
                                ntf = 1

                            if dp[i][nsf][nff][ntf][nmnf][nmxf] == -1:
                                dp[i][nsf][nff][ntf][nmnf][nmxf] = 0

                            dp[i][nsf][nff][ntf][nmnf][nmxf] += dp[i-1][sf][ff][tf][mnf][mxf]

print (max(0,dp[-1][1][1][1][0][1],dp[-1][1][1][1][1][1]))

Submission status: Wrong Answer

Solution code:
a = []

def h(t):
  return 3 in t and 5 in t and 7 in t

def comb(t):
  l = 0
  for i in t:
    l += i
    l = l * 10
  return l // 10

import itertools

for i in range(10):
  a += [comb(x) for x in list(itertools.product([3, 5, 7], repeat=i)) if h(x)]

n = int(input())

t = 0

for i in a:
  if i < n:
    t += 1

print(t)

Submission status: Wrong Answer

Solution code:
import itertools
n=str(input())
ans=0
for i in range(3,len(n)+1):
    for j in itertools.product([3,5,7], repeat=i):
        if (3 not in j) or (5 not in j) or (7 not in j):
            continue
        a=''.join(list(map(str,j)))
        if a<=n:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()

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

print(ans)