n=int(input())

i=1

SP=[]

while i<=n:

  x=i

  if x%3==0:

    SP.append(str(i))

  else:

    while x:

      if x%10==3:

        SP.append(str(i))

        break

      x/=10

  i+=1

print("", " ".join(SP))
n=int(input())

i=1

print("", end=' ')

while i<=n:

  x=i

  if x%3==0:

    print(i, end=' ')

  else:

    while x:

      if x%10==3:

        print(i, end=' ')

        break

      x/=10

  i+=1
n = int(input())
i = 1
SP = []
while i <= n:
    x = i
    if x % 3 == 0:
        SP.append(str(i))
    else:
        while x:
            if x % 10 == 3:
                SP.append(str(i))
                break
            x /= 10
    i += 1
print("", " ".join(SP))

n = int(input())
i = 1
print("", end=" ")
while i <= n:
    x = i
    if x % 3 == 0:
        print(i, end=" ")
    else:
        while x:
            if x % 10 == 3:
                print(i, end=" ")
                break
            x /= 10
    i += 1

-SP = [] +print("", end=" ") -        SP.append(str(i)) +        print(i, end=" ") -                SP.append(str(i)) +                print(i, end=" ") -print("", " ".join(SP))