import re
list = []
n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0 or re.search('3', str(i)):
        list.append(str(i))
print('', ' '.join(list))

75a1ec4e28674f747f31214c00dd4e0239e577f7
<mask token>

<mask token>
for i in range(1, n + 1):
    if i % 3 == 0 or re.search('3', str(i)):
        list.append(str(i))
print('', ' '.join(list))

<mask token>
list = []
n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0 or re.search('3', str(i)):
        list.append(str(i))
print('', ' '.join(list))

import re
list = []
n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0 or re.search('3', str(i)):
        list.append(str(i))
print('', ' '.join(list))
