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

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

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

  while True:
    if x % 10 == 3:
      output += " "
      output += str(i)
      break
    else:
      x /= 10
      if x == 0:
        break
print output

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

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

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

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

Solution (Python):
from itertools import accumulate, repeat, takewhile
(lambda n:
    (lambda include3:
        print('',
              *filter(None,
                      map(lambda i: i if i % 3 == 0 else include3(i),
                          range(1, n+1)))))(
        (lambda x:
            next(map(lambda _: x,
                     filter(lambda d: d % 10 == 3,
                            takewhile(bool,
                                      accumulate(repeat(x),
                                                 lambda a, _: a // 10)))),
                 None))))(int(input()))

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

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

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

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

numbers = ""

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

print(numbers)

Solution (Python):
n = input()
x = 1
print '',
while True:
    if x > n:
        break
    if (x % 3 == 0) or ('3' in str(x)):
        print x,
    x += 1

Solution (Python):
n = input()
x = 1
print '',
while True:
    if x > n:
        break
    if (x % 3 == 0) or ('3' in str(x)):
        print x,
    x += 1

Solution (Python):
import sys

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

Solution (Python):
num = input()
print "",
for x in xrange(1,num+1):
    if x%3==0:
        print x,
    elif "3" in str(x):
        print x,
    else:
        pass

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

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

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

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

Solution (Python):
import sys

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

i = 0
while i < n:
    i = i+1
    x = i
    if x%3 == 0 or str(x).find( "3" ) > -1:
        sys.stdout.write( " " + str(i) )
        continue
print

sys.exit(0)

Solution (Python):
l = int(raw_input())
print "",
for i in range(l+1):
	if i//3 != 0:
		if i%3 ==0:
			print i,
		elif "3" in str(i):
			print i,

Solution (Python):


import sys


n = int(input())

display = []
for i in range(n):
    num = i + 1
    
    if (num % 3 == 0):
        display.append(num)
        continue

    
    original = num
    while (num != 0):
        last_digit = int(num % 10)
        if (last_digit == 3):
            display.append(original)
            num = 0
        num = int(num / 10)

for x in display:
    
    sys.stdout.write(' ' + str(x))
print('')

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

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

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

tmp1 = 3

while tmp1 <= n:
    if tmp1 % 3 == 0:
        string =  ' ' + str(tmp1)
        sys.stdout.write(string )
    else:
        tmp2 = tmp1
        while tmp2 > 0:
            if tmp2 % 10 == 3:
                string = ' ' + str(tmp1)
                sys.stdout.write(string)
                break
            tmp2 /= 10
    tmp1 += 1
    
print ""

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

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

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

Solution (Python):
n = input()
x = 1
print '',
while True:
    if x > n:
        break
    if (x % 3 == 0) or ('3' in str(x)):
        print x,
    x += 1

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

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

Solution (Python):
def check(a,x):
    if x == 3 :
        print a,
    elif x % 10 == 3:
        print a,
    elif x :
        check(a,x/10)
        
        
n = input()
print"",

for i in range(3,n+1) :
    if i % 3 == 0 :
        print i ,
    elif i%10 == 3 :
        print i,
    else :
        check(i,i/10)

Solution (Python):
def check(a,x):
    if x == 3 :
        print a,
    elif x % 10 == 3:
        print a,
    elif x :
        check(a,x/10)
        
        
n = input()
print"",

for i in range(3,n+1) :
    if i % 3 == 0 :
        print i ,
    elif i%10 == 3 :
        print i,
    else :
        check(i,i/10)

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

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):
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):
n = int(raw_input())
s = ''

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

Solution (Python):
import sys
n = input()
for i in range(1,n+1):
  x = i
  if x%3==0:
    sys.stdout.write(' %d' % i)
    continue
  while x<=n:
    if x%10==3:
      sys.stdout.write(' %d' % i)
      break
    else:
      x /= 10
      if x==0:
        break
sys.stdout.write('\n')

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

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

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

print "",

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

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

Solution (Python):


m = []
a = 0
for i in range(input()+1):
    if i == 0:
        continue
    if i % 3 == 0:
        m.append(str(i))
    else:
        a = i
        while True:
            if a % 10 == 3:
                m.append(str(i))
                break
            a /= 10
            if a == 0:
                break
print " " + " ".join(m)

Solution (Python):
n=input()
print "",
for i in xrange(1,n+1):
    if i%3==0 or '3' in str(i):
        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):
n = input()
result = ""
for x in xrange(1,n+1):
    if x % 3 == 0:
        result = result + " " + str(x)

    elif x % 10 == 3:
        result = result + " " + str(x)

    else :
        i = x
        while i :
            i /= 10
            if i % 10 == 3:
                result = result + " " + str(x)
                break
print result

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

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

Solution (Python):
class StructuredProgramming:
    def call(self, n):
        s = ""
        i = 1
        while i <= n:
            x = i
            if x % 3 == 0:
                s += " %d" % (i)
            else:
                while x:
                    if x % 10 == 3:
                        s += " %d" % (i)
                        break
                    x /= 10
            i += 1
        print s

if __name__ == "__main__":
    sp = StructuredProgramming()
    n = int(raw_input())
    sp.call(n)

Solution (Python):
n = input()
print(""),

for i in range(1, n+1):
    k = 1
    a = 0
    x = i
    if x%3 == 0:
        print i,
    else:
        while x != 0 and a == 0:
            if x%10 == 3:
                print i,
                a = 1
                k = 2
            else:
                x = x/10

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

n = int(input())
s=''

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

Solution (Python):
n = int(raw_input())
cout = ""

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

	if (x%3) == 0:
		cout = cout + " " + str(i)
		continue

	while x > 0:
		if (x%10) == 3:
			cout = cout + " " + str(i)
			break
		x /= 10

print cout

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

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):
A = int(input())
for i in range(3, A + 1):
  if i%3 == 0 or i%10 == 3 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:
        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):
