Problem:
Structured Programming In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
} Input An integer n is given in a line. Output Print the output result of the above program for given integer n . Constraints  3 ≤ n ≤ 10000  Sample Input 30 Sample Output 3 6 9 12 13 15 18 21 23 24 27 30 Put a single space character before each element.

Solution (Python):
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    n = Z()
    output = []
    for i in range(1, n+1):
        if i%3 == 0: output.append(i)
        elif '3' in str(i): output.append(i)
    for i in output: print(' ' + str(i), end='')
    print('')

    return

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())

def aho(i):
    ans = ""
    if i % 3 == 0:
        ans += (" " + str(i))
    elif "3" in str(i):
        ans += (" " + str(i))
    return ans

for i in range(1, n+1):
    print(aho(i), end="")
print()

Solution (Python):
N = int(input())
x = 0

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

    if i % 3 == 0:
        print(" %d" % i, end="")
    else:
        x = i
        while (x):
            if x % 10 == 3:
                print(" %d" % i, end="")
                break
            x //= 10
print()

Solution (Python):
a = int(input())
for i in range(1,a + 1):
    if i % 3 == 0 or '3' in str(i):
        print(' {}'.format(i),end = '')
print()

Solution (Python):
n = int(input())
nums = []
for i in range(n + 1):
    if i != 0:
        
        if i % 3 == 0 or str(i).find("3") != -1:
            nums.append(i)
print("", " ".join(map(str, sorted(nums))))

Solution (Python):
N = int(input())
x = 0

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

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

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

Solution (Python):
def call(n):
	for i in range(1, n+1):
		if i%3 == 0:
			print(' {}'.format(i),end='')
		elif str(i).count('3') > 0:
			print(' {}'.format(i),end='')
	print()

a = int(input())
call(a)

Solution (Python):
a = input()
ans = ''
for i in range(1,a+1):
    x=i
    if(x%3==0):
        ans+=' '+str(i)
        continue
    while(x):
        if(x%10==3):
            ans+=' '+str(i)
            break
        x/=10
print ans

Solution (Python):
N = int(input())
x = 0

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

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Solution (Python):
N = int(input())

for i in range(0, N):
    number = i + 1
    if number % 3 == 0:
        print(f" {number}", end="")
    elif "3" in str(number):
        print(f" {number}", end="")
    else:
        continue
    
print()

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

Solution (Python):
import math

n = int(input())

for x in range(1, n + 1):
    if x % 3 == 0:
        print(f" {x}", end="")
    else:
        for y in range(int(math.log10(x)) + 1):
            if int(str(x)[y]) == 3:
                print(f" {x}", end="")
                break
print()

Solution (Python):
n = int(input())

i=1
res=[]
while i<=n:
  chk='3' in str(i)

  if chk==True:
    res.append(str(i))
    
  elif i%3==0:
    res.append(str(i))
    
  i+=1
  
print(' '+' '.join(res))

Solution (Python):
n = int(input())
ans = ""
for i in range(3,n+1):
    if i >= 3000 and (str(i)[-4]) == "3":
        ans += " " + str(i)
    elif i >= 300 and (str(i)[-3]) == "3":
        ans += " " + str(i)
    elif i >= 30 and (str(i)[-2]) == "3":
        ans += " " + str(i)
    elif (i % 3 == 0) or (i % 10 == 3):
        ans += " " + str(i)
print(ans)

Solution (Python):
n = int(input())
for i in range(3, n+1):
    if i % 3 == 0:
        print(f' {i}', end='')
    elif '3' in str(i):
        print(f' {i}', end='')
print()

Solution (Python):
n = int(input())
for i in range(1, n+1):
    if i%3 == 0:
        print(" " + str(i), end='')
    elif str(i).count('3') > 0:
        print(" " + str(i), end='')
print("")

