limit = gets.to_i
numbers = []
result = ""
3.upto(limit) { |num|
    if num % 3 == 0 || num.to_s.include?("3") then
        numbers << num
    end
}
numbers.each { |num| 
    result+=" #{num}"
}
puts result

