N = int(eval(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")))
N = int(eval(input()))

ans = 0



def dfs(x, a, b, c):

    global ans

    if x > N:

        return

    if (a & b & c):

        ans += 1

    dfs(10 * x + 3, 1, b, c)

    dfs(10 * x + 5, a, 1, c)

    dfs(10 * x + 7, a, b, 1)



dfs(0, 0, 0, 0)

print(ans)
N = int(eval(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")))

N = int(eval(input()))
ans = 0


def dfs(x, a, b, c):
    global ans
    if x > N:
        return
    if a & b & c:
        ans += 1
    dfs(10 * x + 3, 1, b, c)
    dfs(10 * x + 5, a, 1, c)
    dfs(10 * x + 7, a, b, 1)


dfs(0, 0, 0, 0)
print(ans)

+ans = 0 -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 +def dfs(x, a, b, c): +    global ans +    if x > N: +        return +    if a & b & c: +        ans += 1 +    dfs(10 * x + 3, 1, b, c) +    dfs(10 * x + 5, a, 1, c) +    dfs(10 * x + 7, a, b, 1) -print((dfs("0"))) +dfs(0, 0, 0, 0) +print(ans)