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

Solution (Python):
def is_correct(i):
    if i % 3 == 0: return True
    while i > 0:
        if i % 10 == 3: return True
        i = i // 10
    return False
 
def main():
    n = int(input())
    answer = ""
    for i in range(1, n + 1):
        if is_correct(i): answer += " " + str(i)
    print(answer)    
 
if __name__ == "__main__":
    main()

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

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

def three(n):
    result = ""
    counter = 3
    while counter < n+1:
        if "3" in str(counter) or counter % 3 == 0:
            result += " {}".format(counter)
        counter += 1
    return(result)


print(three(n))

Solution (Python):
def divisible(n):
    if n % 3 == 0:
        print(' {0}'.format(n), end='')


def include(n):
    if '3' in str(n):
        print(' {0}'.format(n), end='')


n = int(input())
for n in range(3, n+1):
    divisible(n)
    if n % 3:
        include(n)
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())
d=[]
for i in range(1,n+1):
    if i%3==0 or "3" in str(i):
        d.append(i)
print(' ',end="")
print(*d)

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

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

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

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

print()

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

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

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

for i in range(3, n + 1):
	x = i
	if x % 3 == 0 or x % 10 == 3:
		sys.stdout.write(' ')
		sys.stdout.write(str(i))
	else:
		while x != 0:
			x = int(x / 10)
			if x % 10 == 3:
				sys.stdout.write(' ')
				sys.stdout.write(str(i))
				break
print()

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

for i in range(3, n + 1):
	x = i
	if x % 3 == 0 or x % 10 == 3:
		sys.stdout.write(' ' + str(i))
	else:
		while x != 0:
			x = int(x / 10)
			if x % 10 == 3:
				sys.stdout.write(' ' + str(i))
				break
print()

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

i = 1

while i <= n:
    if i % 3 == 0 or str(i).count('3') > 0:
        print(f" {i}", end='')
    i += 1

print()

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

ans_str = " 3"
for i in range(4, n+1):
    if (i % 3) == 0:
        ans_str += " " + str(i)
    else:
        tho = i // 1000
        cto = (i % 1000) // 100
        ten = ((i % 1000) % 100) // 10
        one = ((i % 1000) % 100) % 10
        if tho == 3 or cto == 3 or ten == 3 or one == 3:
            ans_str += " " + str(i)

print(ans_str)

Solution (Python):



integer = int(input())
cout = []

i = 1
while i <= integer:
    x = i
    if x % 3 == 0:
        cout.append(i)
    else:
        while x > 0:
            if x % 10 == 3:
                cout.append(i)
                x = 0
            else:
                x //= 10
    i += 1

for n in cout:
    print(' ' + str(n), end = '')
print()

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

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

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

if __name__ == '__main__':
    main()

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

if __name__ == '__main__':
    main()

Solution (Python):
def call_filter(x):
    if x % 3 == 0: return True

    while x > 0:
        if x % 10 == 3: return True
        x = int(x/10)

    return False

def call(n):
    for i in [x for x in range(1, n+1) if call_filter(x)]:
        print(' {}'.format(i), end='')
    print()

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

Solution (Python):
from sys import stdin

n = int(stdin.readline())

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

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

        x //= 10
print()

Solution (Python):
n = int(input())
i = 1
for i in range(1,n + 1):
    if i%3==0:
        print(f" {i}", end="")
        continue
    else:
        x = i
        while x!=0:
            if x%10==3:
                print(f" {i}", end="")
                break
            else:
                x = 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):
def CHECK_NUM(i):
    x = i
    if x % 3 == 0:
        print(' ', x, sep='', end='')
    else:
        INCLUDE3(x)


def INCLUDE3(i):
    x = i
    while x:
        if x % 10 == 3:
            print(' ', i, sep='', end='')
            return ()
        x //= 10


n = int(input())
for i in range(1, n + 1):
    CHECK_NUM(i)
print()

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

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(3, n+1):
    if i % 3== 0 or "3" in str(i):
        print(" {0}".format(i),end="")
