print(("".join([" " + str(i) for i in range(1, int(eval(input())) + 1) if i % 3 == 0 or '3' in str(i)])))



print("".join(" "+str(i)for i in range(1,eval(input())+1)if i%3==0 or'3'in str(i)))

print(
    (
        "".join(
            [
                " " + str(i)
                for i in range(1, int(eval(input())) + 1)
                if i % 3 == 0 or "3" in str(i)
            ]
        )
    )
)

print(
    "".join(
        " " + str(i) for i in range(1, eval(input()) + 1) if i % 3 == 0 or "3" in str(i)
    )
)

-    ( -        "".join( -            [ -                " " + str(i) -                for i in range(1, int(eval(input())) + 1) -                if i % 3 == 0 or "3" in str(i) -            ] -        ) +    "".join( +        " " + str(i) for i in range(1, eval(input()) + 1) if i % 3 == 0 or "3" in str(i)