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())
count = 0
for i in range(n):
    c = str(i)
    a = []
    a = list(c)
    s = a.count('7')
    f = a.count('5')
    t = a.count('3')
    if s != 0 and f != 0 and t != 0:
        if len(a) == s+t+f:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = input()
digit = len(n)
a753 = 0
a75 = 0
a73 = 0
a53 = 0
now = 0
i = digit - 1
# now + i = digit - 1
while now < digit:
  tmp = int(n[i])
  add = 3 ** now
  sun = (3 ** (now+1) - 3) // 2
  add2 = 2 ** now
  sun2 = 2 ** (now+1) - 2
  if tmp == 8 or tmp == 9:
    a753 = sun + 3 * add
    a75 = sun2 + 2 * add2
    a73 = sun2 + 2 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 7:
    a753 += 3 * add
    a75 += 2 * add2
    a73 += 2 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 6:
    a753 = sun + 2 * add
    a75 = sun2 + 1 * add2
    a73 = sun2 + 1 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 5:
    a753 += 2 * add
    a75 += 1 * add2
    a73 = sun2 + 1 * add2
    a53 += 2 * add2
  elif tmp == 4:
    a753 = sun + 1 * add
    a75 = sun2 + 0 * add2
    a73 = sun2 + 1 * add2
    a53 = sun2 + 1 * add2
  elif tmp == 3:
    a753 += 1 * add
    a75 = sun2 + 0 * add2
    a73 += 1 * add2
    a53 += 1 * add2
  elif tmp == 2 or tmp == 1:
    a753 = sun + 0 * add
    a75 = sun2 + 0 * add2
    a73 = sun2 + 0 * add2
    a53 = sun2 + 0 * add2
    a = 3 * now - 3
  now += 1
  i -= 1
all1 = (10 ** digit - 1) // 9
a = 3 * digit
if int(n) < 7 * all1:
  a -= 1
if int(n) < 5 * all1:
  a -= 1
if int(n) < 3 * all1:
  a -= 1
#print(a753,a75,a73,a53,a)
print(a753 - a75 - a73 - a53 +a)

Submission status: Wrong Answer

Solution code:
n = input()
digit = len(n)
a753 = 0
a75 = 0
a73 = 0
a53 = 0
now = 0
i = digit - 1
# now + i = digit - 1
while now < digit:
  tmp = int(n[i])
  add = 3 ** now
  sun = (3 ** (now+1) - 3) // 2
  add2 = 2 ** now
  sun2 = 2 ** (now+1) - 2
  if tmp == 8 or tmp == 9:
    a753 = sun + 3 * add
    a75 = sun2 + 2 * add2
    a73 = sun2 + 2 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 7:
    a753 += 3 * add
    a75 += 2 * add2
    a73 += 2 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 6:
    a753 = sun + 2 * add
    a75 = sun2 + 1 * add2
    a73 = sun2 + 1 * add2
    a53 = sun2 + 2 * add2
  elif tmp == 5:
    a753 += 2 * add
    a75 += 1 * add2
    a73 = sun2 + 1 * add2
    a53 += 2 * add2
  elif tmp == 4:
    a753 = sun + 1 * add
    a75 = sun2 + 0 * add2
    a73 = sun2 + 1 * add2
    a53 = sun2 + 1 * add2
  elif tmp == 3:
    a753 += 1 * add
    a75 = sun2 + 0 * add2
    a73 += 1 * add2
    a53 += 1 * add2
  elif tmp == 2 or tmp == 1:
    a753 = sun + 0 * add
    a75 = sun2 + 0 * add2
    a73 = sun2 + 0 * add2
    a53 = sun2 + 0 * add2
    a = 3 * now - 3
  now += 1
  i -= 1
all1 = (10 ** digit - 1) // 9
a = 3 * digit
if int(n) < 7 * all1:
  a -= 1
if int(n) < 5 * all1:
  a -= 1
if int(n) < 3 * all1:
  a -= 1
print(a753,a75,a73,a53,a)
print(a753 - a75 - a73 - a53 +a)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
# 桁数を取得
keta = len(str(N))
# 桁数以内で3,5,7で構成される数を生成
l = ['3', '5', '7']
kotae = set()
kotae.add('0')

