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):
l = [];n = int(input())
for i in range(1,n+1):
    x = i
    if x%3==0 or x%10==3:
        l.append(i)
    elif x%10!=3:
        while(x):
            x = int(x/10)
            if(x%10==3):
                l.append(i);break;
for i in range(len(l)):
    print(" %d"%l[i],end = '')
print()

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

Solution (Python):
n=int(input())
x=""
for i in range(2,n+1):   
    if i%3==0 or "3" in str(i):
        print(" {}".format(i), end="")
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(n+1)[1:]:
  if i % 3 == 0:
    print(" {}".format(i),end="")
    continue

  if i % 10 == 3:
    print(" {}".format(i),end="")
    continue

  x = i
  while x > 1:
    x = int(x / 10)
    if x % 10 == 3:
      print(" {}".format(i),end="")
      break


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):
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 "3" in str(i):
        print(f" {i}",end="")
print()

Solution (Python):
n = int(input())
tmp = 0
lis = []
for i in range(1, n+1):
    if i % 3 == 0:
        lis.append(i)
    else:
        tmp = i
        while i > 0:
            if i % 10 == 3:
                lis.append(tmp)
                break
            else:
                i //= 10
print(" ", end="")
print(*lis)

Solution (Python):
n=int(input())
a=0
for i in range(1,n+1):
    x=int(i)
    if  x%3==0:
        a=1

    else:
        while x >= 0 and i >=10:
            if x%10==3:
                a=1
                break
            elif x>10:
                x=x//10
            else:
                break
    if a:
        print(f" {i}",end="")
        a=0
print()

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

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

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

Solution (Python):
n = int(input())
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())
lst =[]
for n in range(1,N+1):
    if n%3 ==0 or '3' in str(n):
        lst.append(n)
        
print(" "+" ".join([str(x) for x in lst]))

Solution (Python):
def calc(n):
    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 = x // 10

    print()

calc(int(input()))

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

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;
            x //= 10;
print("")

Solution (Python):
n = int(input())
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):
if __name__ == "__main__":
    n = int(input())
    x = 0

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

        if i % 3 == 0:
            print(f" {i}", end="")
        else:
            x = i
            while (x):
                if x % 10 == 3:
                    print(f" {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="")
    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:
        print(" {0}".format(i), end="")
    else:
        x = i
        while x != 0:
            if x % 10 == 3:
                print(" {0}".format(i), end="")
                break;
            x //= 10;
print("")

Solution (Python):


x = int(input())
figure = 3

while figure <= x:
    if figure % 3 == 0 or '3' in str(figure):
        print(' ',end = '')
        print(figure, end = '')
    figure += 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())

for i in range(1, n + 1):
    if i % 3 == 0:
        print(" {}".format(i), end='')
        continue
    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):
    x=i
    int(x)
    if x%3==0 :
        print(" %d" % i, end="")
    else:
        while x:
            if int(x)%10==3:
                print(" %d" % i, end="")
                break
            else :
                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(" {}".format(i), end = '')
print()

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

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

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

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

Solution (Python):
n = int(input())
for i in range(n):
    i=i+1
    x=i
    if (x%3==0):
        print(" {}".format(i),end="")
    else:
        while True:
            if (x%10==3):
                print(" {}".format(i), end="")
                break
            x=x//10
            if (x==0):
                break
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):
def has3(x):
    while x>0:
        if x%10==3:
            return True
        x = x//10
    return False

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

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

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

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:
        print("",i,end="")
    else:
        t = i
        while t:
            if t % 10 == 3:
                print("",i,end="")
                break
            t //= 10
print()

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

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

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

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

	if include3(i) or check_num(i):
		print(f' {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):
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())
i=1
L=[]
while i<=n:
    x=i
    if x%3==0:
        L.append(x)
    else:
        while x>0:
            if x%10==3:
                L.append(i)
                break
            x=int(x/10)
    i+=1
l=len(L)

for i in range(l):
    if i!=l-1:
        print(' {}'.format(L[i]),end='')
    else:
        print(' {}'.format(L[i]))

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