import sys
import math

n = input()

for x in xrange(1, n+1) :
    if x % 3 == 0 or str(x).find("3") != -1 :
        sys.stdout.write(" " + str(x))
print

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

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

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

print(end = " ")
print(*l)

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

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

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

print("")

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

print(ans)

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

Solution (Python):
def call(n):
	i = 1
	while True:
		through_flag = False
		x = i
		if x % 3 == 0:
			print(" {}".format(i), end="")
			through_flag = True
		if not through_flag:
			while True:
				if x % 10 == 3:
					print(" {}".format(i), end="")
					through_flag = True
				if not through_flag:
					x //= 10
					if x == 0: break
				if through_flag: break
		i += 1
		if i > n: break
	print("")



call(int(input()))

Solution (Python):
def call(n):
    s = ""
    for x in range(1, n + 1):
        y = x
        if y % 3 == 0:
            s = s + " " + str(x)
        else:
            while y != 0:
                if y % 10 == 3:
                    s = s + " " + str(x)
                    break
                y = int(y / 10)
    return s

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

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

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

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

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

for x in range(3,n+1):
    if x % 3 == 0:
        L.append(x)
    else:
        i = x
        while i != 0:
            if i % 10 == 3:
                L.append(x)
                break
            else : i /= 10

print "",

while L != []:
    print L.pop(0),

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

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

Solution (Python):
n = int(raw_input())
i = 1
print "",

while i <= n:
  if i%3 == 0:
      print i,
  else:
      I = str(i)
      for j in range(len(I)):
          if I[j] == '3':
              print I,
              break
  i += 1

Solution (Python):
n = int(input())
result = ['']

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

print(*result)

Solution (Python):
N = int(input())
Plist = []
i=1
print(" ",end="")
while i <= N:
    k=1
    if i%3 == 0:
        Plist.append(i)
    elif i%10 == 3:
        Plist.append(i)
    else:
        while i//k>1 and k>=0:
            if i//k%10 == 3:
                Plist.append(i)
                break
            else:
                k = k*10
    i=i+1
print(' '.join(map(str,Plist)))

Solution (Python):



n = input()

print "",
for i in xrange(1, n+1):
    if i % 3 == 0:
        print i,
    elif "3" in str(i):
        print i,

Solution (Python):
n = input()
x = 1
print '',

while True:
    if x > n:
        break
    if (x % 3 == 0) or ('3' in str(x)):
        print x,
    x += 1

Solution (Python):
import sys

def call(n):
    i = 1
    while i <= n:
        x = i
        if x % 3 == 0:
            print(' ', i, sep='', end='')
        else:
            while x:
                if x % 10 == 3:
                    print(' ', i, sep='', end='')
                    break

                x //= 10
            
        i += 1
        
    print('')
    
if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    call(n)

Solution (Python):
def include3(n):
    while n!=0:
        if n%10 == 3:
            return True
        n //= 10
    return False