for i in range(keta):
    print('i={}'.format(i))
    kari = copy.copy(kotae)
    for m in kari:
        print(m)
        for n in l:
            k = m + n
            if int(k) <= N:
                kotae.add(k)

count = 0
for s in kotae:
    count += 1 if all(s.count(c) > 0 for c in '753') else 0

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
n = input()
keta = len(list(n))
cnt=0
l = [3,5,7]
for k in range(3,keta+1):
  for i in itertools.product(l, repeat=k):
    if 3 in i and 5 in i and 7 in i:
      tmp=""
      for j in i:
        tmp+=str(j)
      if int(tmp)<int(n):
        cnt+=1
      else:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools as it
N=int(input())
d=0
for i in range(3,10):
    for c in sorted(list(it.product('753',repeat=i))):
        if int(''.join(c))>N:exit(0)
        if len(set(c))==3:d+=1
print(d)

Submission status: Wrong Answer

Solution code:
N = int(input())

N_str = str(N)
List = []
for i in range(len(N_str)):
    List.append(int(N_str[i]))

num = 0
for i in range(3,len(List)):
    num += (3**i-3*2**i+3)


c = 0
while c <= len(List)-4:
    x = len(List) - c
    if List[c] > 7:
        num += (3**x-3*2**x+3)
        break
    elif List[c] > 5:
        num += (3**x-3*2**x+3)*2//3
    elif List[c] > 3:
        num += (3**x-3*2**x+3)//3
    c += 1

def number(x):
    List = []
    X = str(x)
    for i in range(len(X)):
        List.append(int(X[i]))
    a = List.count(3)
    b = List.count(5)
    c = List.count(7)
    if a>=1 and b>=1 and c>=1 and a+b+c==len(X):
        return True
    else:
        return False

j = 357
if N < 10**4:
    num = 0
    while j <= N:
        if number(j):
            num += 1
        j += 2
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())

def search(keta, num):
  if keta == 0:
    if '0' in str(int(num)):
      return 0
    elif int(num) <= N:
      return 1
    else:
      return 0
  else:
    return search(keta-1, num + '0') + search(keta-1, num + '3') + search(keta-1, num + '5') + search(keta-1, num + '7')

keta = len(str(N))

ans = search(keta, '')
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def search(keta, num):
  if keta == 0:
    if int(num) <= N:
      return 1
    else:
      return 0
  else:
    return search(keta-1, num + '0') + search(keta-1, num + '3') + search(keta-1, num + '5') + search(keta-1, num + '7')

keta = len(str(N))

ans = search(keta, '')
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = input()
r = len(n)
n = int(n)
kouho = []
pre = [""]

for i in range(r):
    pro = []
    for temp in pre:
        kouho.append(temp+"3")
        kouho.append(temp+"5")
        kouho.append(temp+"7")
        pro.append(temp+"3")
        pro.append(temp+"5")
        pro.append(temp+"7")
    pre = pro

def ctit(s):
    a = 0
    b = 0
    d = 0
    for c in s:
        if c == "3":
            a += 1
        elif c == "5":
            b += 1
        else:
            d += 1
    if a > 0 and b > 0 and d > 0:
        return True
    else:
        return False

ans = 0
for temp in kouho:
    if int(temp) < n:
        if ctit(temp):
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
s = input()
cnt = 0
# 桁数
digits = len(s)
# 桁数 までのカウントをあらかじめいれておく
cntl = [0, 6, 42, 192, 732, 2538, 8334]
# 七五三 number
number = ["3", "5", "7"]

for i in itertools.product(number, repeat=digits):
    if "3" in i and "5" in i and "7" in i:
        if int(''.join(i)) <= int(s):
            cnt += 1
print(cnt + cntl[digits - 3])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools

a = input()
b = ["3", "5", "7"]
d = 0
for i in range(1, len(a)+1):
    for j in itertools.product(b, repeat=i):
        c = ""
        for k in range(len(j)):
            c += j[k]
        if int(c) < int(a):
            if "3" in c and "5" in c and "7" in c:
                d += 1
print(d)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
"""
753の数
"""