for i in range(n + 1):
    if i != 0 and (i % 3 == 0 or '3' in str(i)):
            print(" " + str(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(" " + str(i), end="")

print()

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

print(a)

Solution (Python):
n=int(input())
for i in range(3,n+1):
  if i%3==0 or '3' in str(i):
    print( " ",i,sep='',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(" {}".format(i), end ="")
print()

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

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


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

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

for i in range(1,s+1):
  
  a = i%10
  
  b = ((i-a)//10)%10
  
  c = ((i-(a+b*10))//100)%10
  
  d = ((i-(a+b*10+c*100))//1000)%10
  
  e = ((i-(a+b*10+c*100+d*1000))//10000)%10

  if a==3 or b==3 or c==3 or d==3 or e==3 or i%3==0:
      print(" %d"%i, end = "")
      
  a = 0
  b = 0
  c = 0
  d = 0
  e = 0
  
print()

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

Solution (Python):
n = input()
x = int(n)
for i in range(3,x+1) :
 if i%3 == 0 or '3' in str(i) :
   print('',i,end='')
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):
def call(num):
  ans=[]
  for i in range(1,n+1):
    if i%3==0:
      ans.append(i)
    else:
      tmp=i
      flag=False
      while tmp>0:
        if tmp%10==3:
          flag=True
        tmp=tmp//10
      if flag:
        ans.append(i)
  print(' '+' '.join(map(str,ans)))

n=int(input())
call(n)

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

for i in range(1,n+1):
  if i % 3 == 0:
    print("", i, end = "")
  else:
      x = i
      while(x):
        if(x % 10 == 3):
          print("", i, end = "")
          break
        x //= 10
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;
            x //= 10;
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;
            x //= 10;
print("")

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

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

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

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

Solution (Python):
n = int(input())
l = []
for i in range(1,n+1):
    check = []
    if i%3 == 0:
        l.append(str(i))
    for j in str(i):
        if j == "3" and (not i%3 == 0):
            l.append(str(i))
            break
str = ' '.join(l)

print(" "+str)

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

def call(n):
	lstAns=list()
	for x in range(1,n+1):
		if x % 3 == 0:
			lstAns.append(x)
			continue
		y = x
		while 0 < y:
			if y % 10 == 3:
				lstAns.append(x)
				break
			else:
				y //= 10

	return lstAns

ans = call(N)

ans = " ".join(map(str,ans))
if 0 < len(ans):
	ans = " " + ans

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):
inVal = int(input())
outLen = ""
for i in range(1, inVal + 1):
    if i % 3 == 0:
        outLen = outLen + " " + str(i)
    else:
        x = i
        while (x):
            if x % 10 == 3:
                outLen = outLen + " " + str(i)
                break
            x = x // 10
print(outLen)

Solution (Python):
n = int(input())
i = n
for i in range(1,n+1):
    if i % 3 == 0:
        print(' {}'.format(i),end = '')
    
    else:
        st = str(i)
        for j in range(len(st)):
            if(st[j] == '3'):
                print(' {}'.format(i),end = '')
                break
print()

Solution (Python):
if __name__ == '__main__':
	n = int(input())
	res = ""
	for i in range(1,n+1):
		x = i
		if i % 3 == 0:
			res=res+" "+str(i)
			x = 0
		elif i % 10 == 3:
			res=res+" "+str(i)
			x = 0
		while x != 0:
			x = x // 10
			if x % 10 == 3:
				res=res+" "+str(i)
				x = 0
				
	print(res)

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 = 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):
  x = i
  if x%3 == 0:
    print("", i, end = "")
  else:
    while(x > 0):
      if x%10 == 3:
        print("", i, end = "")
        break
      else:
        x = x//10
print()

Solution (Python):
ans = []
num = int(input())
for i in range(1,num+1):
	if i % 3 == 0 or i % 10 == 3 or '3' in str(i):
		ans.append(" " + str(i))
print(*ans,sep="")

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

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

print('\r')

Solution (Python):
l=[]
num=int(input())
for i in range(num+1):
	if i%3==0 and i!=0:
		l.append(i)
	elif '3' in str(i):
		l.append(i)

ans=' '.join(list(map(str,l)))
print(' '+ans)

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

Solution (Python):
n = int(input())
nums = []
for i in range(1, n+1):
    if i%3 == 0:
        nums.append(i)
    elif '3' in list(str(i)):
        nums.append(i)
m = len(nums)
print('', end = ' ')
for i in range(m-1): 
    print(nums[i], end = ' ')
print(nums[m-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())
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):



def checkNum(n):
  if n % 3 == 0:
    return True
  elif include3(n):
    return True
  else :
    k = n
    while k >= 30:
      k = int(k / 10)
      if include3(k):
        return True
  
def include3(n):
  if n % 10 == 3:
    return True
  else :
    return False

input_int = int(input())

numbers = []
for i in range(1, input_int+1):
  if checkNum(i):
    numbers.append(i)

str_numbers = list(map(str, numbers))
print(' '+' '.join(str_numbers))

Solution (Python):
n = int(input())
i = 1
while 1:
    x = i
    if x % 3 ==0:
        print(' ', i, sep='', end='')
    else:
        while x:
            if x % 10 == 3:
                print(' ', i, sep='', end='')
                break
            x //= 10
    if i >= n:
        break
    else:
        i += 1
print()

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

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

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

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

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

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

Solution (Python):



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

Solution (Python):
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)

Solution (Python):
n = int(input())
li = []

for i in range(1,n+1):
    if (i%3 == 0) or (i%10 ==3) or(int(i/10)%10 ==3) or(int(i/100)%10 ==3)or(int(i/1000)%10 ==3):
        print(" "+str(i),end="")

print("")

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

for i in range(i):
    i = i+1
    a = True

    if i%3 == 0:
        print(' ', end = '')
        print(i, end = '')
    else:
        x = i
        while a:
            if x%10 == 3:
                print(' ', end = '')
                print(i, end = '')
                break
            x //= 10
            if x == 0:
                a = False

print()

Solution (Python):


import sys


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


N = int(input())
call(N)

Solution (Python):
N=int(input())
i=1
while i<=N:
    if(i%3==0 or str(i).find("3")!=-1):
        print(' {}'.format(i),end='')
    i+=1
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 i in range(1, n+1):
    if i%3 == 0 or '3' in str(i):
        print(' %d'%i, end='')
print()

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

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

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):
a = int(input())
n = 1
while True:
    if n > a:
        break
    if n % 3 == 0:
        print(" {}".format(n),end="")
    else:
        m = n
        while m >= 3:
            if m % 10 == 3:
                print(" {}".format(n),end="")
                break
            else:
                m = m // 10
    n += 1
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):
n =int(input())
for i in range(1,n + 1):
        s = i
        if i % 3 == 0:
                print(" %d" % i,end = "")
        elif i / 10 != 0:
                for k in range(5):
                        if s % 10 == 3:
                                print( " %d"% i ,end = "")
                                break
                        elif s == 0:
                                break
                        s //= 10
print('')

Solution (Python):
n = int(input())
output = [""]

for i in range(1, n + 1):
    if i % 3 == 0:
        output.append(i)
    elif i % 10 == 3:
        output.append(i)
    elif str(3) in str(i):
        output.append(i)

print(' '.join(map(str, output)))

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):

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