Solution (Python):
for x in range(1, int(input()) + 1):
  if x % 3 == 0:
    print(f' {x}', end = '')
  else:
    y = x
    while (y):
      if y % 10 == 3:
        print(f' {x}', end = '')
        break
      else:
        y //= 10
print()

Solution (Python):
n = int(input())

outp = ""

for i in range(n):
    x = i + 1
    if x % 3 == 0:
        outp += " " + str(x)
        continue

    for num in range(10):
        if x % 10 == 3:
            outp += " " + str(i+1)
            break
        x = x // 10
        if x < 3:
            break

print(outp)

Solution (Python):
n = int(input())

def dividable3(x):
    if x % 3 == 0:
        return True
    return False

def include3(x):
    while x > 0:
        if x % 10 == 3:
            return True
        x = x // 10
    return False

def call(x):
    return dividable3(x) or include3(x)

line = ""
for i in range(1, n+1):
    if call(i):
        line += " " + str(i)
print(line)

Solution (Python):
n = int(input())
for _ in range(1,n+1):
    if "3" in str(_):
        print(" "+str(_),end="")
    elif _%3==0:
        print(" "+str(_),end="")
print("")

Solution (Python):
n = int(input())
ls = []
for i in range(3,n+1):
    if (i % 3 == 0) or ("3" in str(i)):
        ls.append(str(i))
s = " ".join(ls)
print(" " + s)

Solution (Python):
n = int(input())

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

Solution (Python):
import sys
n = int(input())
x = 0
for i in range(1,n+1):
    if i % 3 == 0:
        print(" %d"%i, end = "");
    else:
        x = i
        while (x):
            if x % 10 == 3:
                print(" %d"%i, end = "")
                break
            x //= 10
print()

Solution (Python):
N = int(input())

def calc(x):
    if x % 3 == 0:
        return True
    for i in str(x):
        if i == '3':
            return True
    return False

ret = []
for i in range(1, N+ 1):
    if calc(i):
        ret.append(i)

ret2 = ''
for r in ret:
    ret2 = ret2 + ' ' + str(r)
print(ret2)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    n = int(input())
    
    for i in range(1, n+1):
        if i % 3 == 0:
            print(' ' + str(i), end="")
        elif "3" in str(i):
            print(' ' + str(i), end="")
    print("")

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
for i in range(1,n+1):
    if i % 3 == 0:
        print("",i,end="")
    else:
        num = i
        while num != 0:
            if num % 10 == 3:
                print("",i,end="")
                break
            else:
                num //= 10
print()

Solution (Python):
n = int(input())
for i in range(n):
    if (i+1)%3 ==0 or "3" in str(i+1):
        print(" {}".format(i+1), end="")
print()

Solution (Python):
n=int(input())
i=1


op=[]
while i<=n:
	x=i
	if x%3==0:
		op.append(i)
	else:
		while x>1:
			if x%10==3:
				op.append(i)
				break
			else:
				x//=10
	i+=1

for i in op:
	print(f" {i}",end="")

print()

Solution (Python):

def call(n):
    i=1
    
    
    
    for i in range(1,n+1):
        x=i
        
        if x%3==0:
            print(f" {i}",end="")
            continue
        
        
        
        while x!=0:
            
            if x%10==3:
                print(f" {i}",end="")
                break
                
            x=int(x/10)
            
    print("")
    

n=int(input())

call(n)

Solution (Python):
n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0 or '3' in str(i):
        print(f' {i}', end='')
print()

Solution (Python):
n = int(input())
ans = ""
for i in range(1,n+1):
    if i%3 == 0:
        ans += " "
        ans += str(i)
    else:
        if "3" in list(str(i)):
            ans += " "
            ans += str(i)
print(ans)

Solution (Python):
n = int(input())
ans = ''
for i in range(1,n+1):
    if i%3==0:
        ans+=' '+str(i)
    else:
        x = i
        while x>0: 
            if x%10==3:
                ans+=' '+str(i)
                break
            x = x//10
        