import sys
sys.setrecursionlimit(100000)
N = int(input())
# seen = [False] * N
"""
1. Gを予め作って探索するパターン
2. Gを作りながら探索するパターン
"""
cnt = 0
def dfs(v):
    global cnt
    # vを訪問済みにする
    # seen[v] = True
    num = "753"
    #グラフ中の次のVについて
    for n in num:
        next_v = v + n
        # 探索打ち切り条件->
        # すでに探索済み or なにかの終了条件に引掛かる
        if int(next_v) >= N: continue
        # 見られていない場合、再帰的に探索
        dfs(next_v)
        if "3" in next_v and "5" in next_v and "7" in next_v:
            cnt += 1

dfs("")
print(cnt)

Submission status: Wrong Answer

Solution code:
"""
753の数
"""

import sys
sys.setrecursionlimit(100000)
N = 999999999
# seen = [False] * N
"""
1. Gを予め作って探索するパターン
2. Gを作りながら探索するパターン
"""
cnt = 0
def dfs(v):
    global cnt
    # vを訪問済みにする
    # seen[v] = True
    num = "753"
    #グラフ中の次のVについて
    for n in num:
        next_v = v + n
        # 探索打ち切り条件->
        # すでに探索済み or なにかの終了条件に引掛かる
        if int(next_v) >= N: continue
        # 見られていない場合、再帰的に探索
        dfs(next_v)
        if "3" in next_v and "5" in next_v and "7" in next_v:
            cnt += 1

dfs("")
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N=input()
M=int(N)
NList = [int(n) for n in list(N)]
keta = int(math.log10(M))+1
DP753 = [[0]*2 for i in range(len(N))]#DP[i][smaller]:smaller = 0でi+1桁目までぴったし一致
for k,n in enumerate(NList):
    if k==0:
        if n in (3,5,7):
            DP753[0][0] = 1
        DP753[0][1] = (n>3)+(n>5)+(n>7)
    else:
        equal,miman = DP753[k-1]
        if n in (3,5,7):
            DP753[k][0] = equal
        miman753 = (n>3)+(n>5)+(n>7)+1#0もある
        DP753[k][1] = equal*miman753+miman*4
Num753 = sum(DP753[len(N)-1])

DP75 = [[0]*2 for i in range(len(N))]#DP[i][smaller]:smaller = 0でi+1桁目までぴったし一致
for k,n in enumerate(NList):
    if k==0:
        if n in (5,7):
            DP75[0][0] = 1
        DP75[0][1] = (n>5)+(n>7)
    else:
        equal,miman = DP75[k-1]
        if n in (5,7):
            DP75[k][0] = equal
        miman753 = (n>5)+(n>7)+1
        DP75[k][1] = equal*miman753+miman*3
Num75 = sum(DP75[len(N)-1])

DP73 =  [[0]*2 for i in range(len(N))]#DP[i][smaller]:smaller = 0でi+1桁目までぴったし一致
for k,n in enumerate(NList):
    if k==0:
        if n in (3,7):
            DP73[0][0] = 1
        DP73[0][1] = (n>3)+(n>7)
    else:
        equal,miman = DP73[k-1]
        if n in (3,7):
            DP73[k][0] = equal
        miman753 = (n>3)+(n>7)+1
        DP73[k][1] = equal*miman753+miman*3
Num73 = sum(DP73[len(N)-1])

DP53 =  [[0]*2 for i in range(len(N))]#DP[i][smaller]:smaller = 0でi+1桁目までぴったし一致
for k,n in enumerate(NList):
    if k==0:
        if n in (3,5):
            DP53[0][0] = 1
        DP53[0][1] = (n>3)+(n>5)
    else:
        equal,miman = DP53[k-1]
        if n in (5,3):
            DP53[k][0] = equal
        miman753 = (n>3)+(n>5)+1
        DP53[k][1] = equal*miman753+miman*3
Num53 = sum(DP53[len(N)-1])

def Xonly(X,Y):
    """
    引数２個ともstr
    """
    if int(Y)>int(X*len(Y)):
        return(len(Y))
    else:return(len(Y)-1)

Num7,Num5,Num3 = Xonly("7",N),Xonly("5",N),Xonly("3",N)

Only7,Only5,Only3 = Num753-Num53,Num753-Num73,Num753-Num75

print(Num7+Num5+Num3+Only7+Only5+Only3-2*Num753)

Submission status: Wrong Answer

Solution code:
def num(n):
  if n==3:
    return ["357","375","537","573","753","735"]
  else:
    l=[]
    l1=num(n-1)
    for i in ["3","5","7"]:
      for j in l1:
        l.append(i+j)
    return l
