import scala.io.StdIn object Main { def main(args: Array[String]): Unit = { val d = StdIn.readInt val b = StdIn.readLine.split(' ').map(_.toInt).toArray val sz = b.size for (i <- (3 to d).reverse) { b(i - 2) += b(i) b(i) = 0 } val dd = if (d >= 2 && b(2) != 0) { 2 } else if (d >= 1 && b(1) != 0) { 1 } else { 0 } println(dd) println(b.slice(0, dd + 1).mkString(" ")) } }