from collections import Counter

ls=[]

def rec(n):

    if len(str(n))>9: return

    ls.append(n)

    rec(n*10+3)

    rec(n*10+5)

    rec(n*10+7)

n=int(eval(input()))

rec(3)

rec(5)

rec(7)

cnt=0

for l in ls:

    temp=Counter(str(l))

    if l<=n and len(list(temp.keys()))==3:

        cnt+=1

print(cnt)
ls=[]

def rec(n):

    if len(str(n))>9: return

    ls.append(n)

    for i in [3,5,7]: rec(10*n+i)

n=int(eval(input()))

rec(0)

cnt=0

for l in ls:

    if l<=n and all(str(l).count(i)>0 for i in "357"): cnt+=1

print(cnt)
from collections import Counter

ls = []


def rec(n):
    if len(str(n)) > 9:
        return
    ls.append(n)
    rec(n * 10 + 3)
    rec(n * 10 + 5)
    rec(n * 10 + 7)


n = int(eval(input()))
rec(3)
rec(5)
rec(7)
cnt = 0
for l in ls:
    temp = Counter(str(l))
    if l <= n and len(list(temp.keys())) == 3:
        cnt += 1
print(cnt)

ls = []


def rec(n):
    if len(str(n)) > 9:
        return
    ls.append(n)
    for i in [3, 5, 7]:
        rec(10 * n + i)


n = int(eval(input()))
rec(0)
cnt = 0
for l in ls:
    if l <= n and all(str(l).count(i) > 0 for i in "357"):
        cnt += 1
print(cnt)

-from collections import Counter - -    rec(n * 10 + 3) -    rec(n * 10 + 5) -    rec(n * 10 + 7) +    for i in [3, 5, 7]: +        rec(10 * n + i) -rec(3) -rec(5) -rec(7) +rec(0) -    temp = Counter(str(l)) -    if l <= n and len(list(temp.keys())) == 3: +    if l <= n and all(str(l).count(i) > 0 for i in "357"):