print()

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

for i  in range( x ):
    j = i + 1
    if j % 3 == 0:
        print(f" {j}", end = "" )
    else:
        for k in range(4):
            if ( (j//10**k) %10) == 3:
                print(f" {j}", end = "")
                break
print(sep = "\n")

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

Solution (Python):
print("",*[i for i in range(3,-~int(input()))if 0==i%3or"3"in str(i)])

Solution (Python):
n = int(input())
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()

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

Solution (Python):
x = int(input())
data = [""]
for i in range(3,x+1):
  flag = 0

  for j in str(i):
    if int(j) == 3:
      flag = 1
  if i % 3 == 0:
    flag = 1
  if flag == 1:
    data.append(i)
ans = ' '.join(map(str, data))
print(ans)

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

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

Solution (Python):
N=int(input())
s=""
for i in range(1,N+1):
    x=i
    if x%3==0:
        s+=" {}".format(i)
        continue
    while x!=0:
        if x%10==3:
            s+=" {}".format(i)
            break
        x//=10

print(s)

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(3, n + 1):
    if i % 3 == 0 or '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())
n_list = []
counter = 0
for i in range(3, n+1):
    if i%3 == 0:
      n_list.append(i)
      counter += 1
    else:
      x = i
      while x > 0:
        if x%10 == 3:
          n_list.append(i)
          counter += 1
          break
        x //= 10
for i in range(counter):
    print(' %d'%n_list[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):
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):
n = int(input())
ans = ""
for i in range(1, n+1):
  if i % 3 == 0:
    ans += " " + str(i)
  else:
    x = i
    while x:
      if x % 10 == 3:
        ans += " " + str(i)
        break
      x //= 10
print(ans)

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())
i = 1
while i <= n:
    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 = x // 10
    i += 1
print('')

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

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

Solution (Python):




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


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
def Nabeatsu(num):
    ans=[]
    for i in range(1,num+1):
        if i%3==0 or ("3" in str(i)):
            ans.append(str(i))
    ans=" "+" ".join(ans)
    return ans

print(Nabeatsu(int(input())))

Solution (Python):
n=int(input())
a=1
for i in range(n):
    if a%3==0:
        print(" "+str(a),end="")
        a=a+1
    elif a%10==3:
        print(" "+str(a),end="")
        a=a+1
    elif 30<=a%100<=39:
        print(" "+str(a),end="")
        a=a+1
    elif 300<=a%1000<=399:
        print(" "+str(a),end="")
        a=a+1
    elif 3000<=a<=3999:
        print(" "+str(a),end="")
        a=a+1
    else:
        a=a+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):
print("", *[n for n in range(1,int(input())+1) if "3" in str(n) or n%3==0])

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

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

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

print("")

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

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

        continue

    while True :
        if(x % 10 == 3):
            print(" "+str(i),end = "")

            break
        x //= 10
        if(x == 0):

            break


print("")

Solution (Python):
n = int(input())
for i in range(3,n+1):
    if i % 3 == 0:
        print(" "+str(i),end="")
    else:
        x = i
        while x >= 3:
            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(" %d" % (i),end="")
print()

Solution (Python):
n=int(input())
lis = list(range(1,n+1))

for i in lis:
    if i%3==0 or "3" in str(i):
        print(" {}".format(i),end="")
print()

Solution (Python):
n = int(input())
i = 1
ans = ['']
while True :
    x = i
    if x > n :
        break
    if x % 3 == 0 :
        ans.append(i)
    else :
        while x != 0 :
            if x % 10 == 3 :
                ans.append(i)
                break
            else :
                x = x // 10 
    i += 1
print(*ans)

Solution (Python):
n = int(open(0).read())

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

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

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

