Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

1 \leq N < 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

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

Sample Input 1

575

Sample Output 1

4

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

Sample Input 2

3600

Sample Output 2

13

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

Sample Input 3

999999999

Sample Output 3

26484



Sample input:
575


Sample output:
4

Submission status: Accepted

Solution code:
n=int(input())
num=[3,5,7]
#a[0]=3,a[1]=5,a[7]=5
ans=[3,5,7]
answ=[]
for i1 in range(3):
  for i2 in range(3):
    for i3 in range(3):
      a=set([i1,i2,i3])
      if len(a)>2:
        answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])))
      for i4 in range(3):
        a=set([i1,i2,i3,i4])
        if len(a)>2:
          answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i4])))
        for i5 in range(3):
          a=set([i1,i2,i3,i4,i5])
          if len(a)>2:
            answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i5])+str(num[i4])))
          for i6 in range(3):
            a=set([i1,i2,i3,i4,i5,i6])
            if len(a)>2:
              answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i6])+str(num[i5])+str(num[i4])))
            for i7 in range(3):
              a=set([i1,i2,i3,i4,i5,i6,i7])
              if len(a)>2:
                answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
              for i8 in range(3):
                a=set([i1,i2,i3,i4,i5,i6,i7,i8])
                if len(a)>2:
                  answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
                for i9 in range(3):
                  a=set([i1,i2,i3,i4,i5,i6,i7,i8,i9])
                  if len(a)>2:
                    answ.append(int(str(num[i1])+str(num[i2])+str(num[i3])+str(num[i9])+str(num[i8])+str(num[i7])+str(num[i6])+str(num[i5])+str(num[i4])))
answ.sort()
left=0
right=len(answ)
while right-left>1:
  mid=(left+right)//2
  
  if n<answ[mid]:
    right=mid
  else:
    left=mid
if 357>n:
  print(0)
else:
  print(left+1)

Submission status: Accepted

Solution code:
import itertools


n=int(input())
ans=0

for i in range(3,10):
  for lst in itertools.product(['3','5','7'],repeat=i):
    if '3' in lst and '5' in lst and '7' in lst:
      lst=''.join(lst)
      lst=int(lst)
      if n>=lst:
        ans+=1
        

print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())


def generate(n):
    _list = []
    queue = collections.deque([0])
    while queue:
        _temp = queue.popleft()
        if _temp <= n and '3' in str(_temp) and '7' in str(_temp) and '5' in str(_temp):
            _list.append(_temp)
        if len(str(_temp)) > 9:
            break
        queue.append(_temp * 10 + 7)
        queue.append(_temp * 10 + 5)
        queue.append(_temp * 10 + 3)
    return _list