n=int(input())
if n<357:
  print(0)
elif n<375:
  print(1)
elif n<537:
  print(2)
elif n<573:
  print(3)
elif n<735:
  print(4)
elif n<753:
  print(5)
elif n<1000:
  print(6)
else:
  s=len(str(n))
  dic=num(s-1)
  c=0
  for i in dic:
    for j in ["3","5","7"]:
      if int(j+i)<=n:
        c+=1
  for i in range(3,s):
    c+=len(num(i))
  print(c)

Submission status: Wrong Answer

Solution code:
n = input()
a = "357"
count357 = ["3", "5", "7"]
i = 0
while int(count357[-1]) <= int(n):
    for j in range(3):
        count357.append(str(int(count357[i])*10 + int(count357[j])))
        if int(count357[-1]) > int(n):
            break
    i += 1
count357.pop(-1)
count = 0
for i in range(len(count357)):
    for j in range(len(a)):
        if a[j] not in count357[i]:
            continue
    else:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = input()
a = "357"
count357 = ["3", "5", "7"]
i = 0
count = 0
while int(count357[i]) * 10 < int(n):
    for j in range(3):
        count357.append(str(int(count357[i])*10 + int(count357[j])))
    i += 1

for i in range(len(count357)):
    if "3" in count357[i] and "5" in count357[i] and "7" in count357[i]:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5)
N = int(input())

def rec(num, use, cnt):
    if num > N:
        return cnt-1

    if (use == 0b111):
        cnt += 1

    return rec(num*10+7, use | 0b100, cnt)\
         + rec(num*10+5, use | 0b010, cnt)\
         + rec(num*10+3, use | 0b001, cnt)

print(rec(0,0,0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5)
N = int(input())

def rec(num, use, cnt):
    if num > N:
        return cnt

    if (use == 0b111):
        cnt = 1

    return rec(num*10+7, use | 0b100, cnt)\
         + rec(num*10+5, use | 0b010, cnt)\
         + rec(num*10+3, use | 0b001, cnt)

print(rec(0,0,0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5)
N = int(input())

def rec(num, use, cnt):
    if num > N:
        return cnt

    if (use == 0b111):
        cnt += 1

    return rec(num*10+7, use | 0b100, cnt)\
         + rec(num*10+5, use | 0b010, cnt)\
         + rec(num*10+3, use | 0b001, cnt)

print(rec(0,0,0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5)
N = int(input())

def rec(num, use, cnt):
    if num > N:
        return cnt

    if (use == 0b111):
        cnt += 1

    return rec(num*10+7, use | 0b100, cnt)\
        + rec(num*10+5, use | 0b100, cnt)\
        + rec(num*10+3, use | 0b100, cnt)

print(rec(0,0,0))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5)
N = int(input())

def rec(num ,cnt=0):
    if int(num) > N:
        return cnt

    if '7' in num and '5' in num and '3' in num:
        cnt += 1

    return rec('7'+num, cnt) + rec('5'+num, cnt) + rec('3'+num, cnt)

print(rec('7')+rec('5')+rec('3'))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**5)
N = int(input())

def rec(num='0',cnt=0):
    if int(num) > N:
        return cnt

    if '7' in num and '5' in num and '3' in num:
        cnt += 1

    return rec('7'+num, cnt) + rec('5'+num, cnt) + rec('3'+num, cnt)

print(rec())

Submission status: Wrong Answer

Solution code:
n=int(input())
i=1
j=0
k=0
s=["3","5","7"]
d=["3","5","7"]
g=[]
k2=0
while i!=10:
    f=len(d)
    while j!=3:
        k = k2
        while k!=f:
            d.append(d[k]+s[j])
            k+=1


        j+=1
    k2 = f
    j=0
    i+=1
i=0
while i!=len(d):
    if ("3" in d[i])==True and ("5" in d[i])==True and ("7" in d[i])==True:
        i+=1
    else:
        del d[i]

d=list(map(int,d))
d.sort()
ans=0
i=0
x=d[i]
while x<n:
    ans+=1
    i+=1
    x=d[i]

#print(d)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
i=1
j=0
k=0
s=["3","5","7"]
d=["3","5","7"]
g=[]
k2=0
while i!=10:
    f=len(d)
    while j!=3:
        k = k2
        while k!=f:
            d.append(d[k]+s[j])
            k+=1


        j+=1
    k2 = f
    j=0
    i+=1
i=0
while i!=len(d):
    if ("3" in d[i])==True and ("5" in d[i])==True and ("7" in d[i])==True:
        i+=1
    else:
        del d[i]

d=list(map(int,d))
d.sort()
ans=0
i=0
x=0
while x<n:
    ans+=1
    i+=1
    x=d[i]

#print(d)
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())
def next_357(num_arr,i=-1):
    if len(num_arr) < -i:
        num_arr.insert(0,3)
        return num_arr
    if num_arr[i] == 3:
        num_arr[i] = 5
        return num_arr
    elif num_arr[i] == 5:
        num_arr[i] = 7
        return num_arr
    elif num_arr[i] == 7:
        num_arr[i] = 3
        i -= 1
        return next_357(num_arr,i)
