def koch_curve a, b, n
  return if n == 0

  new_coords = [a, nil, nil, nil, b]

  a_x = a[0]
  a_y = a[1]
  b_x = b[0]
  b_y = b[1]
  new_coords[1] = [a_x + (b_x - a_x) / 3.0, a_y + (b_y - a_y) / 3.0]
  new_coords[2] = if a_y == b_y
                    [(a_x + b_x) / 2.0, a_y + (b_x - a_x) / 6.0 * Math.sqrt(3)]
                  elsif a_x < b_x && a_y > b_y
                    [b_x, a_y + (b_y - a_y) / 3.0]
                  elsif a_x < b_x && a_y < b_y
                    [a_x, a_y + (b_y - a_y) / 3.0 * 2.0]
                  elsif a_x > b_x && a_y > b_y
                    [a_x, a_y + (b_y - a_y) / 3.0 * 2.0]
                  else
                    [b_x, a_y + (b_y - a_y) / 3.0]
                  end
  new_coords[3] = [a_x + (b_x - a_x) / 3.0 * 2.0, a_y + (b_y - a_y) / 3.0 * 2.0]

  koch_curve new_coords[0], new_coords[1], n - 1
  puts "#{sprintf('%.8f', new_coords[1][0])} #{sprintf('%.8f', new_coords[1][1])}"
  koch_curve new_coords[1], new_coords[2], n - 1
  puts "#{sprintf('%.8f', new_coords[2][0])} #{sprintf('%.8f', new_coords[2][1])}"
  koch_curve new_coords[2], new_coords[3], n - 1
  puts "#{sprintf('%.8f', new_coords[3][0])} #{sprintf('%.8f', new_coords[3][1])}"
  koch_curve new_coords[3], new_coords[4], n - 1
end

n = gets.chomp.to_i
coords = [[0.0, 0.0], [100.0, 0.0]]
puts "#{sprintf('%.8f', coords[0][0])} #{sprintf('%.8f', coords[0][1])}"
koch_curve(coords[0], coords[1], n)
puts "#{sprintf('%.8f', coords[1][0])} #{sprintf('%.8f', coords[1][1])}"