n = int(input())
d = [x for x in range(1 ,n+1) if (x % 3 == 0)|(x % 10 == 3)|(include3(x))]
s = ''
for i in d:
    s += ' {}'.format(i)
print(s)

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

Solution (Python):
n = [int(x) for x in input().split()]

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

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

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

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

Solution (Python):

def getLnInput():
    return input().split()



def ceilDivision(a, b):
    return (a - 1) // b + 1


def call(n):
    i = 1
    while i < n:
        i += 1
        x = i
        if not x % 3:
            print(" " + str(i), end="")
        else:
            while True:
                if x % 10 == 3:
                    print(" " + str(i), end="")
                    break
                x //= 10
                if not x:
                    break
    print()


def main():
    n = int(getLnInput()[0])
    call(n)
    return


main()

Solution (Python):
n = input()
i = 1
num = []
while i <= n:
    if i % 3 == 0:
        num.append(i)
        i +=1
    else:
        x = i
        while x > 0:
            if x % 10 == 3:
                num.append(i)
                break
            elif x / 10 == 3:
                num.append(i)
                break
            else:
                x /=  10                
        i += 1
print("{}".format(str(num)).replace("["," ").replace("]","").replace(",",""))

Solution (Python):
n = input()
i = 1
num = []
while i <= n:
    if i % 3 == 0:
        num.append(i)
        i +=1
    else:
        x = i
        while x > 0:
            if x % 10 == 3:
                num.append(i)
                break
            else:
                x /=  10                
        i += 1
print("{}".format(str(num)).replace("["," ").replace("]","").replace(",",""))

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):
def contains3(n):
    x = n
    while x > 0:
        if x % 10 == 3:
            return True
        else:
            x //= 10
    return False

x = int(input())
out = ""
for i in range(x):
    n = i + 1
    if n % 3 == 0 or contains3(n):
        out += (" %d" % n)
print(out)

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

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

Solution (Python):
import sys

n = int(raw_input())
i = 1
while i <= n:
    x = i
    if x%3 == 0:
        sys.stdout.write(' '+str(i))
        i += 1
        continue
    while x != 0:
        if x%10 == 3:
            sys.stdout.write(' '+str(i))
            break
        x /= 10
    i += 1
print

Solution (Python):
import sys

input_num = int(sys.stdin.readline())

ans = ''
for i in range(3, input_num + 1):
    if i % 3 == 0 or '3' in str(i):
        ans += ' ' + str(i)
print ans

Solution (Python):
from __future__ import print_function
n = int(raw_input())

for i in range(n+1):
    if i != 0 and i % 3 == 0:
        print (" %i" % i, end="")
    elif i != 0 and i % 10 == 3:
        print (" %i" % i, end="")
    else:
        if str(i).find('3') >= 0:
            print (" %i" % i, end="")
print("")

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

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

Solution (Python):
if __name__ == '__main__':
    limit = int(input())

    data = []
    for i in range(3, limit+1):
        if (i % 3) == 0 or (i % 10 == 3) or '3' in str(i):
            data.append(str(i))

    txt = ' '.join(data)
    print(' {0}'.format(txt))

Solution (Python):
if __name__ == '__main__':
    limit = int(input())

    data = []
    for i in range(3, limit+1):
        if (i % 3) == 0 or '3' in str(i):
            data.append(str(i))

    txt = ' '.join(data)
    print(' {0}'.format(txt))

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

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

Solution (Python):
import sys

n = int(input())
for i in range(1, n + 1):
  x = i
  if x % 3 == 0:
    sys.stdout.write(" %d" % i)
  else:
    while x > 1:
      if x % 10 == 3:
        sys.stdout.write(" %d" % i)
        break
      x //= 10
print()

Solution (Python):
def call(n):
    s = ""
    i = 1
    while i <= n:
        x = i
        if x%3 == 0:
            s += " {0}".format(i)
        else:
            while x > 0:
               if x%10 == 3:
                   s += " {0}".format(i)
                   break
               x = x // 10
        i += 1
    print(s)

m = int(input())
call(m)

Solution (Python):
def call(n):
    s = ""
    i = 1
    while i <= n:
        x = i
        if x%3 == 0:
            s += " {0}".format(i)
        else:
            while x > 0:
               if x%10 == 3:
                   s += " {0}".format(i)
                   break
               x = x // 10
        i += 1
    print(s)

m = int(input())
call(m)

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

m = int(input())
call(m)

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

m = int(input())
call(m)

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

m = int(input())
call(m)

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

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