print(ans)

Solution (Python):
n = int(input())
for i in range(1, n + 1):
	if i % 3 == 0 or str(i).find("3") != -1:
		print(" {}".format(i), end = '')
print()

Solution (Python):
n = int(input())
x = []
for i in range(1,n+1):
    if i%3 == 0:
        x.append(i)
        continue
    if i%10 == 3:
        x.append(i)
        continue
    i = str(i)
    if '3' in list(map(str,i)):
        x.append(int(i))
print(' '+' '.join(map(str,x)))

Solution (Python):
x=int(input())
a=0
for i in range(1,x+1):
    if i%3==0:
        print(" %d"%i,end="")
    else :
        a=i
        while (a):
            if a%10==3:
                print(" %d"%i,end="")
                break
            a//=10
print()

Solution (Python):
n = int(input())
m = [i for i in range(3, n + 1, 3)]
s = [str(i) for i in range(1, n+1)]
s = [int(i) for i in s if '3' in i]
a = set(m + s)
b = ' '
for i in a:
    b += str(i) + ' '
print(b[:-1])

Solution (Python):
n = int(input())

for i in range(1,n+1):
    if i % 3 == 0 :
        print(" {}".format(i),end="")
    elif "3" in str(i):
        print(" {}".format(i),end="")
print()

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

Solution (Python):
N=int(input())
for i in range(1,N+1):
    if i%3==0 or '3' in str(i):
        print(' {}'.format(i),end='')
print()

Solution (Python):
N = int(input())

for e in range(1, N + 1):
    if e % 3 == 0 or str(e).find("3")!=-1:
        print(" {}".format(e), end="")
print()

Solution (Python):
n=int(input())
for i in range(1,n+1):
    if i%3==0 or "3" in str(i):
        print(" %d"%i,end="")
print()

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

Solution (Python):
n = int(input())
res = ' ' + ' '.join(str(i) for i in range(1, n+1) if i % 3 == 0 or '3' in str(i))
print(res)

Solution (Python):
a=int(input())
for i in range(1,a+1):
    if '3' in str(i):
        print('',i,end='')
        continue
    if i%3==0:
        print('',i,end='')
print()

Solution (Python):
n = int(input())
s = ""
for i in range(1, n + 1):
    tmp = str(i)
    if i % 3 == 0 or '3' in tmp:
        s += f' {i}'
        continue
print(s)

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

Solution (Python):
i = 1
flag = True
n = int(input())
l = []

while flag:
    x = i
    if x % 3 == 0:
        l.append(i)

    else:
        flag2 = True
        while flag2:
            if x % 10 == 3:
                l.append(i)
                break

            else:
                x //= 10
                if x < 1:
                    flag2 = False

    i += 1
    if i > n:
        flag = False

m = map(str, l)
print(" ", end = "")
print(" ".join(m))

Solution (Python):
n = int(input())

for i in range(1, n+1, 1):
    if i % 3 ==0:
        print(" ", end = "")
        print(i, end="")
    else:
        x = i
        while x:
            if x % 10 == 3:
                print(" ",end = "")
                print(i, end="")
                break
            x//=10
print()

Solution (Python):
n = int(input())
print(' ' + ' '.join([str(i) for i in range(1, n + 1) if i % 3 == 0 or '3' in [j for j in str(i)]]))

Solution (Python):
def aho(x):
    if x % 3 == 0:
        return True
    while x:
        if x % 10 == 3:
            return True
        x //= 10
    return False

n = int(input())
for i in range(1, n + 1):
    if aho(i):
        print(' ', i, sep='', end='')
print()

Solution (Python):
"""
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}
"""
n = int(input())
i = 1
while True:
    x = i
    if x % 3 == 0:
        print (f' {i}', end='')
    else:
        while x:
            if x % 10 == 3:
                print(f' {i}', end='')
                break
            x //= 10
    i += 1
    if i > n:
        break
