n = int(input())

for i in range(1,n+1):

    if i % 3 == 0:

        print(" {0}".format(i), end="")

    else:

        x = i

        while x != 0:

            if x % 10 == 3:

                print(" {0}".format(i), end="")

                break;

            x //= 10;

print("")

n=int(input())

d=[]

for i in range(3,n+1):

    if i%3==0 or "3" in str(i):

        d.append(i)

print(' ',end="")

print(*d)

n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0:
        print(" {0}".format(i), end="")
    else:
        x = i
        while x != 0:
            if x % 10 == 3:
                print(" {0}".format(i), end="")
                break
            x //= 10
print("")

n = int(input())
d = []
for i in range(3, n + 1):
    if i % 3 == 0 or "3" in str(i):
        d.append(i)
print(" ", end="")
print(*d)

-for i in range(1, n + 1): -    if i % 3 == 0: -        print(" {0}".format(i), end="") -    else: -        x = i -        while x != 0: -            if x % 10 == 3: -                print(" {0}".format(i), end="") -                break -            x //= 10 -print("") +d = [] +for i in range(3, n + 1): +    if i % 3 == 0 or "3" in str(i): +        d.append(i) +print(" ", end="") +print(*d)