ans = 1
a357 = [3,5,7]
while True:
    if N < 357:
        ans = 0
        break
    elif N == 357:
        break
    else:
        a357 = next_357(a357)
        if int("".join(map(str, a357))) <= N:
            ans += 1
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
ch=set(["3","5","7"])
for i in range(1,n+1):
  if set(str(i)) &ch == ch:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
n = input()
dp = [[[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]for l in range(len(n))]
#dp[i桁目][nより小さいかどうか][3がある][5がある][7がある]

for i in range(len(n)):
    dp[i][0][0][0][0] = 1

for j in range(10):
    if int(n[0]) >= j:
        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1

for i, j, k, l, m in itertools.product(range(len(n)-1), range(2), range(2), range(2), range(10)):
    if m in [3, 5, 7]:
        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]
        if m <= int(n[i+1]):
            dp[i + 1][m == int(n[i+1])][j or m == 3][k or m == 5][l or m == 7] += dp[i][1][j][k][l]

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

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
p = [0]
while p:
    k = p.pop()
    if k > N:
        continue
    if '7' in str(k) and '5' in str(k) and '3' in str(k):
        ans += 1
    p.extend([k*10+3, k*10+5, k*10+7])

Submission status: Wrong Answer

Solution code:
# ABC114C - 755
from itertools import product

n = input()
digit = len(n)
ans = 0
for i in range(1, digit):
    ans += len([i for i in product("357", repeat=i) if len(set(i)) == 3])

tup = tuple(i for i in n)
lst = [i for i in product("357", repeat=digit) if len(set(i)) == 3] + [tup]
lst.sort()
ans += lst.index(tup)
print(ans)

Submission status: Wrong Answer

Solution code:
def base2n(Num,n):
    if Num<n:
        return str(Num)
    else:
        return base2n(Num//n,n)+str(Num%n)

N=int(input())
cnt=0
for j in range(3,10):
    for i in range(3**j):
        i=("0"*i+base2n(i,3))[-j:]
        if min(i.count("0"),i.count("1"),i.count("2"))!=0:
            i=list(i)
            i.reverse()
            i="".join(i)
            i=i.replace("0","3")
            i=i.replace("1","5")
            i=i.replace("2","7")
            if int(i)<=N:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
for i in range(1,n+1):
  if "3" in str(i) and "5" in str(i) and "7" in str(i):
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:

# N以下で7,5,3の組み合わせでできる数は何通りか
# 7,5,3は1回以上使わなくてはならない
# 最小の数字は357
# 順に375, 537, 573, 735, 753, 3357, 
#    3375,3537,3573,.......
# N以上になれば終了

Submission status: Wrong Answer

Solution code:
n=int(input())

d=['3','5','7','']
k=10
a=d
def make(k,l):
    if k==0:
        return l
    t=set()
    for i in l:
        for j in d:
            t.add(i+j)
    return make(k-1,t)

s=[]    
for i in make(k,d):
    if i!='':
        u=set()
        for j in i:
            u.add(j)
        if len(u)==3:
            s.append(int(i))
s.append(n)
s.sort()
ans=s.index(n)

u=set()
u.add(3)
u.add(5)
u.add(7)
for j in str(n):
    u.add(j)
if len(u)==3:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

d=['3','5','7','']
k=9
a=d
def make(k,l):
    if k==0:
        return l
    t=set()
    for i in l:
        for j in d:
            t.add(i+j)
    return make(k-1,t)

s=[]    
for i in make(k,d):
    if i!='':
        u=set()
        for j in i:
            u.add(j)
        if len(u)==3:
            s.append(int(i))
s.append(n)
s.sort()
ans=s.index(n)

u=set()
u.add(3)
u.add(5)
u.add(7)
for j in str(n):
    u.add(j)
if len(u)==3:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

d=['3','5','7','']
k=9
a=d
def make(k,l):
    if k==0:
        return l
    t=set()
    for i in l:
        for j in d:
            t.add(i+j)
    return make(k-1,t)

s=[]    
for i in make(k,d):
    if i!='':
        u=set()
        for j in i:
            u.add(j)
        if len(u)==3:
            s.append(int(i))
s.append(n)
s.sort()
ans=s.index(n)

u=set()
for j in str(n):
    u.add(j)
if len(u)==3:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())