print()

Solution (Python):
num = int(input())
k = int(1)

for i in range(1,num+1):
    if i%3 == 0:
        print(" %d"%i, end="")

    else:
        k = i
        while (k):
            if k%10 == 3:
                print(" %d"%i, end="")
                break
            k //=10
print()

Solution (Python):
data = int(input())

for i in range(1,data+1):
    if i % 3 == 0 or i % 10 == 3 or '3' in str(i):
        print(" "+str(i), end="")
print()

Solution (Python):
x = int(input())
for i in range(3, x+1):
    if i % 3 == 0:
        print(' ' + str(i), end='')
    elif i % 10 == 3:
        print(' ' + str(i), end='')
    elif '3' in str(i):
        print(' ' + str(i), end='')
print()

Solution (Python):
x = int(input())
y = 0

for i in range(1, x+1):
    if i % 3 == 0:
        print(" %d"%i, end='')

    else:
        y = i
        while (y):
            if y % 10 == 3:
                print(" %d"%i, end='')
                break
            y //= 10
print()

Solution (Python):

for i in range(1,int(input()) + 1):
    if "3" in str(i) or i % 3 == 0:print(" " + str(i),end="")
print()

Solution (Python):
n = int(input())

a = []

for i in range(1,n+1):
    
    if i % 3 == 0 or i % 10 == 3:
        a.append(i)
    elif int(int(i / 10) % 10) == 3:
        a.append(i)
    elif int(int(i / 100) % 10) == 3:
        a.append(i)
    elif int(int(i / 1000) % 10) == 3:
        a.append(i)

a = sorted(set(a))
print(" ",end="")
print(*a)

Solution (Python):
n = int(input())
3 <= n <= 10000
for i in range(n) :
    if (i + 1) % 3 == 0 :
        print(" " + str(i + 1), end = "")
    else :
        x = i + 1
        while (x) :
            if x % 10 == 3 :
                print(" " + str(i + 1), end = "")
                break
            x //= 10
print()

Solution (Python):
n = int(input())

ans = []
for i in range(1, n+1):
    if i % 3 == 0:
        ans.append(i)
    elif '3' in str(i):
        ans.append(i)

print('', *ans)

Solution (Python):
n = int(input())
for i in range(1,n+1):
    if i % 3 == 0:
        print('', i, end='')
    elif '3' in str(i):
        print('', i, end='')
print()

Solution (Python):
N=int(input())
for i in range(1,N+1):
    if i%3==0 or "3" in str(i):
        print(" {}".format(i),end="")
print()

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

Solution (Python):
def call(n):
    row = []
    for i in range(1, n + 1):
        
        
        if i % 3 == 0 :
            row.append(str(i))
        
        
        else:
            j = i
            while j != 0:
                if j % 10 == 3:
                    row.append(str(i))
                    break
                j //= 10
            
    return row
    
num = int(input())
print("", " ".join(call(num)))

Solution (Python):
x = int(input())

for i in range(1,x+1):
    if i % 3 == 0 or '3' in str(i):
        print(" {}".format(i),end = "")
print()

Solution (Python):
N=int(input())
list_num=[]
for i in range(1,N+1):
    if i%3==0:
        list_num.append(i)
        
    else:
        s=str(i)
        if list(s).count('3')!=0:
            list_num.append(i)
            
list_num.sort()

[print(' ' + str(i),end='') for i in list_num]
print()

Solution (Python):
n = int(input())
i = 1
while i <= n:
    if i % 3 == 0 or "3" in str(i):
        print(f" {i}",end="")
    i+=1
print()

Solution (Python):
n = int(input())

b = []
for a in range(n):
    if (a+1) % 3 == 0:
        b.append(a+1)
    elif '3' in str(a+1):
        b.append(a+1)

for a in b:
    print(' ',end='')
    print(a,end='')