Solution (Python):
i = 1
rs = []
n = int(input())

while i <= n:
    x = i
    if x % 3 == 0:
        rs.append(i)
    else:
        while x:
            if x % 10 == 3:
                rs.append(i)
                break
            x //= 10

    i += 1

print(' ' + ' '.join(map(str, rs)))

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

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

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

i = 0
print(" ", end="")
for r in res:
    print(r, end="")
    if i == len(res)-1:
        
         print('\n', end="")
    else:
        print(" ", end="")

    i += 1

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

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

list = []
for x in range(3, n + 1):
    if x % 3 == 0:
        list.append(x)
    else:
        y = x
        while(y > 0):
            if(y % 10 == 3):
                list.append(x)
                break
            y //= 10

ans = ""
for x in list:
    ans += " " + str(x)
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):
def main():
    n = int(input())
    ans = ['']
    for i in range(1, n + 1):
        x = i
        if x % 3 == 0:
            if i not in ans:
                ans.append(i)
        else:
            while x > 0:
                if x % 10 == 3:
                    if i not in ans:
                        ans.append(i)
                x //= 10
    print(' '.join(map(str, ans)))


main()

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

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):
num = int(input())
num_list = []
for n in range(3, num + 1):
    if n % 3 == 0:
        num_list.append(n)
    elif '3' in str(n):
        num_list.append(n)
print('', *num_list)

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

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

print("")

Solution (Python):
def include(a):
    while True:
        a = a // 10
        if a == 0:
            return False
        if a % 10 == 3:
            return True
n = int(input())
print('', ' '.join([str(i) for i in range(1, n + 1) if i % 3 == 0 or i % 10 == 3 or include(i)]))

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

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

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 str(i).find("3") != -1:
		print(" {}".format(i), end = '')
print()

Solution (Python):
import sys


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


call(int(sys.stdin.read()))

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

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

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

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

Solution (Python):
def main():
	n = int(input())
	for i in range(n):
		x = i + 1
		multipleOf3(i, x)
	print('')

def multipleOf3(i, n):
	if(n % 3) == 0:
		print(' %d' % (i + 1), end='')
	else:
		firstDigitis3(i, n)

def firstDigitis3(i, n):
	if(n % 10) == 3:
		print(' %d' % (i + 1), end='')
	else:
		n = n // 10
		if n > 0:
			firstDigitis3(i, n)

main()

Solution (Python):
n=int(input())
l=[i for i in range(3,n+1) if i%3==0 or i%10 ==3 or int(i/10)%10==3 or int(i/100)%10==3 or int(i/1000)%10==3]
s=" ".join(map(str,l))
print(" "+s)

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

for x in range(1, i + 1) :
    tmpX = int(x // 10)
    isFinish = False

    if x % 3 == 0 :
        print(' {}'.format(x), end = '')
    elif (x % 10 == 3) :
        print(' {}'.format(x), end = '')
    elif tmpX % 10 == 3 :
        print(' {}'.format(x), end = '')
    elif tmpX != 0 :
        tmpX //= 10
        while tmpX != 0 and (not isFinish) :
            if tmpX % 10 == 3 :
                print(' {}'.format(x), end = '')
                isFinish = True
            tmpX //= 10
print()