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

Solution (Python):
N = int(input())

def check(n):
 s = str(n)
 return n <= N and s.count('3') * s.count('5') * s.count('7') >= 1

ans = 0
for i1 in [3,5,7]:
 if check(i1):
  ans += 1
 for i2 in [3,5,7]:
  if check(i2*10 + i1):
   ans += 1
  for i3 in [3,5,7]:
   if check(i3*100 + i2*10 + i1):
    ans += 1
   for i4 in [3,5,7]:
    if check(i4*1000 + i3*100 + i2*10 + i1):
     ans += 1
    for i5 in [3,5,7]:
     if check(i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
      ans += 1
     for i6 in [3,5,7]:
      if check(i6*100000 + i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
       ans += 1
      for i7 in [3,5,7]:
       if check(i7*1000000 + i6*100000 + i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
        ans += 1
       for i8 in [3,5,7]:
        if check(i8*10000000 + i7*1000000 + i6*100000 + i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
         ans += 1
        for i9 in [3,5,7]:
         if check(i9*100000000 + i8*10000000 + i7*1000000 + i6*100000 + i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
          ans += 1
print(ans)

Solution (Python):
N = int(input())
counter = 0
list = ['3','5','7']
ok = []
for a in list:
    for b in list:
        for c in list:
            ok.append(a+b+c)
            for d in list:
                ok.append(a+b+c+d)
                for e in list:
                    ok.append(a+b+c+d+e)
                    for f in list:
                        ok.append(a+b+c+d+e+f)
                        for g in list:
                            ok.append(a+b+c+d+e+f+g)
                            for h in list:
                                ok.append(a+b+c+d+e+f+g+h)
                                for i in list:
                                    ok.append(a+b+c+d+e+f+g+h+i)
                                    for j in list:
                                        ok.append(a+b+c+d+e+f+g+h+i+j)

okk = []
for _ in ok:
    x3 = _.count('3')
    x5 = _.count('5')
    x7 = _.count('7')
    if x3>0 and x5>0 and x7>0:
        okk.append(_)
fin = [int(_) for _ in okk]
fin.sort()
for _ in fin:
    if _ > N:
        print(fin.index(_))
        break

Solution (Python):
def aaa(n):
    n = [x for x in n]
    for i in range(len(n)-1,-1,-1):
        if n[i] == '3':
            n[i] = '5'
            for j in range(i+1,len(n)):
                n[j] = '3'
            return ''.join(n)
        elif n[i] == '5':
            n[i] = '7'
            for j in range(i+1,len(n)):
                n[j] = '3'
            return ''.join(n)
        else:
            pass
    n = '3'*(len(n)+1)
    return n
n = int(input())
check = '357'
ans = 0
if int(check) <= n:
    ans += 1
while True:
    if int(check) > n:
        break
    check = aaa(check)
    acheck = [0,0,0]
    for i in check:
        if i == '3':
            acheck[0] = 1
        if i == '5':
            acheck[1] = 1
        if i == '7':
            acheck[2] = 1
    if acheck[0] == 1 and acheck[1] == 1 and acheck[2] == 1 and int(check) <= n:
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline().strip

def num753(num, keta):
    if len(num) >= keta:
        yield num
    else:
        for n in ('3', '5', '7'):
            tmp = num + n
            
            for nu in num753(tmp, keta):
                yield nu

N = input()
ans = 0
for i in range(3, len(N)+1):
    for num in num753('', i):
        if '3' in num and '5' in num and '7' in num:
            if int(num) <= int(N):
                ans += 1
print(ans)

Solution (Python):
N = int(input())

length = len(str(N))
reuslt = 0
r_list = []

if length <= 2:
    print(0)
    exit()

def search(now, lastNum):
    if lastNum == 0:
        r_list.append(now)
        return
    search(now + "3", lastNum - 1)
    search(now + "5", lastNum - 1)
    search(now + "7", lastNum - 1)


for i in range(length-2):
    search("", length-i)
count = 0
for r in r_list:
    num = int(r)
    if num <= N and (r.count("7") >= 1 and r.count("5") >= 1 and r.count("3") >= 1):
        count += 1
print(count)

Solution (Python):
from itertools import product
S = input()
N = int(S)
X = len(S)+1

ans = 0
for i in range(3,X):
  for pat in product('357', repeat=i):
    if len(set(pat)) < 3:
      continue
    if int("".join(pat)) <= N:
      ans += 1
      
print(ans)

Solution (Python):
n = int(input())

m = '357'
ml = [1,1,1]

count = 0
flag = True
while flag:
    '''
    print(m)
    print(count)
    print(ml)
    '''
    if int(m) <= n:
        if 0 in ml:
            pass
        else:
            count += 1
    else:
        flag = False
    tmpm = m[::-1]
    for i,x in enumerate(tmpm):
        if x == '3':
            m = '3'*i + '5' + tmpm[i+1:]
            m = m[::-1]
            ml[0] -= 1
            ml[0] += i
            ml[1] += 1
            ml[2] -= i
            break
        elif x == '5':
            m = '3'*i + '7' + tmpm[i+1:]
            m = m[::-1]
            ml[0] += i
            ml[1] -= 1
            ml[2] -= i
            ml[2] += 1
            break
        else:
            pass
    if ml[0] == 0 and ml[1] == 0:
        tmpl = len(m)
        m = '3' * (tmpl+1)
        ml = [tmpl+1, 0, 0]


print(count)

Solution (Python):
N = int(input())

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)

def convert(X):
    T = base_10_to_n(X, 3)
    R = ''
    for t in str(T):
        t = int(t)
        if t == 0:
            R += '3'
        elif t == 1:
            R += '5'
        elif t == 2:
            R += '7'
    return R[1:]

ans = 0
searched = set()
for i in range(27, 200000):
    r = convert(i)
    if r in searched:
        continue
    if int(r) > N:
        break
    if len(set(list(r))) == 3:
        searched.add(r)
        ans += 1

print(ans)

Solution (Python):
import itertools, operator
def combinations_with_replacement_counts(n, r):
    size = n + r - 1
    for indices in itertools.combinations(range(size), n-1):
        starts = [0] + [index+1 for index in indices]
        stops = indices + (size,)
        yield tuple(map(operator.sub, stops, starts))
        
a = (input())
ok = dict()
aller = list(range(len(a)))
out = 0
if len(a) <= 2:
	print(0)
if len(a) >= 3:
	num = int(a)
	for times in range(len(a) - 3):
		no = list(range(times + 3))
		for i in combinations_with_replacement_counts(3, times):
			for j in itertools.combinations(no, i[0] + 1):
				for k in itertools.combinations([ele for ele in no if ele not in j], i[1] +1):
					for l in itertools.combinations([ele for ele in no if ele not in j and ele not in k], i[2] + 1):
						out += 1
					
	for i in combinations_with_replacement_counts(3, len(a) - 3):
		for j in itertools.combinations(aller, i[0] + 1):
			for k in itertools.combinations([ele for ele in aller if ele not in j], i[1] +1):
				for l in itertools.combinations([ele for ele in aller if ele not in j and ele not in k], i[2] + 1):
					number = sum([3*10**ele for ele in j]) +sum([5*10**ele for ele in k]) + sum([7*10**ele for ele in l])
					if number <= num:
						out += 1
	print(out)

Solution (Python):
n = int(input())
s = "0357"
ans = []
for a in s:
    for b in s:
        for c in s:
            for d in s:
                for e in s:
                    for f in s:
                        for g in s:
                            for h in s:
                                for i in s:
                                    for j in s:
                                        for k in s:
                                            o = int(a+b+c+d+e+f+g+h+i+j+k)
                                            if o > n:
                                                break
                                            elif set(str(o)) == {"3","5","7"}:
                                                ans.append(o)
print(len(ans))

Solution (Python):
from itertools import product
from collections import Counter

if __name__ == '__main__':
    n = input()
    length = len(n)
    facts = [0] * length
    facts[0] = 1
    for i in range(1, length):
        facts[i] = (i + 1) * facts[i - 1]

    ans = 0
    for m in range(3, length):
        for i in range(1, length):
            for j in range(1, length - i):
                k = m - i - j
                ans += facts[m - 1] // (facts[i - 1] * facts[j - 1] * facts[k - 1])

    for s in (''.join(list(t)) for t in product(*(['357'] * length))):
        if n < s:
            break
        if set(Counter(s).keys()) != {'3', '5', '7'}:
            continue
        ans += 1
    print(ans)

Solution (Python):
T="357"
N=int(input())
sts = {""}
for _ in range(len(str(N))):
    sts = sts | {s+t for t in T for s in sts}
    

sts = [s for s in sts if '3' in s and '5' in s and '7' in s]

sts = [int(s) for s in sts if int(s)<=N]

print(len(sts))

Solution (Python):
import itertools
n=int(input())
count=0
nums=["3","5","7"]

k=3
while k <= len(str(n)):
  for i in itertools.product(nums,repeat=k):
    count_3=0
    count_5=0
    count_7=0
    if (int("".join(i))) <=n:
      for j in i:
        if j == "7":
          count_7+=1
        if j == "3":
          count_3+=1
        if j == "5":
          count_5+=1
      if count_5>=1 and count_3>=1 and count_7>=1:
        count+=1
  k+=1
print(count)

Solution (Python):
n=int(input())


arr=["3","5","7"]
for i in range(9):
    t_arr=[]
    for i in arr:
        t_arr.append("3"+i)
        t_arr.append("5"+i)
        t_arr.append("7"+i)
    arr.extend(t_arr)


count=0
for i in set(arr):
    if n>=int(i) and "3" in i and "5" in i and "7" in i:
        count+=1
        
print(count)

Solution (Python):
n = int(input())

def tobase4(num):
    ans = ''
    while num>0:
        ans += str(num%4)
        num //= 4
    return ans[::-1]

def check(s):
    if '1' in s and '2' in s and '3' in s and '0' not in s:
        return True
    return False

def conv(s):
    s = s.replace('2','5')
    s = s.replace('3','7')
    s = s.replace('1','3')
    return s

res = 0
for i in range(10**9):
    s = tobase4(i)
    if not check(s):
        continue
    s = conv(s)
    s = int(s)
    
    if n < s:
        break
    
    res += 1
print(res)

Solution (Python):
import math

N = int(input())

n = math.floor(math.log10(N))


def check(n):
    c7 = False
    c5 = False
    c3 = False
    while n != 0:
        d = n % 10
        if d == 7:
            c7 = True
        elif d==5:
            c5 = True
        elif d==3:
            c3 = True
        else:
            return False


        n //= 10
    if c7 and c5 and c3:
        return True
    else:
        return False


def f(cur, i):
    if cur > N:
        return 0

    if i==-1:
        if check(cur):
            
            return 1
        else:
            
            return 0

    r7 = f(cur + 7 * (10 ** i), i - 1)
    r5 = f(cur + 5 * (10 ** i), i - 1)
    r3 = f(cur + 3 * (10 ** i), i - 1)
    r0 = f(cur + 0 * (10 ** i), i - 1)
    return r7 + r5 + r3 + r0

nn = 10 ** n

r7 = f(7 * nn, n - 1)
r5 = f(5 * nn, n - 1)
r3 = f(3 * nn, n - 1)
r0 = f(0 * nn, n - 1)

ret = r7 + r5 + r3 + r0

print(ret)

Solution (Python):

def check(l):

	for j in range(0,10):
		if(j==3 or j== 5 or j==7):
			if(str(j) not in l):return(0)
		else:
			if(str(j) in l):return(0)
	else:
		
		return(1)


n=int(input())
c=0
i=357
while(i < n+1):
	l=list(str(i))
	for j in range(len(l)):
		x=int(l[j])
		if(x !=3 and x!=5 and x!=7):
			
			if(x<3):
				dx=3-x
			elif(x<5):
				dx=5-x
			elif(x<7):
				dx=7-x
			else:
				dx=10-x
			i+=dx*10**(len(l)-j-1)-1
			break
	l=list(str(i))
	
	c+=check(l)
	i+=1
	
print(c)

Solution (Python):
n = int(input())

nana_go_sans = [{357, 375, 537, 573, 735, 753}]

order = len(str(n))
for i in range(3, order):
    nana_go_san = set()
    nana_go_san.add(int("3" + "5" * (i - 1) + "7"))
    nana_go_san.add(int("3" + "7" * (i - 1) + "5"))
    nana_go_san.add(int("5" + "3" * (i - 1) + "7"))
    nana_go_san.add(int("5" + "7" * (i - 1) + "3"))
    nana_go_san.add(int("7" + "3" * (i - 1) + "5"))
    nana_go_san.add(int("7" + "5" * (i - 1) + "3"))
    for num in nana_go_sans[i - 3]:
        nana_go_san.add(int("3" + str(num)))
        nana_go_san.add(int("5" + str(num)))
        nana_go_san.add(int("7" + str(num)))
        nana_go_san.add(int(str(num) + "3"))
        nana_go_san.add(int(str(num) + "5"))
        nana_go_san.add(int(str(num) + "7"))
    nana_go_sans.append(nana_go_san)

count = 0
for nana_go_san in nana_go_sans:
    for num in nana_go_san:
        if num <= n:
            count += 1

print(count)

Solution (Python):
import itertools as itr
import bisect
n = int(input())

arr = []
for n_order in range(3,10):
    for a in itr.product([3,5,7], repeat=n_order):
        if 7 in a:
            if 5 in a:
                if 3 in a:
                    n753=0
                    for l in range(n_order):
                        n753+=10**l*a[l]
                    arr.append(n753)
arr.sort()

ans = bisect.bisect_right(arr,n)
print(ans)

Solution (Python):
import itertools

n = input()
gomen = {3:0, 4:6, 5:18, 6:54,7:162,8:486,9:1458}

if len(n) < 3:
    print(0)
    exit()
cnt = 0
for i in range(3, len(n)+1):
    c = list(itertools.product(["3", "5", "7"], repeat=i))
    for num in c:
        if int(n) >= int("".join(num)) and (num.count("3") >=1
                and num.count("5") >= 1 and num.count("7") >= 1):
            cnt += 1

print(cnt)

Solution (Python):
import itertools

N = int(input())
sft = ("0", "3", "5", "7")

num = itertools.product(sft, sft, sft,sft, sft, sft,sft, sft, sft)

cnt = 0
for x in num:
    stnum = "".join(x)
    if stnum.find("3") != -1 and stnum.find("5") != -1 and stnum.find("7") != -1:
        tmp = str(int(stnum))
        if tmp.find("0") == -1:
            if N >= int(tmp):
                cnt = cnt + 1
print(cnt)

Solution (Python):
N = int(input())

def rec(p, ptn, ans):
    if len(ptn) > 0 and int(ptn) <= int(N) and '3' in ptn and '5' in ptn and '7' in ptn:
        ans[0] += 1

    if p >= len(str(N)):
        return
    else:
        for n in ('3', '5', '7'):
            ptn += n
            rec(p+1, ptn, ans)
            ptn = ptn[:-1]

ans = [0]
rec(0, "", ans)

print(ans[0])

Solution (Python):

import itertools
n = int(input())
ls_all = []
A = ['3','5','7']
for j in range(3,10):
    ls = list(itertools.product(A, repeat=j))
    ls = [int(''.join(i)) for i in ls if ('3' in i and '5' in i and '7' in i)]
    ls_all.extend(ls)
ans = [n >= i for i in ls_all]
print (sum(ans))

Solution (Python):


N = int(input())
result_list = []
'''
for i in range(N):
    i = str(i)
    if '1' in i or '2' in i or '4' in i or '6' in i or '8' in i or '9' in i or '0' in i:
        continue
    if '7' in i and '5' in i and '3' in i:
        result_list.append(i)
print(len(result_list))
'''
current = 3


def get_next(current_str):
    '''
    i:str
    '''
    if current_str[-1] == '3':
        current_str = current_str[:-1] + '5'
    elif current_str[-1] == '5':
        current_str = current_str[:-1] + '7'
    elif current_str[-1] == '7':
        if len(current_str) != 1:
            current_str = get_next(current_str[:-1]) + '3'
        else:
            current_str = '33'
    return current_str


count = 0
while current <= N:
    current_str = str(current)
    current = int(get_next(current_str))
    if '7' in current_str and '5' in current_str and '3' in current_str:
        count += 1

print(count)

Solution (Python):


import time

N = int(input())

all_num_list = []
nums = ["3", "5", "7"]

for a in nums:
    for b in nums:
        for c in nums:
            all_num_list.append(a+b+c)
            for d in nums:
                all_num_list.append(a+b+c+d)
                for e in nums:
                    all_num_list.append(a+b+c+d+e)
                    for f in nums:
                        all_num_list.append(a+b+c+d+e+f)
                        for g in nums:
                            all_num_list.append(a + b + c + d + e + f+g)
                            for h in nums:
                                all_num_list.append(a + b + c + d + e + f + g+h)
                                for i in nums:
                                    all_num_list.append(a+b+c+d+e+f+g+h+i)

cnt = 0
for num in all_num_list:
    if int(num) <= N and "3" in num and "5" in num and "7" in num:
        cnt += 1

print(cnt)

Solution (Python):
def base_10_to_n_ex(x, n=4):
    d, m = divmod(x, n)
    mm = '0' if m == 0 else '3' if m == 1 else '5' if m == 2 else '7'
    if d:
        return base_10_to_n_ex(d, n) + mm
    return mm


n = int(input())
i = 27
s = '357'
ans = 0
while int(s) <= n:
    if '3' in s and '5' in s and '7' in s and '0' not in s:
        ans += 1
    i += 1
    s = base_10_to_n_ex(i)
print(ans)

Solution (Python):
from itertools import product
N = int(input())
count = 0
loop = len(str(N))
X = ('7','5','3')
for i in range(3, loop+1):
    for x in product(X, repeat=i):
        S = ''.join(x)
        if int(S) > N:
            continue
        c7 = S.count('7')
        c5 = S.count('5')
        c3 = S.count('3')
        if c7 and c5 and c3 and (c7+c5+c3==i):
            count += 1

print(count)

Solution (Python):
s = ["3", "5", "7"]
s2 = ["357", "375", "537", "573", "735", "753"]
s3 = []
s4 = []
s5 = []
s6 = []
s7 = []
s8 = []

def PowerGorilla(s_t, s_i):
    s_new = []
    for j in range(len(s_t)):
        for i in range(len(s_t[0])+1):
            for k in range(3):
                s_new.append(s_t[j][:i] + s_i[k] + s_t[j][i:])

    sss = list(set(s_new))
    return sss

s3 = PowerGorilla(s2, s)
s4 = PowerGorilla(s3, s)
s5 = PowerGorilla(s4, s)
s6 = PowerGorilla(s5, s)
s7 = PowerGorilla(s6, s)
s8 = PowerGorilla(s7, s)



num = []
num.extend(int(i) for i in s2)
num.extend(int(i) for i in s3)
num.extend(int(i) for i in s4)
num.extend(int(i) for i in s5)
num.extend(int(i) for i in s6)
num.extend(int(i) for i in s7)
num.extend(int(i) for i in s8)

num.sort()

count = 0

n = int(input())
for i in range(len(num)):
    if num[i] <= n:
        count += 1

print(count)

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

def rec(pref):
	global cnt
	if pref <= n:
		s = str(pref)
		if '3' in s and '5' in s and '7' in s:
			
			cnt += 1
		for d in {3, 5, 7}:
			rec(pref * 10 + d)


rec(0)
print(cnt)

Solution (Python):
N=int(input())
s=str(N)
l=len(s)
ans=0
stack=[[] for i in range(l)] 
stack[0]=["3","5","7"]
for i in range(l-1):
  for a in stack[i]:
    if "5" in list(a+"3") and "7" in list(a+"3") and int(a+"3")<=N:
      ans+=1
    if "3" in list(a+"5") and "7" in list(a+"5") and int(a+"5")<=N:
      ans+=1
    if "3" in list(a+"7") and "5" in list(a+"7") and int(a+"7")<=N:
      ans+=1
    stack[i+1].append(a+"3")
    stack[i+1].append(a+"5")
    stack[i+1].append(a+"7")
print(ans)

Solution (Python):
import itertools
a=input()
b=int(a)
s=0
for l in range(3,len(a)+2):
  for i in itertools.product('753',repeat=l):
    if len(set(i))==3 and int("".join(i))<=b:
      s+=1

print(s)

Solution (Python):
N = input()

count = 0

def sitigosan(x):
    global count
    if len(x) > 2:
        if int(N) >= int(x):
            if "7" in x and "5" in x and "3" in x:
                count += 1

    if len(x) != len(N):
        y = "7" + x
        sitigosan(y)
        y = "5" + x
        sitigosan(y)
        y = "3" + x
        sitigosan(y)

sitigosan("")

print(count)

Solution (Python):
N = int(input())

L = ["3","5","7"]
A = [L]
for i in range(8):
    B = []
    for a in A[i]:
        for l in L:
            B.append(a+l)
    A.append(B)
c = 0
for i in range(9):
    for a in A[i]:
        if "3" in a and "5" in a and "7" in a:
            if int(a) <= N:
                c += 1
            
print(c)

Solution (Python):
from itertools import product
lst = ["3","5","7"]
x = input()
n = len(x)
cnt = 0

for i in range(3, n+1):
    for j in product(lst, repeat=i):
        y = "".join(j)
        if ("3" in y) & ("5" in y) & ("7" in y):
            if int(x) >= int(y):
                cnt += 1

print(cnt)

Solution (Python):
from collections import Counter
from itertools import product


def solve(N):
    sum = 0
    for k in range(1, 10):
        for i in product('357', repeat=k):
            d = int("".join(list(i)))
            c = Counter(i)
            if '3' in c and '5' in c and '7' in c and len(c) == 3 and d <= N:
                sum += 1
    return sum


if __name__ == "__main__":
    print(solve(int(input())))

Solution (Python):
s = int(input())
ka = [3,5,7]
zen = []
for i in range(3):
  zen.append(str(ka[i]))
for j in range(3):
  for i in range(3):
    zen.append(str(ka[i])+str(ka[j]))
for a in range(3):
  for b in range(3):
    for c in range(3):
      zen.append(str(ka[a])+str(ka[b])+str(ka[c]))
for a in range(3):
  for b in range(3):
    for c in range(3):
      for d in range(3):
        zen.append(str(ka[a])+str(ka[b])+str(ka[c])+str(ka[d]))
for a in range(3):
  for b in range(3):
    for c in range(3):
      for d in range(3):
        for e in range(3):
          zen.append(str(ka[a])+str(ka[b])+str(ka[c])+str(ka[d])+str(ka[e]))
for a in range(3):
  for b in range(3):
    for c in range(3):
      for d in range(3):
        for e in range(3):
          for f in range(3):
            zen.append(str(ka[a])+str(ka[b])+str(ka[c])+str(ka[d])+str(ka[e])+str(ka[f]))
for a in range(3):
  for b in range(3):
    for c in range(3):
      for d in range(3):
        for e in range(3):
          for f in range(3):
            for g in range(3):
              zen.append(str(ka[a])+str(ka[b])+str(ka[c])+str(ka[d])+str(ka[e])+str(ka[f])+str(ka[g]))        
for a in range(3):
  for b in range(3):
    for c in range(3):
      for d in range(3):
        for e in range(3):
          for f in range(3):
            for g in range(3):
              for h in range(3):
                zen.append(str(ka[a])+str(ka[b])+str(ka[c])+str(ka[d])+str(ka[e])+str(ka[f])+str(ka[g])+str(ka[h]))         
for a in range(3):
  for b in range(3):
    for c in range(3):
      for d in range(3):
        for e in range(3):
          for f in range(3):
            for g in range(3):
              for h in range(3):
                for i in range(3):
                  zen.append(str(ka[a])+str(ka[b])+str(ka[c])+str(ka[d])+str(ka[e])+str(ka[f])+str(ka[g])+str(ka[h])+str(ka[i]))            
ans = 0
for i in zen:
  if int(i) > s:
    continue
  flag = 1
  if i.count("3") == 0 or i.count("5") == 0 or i.count("7") == 0:
    flag = 0
  if flag:
    ans += 1
print(ans)

Solution (Python):
import itertools
n = int(input())

a = []

for i in range(1, 10):
    a += list(itertools.product('357', repeat=i))

cnt = 0
for s in a:
    if int("".join(s)) > n:
        continue

    if s.count('3') > 0 and s.count('5') > 0 and s.count('7') > 0:
        cnt += 1

print(cnt)

Solution (Python):
import itertools

def main():
    n = int(input())
    c = 0
    for m in gen():
        if m > n:
            break

        if is_753(m):
            c += 1

    print(c)

def is_753(n):
    s = str(n)
    if '3' in s and '5' in s and '7' in s:
        return True
    else:
        return False

def gen():
    for i in itertools.count(1):
        for x in gen_1(i):
            yield x

def gen_1(num_digits):
    if num_digits == 1:
        yield 3
        yield 5
        yield 7
    else:
        for sub in gen_1(num_digits - 1):
            yield sub * 10 + 3
            yield sub * 10 + 5
            yield sub * 10 + 7

main()

Solution (Python):
def dp(x, N):
  if x > N:
    return 0
  ans = 1 if len(set(str(x))) > 2 else 0
  for n in (3, 5, 7):
  	ans += dp(x*10+n, N)
  return ans

N = long(raw_input())
print dp(3, N)+dp(5, N)+dp(7, N)

Solution (Python):

import itertools

n = int(input())
nlen = len(str(n))
A = ['3','5','7']
lis = [0,0,6,36,150,540,1806,5796,18150]
ans = 0
for i in itertools.product(A, repeat=nlen):
    string = "".join(i)
    if('3' in string and '5' in string and '7' in string) :
        if(int(string) <= n):
            ans += 1
for i in range(nlen-1):
    ans += lis[i]
print(ans)

Solution (Python):

n = int(input())

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

def inc(ary):
    ary[0] += 1
    for i in range(len(ary)-1):
        if ary[i]==0:
            ary[i] = 3
            break
        elif ary[i]==4:
            ary[i] = 5
            break
        elif ary[i]==6:
            ary[i] = 7
            break
        elif ary[i]==8:
            ary[i] = 3
            if ary[i+1]==0:
                ary[i+1] = 3
                break
            else:
                ary[i+1] += 1

cnt = 0
digit = [0 for _ in range(10)]
digit[0] = 3
while True:
    x = int("".join(map(str,reversed(digit))))
    if x>n:
        break
    if 3 in digit and 5 in digit and 7 in digit:
        cnt += 1

    inc(digit)
print(cnt)

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N = int(input())
    ans = 0
    k = 357
    
    while k <= N:
        if set(str(k)) == set("357"):
            ans += 1
            r = k % 10
            if r == 3 or r == 5:
                k += 2
            else:
                k += 6
        else:
            f = False
            for d in range(len(str(k))-1):
                if str(k)[d] not in "357":
                    digit = len(str(k))
                    elsenum = int(str(k)[d])
                    k += [3, 2, 1, 0, 1, 0, 1, 0, 5, 4][elsenum] * 10 ** (digit - (d + 1))
                    f = True
                    break
            
            if f:
                continue

            r = k % 10
            if r == 3 or r == 5:
                k += 2
            else:
                k += 6
                

    print(ans)



main()

Solution (Python):
n = int(input())

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)

ans = 0

for i in range(0, 10**9):
	i_3 = Base_10_to_n(i, 4)
	i_3 = i_3.replace('1', '
	i_3 = i_3.replace('2', '5')
	i_3 = i_3.replace('3', '7')
	i_3 = i_3.replace('
	i_753 = int(i_3)
	
	if i_753 <= n and i_3.count('0') == 0 and i_3.count('3')>0 and i_3.count('5')>0 and i_3.count('7')>0:
		ans += 1
	elif i_753 > n:
		break
	else:
		continue

print(ans)

Solution (Python):




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

    digits = [0, 3, 5, 7]
    ans = 0
    for i in range(4**9):
        cur = 0
        for j in range(10):
            cur += digits[i % 4] * 10 ** j
            i //= 4

        num = cur
        cnt = [0] * 10
        while num:
            cnt[num % 10] += 1
            num //= 10

        if cur <= n and not cnt[0] and cnt[3] and cnt[5] and cnt[7]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def n_based(n:int, base:int) -> str:
    if n == 0:
        return "0"
    
    ans = ""
    res = n
    
    while abs(res) > 0:
        q = res%base
        if q>=0:
            ans = str(q) + ans
            res //= base
        else:
            q += abs(base)
            ans = str(q) + ans
            res //= base
            res += 1
        
    return ans

stf = ["7","5","3"]
n = ni()

ans = 0
for pw in range(3,11):
    for i in range(3**pw):
        s = str(n_based(i,3)).zfill(pw)
        num = ""
        for i in range(pw):
            num += stf[int(s[i])]
            
        if int(num) <= n and ("3" in num and "5" in num and "7" in num):
            ans += 1
            
print(ans)

Solution (Python):
import itertools

N = int(input())

num_753 = [7,5,3]
anslist = []

keta = len(str(N))
for i in range(3, keta+ 1):
    tmp = list(itertools.product(num_753, repeat=i))
    for item in tmp:
        item = list(item)
        item = map(str, item)
        item = "".join(item)
        anslist.append(int(item))

anslist = [s for s in anslist if s <= N]
anslist.sort()

anslist2 = []

for ans in anslist:
    tmp = str(ans)
    if "3" not in tmp:
        continue
    elif "5" not in tmp:
        continue
    elif "7" not in tmp:
        continue
    else:
        anslist2.append(tmp)


print(len(anslist2))