print('')

Solution (Python):
def call(n):
    print "",
    i = 1
    while i <= n:
        x = i
        if x % 3 == 0:
            print str(i),
            i += 1
            continue

        while x:
            if x % 10 == 3:
                print str(i),
                break
            x /= 10
            
        i += 1
        
    print

n = int(raw_input())
call(n)

Solution (Python):
num = int(input())
cnt = 1
s = []
while cnt <= num:
  x = cnt
  if x % 3 == 0:
    s.append(cnt)
    x = 0
  while x > 0:
    if x % 10 == 3:
      s.append(cnt)
      break
    x = x // 10
  cnt += 1
s = ' '.join(str(i) for i in s)
s = ' ' + s
print(s)

Solution (Python):
n = int(input())

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

Solution (Python):
from sys import stdin

n = int(stdin.readline())

for i in range(1,n+1):
    x = i
    if x % 3 == 0:
        print('', i, end='')
    else:
        while x:
            if x % 10 == 3:
                print('', i, end='')
                break
            else:
                x //= 10
print()

Solution (Python):
n = int(input())

for x in range(1,n+1):
  if x % 3 == 0:
    print(" " + str(x), end ="")
  elif x % 10 == 3:
    print(" " + str(x), end = "")
  else:
    y = int(x /10)
    while y:
      if y % 10 == 3:
        print(" " + str(x), end = "")
        break
      else:
        y = int(y /10)

print("")

Solution (Python):
def main():
    n = int(input())
    for i in range(1, n+1):
        x = i
        if x % 3 == 0:
            print(f" {i}", end="")
        else:
            while (x):
                if x % 10 == 3:
                    print(f" {i}", end="")
                    break
                x = x // 10
    print()


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
x = 0

for i in range(1,n+1):
    if i%3 == 0:
        print(" %d"%i,end = "")
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Solution (Python):
N = int(input())
x  = 0
for i in range(1,N+1):
    if i%3 == 0:
            print(" "+ str(i),end = "")
    else:
        x = i
        while (x):
            if x % 10 == 3:
                print(" " + str(i),end = "")
                break
            x //= 10
print("")

Solution (Python):
N = int(input())
for i in range(1, N + 1):
    if i % 3 == 0 or str(i).find('3') != -1:
        print(f' {i}', end='')
print()

Solution (Python):
N = int(input())
for i in range(1, N+1):
    if i % 3 == 0 or i % 10 == 3 or str(i).find("3") != -1:
        print(" {}".format(i), end='')
print()

Solution (Python):
n = int(input())
for i in range(1, n+1):
    if i % 3 == 0 or str(i).find("3") != -1:
        print(f" {i}", end = '')
print()

Solution (Python):
n = int(input())
for i in range(1,n+1):
    if i%3==0:
        print(" {}".format(i),end="")
    elif "3" in str(i):
        print(" {}".format(i),end="")
print()

Solution (Python):
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
            else:
                x=x//10
print('')

Solution (Python):
N = int(input())
res = []

for n in range(3,N+1):
    if n % 3 == 0:
        res.append(n)
    elif '3' in str(n):
        res.append(n)
for nn in res:
    print(' %d' % nn, end='')
print()

Solution (Python):
n = int(input())

for i in range(1, n+1):
    if i % 3 == 0:
        print(' {}'.format(i), end = '')
    elif '3' in str(i):
        print(' {}'.format(i), end = '')
print()

Solution (Python):
n=int(input())

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

print("")

Solution (Python):

BIG_NUM = 2000000000


N = int(input())
x = 0

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

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Solution (Python):
n=int(input())

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

Solution (Python):
N = int(input())

for i in range(1, N + 1, 1):
    if i % 3 == 0 or str(i).find('3') >= 0:
        print(f" {i}", end="")
print()

Solution (Python):
N = int(input())
l = ""
i = 1

