import scala.math.BigDecimal
import scala.math.BigDecimal.RoundingMode
import scala.io.StdIn.readInt
object Main {
    def main(args: Array[String]): Unit = {
        println("0.00000000 0.00000000")
        koch(new Point(0.0, 0.0), 0, 100, readInt)
    }
    def koch(point: Point, angle: Int, len: Double, count: Int): Point = {
        if (count == 0) {
            val p = point.add(len * cos(angle), len * sin(angle))
            println(p)
            p
        } else {
            val nextLen = len / 3.0
            List(0, 60, 300, 360).foldLeft(point) { (p, a) =>
                koch(p, angle + a, nextLen, count - 1)
            }
        }
    }
    def cos(angle: Int) = Math.cos(Math.toRadians(angle % 360))
    def sin(angle: Int) = Math.sin(Math.toRadians(angle % 360))
}
case class Point(x: Double, y: Double) {
    override def toString(): String = {
        val a = "%.8f".format(BigDecimal(x).setScale(8, RoundingMode.HALF_UP))
        val b = "%.8f".format(BigDecimal(y).setScale(8, RoundingMode.HALF_UP))
        a + " " + b
    }
    def add(xx: Double, yy: Double): Point = new Point(x + xx, y + yy)
}
