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 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.



Sample input:
30


Sample output:
 3 6 9 12 13 15 18 21 23 24 27 30

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

lis = ['']
for i in range(1, n+1):
    if i%3==0 or '3' in list(str(i)):
        lis.append(i)
        
print(*lis)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

for i in range(1, n + 1):
    if i % 3 == 0 or i % 10 == 3 or '3' in str(i):
        print('',i,end='')      #改行なしで出力したい時に「end=''」を使います。
    else:
        print(end='')
print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def call(n):
    i = 1
    while True:
        x = i
        if x%3 == 0:
            print(f' {i}', end = '')
        else:
            while True:
                if x%10 == 3:
                    print(f' {i}', end = '')
                    break
                x //= 10
                if x == 0:
                    break
        i = i + 1
        if i > n:
            break
    print()

call(int(input()))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

ans = []
while True:
    if n % 3 == 0:
        ans.append(n)
    elif str(n).find('3') != -1:
        ans.append(n)
    n -= 1
    if n < 3:
        break

print('',*ans[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())

num =[]

for i in range(1, a + 1):
    if i % 3 == 0:
        num.append(i)
        
    x = str(i)
    x = list(x)

    if ("3" in x) and (i not in num):
        num.append(i)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

i = 1

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())

out = ""

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

print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
table = []

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

print(' ', end="")
print(' '.join(map(str, table)))

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
n = int(input())

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

print(' '+' '.join(list(map(str, int_list))))

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

def checker(n):
    n = str(n)
    n_list = list(n)
    for i in n_list:
        if i == "3":
            return True

n = int(input())
ans =[]
for i in range(1, n+1, 1):
    if i%3==0 or checker(i):
        ans.append(i)

print("", *ans, sep=" ")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
lst = []
ans = " "
for i in range(1, num+1):
  if i % 3 == 0:
    lst.append(i)
  else:
    nume = []
    k = i
    while k > 0:
      if k % 10 == 3:
        lst.append(i)
        break;
      else:
        k //= 10 # 必須
length = len(lst)
for j in range(length-1):
  ans += str(lst[j]) + " "
ans += str(lst[length-1])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

print()

Submission status: Accepted

Solution code:
#2020-03-18
num = int(input())
for i in range(1,num+1):
    if i % 3 == 0 or  "3" in str(i):
        print(f" {i}",end="")
print()

Submission status: Accepted

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



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

Submission status: Accepted

Solution code:
num = int(input())

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

Submission status: Accepted

Solution code:
n = int(input())
def divn(x, i, d, m):
    if x % d == m:
        print("", i, end="")
        return True
    return False

def call(i):
    x = i
    if divn(x, i, 3, 0):return
    if divn(x, i, 10, 3):return
    tmp = 1
    while tmp:
        x = x // 10
        tmp = x
        if not tmp:return
        if divn(x, i, 10, 3):return
    return

for i in range(n):
    call(i+1)
print("")

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num=int(input())

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

Submission status: Accepted

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

print()

Submission status: Accepted

Solution code:
n = int(input())

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

print()

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
n = int(input())
ans = ' '
for i in range(1, n+1):
    x = i
    if x%3 == 0:
        ans += str(i) + ' '
    elif "3" in str(x):
        ans += str(i) + ' '
print(ans[0:-1])

Submission status: Accepted

Solution code:
x=int(input())
n=[]
for i in range(3,x+1):
	if i%3==0:
		n.append(i)
	elif '3' in str(i):
		n.append(i)
c=0
for j in n:
	n[c]=str(j)
	c+=1
print(' '+' '.join(n))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 構造化プログラミング

n = int(input())

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

Submission status: Accepted

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

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

print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_value = input()

n = int(input_value)

numbers = range(1, n + 1)

multiples_of_three = [i for i in numbers if i % 3 == 0]

numbers_with_three = [i for i in numbers if '3' in str(i)]

related_three = multiples_of_three + numbers_with_three

related_three.sort()

sorted_related_three = sorted(set(related_three), key=related_three.index)

multiples_and_with_three_strings = list(map(str, sorted_related_three))

print(' ' + ' '.join(multiples_and_with_three_strings))

Submission status: Accepted

Solution code:
x=[]
for i in range (1,int(input())+1):
  if i%3==0:
    x.append(str(i))
  elif i%10==3:
    x.append(str(i))
  elif 30<=i%100<40:
    x.append(str(i))
  elif 300<=i%1000<400:
    x.append(str(i))
  elif 3000<=i%10000<4000:
    x.append(str(i))