while True:
    x = i
    
    if x%3 == 0:
        l += " {}".format(i)

    
    else:
        while True:
            if x%10 == 3:
                l += " {}".format(i)
                break
            x //= 10
            if x < 1:
                break
    i += 1
    if i > N:
        print(l)
        break

Solution (Python):

n = int(input())
for i in range(1,n+1):
    if i %3==0 or str(i).find("3") !=-1 :
        print(" {}".format(i),end="")
print()

Solution (Python):
print('',*[i for i in range(3,int(input())+1)if i%3==0 or'3'in str(i)])

Solution (Python):
n = int(input())

for i in range(1, n + 1):
	if i % 3 == 0 or str(i).count('3') != 0:
		print(' {0}'.format(i), end='')
print()

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

Solution (Python):
n = int(input())

for i in range (1, n+1):
    if i%3==0:
        print(" %d" %i, end="")
    else:
        x = i
        while(x):
            if x%10==3:
                print(" %d" %i, end="")
                break
            x//=10
print()

Solution (Python):
def include_3 (x):

    if x < 1:
        return False
    elif x % 10 == 3:
        return True
    else:
        return include_3(x // 10)

n = int(input())

for i in range (1,n+1):
    if i % 3 == 0:
        print(" %d" % i,end="")
    elif include_3(i) :
        print(" %d" % i,end="")
print()

Solution (Python):
n = int(input())
A = list()
for i in range(1,n+1):
    if i % 3 == 0:
        A.append(i)
    elif "3" in str(i):
        A.append(i)
print(" ", end="")
for i in range(len(A)-1):
    print(A[i], end=" ")
print(A[len(A)-1])

Solution (Python):
n = int(input())
for i in range(1, n+1):
  if i % 3 == 0 or '3' in str(i):
    print(" {}".format(i), end='')
print()

Solution (Python):
n = int(input())

for i in range(1, n+1):
    if i%3 == 0 or "3" in str(i):
        print(f" {i}", end="")

print()

Solution (Python):
num = int(input())

for i in range(1, num+1):
    if i % 3 == 0 or ('3' in str(i)):
        print(' {}'.format(i), end='')
print()

Solution (Python):
N=str(input())
S=""
for i in range(1,int(N)+1):
    m=str(i)
    if i%3==0 or "3" in m:
        S=S+" "+str(i)
print(S)

Solution (Python):
N = int(input())
x = 0

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

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Solution (Python):
n = int(input())

for i in range(1, n + 1):
    if i % 3 == 0:
        print(" " + str(i), end = "")
        continue
    x = i
    while True:
        if x % 10 == 3:
            print(" " + str(i) , end = "")
            break
        elif x == 0:
            break
        x //= 10
print()

Solution (Python):
n = int(input())

for i in range(1, n + 1):
    if i % 3 == 0:
        print("", i, end = "")
        continue
    x = i
    while x != 0:
        if x % 10 == 3:
            print("", i , end = "")
            break
        x //= 10
print()

Solution (Python):
N = int(input())
x = 0

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

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Solution (Python):
N = int(input())
for i in range(1, N + 1):
	if i % 3 == 0 or str(i).find('3') != -1:
		print(' ', i, sep='', end = '')
print()

Solution (Python):
n = int(input())
number = []
for i in range(1, n + 1):
	if i % 3 == 0 or str(i).find("3") != -1:
		number.append(i)

answer = "".join(" "+str(j) for j in number)
print(answer)

Solution (Python):
n = int(input())
for i in range(1, n+1):
    x = i

    if x%3 ==0 :
        print(" %d" %(i),end="")
        continue
    else :
        while(True):
            if x%10 ==3 :
                print(" %d" %(i),end="")
                break
            x//=10
            if x == 0:
                break
print("")

Solution (Python):
n = int(input())

for i in range(1, n+1):
    if i % 3 ==0:
        print(" " , end="")
        print(i , end="")

    elif '3' in str(i):
        print(" " , end="")
        print(i , end="")

print()

Solution (Python):
base = input()
a = int(base)

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

    if i%3 == 0:
            print(" %d"%i,end = "")
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Solution (Python):
def calc(x):
    if x%10 == 3:
        return True
    
    else: return False
    

n = int(input())
res = []
i = 1

while True:
    x = i
    x1 = 0
    x2 = 0
    x3 = 0
    if x%3 == 0:
        res.append(i)
    
    elif x%10 == 3:
        res.append(i)
    
    else:
        if x > 10 and x < 100:
            x1 = x//10
            if calc(x1) == True:
                res.append(i)
        
        if x > 100 and x < 1000:
            x1 = x//10
            x2 = x1//10
            if calc(x1) == True or calc(x2) == True:
                res.append(i)
  
        if x > 1000 and x < 10000:
            x1 = x//10
            x2 = x1//10
            x3 = x2//10
            if calc(x1) == True or calc(x2) == True or calc(x3) == True:
                res.append(i)
     
    i += 1
    if i > n:
        break

print("", " ".join(map(str, res)))

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

Solution (Python):
i = int(input())
str1 = ''
for z in range(1,i+1):
    x = z
    if x % 3 == 0:
        str1 =  str1 +' '+ str(z)
        continue
    while x > 0:
        if x % 10 == 3:
            str1 =  str1 +' '+ str(z)
            break
        x //= 10
print(str1)

Solution (Python):
n = int(input())
ans = list()
x = 0
for i in range(1, n+1):
    if i % 3 == 0:
        ans.append(' ' + str(i))
    else:
        x = i
        while (x > 0):
            if x % 10 == 3:
                ans.append(' ' + str(i))
                break
            else:
                x //= 10

print(''.join(ans))

Solution (Python):
n = int(input())
for i in range(1, n + 1):
	if i % 3 == 0:
		print(' %d' % i, end="")
	else:
		j = i
		while j > 0:
			if j % 10 == 3:
				print(' %d' % i, end="")
				break
			j //= 10
print("")

Solution (Python):
n = int(input())
i = 1
while n >= i:
    c3 = i
    if i % 3 == 0:
        print(" {}".format(i), end = "")
    else:
        while c3 != 0:
            if c3 % 10 == 3:
                print(" {}".format(i), end = "")
                break
            c3 = int(c3 / 10)
    i += 1
print("")

Solution (Python):
n = int(input())
x = 1
while x <= n:
    a = [int(x % 10), int((x/10) % 10), int((x/100) % 10), int((x/1000) % 10)]
    if x % 3 == 0 or ("3" in (" ".join(map(str, a)))):
        print (f" {x}", end = "")
    x += 1
print ()

Solution (Python):
N = int(input())
x = 0

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

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Solution (Python):
n=int(input())
x=0
ans=[]
for i in range(1,n+1):
  if i%3==0:ans.append(str(i))
  else:
    x=i
    while x:
      if x%10==3:
        ans.append(str(i))
        break
      x//=10
print(" "+" ".join(ans))

Solution (Python):
N=int(input())
for i in range(1,N+1):
   
    if i%3==0:
        print(" ",end="")
        print(i,end="")
    else:
        s=str(i)
        for sent in s:
            if sent=="3":
                print(" ",end="")
                print(s,end="")
                break

print()

Solution (Python):
N = int(input())

ans = []

for i in range(1,N+1):
    n = i
    if i%3 == 0:
        ans.append(i)

    while n > 0:

        if n % 10 == 3:
            ans.append(i)

        n = n//10


print(" "+" ".join([str(i) for i in set(ans)]))

Solution (Python):
N = int(input())
x = 0

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

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Solution (Python):
n=int(input())
for i in range(1,n+1):
    if 0 == i%3 or str(i).find("3") != -1:
        print(" {}".format(i),end ="")
print()

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