number = [7, 5, 3]

ans = 0
for i in range(10):
    for conv in itertools.product(number, repeat=i+1):
        
        tmp = 0
        for j in range(len(conv)):
            tmp += conv[j] * 10 ** (len(conv) - j - 1)
            
        
        if ((3 in conv) and (5 in conv) and (7 in conv)) and tmp < N:
            ans += 1
            
        
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

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

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
for n in range(1, N):
	n = list(str(n))
	if n.count("7") > 0:
		n = [i for i in n if i != "7"]
		if n.count("5") > 0:
			n = [j for j in n if j != "5"]
			if n.count("3") > 0:
				n = [k for k in n if k != "3"]
				if len(n) == 0:
					ans += 1
print(ans)

Submission status: Wrong Answer

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

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

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

        return

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = int(input())

count = 0
for i in range(n+1):
    s = str(i)
    if '3' in s and '5' in s and '7' in s:
        count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

if (top == 3 or top == 5 or top == 7):
    # ややこなのでforチェックする.
    for number in range(top * (10 ** (digit - 1)), n):
        count3 = 0
        count5 = 0
        count7 = 0
        for num in str(number):
            if(int(num) == 3):
                count3 += 1
            elif(int(num) == 5):
                count5 += 1
            elif(int(num) == 7):
                count7 += 1 
            else:
                break
        else:
            if(count3 != 0 and count5 != 0 and count7 != 0):
                print("num:{}".format(number))
                answer += 1
print (answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
def dfs(s): # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        print("invalid  ",s)
        return 0
    print("valid    ",s)
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
    for c in '753':
        ret += dfs(s+c) #ここに再起表現が入る
    return ret

print(dfs('0'))

Submission status: Wrong Answer

Solution code:
N = int(input())
def dfs(s): # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        print("invalid  ",s)
        return 0
    print("valid    ",s)
    cnt = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
    for c in '753':
        cnt += dfs(s+c) #ここに再起表現が入る
    return cnt
dfs("0")

Submission status: Wrong Answer

Solution code:
S = input()
ans = 999

for i in range(len(S)-2):
    x = int(S[i:i+3])

    if abs(x-753) < ans:
        ans = abs(x-753)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = str(N)
tst = ["0", "1", "2", "4", "6", "8", "9"]
cnt = 0

for i in range(N):
  n = str(i)
  lst = list(n)
  if "3" in lst:
    if "5" in lst:
      if "7" in lst:
        if "0" not in lst:
          if "1" not in lst:
            if "2" not in lst:
              if "4" not in lst:
                if "6" not in lst:
                  if "8" not in lst:
                    if "9" not in lst:
                      cnt +=1
  else:
    continue
print(cnt)

Submission status: Wrong Answer

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

for i in range(N):
    flag3 = False
    flag5 = False
    flag7 = False

    judge = True
    for j in range(10):
        if j == 3 and str(j) in str(i):
            flag3 = True
        elif j == 5 and str(j) in str(i):
            flag5 = True
        elif j == 7 and str(j) in str(i):
            flag7 = True
        else:
            if str(j) in str(i):
                judge = False
                break
    if flag3 and flag5 and flag7 and judge:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = input()

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

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

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

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

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


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

Submission status: Wrong Answer

Solution code:
S = input()

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

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

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

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

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


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