print(""," ".join(list(map(str,x))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = ""
for i in range(n):
    i += 1
    if i % 3 == 0:
        s += " " + str(i)
    else:
        x = i
        while True:
            if x % 10 == 3:
                s += " " + str(i)
                break
            elif x == 0:
                break
            x //= 10
print(s)

Submission status: Accepted

Solution code:
n = int(input())
i = 1
k = ""
while i <= n:
    if i%3 == 0:
        print(k, end=" ")
        k = i
    else:
        m = i
        while m//10 > 0:
            if m%10 == 3 or m//10 == 3:
                print(k, end=" ")
                k = i
                m = 0
            else:
                m = m//10
    i += 1
    
print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
a = int(input())
ans = []
for i in range(1,a+1):
    if i % 3 == 0:
        ans.append(str(i))
    elif "3" in str(i):
        ans.append(str(i))

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inc3(i):
    if i - (i // 10)*10 == 3:
        return(True)
    elif i//10==0:
        return(False)
    else:    
        return(inc3(i//10))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans_list = list()

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

print('', ' '.join(ans_list))

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

n= int(input())
#tmp= float(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = []
for i in range(1,n+1):
    if i % 3 == 0 or i % 10 == 3:
        ans.append(i)
    else:
        tmp =  i // 10
        while True:
            if tmp == 0:
                break
            if tmp % 10 == 3:
                ans.append(i)
                break
            tmp //= 10


print(' ',end='')
print(*ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
i = x = 1
ans = ""
inc = True
while True:
    if (x % 3) == 0 and inc:
        ans = " " + str(i)
        print(ans, end='')
    elif (x % 10) == 3:
        ans = " " + str(i)
        print(ans, end='')
    else:
        x //= 10
        if x != 0:
            inc = False
            continue
    i += 1
    if i <= n:
        x = i
        inc = True
        continue
    break
print()

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
def main():
    num = int(input())
    #origin(num)
    origin2(num)

def origin2(n):
    i = 1
    while i <= n:
        x = i
        if x % 3 == 0:
            print(' %d' % i, end='')
            i += 1
            continue
        else:
            while x != 0:
                if x % 10 == 3:
                    print(' %d' % i, end='')
                    break
                else:
                    x //= 10
            # end of while x:
        i += 1
    # end of while 1 <= n: 

if __name__ == '__main__':
    main()
    print()

Submission status: Accepted

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

s = input()
call(int(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lst = []
for i in range(1, n + 1):
    if i % 3 == 0:
        lst.append(i)
    if '3' in str(i):
        lst.append(i)

lst = set(lst)
lst = [str(i) for i in lst]
print(' ' + ' '.join(lst))

Submission status: Accepted

Solution code:
num = int(input())
x = 0
for i in range(1,num+1):
    if i % 3 == 0:
        print(end=" ")
        print(i, end="")
    elif "3" in str(i):
        print(end=" ")
        print(i, end="")
print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = []
for i in range(1,n+1):
    fixi = i
    if i % 3 == 0:
        A.append(i)
    else:
        for j in range(1, len(str(fixi)) + 1):
            if i % 10 == 3:
                A.append(fixi)
                break
            else:
                i = int(i / 10)

print("", *A)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
i = 1
while i <= n:
  if not i % 3 or '3' in str(i):
    print(' {}'.format(i), end='')
  i += 1
print()

Submission status: Accepted

Solution code:
def call(n: int) -> list:
    ret = []
    for i in range(1, n+1):
        if i%3 == 0:
            ret.append(i)
            continue

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

            x //= 10

    return ret

n = int(input())
print(" ", end="")
print(*call(n))

Submission status: Accepted

Solution code:
n = int(input())
num = []
for i in range(1, n+1):
    if i % 3 == 0:
        num.append(str(i))
    elif list(str(i)).count('3') > 0:
        num.append(str(i))

ans = ' '.join(num)
print(' {}'.format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

def aaa(a, b):
    if a % 10 == 3:
        print(f' {b}', end='')
    
    elif (a // 10 > 0):
        aaa(a // 10, b)

for i in range(1, n + 1):
    if i % 3 == 0:
        print(f' {i}', end='')
    
    else:
        aaa(i, i)
        
print()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    call(int(input()))


def call(n):
    i = 1
    while True:
        x = i
        # CHECK_NUM
        if int(x % 3) == 0:
            print(" {}".format(i), end="")
        else:
            # INCLUDE3
            while True:
                if (x % 10) == 3:
                    print(" {}".format(i), end="")
                    break
                else:
                    x = int(x / 10)
                    if not(x):
                        break
        # END_CHECK_NUM
        i += 1
        if n < i:
            break

    print("")

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
for i in range(1,n+1):
    flag=0
    j=i
    while j>=1:
        j,a=divmod(j,10)
        if a==3:
            flag=1
            break
    if i%3==0 or flag==1:
        print(" %d"%i,end="")
print("")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
count = int(input())
result = ""

for i in range(1, count + 1):
    if i % 3 == 0 or ("3" in str(i)) == True:
        result += f" {i}"

print(result)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:



#３の倍数か、個数桁に３を含むかを確認する


def check_num(n):
    #３の倍数か、最下位に3を含むかをチェックする
    return 1 if (n%10 == 3 or n%3 ==0) else 0

def include_3(n):
    #３の倍数か、最下位に3を含むかをチェックする
    return 1 if (n%10 == 3 ) else 0

str_n = input()
int_n = int(str_n)

for i in range(1,int_n+1):
    #最下位桁チェック
    if check_num(i):
        print('',i, end="")
        continue
    else: #上位桁チェック
        x = i
        while True:
            x = x//10
            if x == 0:#上位桁もない
                break
            if include_3(x):
                print('',i, end="")
                break

print()

Submission status: Accepted

Solution code:
def call(n):
    for i in range(1,n+1):
        # 3で割れるかを判定する
        if i % 3 == 0:
            print(f' {i}',end='')
        else:
            # 数字に3が含まれるかを判定する
            tmp = i
            while tmp > 0:
                if tmp % 10 == 3:
                    print(f' {i}',end='')
                    break
                tmp //= 10
    #末尾で改行
    print()


call(int(input()))