_list = generate(N)
print(len(_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
alist=[]
import itertools
for i in range(3,10):
  blist=itertools.product(['3','5','7'], repeat=i)
  for j in blist:
    if '3' in j and '5' in j and '7' in j:
      alist.append(int(''.join(j)))
ans=0
for i in alist:
  if i<=n:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    def rec(vec):
        if vec and int(''.join(vec)) > N:
            return 0
        ans = 0
        if all(c in vec for c in '357'):
            ans += 1
        for c in '357':
            vec.append(c)
            ans += rec(vec)
            vec.pop()
        return ans

    ans = rec([])
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    def rec(s):
        if int(s) > N:
            return 0
        ans = 0
        if all(c in s for c in '357'):
            ans += 1
        for c in '357':
            ans += rec(s + c)
        return ans

    ans = rec('0')
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    L = len(S)

    def rec(i, vec, smaller):
        if i == L:
            s = set(vec)
            if 3 in s and 5 in s and 7 in s:
                return 1
            else:
                return 0

        ans = 0
        if not vec:
            ans += rec(i + 1, vec, True)
        if smaller:
            for n in (3, 5, 7):
                vec.append(n)
                ans += rec(i + 1, vec, True)
                vec.pop()
        else:
            for n in (3, 5, 7):
                if n > int(S[i]):
                    break
                vec.append(n)
                if n < int(S[i]):
                    ans += rec(i + 1, vec, True)
                else:
                    ans += rec(i + 1, vec, False)
                vec.pop()

        return ans

    ans = rec(0, [], False)

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())

def Base_10_to_n(X, n=3):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

s = 0
m = 0

f = len(str(n))

for i in range(1, f):
    if i < 3:
        pass
    else:
        s += 3 ** i - 3 * (2 ** i) + 3 

while True:
    l = Base_10_to_n(m)
    flag = [False] * 3
    if len(l) < f:
        l = "0" * (f-len(l)) + l
    k = ""
    for i in range(len(l)):
        if l[i] == "0":
            k += "3"
            flag[0] = True
        elif l[i] == "1":
            k += "5"
            flag[1] = True
        else:
            k += "7"
            flag[2] = True
    #print(k)

    if int(k) <= n:
        if False not in flag:
            s += 1
        m += 1
    else:
        break

print(s)

Submission status: Accepted

Solution code:
n=input()
a = lambda x,y:3**x - y*2**x + y -1+(y%3==0)
ans = 0
ln = len(n)
s = set()
b = True
for p, i in enumerate(n):
    m = int(i) 
    if b:
        if m > 7:
            ans += a(ln-p-1,3-len(s|{7}))
        if m > 5:
            ans += a(ln-p-1,3-len(s|{5}))
        if m > 3:
            ans += a(ln-p-1,3-len(s|{3}))
        if m in (7,5,3):
            s.add(m)
            if ln == p+1:
                ans += len(s)==3
        else:
            b = False
    if ln > p +1:
        ans += a(ln - p -1,3)
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = input()
ans =0

    
if len(n) < 3:
    ans = 0

else:
    if int('7'*len(n)) <= int(n):
        ans = 3**(len(n))- 3*2**(len(n)) + 3
    elif int('3'*len(n)) > int(n):
        ans = 0
    else:
        con = []
        for i in range(len(n)):
            con.append(0)
        con_num = []
        for i in range(3**len(n)):
            con[-1] +=1
            for j in range(len(n)-1,0,-1):
                if con[j] == 3:
                    con[j-1] +=1
                    con[j] = 0
            if con[0] == 0:
                b = '3'
            elif con[0] == 1:
                b= '5'
            elif con[0] == 2:
                b = '7'
            for j in range(1,len(n)):
                if con[j] == 0:
                    a = '3'
                elif con[j] == 1:
                    a = '5'
                elif con[j] == 2:
                    a = '7'
                b += a
            c = list(b)
            if c.count('3') != 0 and c.count('5') != 0 and c.count('7') != 0 and len(b) == len(n):
                con_num.append(int(b))
        for i in range(len(con_num)):
            if int(n) >= con_num[i]:
                ans +=1
    for i in range(3,len(n)):
        ans += 3**(i)- 3*2**(i) + 3
    

print(ans)

Submission status: Accepted

Solution code:
N=input()
n=int(N)
from itertools import product
print(sum([sum(["3" in p and "5" in p and "7" in p and int(''.join(p))<=n for p in product("357",repeat=i+1)]) for i in range(len(N))]))

Submission status: Accepted

Solution code:
N = int(input())

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

print(dfs("0"))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ans = 0
def dfs(A):
    if A and int(A) > n:
        return
    if len(A) >= 3:
        c = Counter(A)
        is753 = True
        for i in ['7','5','3']:
            if c[i] < 1:
                is753 = False
        if is753:
            global ans 
            ans += 1
    for nex in ['7','5','3']:
        A += nex
        dfs(A)
        A = A[:-1]
dfs('')
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
def dfs(s):
    if int(s)>n:
        return 0
    a=s.count("7")
    b = s.count("5")
    c = s.count("3")
    if min(a,b,c)>0:
        ans=1
    else:
        ans=0
    for c in "753":
        ans+= dfs(s+c)
    return ans

print(dfs("0"))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# 整数の入力
N = int(input())
ans = 0

def dfs(num, use7, use5, use3):
    if num > N:
        return 0
    else:
        ret = 0
        if use7 == True and use5 == True and use3 == True:
            ret += 1
            #print(num)

        ret += dfs(num*10+7, True, use5, use3)
        ret += dfs(num*10+5, use7, True, use3)
        ret += dfs(num*10+3, use7, use5, True)

    return ret



print(dfs(0, False, False, False))

Submission status: Accepted

Solution code:
n = int(input())
li = []
import itertools
for j in range(3,10):
    for i in itertools.product([3,5,7],repeat=j):
        if i.count(3)<1 or i.count(5)<1 or i.count(7)<1:
            pass
        else:
            li += [int(''.join(map(str,i)))]

import bisect
print(bisect.bisect(li,n))

Submission status: Accepted

Solution code:
n=int(input())
digits=len(str(n))
dlst=['3','5','7']
ans=0

for d in range(3,digits+1):
    for i in range(3**d):
        cur=[dlst[k] for k in [i//(3**j)%3 for j in range(d)]]
    
        cnt=[0]*3

        for j in range(d):
            for k in range(3):
                cnt[k]+=1 if dlst[k]==cur[j] else 0
        
        if cnt[0]*cnt[1]*cnt[2]==0 or int(''.join(cur))>n:
            continue

        ans+=1

print(ans)

Submission status: Accepted

Solution code:
# a brute bitch
from bisect import bisect_right
def comb (n,s):
    capt = []; ind = n; 
    stp = n+1; boo = ""
    while bk[0] < 1:
        if bk[ind] < s:
            boo += dip[bk[ind]];
            bk[ind]+=1; 
            if ind + 1 == stp:
                if '7' in boo and '3' in boo and '5' in boo:
                    capt.append(int(boo)); 
                boo = boo[:len(boo)-1];
            ind += 1 if ind + 1 < stp else 0
        else: bk[ind] = 0;ind -= 1; boo = boo[:len(boo)-1]
    return bisect_right(capt,int(val))
val = input()
bk = [0]*(len(val)+1); dip = ['3','5','7']
print(comb(len(val),3))

Submission status: Accepted

Solution code:
import sys
n=int(input())

def f(x):
    m=0
    while x>0:
        m+=1
        x=x//10
    return m
m=f(n)

a=[(3**(i+1)-3)//2-6*(2**i-1)+3*i for i in range(1,10)]
a.insert(0,0)
if m==1 or m==2:
    print(0)
    sys.exit()
ans=a[m-1]
def g(x):
    z=[]
    while x>0:
        z.insert(0,x%10)
        x=x//10
    return z
for i in range(3**m):
    x=["" for i in range(m)]
    for j in range(m):
        if i%3==0:
            x[j]="3"
        elif i%3==1:
            x[j]="5"
        else:
            x[j]="7"
        i=i//3
    if int("".join(x))<=n and "3" in x and "5" in x and "7" in x:
        ans+=1
    
print(ans)

Submission status: Accepted

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

que = deque(['7','5','3'])
semi = []

while que:
    x = que.popleft()
    if int(x) <= n:
        semi.append(x)
        for new_x in [x+c for c in ['7','5','3']]:
            que.append(new_x)

cnt = 0
for i in semi:
    if all(i.count(c)>0 for c in ['7','5','3']):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

def func(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 += func(s+c)
    return ret

print(func('0'))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans, q = 0, ["3", "5", "7"]

while q:
    p = q.pop()
    for s in ["3", "5", "7"]:
        t = p + s
        if int(t) <= n:
            q.append(str(t))
            if len(list(set(list(str(t))))) == 3:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
import typing
n = int(input())

res = 0
str_num = ""


def dfs(str_num: str, i: int, finish:int):
    global res
    if i == finish:
        # print(str_num)
        if str_num and int(str_num) <= n and len(set(str_num)) == 3:
            res += 1
            # print(res, str_num)
        return 0
    dfs(str_num + "3", i + 1, finish)
    dfs(str_num + "5", i + 1, finish)
    dfs(str_num + "7", i + 1, finish)
    # dfs(str_num, i + 1)


if __name__ == "__main__":
    for i in range(3, 10):
        dfs(str_num, 0, i)
    print(res)

Submission status: Accepted

Solution code:
import typing
n = int(input())

res = set()
str_num = ""
def dfs(str_num:str, i:int):
    global res
    if i == 10 :
        # print(str_num)
        if str_num and int(str_num) <= n and len(set(str_num)) == 3:
            res.add(str_num)
            # print(res, str_num)
        return 0
    dfs(str_num + "3", i + 1)
    dfs(str_num + "5", i + 1)
    dfs(str_num + "7", i + 1)
    dfs(str_num      , i + 1)

if __name__ == "__main__":
    dfs(str_num, 0)
    print(len(res))

Submission status: Accepted

Solution code:
n = int(input())
L = [3,5,7]
for i in range(9):
    P = []
    for p in L:
        a = str(p)+"3"
        P.append(int(a))
        b = str(p)+"5"
        P.append(int(b))
        c = str(p)+"7"
        P.append(int(c))
        
    L.extend(P)
L = list(set(L))
ans = 0
for q in L:
    x = list(str(q))
    if q <= n:
        if "3" in x and "5" in x and "7" in x:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
list_3_5_7 = ["3", "5", "7"]

res = 0
for i in range(3, 10):
    tmp_product_list = list(itertools.product(list_3_5_7, repeat = i))
    for tmp_list in tmp_product_list:
        tmp_str = "".join(tmp_list)
        if len(set(tmp_str)) == 3 and int(tmp_str) <= n:
            res += 1

print(res)

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
result = set()

queue = deque([3, 5, 7])

count = 0
while queue:
    number = queue.pop()

    if number <= N:
        string = str(number)
        if '3' in string and '5' in string and '7' in string:
            result.add(number)
        for i in range(3, 8, 2):
            queue.appendleft(number * 10 + i)

print(len(result))

Submission status: Accepted

Solution code:
N = int(input())

def func(cur, use, counter):
	#今の値がNより大きければ処理をやめる
	if cur > N:
		return
	#現在の値が7, 5, 3を一つ以上使っていればカウンタを1増やす
	if use == 0b111:
		counter.append(1)

	#7を追加する
	func(cur*10+7, use | 0b001, counter)
	#5を追加する
	func(cur*10+5, use | 0b010, counter)
	#3を追加する
	func(cur*10+3, use | 0b100, counter)

res = []
func(0, 0, res)
print(sum(res))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
n=int(input())
tex=['3','5','7']

def dfs(value):
  ans=0
  if value != '' and int(value) > n:
    return 0
  for x in tex:
    if not x in value:
      break
  else:
    ans += 1 
  for x in tex:
    ans += dfs(value+x)
  #print(value,ans)
  return ans

print(dfs(''))

Submission status: Accepted

Solution code:
from itertools import product

n = input()

if int(n) < 100:
    print(0)

else:
    ans = 0

    for i in range(3,len(n)+1):
        s = list(product("753",repeat=i))
        for combi in s:
            n_s = "".join(combi)
            if int(n_s) > int(n):
                continue
            if ("7" in combi) and ("5" in combi) and ("3" in combi):
                ans += 1
    
    print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = [0, 3, 5, 7]
ans = []
res = 0
for i in itertools.product(a, repeat = 9):
    val = 0
    for j in range(len(i)):
        val += 10 ** j * i[j]
    # print(val)
    tmp = str(val)
    if val <= n and len(set(tmp)) == 3 and "0" not in tmp:
        res += 1
        ans.append(val)

ans.sort()
print(res)
# print(ans)

Submission status: Accepted

Solution code:
from collections import deque, Counter
N = int(input())
num_357 = [3, 5, 7]
dq = deque(num_357)
while dq:
    x = dq.popleft()
    if x <= 10**9:
        num_357.append(int(str(x) + "3"))
        num_357.append(int(str(x) + "5"))
        num_357.append(int(str(x) + "7"))
        dq.append(int(str(x) + "3"))
        dq.append(int(str(x) + "5"))
        dq.append(int(str(x) + "7"))

ans = 0
for num in num_357:
    if num <= N:
        c = {3: 0, 5: 0, 7: 0}
        for i in range(len(str(num))):
            if str(num)[i] == "3":
                c[3] += 1
            elif str(num)[i] == "5":
                c[5] += 1
            elif str(num)[i] == "7":
                c[7] += 1
        if c[3] >= 1 and c[5] >= 1 and c[7] >= 1:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

list753 = [3, 5, 7]
beforeLength = 0
for i in range(1, 9):
    afterLength = len(list753)
    for j in range(3):
        for k in range(beforeLength, afterLength):
            x = list753[k] + 10 ** i * list753[j]
            list753.append(x)
    beforeLength = afterLength

listTrue753 = []
for i in list753:
    numberString = str(i)
    if numberString.count("3") > 0 and numberString.count("5") > 0 and numberString.count("7"):
        listTrue753.append(i)

count = 0
for i in listTrue753:
    if i <= N:
        count += 1
print(count)

Submission status: Accepted

Solution code:
S=input()
N=int(S)
cnt=0
def rec(l,x,N):
    global cnt
    if  len(l)==x:
        tmp=int("".join(map(str,l)))
        if tmp<=N and len(set(l))==3:
            cnt+=1
    else:
        for n in range(3):
            l.append(3+2*n)
            rec(l,x,N)
            l.pop()

for n in range(3,len(S)+1):
    rec([],n,N)
print(cnt)

Submission status: Accepted

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

N = I()

A = [0]*10  # A[i] = i桁の七五三数の個数
for i in range(1,10):
    A[i] = 3**i-3*2**i+3

d = len(str(N))  # Nの桁数
ans = sum(A[i] for i in range(1,d))  # d桁未満の七五三数の個数
B = []  # d桁の七五三数list

from itertools import product

for a in list(product(['3','5','7'],repeat=d)):
    if len(set(a)) == 3:
        b = ''
        for i in range(d):
            b += a[i]
        B.append(int(b))

print(ans+sum(n <= N for n in B))

Submission status: Accepted

Solution code:
n=int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
n = int(input())

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

print(dfs('0'))

Submission status: Accepted

Solution code:
import copy

n = int(input())

judge = []
ans3 = 3
ans5 = 5
ans7 = 7
ans35 = []
ans37 = []
ans57 = []
ans357 = []

for i in range(8):
  key = []
  for v in ans357:
    key.append(v*10+3)
    key.append(v*10+5)
    key.append(v*10+7)
  for v in ans35:
    key.append(v*10+7)
  for v in ans37:
    key.append(v*10+5)
  for v in ans57:
    key.append(v*10+3)
  ans357 = copy.deepcopy(key)
  
  key = [ans3*10+5, ans5*10+3]
  for v in ans35:
    key.append(v*10+3)
    key.append(v*10+5)
  ans35 = copy.deepcopy(key)
    
  key = [ans3*10+7, ans7*10+3]
  for v in ans37:
    key.append(v*10+3)
    key.append(v*10+7)
  ans37 = copy.deepcopy(key)
  
  key = [ans5*10+7, ans7*10+5]
  for v in ans57:
    key.append(v*10+5)
    key.append(v*10+7)
  ans57 = copy.deepcopy(key)
  
  ans3 = ans3*10+3
  ans5 = ans5*10+5
  ans7 = ans7*10+7
  
  judge = judge+ans357
ans = 0
for v in judge:
  if v <= n:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import product as pro
n = int(input())
m = len(str(n))
ans = 0
for i in range(3,m+1):
    for l in pro([3,5,7],repeat=i):
        lst = list(l)
        x = ""
        for j in lst:
            x += str(j)
        if 3 in lst and 5 in lst and 7 in lst:
            if int(x) <= n:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
def count(s, N):
    if s != "" and int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "357") else 0
    for c in "357":
        ret += count(s + c, N)
    return ret


def resolve():
    N = int(input())
    print(count("", N))


resolve()

Submission status: Accepted

Solution code:
def main():
    import sys
    from heapq import heappop, heappush
    from collections import deque

    def input(): return sys.stdin.readline().rstrip()

    def check(k):
        tmp = str(k)
        flag = 1
        if len(tmp) > 2:
            for s in nums:
                flag &= (s in tmp)
            if flag: 
                return True
        return False

    n = int(input())
    num = [3, 5, 7]
    nums = ['3', '5', '7']
    que = deque([3, 5, 7])
    cnt = 0
    while que:
        x = que.popleft()
        if x > n:
            break
        if check(x):
            cnt += 1
        for i in num:
            que.append(10*x+i)
    print(cnt)


    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
list = [3, 5, 7]
num = 0

def dfs(S):
  num_S = 0
  for i in range(len(S)):
    num_S += S[len(S)-i-1]*10**i
  if num_S > N:
    return
  else:
    a = [0, 0, 0]
    for i in range(len(S)):
      if S[i] == 3:
        a[0] += 1
      elif S[i] == 5:
        a[1] += 1
      else:
        a[2] += 1
    if a[0] >= 1 and a[1] >= 1 and a[2] >= 1:
      global num
      num += 1
    dfs(S+[3])
    dfs(S+[5])
    dfs(S+[7])
    return

dfs([])
print(num)

Submission status: Accepted

Solution code:
N = int(input())
def dfs(x):
  ret = 0
  if int(x)>N:
    return 0
  if all(x.count(i)>0 for i in "753"):
    ret += 1
  for i in "753":
    ret += dfs(x+i)
  return ret
print(dfs("0"))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
  # 再帰の基底部
  if len(s) > 0 and int(s) > N:
    return 0
  
  # s自体が七五三数なら+1
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0
  
  return ret + sum((dfs(s+c) for c in '753'))

print(dfs(''))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
  #文字列sで始まる七五三数の個数
  if int(s) > N:
    return 0
  
  # s自体が七五三数なら+1
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0
  
  return ret + sum((dfs(s+c) for c in '753'))

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())

def dfs(s):
  #文字列sで始まる七五三数の個数
  if int(s) > N:
    return 0
  
  # s自体が七五三数なら+1
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0
  
  for c in '753':
    ret += dfs(s+c)
  
  return ret

print(dfs('0'))

Submission status: Accepted

Solution code:
N = int(input())
def dfs(s):
  if int(s)>N:
    return 0
  if all(s.count(i)>0 for i in "357"):
    c = 1
  else:
    c = 0
  for i in "357":
    c += dfs(s+i)
  return(c)
print(dfs("0"))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import product

S = input()
nd,N = len(S),int(S)

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

count = 0
for n_digit in range(3,nd+1):
  for p in product(['3','5','7'],repeat=n_digit):
    if set(p) == {'3','5','7'} and int(''.join(p))<=N:
      count += 1
print(count)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    ans = [0]

    def dfs(num):
        if not num or num and int(''.join(num)) <= N:
            if num.count('7') >= 1 and num.count('5') >= 1 and num.count('3') >= 1:
                ans[0] += 1
            for i in ('7', '5', '3'):
                num.append(i)
                dfs(num)
                num.pop()

    dfs([])
    
    print(ans[0])

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
cnt = 0
num = ["3","5","7"]
for k in range(3,10):
    for x in product(num,repeat=k):
        if x.count("3")>=1 and x.count("5")>=1 and x.count("7")>=1:
            if int("".join(x))<=N:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import product


def dfs(num_s, n, ansl):
    num = int(num_s)
    if num > n:
        return

    if '7' in num_s and '5' in num_s and '3' in num_s:
        ansl.append(int(num_s))
    dfs(num_s+'7', n, ansl)
    dfs(num_s+'5', n, ansl)
    dfs(num_s+'3', n, ansl)



def main():
    n = int(input())
    ansl = []
    dfs('7',n,ansl)
    dfs('5',n,ansl)
    dfs('3',n,ansl)

    print(len(ansl))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
from itertools import product
ans = 0
for i in range(3,len(str(N))+1):
    for ptn in product('753',repeat=i):
        s = ''.join(ptn)
        for c in '753':
            if c not in s:
                break
        else:
            if int(''.join(ptn)) <= N:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
nl = len(str(n))
nya = ['3','5','7']
def dfs(s):
    if len(s) > nl:
        return
    if len(s) >= 3:
        if s.count('7') >= 1 and s.count('5') >= 1 and s.count('3') >= 1:
            if int(s) <= n:
                global cnt
                cnt += 1
    for i in range(3):
        s += nya[i]
        dfs(s)
        s = s[:-1]
    return
cnt = 0
dfs('')
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
import itertools
res = []
A = ['', '3', '5', '7']
for p in itertools.product(A, repeat=10):
    p = list(p)
    p = ''.join(p)
    if p.count('3') == 0 or p.count('5') == 0 or p.count('7') == 0:
        continue
    p = int(p)
    res.append(p)
res = list(set(res))
#print(res[0:10])
cnt = 0
for i in res:
    if i <= n:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import *
N = int(input())
S = []
ans = 0

for n in range(10):
  S+=list(product("357",repeat=n))

for s in S:
  if len(set(s))==3 and int("".join(s))<=N:
    ans+=1

print(ans)

Submission status: Accepted

Solution code:
from itertools import *
N = int(input())
ans = 0

for i in product("0357",repeat=10):
  j = "".join(i)
  if "0" not in str(int(j)) and "3" in j and "5" in j and "7" in j and int(j)<=N:
    ans+=1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
d=["3","5","7"]
ans=0
while d:
    a=d.pop(0)
    if int(a)<=n and len(set(a))==3:ans+=1
    if len(a)<9:
        for i in "357":d+=[i+a]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
d=["3","5","7"]
ans=[]
ans+=d
while d:
    a=d.pop(0)
    if len(a)<9:
        for i in "357":
            d+=[i+a]
            ans+=[i+a]
ans=list(map(int,ans))
ans.sort()
print(sum(i<=n for i in ans if len(set(str(i)))==3))

Submission status: Accepted

Solution code:
from itertools import product
n=int(input())
ans=0
for k in range(3,10):
  dp=list(product("753",repeat=k))
  for i in range(len(dp)):
    if n>=int("".join(dp[i])) and "3" in dp[i] and "5" in dp[i] and "7" in dp[i]:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

cnt = 0
L = ["3","5","7"]
def migona(x):
    global cnt
    if int(x) > n:
        return
    if all(str(int(x)).count(i) > 0 for i in "357"):
        cnt +=1
        #print(x)
    
    migona(x+"3")
    migona(x+"5")
    migona(x+"7")
    
    return

migona("0")
print(cnt)