n = int(eval(input()))



def squ(x):

    if x == 0:

        return '0'

    a = ""

    while x != 0:

        x, mod = divmod(x, 4)

        a += str(mod)

    return a[::-1]





ans = 0



for x in range(10**6):

    x_squ = squ(x)

    x_str = x_squ.replace('3', '7').replace('2', '5').replace('1', '3')



    if "0" in x_str:

        continue



    if int(x_str) > n:

        break



    if len(set(x_str)) != 3:

        continue



    ans += 1



print(ans)

N = int(eval(input()))



def dfs(x):

    if int('0'+x) > N:

        return 0



    retval = 1 if len(set(x)) == 3 else 0

    for c in '753':

        retval += dfs(x + c)

    return retval





print((dfs('')))
n = int(eval(input()))


def squ(x):
    if x == 0:
        return "0"
    a = ""
    while x != 0:
        x, mod = divmod(x, 4)
        a += str(mod)
    return a[::-1]


ans = 0
for x in range(10**6):
    x_squ = squ(x)
    x_str = x_squ.replace("3", "7").replace("2", "5").replace("1", "3")
    if "0" in x_str:
        continue
    if int(x_str) > n:
        break
    if len(set(x_str)) != 3:
        continue
    ans += 1
print(ans)

N = int(eval(input()))


def dfs(x):
    if int("0" + x) > N:
        return 0
    retval = 1 if len(set(x)) == 3 else 0
    for c in "753":
        retval += dfs(x + c)
    return retval


print((dfs("")))

-n = int(eval(input())) +N = int(eval(input())) -def squ(x): -    if x == 0: -        return "0" -    a = "" -    while x != 0: -        x, mod = divmod(x, 4) -        a += str(mod) -    return a[::-1] +def dfs(x): +    if int("0" + x) > N: +        return 0 +    retval = 1 if len(set(x)) == 3 else 0 +    for c in "753": +        retval += dfs(x + c) +    return retval -ans = 0 -for x in range(10**6): -    x_squ = squ(x) -    x_str = x_squ.replace("3", "7").replace("2", "5").replace("1", "3") -    if "0" in x_str: -        continue -    if int(x_str) > n: -        break -    if len(set(x_str)) != 3: -        continue -    ans += 1 -print(ans) +print((dfs("")))