import copy



word = "753"





def dfs(n):

    ret = 0



    num = 0 if not n else int(''.join(n))



    if N < num:

        return ret



    ret += 1 if len(set(''.join(n)) & set(word)) == len(word) else 0



    for c in word:

        tmp = copy.deepcopy(n)

        n.append(c)

        ret += dfs(n)

        n = tmp



    return ret





N = int(eval(input()))



print((dfs([])))

ans = 0





def dfs(n, f1, f2, f3):

    if N < n:

        return



    global ans

    ans += 1 if f1 & f2 & f3 else 0



    dfs(n * 10 + 7, True, f2, f3)

    dfs(n * 10 + 5, f1, True, f3)

    dfs(n * 10 + 3, f1, f2, True)





N = int(eval(input()))



dfs(0, False, False, False)



print(ans)

import copy

word = "753"


def dfs(n):
    ret = 0
    num = 0 if not n else int("".join(n))
    if N < num:
        return ret
    ret += 1 if len(set("".join(n)) & set(word)) == len(word) else 0
    for c in word:
        tmp = copy.deepcopy(n)
        n.append(c)
        ret += dfs(n)
        n = tmp
    return ret


N = int(eval(input()))
print((dfs([])))

ans = 0


def dfs(n, f1, f2, f3):
    if N < n:
        return
    global ans
    ans += 1 if f1 & f2 & f3 else 0
    dfs(n * 10 + 7, True, f2, f3)
    dfs(n * 10 + 5, f1, True, f3)
    dfs(n * 10 + 3, f1, f2, True)


N = int(eval(input()))
dfs(0, False, False, False)
print(ans)

-import copy - -word = "753" +ans = 0 -def dfs(n): -    ret = 0 -    num = 0 if not n else int("".join(n)) -    if N < num: -        return ret -    ret += 1 if len(set("".join(n)) & set(word)) == len(word) else 0 -    for c in word: -        tmp = copy.deepcopy(n) -        n.append(c) -        ret += dfs(n) -        n = tmp -    return ret +def dfs(n, f1, f2, f3): +    if N < n: +        return +    global ans +    ans += 1 if f1 & f2 & f3 else 0 +    dfs(n * 10 + 7, True, f2, f3) +    dfs(n * 10 + 5, f1, True, f3) +    dfs(n * 10 + 3, f1, f2, True) -print((dfs([]))) +dfs(0, False, False, False) +print(ans)