n = int(input())

s = ''



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

    if i%3 == 0:

        s = s + ' ' + str(i)

    else:

        temp = ''

        temp = str(i)

        for j in range(len(temp)):

            if temp[j] == '3':

                s = s + ' ' + str(i)

                break

print(s)
n = int(input())

i = 1

print("", end=' ')



while i <= n:

  if i%3 == 0:

      print(i, end=' ')

  else:

      I = str(i)

      for j in range(len(I)):

          if I[j] == '3':

              print(I, end=' ')

              break

  i += 1
n = int(input())
s = ""
for i in range(1, n + 1):
    if i % 3 == 0:
        s = s + " " + str(i)
    else:
        temp = ""
        temp = str(i)
        for j in range(len(temp)):
            if temp[j] == "3":
                s = s + " " + str(i)
                break
print(s)

n = int(input())
i = 1
print("", end=" ")
while i <= n:
    if i % 3 == 0:
        print(i, end=" ")
    else:
        I = str(i)
        for j in range(len(I)):
            if I[j] == "3":
                print(I, end=" ")
                break
    i += 1

-s = "" -for i in range(1, n + 1): +i = 1 +print("", end=" ") +while i <= n: -        s = s + " " + str(i) +        print(i, end=" ") -        temp = "" -        temp = str(i) -        for j in range(len(temp)): -            if temp[j] == "3": -                s = s + " " + str(i) +        I = str(i) +        for j in range(len(I)): +            if I[j] == "3": +                print(I, end=" ") -print(s) +    i += 1