print(out)

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 = "")
    else:
        x = i 
        while x:
            if x % 10 == 3:
                print(" {}".format(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())
flg = True
count = 0
while count < n:
    flg = True
    count += 1
    x = count
    if x % 3 == 0:
        print(" {}".format(count), end="")
        continue
    while x != 0 and flg:
        if x % 10 == 3:
            print(" {}".format(count), end="")
            flg = False
        x = x // 10
print("")

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

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

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

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

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


resolve()

Solution (Python):
def call(n):
    s = ''
    for i in range(1,n+1):
        if i%3==0:
            s += ' ' + str(i)
        else:
            x = i
            while x:
                if x%10==3:
                    s += ' ' + str(i)
                    break
                x //= 10
    print(s)

if __name__ == "__main__":
    call(int(input()))

Solution (Python):
n = int(input())
result = ''
for j in range(1, n + 1):
    i = j
    if i % 3 == 0:
        result += f' {i}'
    elif i % 10 == 3:
        result += f' {i}'
    else:
        while True:
            i = i // 10
            if i == 0:
                break
            elif i % 10 == 3:
                result += f' {j}'
                break
print(result)

Solution (Python):
n = int(input())
list = list()
def call(num) :
	for i in range(1,num+1) :
		if i%3 == 0 or str(i).count("3") :
			print(" ", end="")
			print(i, end="")
			continue
call(n)
print("")

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

for i in range(1, n + 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())

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

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

print()

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

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


def f(x):
    if not x:
        return

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

    return f(x)


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

print("")

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

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

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):
n = int(input())
i = 1
l = []
while i <= n:
  x = i
  if x % 3 == 0:
    l.append(i)
  else:
    while x:
      if int(x) % 10 == 3:
        l.append(i)
        break
      x /= 10
  i += 1
for n in l:
  print(" {0}".format(n), end='')
print('', sep='\n')

Solution (Python):


n = int(input())

i = 1
ans = ""
while i <= n:
    x = i
    if x % 3 == 0:
        ans += (" " + str(i))
    else:
        while x:
            if x % 10 == 3:
                ans += (" " + str(i))
                break
            else:
                x = x // 10
    i += 1
print(ans)

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

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

index = 1
while index <= number:
    current = index
    if current % 3 == 0:
        print(f" {index}", end="")
    else:
        while current != 0:
            if current % 10 == 3:
                print(f" {index}", end="")
                break
            current //= 10
    index += 1 
print("")

Solution (Python):
write = open(1, 'w').write
for i in range(1, int(open(0).read())+1):
    if i % 3:
        if "3" in str(i):
            write(" %d" % i)
    else:
        write(" %d" % i)
write("\n")

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

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

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

print("")

Solution (Python):

i = 1
x = i
n = int(input())

while i <= n:
    x = i
    check = False

    while True:
        if x % 3 == 0 and check == False:
            print(" %s" % i,end="")
            break
        elif x % 10 == 3:
            print(" %s" % i,end="")
            break
        else:
            x /= 10
            x = int(x)
            check = True
            if x <= 0:
                break

    i += 1
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):
a = int(input())

for i in range(1,a+1):
    if str(3) in str(i):
        print("",i,end="")
    elif i%3 == 0:
        print("",i,end="")
    elif i%10 == 3:
        print("",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:
    print(" {}".format(i), end = "")
  else:
    x = i
    while x:
      if x % 10 == 3:
        print(" {}".format(i), end = "")
        break
      x = x // 10
print()

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

Solution (Python):


def cal(x,i,answer):
    if x >0:
        x//=10
        if x%10==3:
            answer.append(i)
        else:
            cal(x,i,answer)

def main():
    number = int(input())
    answer=[""]
    for i in range(1,number+1):
        x=i
        if x%3 ==0:
            answer.append(i)
        elif x%10==3:
            answer.append(i)
        else:
            cal(x,i,answer)
    print(*answer)

if __name__=="__main__":
    main()

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):
print('',*[i for i in range(3,int(input())+1)if i%3==0 or'3'in str(i)])

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

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

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

s = ""

for i in range(n):
  if ((i+1)%3 == 0) or ("3" in str(i+1)):
    s +=  " " + str(i+1)

print(s)

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

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(" {}".format(i),end="")
print()

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