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


def main():
    n = int(sys.stdin.readline())
    i = 1
    while i <= n:
        x = i
        if x % 3 == 0:
            print(' {}'.format(i), end='')
        else:
            while x > 1:
                if int(x) % 10 == 3:
                    print(' {}'.format(i), end='')
                    break
                x /= 10
        i += 1
    print()
    return


if __name__ == '__main__':
    main()

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

Solution (Python):

N = int(input())

ans = [" " + str(i) for i in range(1, N + 1) if i % 3 == 0 or '3' in str(i)]
print("".join(ans))

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

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

	if x % 3 == 0:
		print("", i, end = "")
		continue

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

		x //= 10

		if x != 0:
			continue

		break
print()

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

Solution (Python):
a = int(input())
b = []
for i in range(1,a+1):
    if i%3 == 0:
        b.append(i)
    elif i%10 == 3:
        b.append(i)
    elif (i//10)%10 == 3:
        b.append(i)
    elif((i//10)//10)%10 == 3:
        b.append(i)
    elif((i//10)//10)//10%10 == 3:
        b.append(i)
    elif((i//10)//10)//10//10%10 == 3:
        b.append(i)
    elif((i//10)//10)//10//10//10%10 == 3:
        b.append(i)
    else:
        continue
for i in b:
    print(" "+str(i),end="")
print("\n",end="")

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

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


def call(m: int) -> str:
    result = ""
    for i in range(1, m + 1):
        if i % 3 == 0 or '3' in str(i): 
            result += " " + str(i)
    return result


print(call(k))

Solution (Python):
n = int(input())
num_list = [i for i in range(1,n+1)]
num2_list = [i for i in num_list if i%3==0]
list_str = [s for s in map(str,num_list) if '3' in s]
list_in = list(map(int,list_str))
list_uniq = list(set(num2_list+list_in))
list_uniq.sort()
print(' '+' '.join(str(i) for i in list_uniq))

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

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):
from sys import stdout
n = int(input())
i = 1

while True:
    x = i
    if x % 3 == 0:
        stdout.write(" " + str(i))
    else:
        while x:
            if x % 10 == 3:
                stdout.write(" " + str(i))
                break
            x //= 10
    i += 1
    if i > n: break
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):
import re
list = []
n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0 or re.search('3', str(i)):
        list.append(str(i))
print('', ' '.join(list))

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

x = int(input())
for i in range(1,x+1):
    if i%3==0:
        print(f" {i}",end="")
        continue
    r=i
    while True:
        if r<=0:
            break
        if r%10==3:
            print(f" {i}",end="")
            break
        r//=10
print("")

Solution (Python):
n = int(input())
x = 1
y = ""
z = 1
while True:
    z = 1
    x += 1
    if x % 3 == 0:
        y += " "
        y += str(x)
    else:
        while True:
            b = int(x % 10 ** (z - 1))
            a = int((x - b) / 10 ** z)
            c = a % 10 ** z
            d = a % 10 ** (z - 1)
            if a == 3 or b == 3 or c == 3 or d == 3:
                y += " "
                y += str(x)
                break
            z += 1
            if a < 3 and z > 3:
                break
    if x >= n:
        break
print(y)

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

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
print(" ", end="")
print(*([x for x in range(3, n+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 or i % 10 == 3:
        print(' %d' % i, end='')
    else:
        tmp = i
        while tmp is not 0:
            tmp //= 10
            if tmp % 10 == 3:
                print(' %d' % i, end='')
                break
print()

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

Solution (Python):
num = int(input())
for i in range(1, num + 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())
a =[]
for i in range(1, n+1):
    if i % 3 == 0 or i % 10 == 3 or (i%100)//10 == 3 or (i%1000)//100 == 3 or (i%10000)//1000 == 3:
        a.append(i)
print(' ', end ='')
print(*a)

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):
inData = int(input())

seqData = list(range(1,inData+1,1))
outData = [0] * inData
for thisData in seqData:
    if thisData == inData:
        if thisData%3 == 0 or thisData%10==3:
            print(" "+str(thisData))
        else:
            for i in range(5):
                i=i+1
                over =  10 ** i
                tmp = thisData/over
                if int(tmp % 10) == 3:
                    print(" "+str(thisData))
                    break
                else:
                    pass
            print("")
    else:
        if thisData%3 == 0 or thisData%10==3:
            print(" "+str(thisData), end = "")
        else:
            for i in range(5):
                i=i+1
                over =  10 ** i
                tmp = thisData/over
                if int(tmp % 10) == 3:
                    print(" "+str(thisData), end = "")
                    break
                else:
                    pass

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

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

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

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

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

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

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

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

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

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, sep = "", end = "")
		i += 1
	else :
		pass
print()

Solution (Python):
def nabeatsu(n):
    if(n % 3 == 0):
        return True
    temp = n
    while(temp > 0):
        if(temp % 10 == 3):
            return True
        temp = temp // 10
    return False

x = int(input())
for i in range(x):
    if(nabeatsu(i + 1)):
        print(' ', end = '')
        print(i + 1, end = '')
print()

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

print(ret)

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())
res = [i for i in range(3, n+1) if (i % 3 == 0) or ("3" in str(i))]
print(" ",end="")
print(*res)

Solution (Python):
x = int(input())
k = []
for i in range(1, x + 1):
    y = i
    if i % 3 == 0:
        k.append(i)
    else:
        while True:
            if y % 10 == 3:
                k.append(i)
                break
            else:
                if y <= 10:
                    break
                else:
                    y //= 10

print(' '+ ' '.join([str(x) for x in k]))

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(" {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())
list = []
for i in range(3, n + 1):
    if i % 3 == 0:
        list.append(i)
    else:
        x = i
        while x:
            if x % 10 == 3:
                list.append(i)
                break
            else:
                x = x // 10
print("", *list)

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

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):
def call(n):
    ans = []

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

        while x:
            if x % 10 == 3:
                ans.append(i)
                break
            x //= 10

    print(" " + " ".join(map(str, ans)))


if __name__ == '__main__':
    from sys import stdin

    n = int(stdin.readline().rstrip())

    call(n)

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

while y <= n :
    if(y % 3 == 0):
        print(' %d'%y,end='')
    else:
        p = y
        while(p != 0):
            if(p % 10 == 3):
                print(' %d'%y,end='')
                break
            p //= 10
    y+=1
print()

Solution (Python):
a = int(input())
for x in range(1,a+1):    
    if x % 3 == 0 or "3" in str(x):
        print(" {}".format(x),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 str(i).find("3") != -1:
        print(" %d" %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(' '+ str(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):
import sys
write = sys.stdout.write
n = input()
i = 1
while i <= n:
	if i % 3 == 0:
		write(' ' + str(i))
	elif i % 10 == 3:
		write(' ' + str(i))
	else:
		j = i
		while j > 0:	
			j /= 10
			if j % 10 == 3:
				write(' ' + str(i))
				break;
	i += 1
print \

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

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

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

Solution (Python):
def call(n):
    res = []
    for i in range(1, n + 1):
        if i % 3 == 0:
            res.append(str(i))
        elif '3' in str(i):
            res.append(str(i))
    print(' ' + ' '.join(res))

call(int(input()))

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

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

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

print "",

for i in xrange(3,n+1):
	x = i
	if x % 3 == 0:
		print i,
		continue
	while x:
		if x % 10 == 3:
			print i,
			break

		elif x / 10 != 0:
			x = x / 10
			continue
		else:
			break

Solution (Python):
import sys
def call(n):	
	for i in xrange(1, n+1):
		if (i % 3) == 0:
			sys.stdout.write(" " + str(i))
		elif (i % 10) == 3:
			sys.stdout.write(" " + str(i))
		else:
			x = i
			x = x / 10
			while x > 0:
				if (x % 10) == 3:
					sys.stdout.write(" " + str(i))
					break
				x = x / 10
				
	print ""
	

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

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

Solution (Python):
x = input()
o = filter(lambda n: n%3 == 0 or '3' in str(n), range(1,x+1))

print " "+" ".join(map(str,o))

Solution (Python):
print " "+" ".join(map(str,filter(lambda n:n%3==0 or '3' in str(n),range(1,input()+1))))

Solution (Python):
import sys
def call(n):
    i = 1
    flg = 1
    while True:
        x = i
        if x % 3 == 0:
            sys.stdout.write(" "+str(i))
            flg = 0
        while flg == 1:
            if x % 10 == 3:
                sys.stdout.write(" "+str(i))
                flg = 0
            x /= 10
            if not x:
                flg = 0
        if i < n :
            i = i+1
            flg = 1
        else:
            sys.stdout.write("\n")
            break
n = input()
call(n)

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

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

ans = []
i = 1

while True:
    """CHECK_NUM"""
    x = i
    if x % 3 == 0:
        ans.append(str(i))
    else:
        while True:
            """INCLUDE3"""
            if x % 10 == 3:
                ans.append(str(i))
                break

            x = int(x / 10)
            
            if x != 0: 
                continue
            else: 
                break
    i += 1
    if i <= n:
        continue
    else:
        break

print(" " + " ".join(ans))

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

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

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

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

Solution (Python):
n = int(raw_input())
print "",
for e in [i for i in range(1,n+1) if i%3==0 or str(i).count('3')>0]: print e,

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

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

Solution (Python):
n = int(raw_input())
i=1
x=i
nums = []


def include3():
    global n
    global i
    global x
    global nums

    while True:
        if x % 10 == 3:
            nums.append(str(i))
            if end_check_num():
                return 0
            return 1

        x /= 10
        if x==0:
            if end_check_num():
                return 0
            return 1
    return 1

def end_check_num():
    global n
    global i
    global x

    i+=1
    if i <= n:
        return False
    return True


while True:
    x=i
    if x % 3==0:
        nums.append(str(i))
        if end_check_num():
            break
        continue
    if 0==include3():
        break

print " " + " ".join(nums)

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

Solution (Python):
n=int(raw_input())
i = 1
print "",
while(i<=n):
    x=i
    if x%3 is 0:
        print i,
    elif x%10 is 3:
        print i,
    elif (x/10)%10 is 3:
        print i,
    elif (x/10**2)%10 is 3:
        print i,
    elif (x/10**3)%10 is 3:
        print i,
    elif (x/10**4)%10 is 3:
        print i,
    i = i+1

Solution (Python):
n=int(raw_input())
i = 1
print "",
while(i<=n):
    x=i
    if x%3 is 0:
        print i,
    elif x%10 is 3:
        print i,
    elif (x/10**1)%10 is 3:
        print i,
    elif (x/10**2)%10 is 3:
        print i,
    elif (x/10**3)%10 is 3:
        print i,
    elif (x/10**4)%10 is 3:
        print i,
    i = i+1

Solution (Python):
n=int(raw_input())
i = 1
print "",
while(i<=n):
    x=i
    if x%3 is 0:
        print i,
    else:
        for j in xrange(0,4):
            if (x/10**j)%10 is 3:
                print i,
                break
    i = i+1

Solution (Python):
import sys

n = input()

for i in range(1,n+1):
    x = i
    y = i
    flag = 0
    if(x % 3 == 0):
        flag = 1
        sys.stdout.write(" ")
        sys.stdout.write(str(x))
        if(i+1 > n):
            break

    while(1):
        if flag == 1:
            break
        if(y % 10 == 3):
            sys.stdout.write(" ")
            sys.stdout.write(str(x))
            break
            if(i+1 > n):
                break
        y = y/10
        if(y == 0):
            break
print

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

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

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

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

Solution (Python):
for i in range(3, int(input()) + 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:
        print(' {0}'.format(i), end='')
        continue

    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):
    x = i
    if x % 3 == 0:
        print(' {0}'.format(i), end='')
        continue

    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):
  x = i
  if x % 3 == 0:
    print(' {0}'.format(i), end='')
    continue

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

print()

Solution (Python):
n = input()
array = []
i = 1
while i <= n:
    x = i
    if x % 3 == 0:
        array.append(i)
    else:
        while x != 0:
            if x % 10 == 3:
                array.append(i)
                break
            x /= 10
    i += 1
print str(array).replace('[', ' ').replace(']', '').replace(',', '')

Solution (Python):
import sys

def call(n):
    nums = []
    for i in range(1, n + 1):
        if i % 3 == 0:
            nums.append(str(i))
            continue
        x = i
        while x > 0:
            if x % 10 == 3:
                nums.append(str(i))
                break
            x = int(x / 10)
    print('', ' '.join(nums))

n = int(sys.stdin.readline())
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):
for i in range(1,int(input())+1):
    x=i
    if x % 3 == 0:
        print(" "+str(i), end="")
    else:
        while x != 0:
            if x % 10 == 3:
                print(" "+str(i), end="")
                break
            else:
                x = x//10
print("")

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

Solution (Python):
import itertools as itr

def call(n):
    def devided_3(x):
        return x % 3 == 0

    def has_3(x):
        return '3' in str(x)

    data = filter(lambda x: devided_3(x) or has_3(x), range(1, n+1))
    [print(' {0}'.format(i), end='') for i in data]
    print()

if __name__ == '__main__':
    n = int(input())
    call(n)

Solution (Python):


def PrintI(i):
	print(" ", i)
	return i + 1

if __name__ == "__main__":
	n = input()
	n = int(n)
	s = ""
	for i in range(1, n + 1):
		if i % 3 == 0:
			s += " " + str(i)
		elif "3" in str(i):
			s += " " + str(i)
	print(s)

Solution (Python):




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

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

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

Solution (Python):
import sys
n=int(input())
for i in range(1,n+1):
	if(i%3==0 or i%10==3 or '3' in str(i)):
		i=str(i)
		sys.stdout.write(' '+i)
		i=int(i)
print('')

Solution (Python):
import sys
n=int(input())
for i in range(1,n+1):
	if(i%3==0 or i%10==3 or '3' in str(i)):		
		sys.stdout.write(' '+str(i))		
print('')

Solution (Python):
import sys

n = int( sys.stdin.readline() )
output = []
for i in range( 1, n+1 ):
	x = i
	if x%3 == 0:
		output.append( " {:d}".format( i ) )
	else:
		while x:
			if x%10 == 3:
				output.append( " {:d}".format( i ) )
				break
			x /= 10
print( "".join( output ) )

Solution (Python):
import sys

n = int( sys.stdin.readline() )
output = []
for i in range( 1, n+1 ):
	x = i
	if x%3 == 0:
		output.append( " {:d}".format( i ) )
	else:
		while x != 0:
			if x%10 == 3:
				output.append( " {:d}".format( i ) )
				break
			x = x//10
print( "".join( output ) )

Solution (Python):
import sys

n = int( sys.stdin.readline() )
output = []
for i in range( 1, n+1 ):
	x = i
	if x%3 == 0:
		output.append( " {:d}".format( i ) )
	else:
		while x != 0:
			if x%10 == 3:
				output.append( " {:d}".format( i ) )
				break
			x = x//10
print( "".join( output ) )

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

Solution (Python):


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


def call(n):
	print '',
	for i in xrange(1, n+1):
		if check(i):
			print(i),
	print

def check(i):
	if i % 3 == 0:
		return True
	elif i % 10 == 3:
		return True
	elif i / 10 > 0:
		x = i
		x /= 10
		while (x > 0):
			if x % 10 == 3:
				return True
			else:
				x /= 10
	return False


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

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

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

Solution (Python):
def modz( x, n):
    a = x / n
    return x - a*n

if __name__ == "__main__":

    n = int(raw_input())

    s = ""
    i = 1

    while True:
        
        x = i;
        if modz(x , 3) == 0:
            s += " " + str(i)
        else:
            ex = 0
            while True:
                if modz(x , 10) == 3:
                    s += " " + str(i)
                    ex = 1
                    break
                x /= 10
                if x == 0:
                    ex = 1
                    break

        if (i+1) > n:
            i += 1
            break
        i += 1

    print s

Solution (Python):



def main():
    def sub():
        n = input()
        i = 1
        s = ''
        
        
        while True:
            x = i
            if x % 3 == 0:
                s += ' '+str(i)
                
                
                i += 1
                if i <= n:
                    
                    continue
                else:
                    
                    break
                
            
            
            while True:
                if x % 10 == 3:
                    s += ' '+str(i)
                    
                    
                    i += 1
                    if i <= n:
                        
                        break
                    else:
                        
                        return s
                    
                else:
                    x /= 10
                    if x:
                        
                        continue
                    else:
                        
                        
                        i += 1
                        if i <= n:
                            
                            break
                        else:
                            
                            return s
                        
            
        
        return s
    print sub()

if __name__ == '__main__':
    main()

Solution (Python):



def main():
    n = input()
    s = ''
    for i in range(1, n + 1):
        x = i
        if x % 3 == 0:
            s += ' ' + str(i)
            continue
        while x:
            if x % 10 == 3:
                s += ' ' + str(i)
                break
            x /= 10
    print s
    
if __name__ == '__main__':
    main()