object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, h, k) = in.next().split(' ').map(_.toInt)
  val (lh, time) = in.next().split(' ').map(_.toInt).foldLeft(0l, 0l) {
    case ((lh, time), el) if lh + el <= h || lh % k + el <= h =>
      ((lh + el) % k, time + (lh + el) / k)
    case ((lh, time), el) => (el % k, time + lh / k + el / k + 1)
  }
  if (lh == 0)
    println(time)
  else
    println(time + 1)
}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._

object _677B extends CodeForcesApp {
  override def apply(io: IO) = {
    val n, h, k = io[Int]
    val potato = io[Vector, Int](n)

    var i, tower = 0
    var t = 0L
    while(i < n) {
      while(i < n && tower + potato(i) <= h) {
        tower += potato(i)
        i += 1
      }
      val target = if (i < n) h - potato(i) else 0
      val smashes = (tower - target) ceilDiv k
      tower = (tower - k*smashes) max 0
      t += smashes
    }

    io += t
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = t.head.ensuring(t.size == 1)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_._1)
    def firstKeyOption: Option[K] = m.headOption.map(_._1)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv._1
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f) findWithIndex c
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    def bitCount: Int = java.lang.Integer.bitCount(x)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    def bitCount: Int = java.lang.Long.bitCount(x)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(n.min(x, y), n.max(x, y), n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: V): Dict[K, V] = Dict.empty[K, V] withDefaultValue default // also to(Dict.empty[K2, V])
  }
  def memoize[A, B](f: A => B): collection.Map[A, B] = new mutable.HashMap[A, B]() {
    override def apply(key: A) = getOrElseUpdate(key, f(key))
  }
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    if (tokenizers.nonEmpty) Some(tokenizers.head) else None
  }

  def apply[A](implicit read: IO.Read[A]): A = read.apply(this)
  def apply[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(apply).to[C]

  def till(delim: String): String = tokenizer().get.nextToken(delim)
  def tillEndOfLine(): String = till("\n\r")

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  var separator = " "
  private[this] var isNewLine = true

  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {
    write(this)(x)
    this
  }
  def ++=[A: IO.Write](xs: Traversable[A]): this.type = (this += xs.size) appendNewLine xs

  def appendNewLine[A: IO.Write](x: A): this.type = {
    println()
    this += x
  }

  override def print(obj: String) = {
    if (isNewLine) isNewLine = false else super.print(separator)
    super.print(obj)
  }
  override def println() = if (!isNewLine) {
    super.println()
    isNewLine = true
  }
  override def close() = {
    flush()
    in.close()
    super.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r[C, A](r[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r[A], r[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))
  }
  trait Write[-A] {
    def apply(out: PrintWriter)(x: A): Unit
  }
  trait DefaultWrite {
    implicit def any[A]: Write[A] = Write(_.toString)
  }
  object Write extends DefaultWrite {
    def apply[A](f: A => String) = new Write[A] {
      override def apply(out: PrintWriter)(x: A) = out.print(f(x))
    }
    implicit val boolean: Write[Boolean] = Write(b => if (b) "YES" else "NO")
    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s"$a $b"}
    implicit def array[A]: Write[Array[A]] = Write(_ mkString " ")
    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {
      override def apply(out: PrintWriter)(xs: Traversable[A]) = {
        xs foreach write(out)
        out.println()
      }
    }
  }
}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._

object _677B extends CodeForcesApp {
  override def apply(io: IO) = {
    val n, h, k = io[Int]
    val potato = io[Vector, Int](n)

    var i, tower = 0
    var t = 0L
    while(i < n) {
      while(i < n && tower + potato(i) <= h) {
        tower += potato(i)
        i += 1
      }
      val target = if (i < n) h - potato(i) else 0
      val smashes = ((1.0 * (tower - target))/k).ceil
      tower = (tower - k*smashes.toInt) max 0
      //debug(t, i, tower, target, smashes)
      t += smashes.toLong
    }

    io += t
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = t.head.ensuring(t.size == 1)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f) findWithIndex c
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    def bitCount: Int = java.lang.Long.bitCount(x)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(n.min(x, y), n.max(x, y), n.one)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: V): Dict[K, V] = Dict.empty[K, V] withDefaultValue default // also to(Dict.empty[K2, V])
  }
  def memoize[A, B](f: A => B): collection.Map[A, B] = new mutable.HashMap[A, B]() {
    override def apply(key: A) = getOrElseUpdate(key, f(key))
  }
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    if (tokenizers.nonEmpty) Some(tokenizers.head) else None
  }

  def apply[A](implicit read: IO.Read[A]): A = read.apply(this)
  def apply[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(apply).to[C]

  def vector[A: IO.Read](n: Int): Vector[A] = apply[Vector, A](n)

  def till(delim: String): String = tokenizer().get.nextToken(delim)
  def tillEndOfLine(): String = till("\n\r")

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  var separator = " "
  private[this] var isNewLine = true

  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {
    write(this)(x)
    this
  }
  def ++=[A: IO.Write](xs: Traversable[A]): this.type = (this += xs.size) appendNewLine xs

  def appendNewLine[A: IO.Write](x: A): this.type = {
    println()
    this += x
  }

  override def print(obj: String) = {
    if (isNewLine) isNewLine = false else super.print(separator)
    super.print(obj)
  }
  override def println() = if (!isNewLine) {
    super.println()
    isNewLine = true
  }
  override def close() = {
    flush()
    in.close()
    super.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r[C, A](r[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r[A], r[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))
  }
  trait Write[-A] {
    def apply(out: PrintWriter)(x: A): Unit
  }
  trait DefaultWrite {
    implicit def any[A]: Write[A] = Write(_.toString)
  }
  object Write extends DefaultWrite {
    def apply[A](f: A => String) = new Write[A] {
      override def apply(out: PrintWriter)(x: A) = out.print(f(x))
    }
    implicit val boolean: Write[Boolean] = Write(b => if (b) "YES" else "NO")
    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s"$a $b"}
    implicit def array[A]: Write[Array[A]] = Write(_ mkString " ")
    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {
      override def apply(out: PrintWriter)(xs: Traversable[A]) = {
        xs foreach write(out)
        out.println()
      }
    }
  }
}

import scala.util.Sorting
import scala.io.StdIn
object App {
  def main(args: Array[String]) {

    val Array(n, h, k) = StdIn.readLine().split(" ").map(_.toLong)

    val A:Array[Long] = StdIn.readLine().split(" ").map(_.toLong)

    var curH = 0L
    var t = 0L
    for ( i <- 0 to A.length - 1) {
      val nd = math.max(A(i) -  (h - curH),0)
      val d = nd / k + (if (nd % k == 0) 0  else 1)
      t += d
      curH = math.max(0L, curH - d * k ) + A(i)
    }
    val d = curH / k + (if (curH % k == 0) 0  else 1)
    t += d
    print(t)
//    print(A.foldLeft((0L,0L))({
//      case(b,a) =>
//        if(i == 0) {
//          (a,a)
//        } else {
//          val k = math.max(0, math.min(b._2 - 1, a))
//          (b._1 + k, k)
//        }
//    })._1)
  }

}

/**
 * @author pvasilyev
 * @since 19 Jun 2016
 */
object A365 extends App {

  def solve() = {
    val Array(n, h, k): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val a: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    var occupation = 0
    var potatoIndex = 0
    var time: Long = 0L
    while (potatoIndex < n) {
      if (occupation + a(potatoIndex) > h) {
        if (occupation % k == 0) {
          time += occupation / k
          occupation = 0
        } else {
          time += occupation / k + 1
          occupation = 0
        }
      }
      while (potatoIndex < n && occupation + a(potatoIndex) <= h) {
        occupation += a(potatoIndex)
        potatoIndex += 1
      }
      if (occupation % k == 0) {
        time += occupation / k
        occupation = 0
      } else {
        time += occupation / k
        occupation = occupation % k
      }
    }
    if (occupation > 0) {
      if (occupation % k == 0) {
        time += occupation / k
        occupation = 0
      } else {
        time += occupation / k + 1
        occupation = 0
      }
    }

    println(time)
  }

  solve()

}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, h, k) = in.next().split(' ').map(_.toInt)
  val (lh, time) = in.next().split(' ').map(_.toInt).foldLeft(0, 0) {
    case ((lh, time), el) if lh + el <= h || lh % k + el <= h =>
      ((lh + el) % k, time + (lh + el) / k)
    case ((lh, time), el) => (el % k, time + lh / k + el / k + 1)
  }
  if (lh == 0)
    println(time)
  else
    println(time + 1)
}

/**
 * @author pvasilyev
 * @since 19 Jun 2016
 */
object A365 extends App {

  def solve() = {
    val Array(n, h, k): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val a: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    var occupation = 0
    var potatoIndex = 0
    var time = 0
    while (potatoIndex < n) {
      if (occupation + a(potatoIndex) > h) {
        if (occupation % k == 0) {
          time += occupation / k
          occupation = 0
        } else {
          time += occupation / k + 1
          occupation = 0
        }
      }
      while (potatoIndex < n && occupation + a(potatoIndex) <= h) {
        occupation += a(potatoIndex)
        potatoIndex += 1
      }
      if (occupation % k == 0) {
        time += occupation / k
        occupation = 0
      } else {
        time += occupation / k
        occupation = occupation % k
      }
    }
    if (occupation > 0) {
      if (occupation % k == 0) {
        time += occupation / k
        occupation = 0
      } else {
        time += occupation / k + 1
        occupation = 0
      }
    }

    println(time)
  }

  solve()

}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._

object _677B extends CodeForcesApp {
  override def apply(io: IO) = {
    val n, h, k = io[Int]
    val potato = io[Vector, Int](n)

    var i, t, tower = 0
    while(i < n) {
      while(i < n && tower + potato(i) <= h) {
        tower += potato(i)
        i += 1
      }
      val target = if (i < n) h - potato(i) else 0
      val smashes = ((1.0 * (tower - target))/k).ceil.toInt
      tower = (tower - k*smashes) max 0
      //debug(t, i, tower, target, smashes)
      t += smashes
    }

    io += t
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = t.head.ensuring(t.size == 1)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f) findWithIndex c
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    def bitCount: Int = java.lang.Long.bitCount(x)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(n.min(x, y), n.max(x, y), n.one)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: V): Dict[K, V] = Dict.empty[K, V] withDefaultValue default // also to(Dict.empty[K2, V])
  }
  def memoize[A, B](f: A => B): collection.Map[A, B] = new mutable.HashMap[A, B]() {
    override def apply(key: A) = getOrElseUpdate(key, f(key))
  }
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    if (tokenizers.nonEmpty) Some(tokenizers.head) else None
  }

  def apply[A](implicit read: IO.Read[A]): A = read.apply(this)
  def apply[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(apply).to[C]

  def till(delim: String): String = tokenizer().get.nextToken(delim)
  def tillEndOfLine(): String = till("\n\r")

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  var separator = " "
  private[this] var isNewLine = true

  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {
    write(this)(x)
    this
  }
  def ++=[A: IO.Write](xs: Traversable[A]): this.type = (this += xs.size) appendNewLine xs

  def appendNewLine[A: IO.Write](x: A): this.type = {
    println()
    this += x
  }

  override def print(obj: String) = {
    if (isNewLine) isNewLine = false else super.print(separator)
    super.print(obj)
  }
  override def println() = if (!isNewLine) {
    super.println()
    isNewLine = true
  }
  override def close() = {
    flush()
    in.close()
    super.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r[C, A](r[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r[A], r[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))
  }
  trait Write[-A] {
    def apply(out: PrintWriter)(x: A): Unit
  }
  trait DefaultWrite {
    implicit def any[A]: Write[A] = Write(_.toString)
  }
  object Write extends DefaultWrite {
    def apply[A](f: A => String) = new Write[A] {
      override def apply(out: PrintWriter)(x: A) = out.print(f(x))
    }
    implicit val boolean: Write[Boolean] = Write(b => if (b) "YES" else "NO")
    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s"$a $b"}
    implicit def array[A]: Write[Array[A]] = Write(_ mkString " ")
    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {
      override def apply(out: PrintWriter)(xs: Traversable[A]) = {
        xs foreach write(out)
        out.println()
      }
    }
  }
}

import scala.util.Sorting
import scala.io.StdIn
object App {
  def main(args: Array[String]) {

    val Array(n, h, k) = StdIn.readLine().split(" ").map(_.toInt)

    val A:Array[Int] = StdIn.readLine().split(" ").map(_.toInt)

    var curH = 0
    var t = 0
    for ( i <- 0 to A.length - 1) {
      val nd = math.max(A(i) -  (h - curH),0)
      val d = nd / k + (if (nd % k == 0) 0  else 1)
      t += d
      curH = math.max(0, curH - d * k ) + A(i)
    }
    val d = curH / k + (if (curH % k == 0) 0  else 1)
    t += d
    print(t)
//    print(A.foldLeft((0L,0L))({
//      case(b,a) =>
//        if(i == 0) {
//          (a,a)
//        } else {
//          val k = math.max(0, math.min(b._2 - 1, a))
//          (b._1 + k, k)
//        }
//    })._1)
  }

}


import java.util.Scanner

/**
 * Created by hama_du on 2014/03/11.
 */
object ProblemB extends App {
  val in = new Scanner(System.in)
  val x,k = in.nextInt
  val rounds = new Array[Boolean](x+1)
  rounds(x) = true
  (0 until k).foreach(_ => {
    val rnd = in.nextInt
    if (rnd == 1) {
      rounds(in.nextInt()) = true
      rounds(in.nextInt()) = true
    } else {
      rounds(in.nextInt()) = true
    }
  })

  val max = (1 to x-1).filter(i => !rounds(i)).size
  val min = count(1, rounds)
  println(min + " " + max)

  def count(idx: Int, rounds: Array[Boolean]): Int = {
    if (idx >= x) {
      0
    } else if (rounds(idx)) {
      count(idx+1, rounds)
    } else {
      if (!rounds(idx+1)) {
        1 + count(idx+2, rounds)
      } else {
        1 + count(idx+1, rounds)
      }
    }
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val Array(x, k) = in.next().split(' ').map(_.toInt)
  val contests = Array.ofDim[Boolean](x - 1)
  (1 to k).foreach { i =>
    in.next().split(' ').map(_.toInt) match {
      case Array(1, f, s) =>
        contests(f - 1) = true
        contests(s - 1) = true
      case Array(2, s) => contests(s - 1) = true
    }
  }
  val res = contests.foldLeft((0, 0, 0)) {
    case((min, max, soFar), false) => (min, max, soFar + 1)
    case((min, max, soFar), true) => (min + soFar / 2 + soFar % 2, max + soFar, 0)
  }
  val min = res._1 + res._3 / 2 + res._3 % 2
  val max = res._2 + res._3
  println(s"$min $max")

}


import java.io._
import java.util.Locale
import scala.annotation.tailrec

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInt = reader.readLine().toInt
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readLongs = reader.readLine().split(" ").map(_.toLong)

  val n = readInt
  def ans = (n +: (1 until n)).mkString(" ")

  def main(a: Array[String]) {
    println(ans)
  }
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P221A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  val N = sc.nextInt
  val answer = N :: List.range(1, N)

  out.println(answer.mkString(" "))
  out.close
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    println((Seq(n) ++ (1 to (n - 1))).mkString(" "))
  }
}

object Code221A extends App {
    val in = new java.util.Scanner(System.in)
    val n = in.nextInt

    println( (n :: (1 to n-1).toList).mkString(" ") )
}

object A {
    def main(args: Array[String]) = {
        val n = readInt;
        val answer = n :: (1 to (n - 1) toList);
        println(answer map {_.toString} reduceLeft {_ + " " + _})
    }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  println((n :: (1 to n - 1).toList).mkString(" "))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  println(((2 to n).toList ::: List(1)).mkString(" "))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  println((1 :: (1 to n - 1).toList).mkString(" "))
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    println((n to 1 by -1).mkString(" "))
  }
}


import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine().toInt
  val a = StdIn.readLine().split(" ").map(_.toLong)
  val init = (0 to n).map {i => if (i == 0) 0l else -1l }
  val results = a.foldLeft(init) { (v, next) =>
    (0 to n).map { i =>
      if (i == 0)
        0
      else if (v(i - 1) == -1)
        -1
      else
        Math.max(v(i), v(i - 1) + next)
    }
  }

  println((0 to n).filter(results(_) != -1).max)
}

import scala.collection.mutable
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine().toInt
  val a = StdIn.readLine().split(" ").map(_.toLong)

  def slowSolution(n: Int, a: Array[Long]): Long = {
    val init = (0 to n).map {i => if (i == 0) 0l else -1l }
    val results = a.foldLeft(init) { (v, next) =>
      (0 to n).map { i =>
        if (i == 0)
          0
        else if (v(i - 1) == -1)
          -1
        else
          Math.max(v(i), v(i - 1) + next)
      }
    }
    (0 to n).filter(results(_) != -1).max
  }

  def fastSolution(n: Int, a: Array[Long]): Long = {
    val q = new mutable.PriorityQueue[Long].reverse
    val (result, _) = a.foldLeft((0l, 0l)) { (state, next) =>
      val (curResult, curSum) = state;
      if (next + curSum >= 0) {
        q.enqueue(next)
        (curResult + 1, next + curSum)
      } else if (q.nonEmpty && q.head < next) {
        val old = q.dequeue()
        q.enqueue(next)
        (curResult, curSum - old + next)
      } else {
        (curResult, curSum)
      }
    }
    result
  }

  println(fastSolution(n, a))
}

object C1 extends App {
  import scala.io.StdIn._

  val n  = readInt()
  val an = readLine().split(" ").map(_.toLong).toList

  val ans = {
    val cn = Array.fill[Long](n + 1, n + 1)(-1L)
    (0 to n).foreach(cn(_)(0) = 0L)

    for {
      i     <- 1 to n
      potion = an(i - 1)
      j     <- 1 to i if cn(i - 1)(j - 1) >= 0
      c      = cn(i - 1)(j - 1) + potion
    } cn(i)(j) =
      if (c >= 0) c max cn(i - 1)(j)
      else cn(i - 1)(j)

    cn(n).lastIndexWhere(_ >= 0)
  }

  println(ans)
}

object C1 extends App {
  import scala.io.StdIn._

  val n  = readInt()
  val an = readLine().split(" ").map(_.toLong).toList

  val ans = {
    val cn = Array.fill[Option[Long]](n + 1, n + 1)(None)
    cn(0)(0) = Some(0L)

    for {
      i     <- 1 to n
      potion = an(i - 1)
      j     <- 1 to i
    } cn(i)(j) = cn(i - 1)(j - 1).map(_ + potion) match {
      case Some(c) if c >= 0 => Some(c max cn(i - 1)(j).getOrElse(0L))
      case _                 => cn(i - 1)(j)
    }

    cn(n).lastIndexWhere(_.isDefined)
  }

  println(ans)
}

import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine().toInt
  val a = StdIn.readLine().split(" ").map(_.toInt)
  val init = (0 to n).map {i => if (i == 0) 0 else - 1 }
  val results = a.foldLeft(init) { (v, next) =>
    (0 to n).map { i =>
      if (i == 0)
        0
      else if (v(i - 1) == -1)
        -1
      else
        Math.max(v(i), v(i - 1) + next)
    }
  }

  println((0 to n).filter(results(_) != -1).max)
}


object B extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, a, b) = readLine().split(" ").map(_.toInt)
    val s              = readLine()

    val ans =
      if (b >= 0) n * (a + b)
      else {
        val (c, _) = s.tail.foldLeft((1, s.head)) {
          case (state @ (_, p), c) if p == c => state
          case ((m, _), c)                   => (m + 1, c)
        }
        n * a + (c / 2 + 1) * b
      }

    println(ans)
  }
}

object B extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, a, b) = readLine().split(" ").map(_.toInt)
    val s              = readLine()

    def f: Int => Int      = l => if (l == 0) 0 else a * l + b
    def g: Seq[Int] => Int = ls => ls.foldLeft(0) { case (s, l) => s + f(l) }

    val ans =
      if (b >= 0) n * f(1)
      else {
        val zeros = s.split("1").map(_.length)
        val ones  = s.split("0").map(_.length)

        (g(zeros) + f(ones.sum)) max (g(ones) + f(zeros.sum))
      }

    println(ans)
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]) = {
    def rep[A](n: Int)(f: => A) { if (n > 0) { f; rep(n - 1)(f) } }
    rep(StdIn.readInt) { f }

    def f() {
      def calc(l: Int, a: Int, b: Int): Int =
        (a * l) + b

      def doSomething(in: String, a: Int, b: Int) = {
        val first = in.head
        val second = if (first == '1') '0' else '1'

        val part1 = in.split(second).filter(_ != "")
        val part2 = in.split(first).filter(_ != "")

        val part2Sum = part2.map { l => calc(l.length, a, b) }.sum
        val part1Sum = calc(part1.reduce(_ + _).length, a, b)

        part2Sum + part1Sum
      }

      def points(in: String, a: Int, b: Int) = {

        if (b < 0) doSomething(in, a, b)
        else {
          val ones = in.split('0')
          val zeros = in.split('1')
          val all = (ones ++ zeros).filter(_ != "")
          (all.flatMap(_.toCharArray)).map(e => calc(1, a, b)).sum
        }
      }

      val arr = (StdIn.readLine.split(" ") map (_.toInt))
      val (n, a, b) = (arr(0), arr(1), arr(2))
      val str = StdIn.readLine
      println(points(str, a, b))

    }

  }
}


//package codeforces

/*
https://codeforces.com/contest/1175/problem/B
 */
object CatchOverFlow {

  type Statements = List[List[String]]

  def main(args: Array[String]): Unit = {
    val lines = io.StdIn.readInt()

    countIncrements((1 to lines).map(_ => io.StdIn.readLine().split(" ").toList).toList, 0) match {
      case Some((result, Nil)) => println(result)
      case None => println("OVERFLOW!!!")
    }

    def countIncrements(statements: Statements, result: Long): Option[(Long, Statements)] = {
      if (result > (1l << 32) - 1)
        None
      else
        statements match {
          case Nil => Some(result, Nil)
          case statement :: rest =>

            statement match {
              case "for" :: n :: Nil =>
                countIncrements(rest, 0).flatMap {
                  case (forLoopResult, statementsAfterForLoop) =>
                    countIncrements(statementsAfterForLoop, result + forLoopResult * n.toInt)
                }

              case "end" :: Nil =>
                Some(result, rest)

              case "add" :: Nil =>
                countIncrements(rest, result + 1)
            }
        }
    }
  }

}

import scala.collection.mutable
import scala.io.StdIn._

object B_1175 extends App {
  val Max   = 4294967295L
  var n     = readInt()
  var value = 0L
  val stack = mutable.Stack[Long]()

  stack.push(1)

  var overflow = false

  1 to n foreach { _ =>
    val line = readLine()
    if (!overflow) {
      line.split(" ") match {
        case Array("add") =>
          value += stack.top
          if (value > Max) overflow = true
        case Array("for", x) =>
          val mul = x.toInt * stack.top
          if (mul < Max) stack.push(mul)
          else stack.push(Max + 1)
        case Array("end") => stack.pop()
      }
    }

  }

  println(if (value >= 0 && value <= Max) value else "OVERFLOW!!!")

}

import scala.collection.mutable
import scala.io.StdIn._

object B_1175 extends App {
  var n     = readInt()
  var value = 0L
  val stack = mutable.Stack[Long]()

  stack.push(1)

  1 to n foreach { _ =>
    readLine().split(" ") match {
      case Array("add")    => value += stack.top
      case Array("for", x) => stack.push(x.toInt * stack.top)
      case Array("end")    => stack.pop()
    }
  }

  println(if (value >= 0 && value <= 2147483646L) value else "OVERFLOW!!!")

}

import scala.collection.mutable
import scala.io.StdIn._

object B_1175 extends App {
  var n     = readInt()
  var value = 0L
  val stack = mutable.Stack[Long]()

  stack.push(1)

  1 to n foreach { _ =>
    readLine().split(" ") match {
      case Array("add")    => value += stack.top
      case Array("for", x) => stack.push(x.toInt * stack.top)
      case Array("end")    => stack.pop()
    }
  }

  println(if (value >= 0 && value <= 2147483646L) value else "OVERFLOW")

}

import scala.collection.mutable
import scala.io.StdIn._

object B_1175 extends App {
  val Max   = 2147483646L
  var n     = readInt()
  var value = 0L
  val stack = mutable.Stack[Long]()

  stack.push(1)

  var overflow = false

  1 to n foreach { _ =>
    val line = readLine()
    if (!overflow) {
      line.split(" ") match {
        case Array("add") =>
          value += stack.top
          if (value > Max) overflow = true
        case Array("for", x) =>
          val mul = x.toInt * stack.top
          if (mul < Max) stack.push(mul)
          else stack.push(Max + 1)
        case Array("end") => stack.pop()
      }
    }

  }

  println(if (value >= 0 && value <= Max) value else "OVERFLOW!!!")

}


import scala.io.StdIn._

object D extends App {
  val n = readInt()
  val P = readLine().split(" ").map(_.toInt).sortWith(_ < _)
//  println(P.mkString(" "))

  def solve(): Int = {
    var happy = 0
    var needToWait = 0
    for (i <- 0 until P.length) {
//      println(s"($needToWait <= ${P(i)})")
      if (needToWait <= P(i)) {
        needToWait += P(i)
        happy += 1
      }

      if (needToWait > 1000000000) return happy
    }
    happy
  }

  println(solve())

}

import scala.io.StdIn

/**
  * http://codeforces.com/problemset/problem/545/D
  **/
object DQueue {
  def main(args: Array[String]): Unit = {
    StdIn.readLine()
    val timesToServe = StdIn.readLine().split(" ").map(_.toInt)
    val (nbHappyPersons, _) = timesToServe.sorted.foldLeft((0, 0)) { case ((nbHappyPersons, accTime), timeToServe) =>
      if (accTime > timeToServe) (nbHappyPersons, accTime)
      else (nbHappyPersons + 1, accTime + timeToServe)
    }
    println(nbHappyPersons)
  }
}

import scala.io.StdIn
object b extends App {
  var r = 0
  StdIn.readLine
  StdIn.readLine.split(" ")
    .map(_.toInt)
    .sorted
    .reduce((s,x) => if (s<=x) {r+=1; s+x} else s)
  println(r+1)
}

import scala.util.Sorting
import scala.io.StdIn
object App {
  def main(args: Array[String]) {

    StdIn.readLine()
    print(StdIn.readLine()
      .split(" ")
      .map(_.toInt)
      .sorted
      .foldLeft( (0,0) )((r,c) =>
        if(r._1 > c) {
          r
        } else {
          (r._1 + c, r._2 + 1)

        }
      )._2)

//    val in = scala.io.Source.stdin.getLines()
//    val n = in.next().toInt

//    val Array(n, h, k) = StdIn.readLine().split(" ").map(_.toLong)
//
//    val A:Array[Long] = StdIn.readLine().split(" ").map(_.toLong)
//
//
//    var curH = 0L
//    var t = 0L
//    for ( i <- 0 to A.length - 1) {
//      val nd = math.max(A(i) -  (h - curH),0)
//      val d = nd / k + (if (nd % k == 0) 0  else 1)
//      t += d
//      curH = math.max(0L, curH - d * k ) + A(i)
//    }
//    val d = curH / k + (if (curH % k == 0) 0  else 1)
//    t += d
//    print(t)
//    print(A.foldLeft((0L,0L))({
//      case(b,a) =>
//        if(i == 0) {
//          (a,a)
//        } else {
//          val k = math.max(0, math.min(b._2 - 1, a))
//          (b._1 + k, k)
//        }
//    })._1)
  }

}

import java.util.StringTokenizer

object _545D extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt).sorted.toArray

  def calc(i: Int, sum: Int, acc: Int): Int = {
    if (i >= n) acc
    else {
      if (sum <= a(i)) calc(i + 1, sum + a(i), acc + 1)
      else calc(i + 1, sum, acc)
    }
  }
  println(calc(0, 0, 0))
}

import scala.io.StdIn

object CF545D extends App {
  val n = StdIn.readInt
  val ts = StdIn.readLine.split(' ').map(_.toInt)

  var peopleLeft = ts.sorted
  var notDisappointed = 0
  var sum = 0
  while (peopleLeft.nonEmpty) {
    peopleLeft = peopleLeft.dropWhile(_ < sum)
    if (peopleLeft.nonEmpty) {
      sum += peopleLeft.head
      notDisappointed += 1
      peopleLeft = peopleLeft.tail
    }
  }
  println(notDisappointed)
}

object D545 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readLongs(n).sorted
    var curr = 0L
    var res = 0
    for(num <- in) {
      if(curr <= num) {
        res += 1
        curr += num
      }
    }
    println(res)
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine;
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

/**
 *
 * Created by ronaflx on 15-4-3.
 */

import java.io._
import java.util.StringTokenizer

import scala.Ordering.Implicits._
import scala.collection.immutable.Queue
import scala.collection.mutable.ArrayBuffer

object Codeforces {
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    st.nextToken
  }

  def nextInt: Int = {
    Integer.parseInt(next)
  }

  def nextLong: Long = {
    java.lang.Long.parseLong(next)
  }

  def lowerBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (!(array(mid) < value)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  def solve(): Unit = {
    val n = nextInt
    val service_time = new Array[Int](n)
    for (i <- 0 until n) {
      service_time(i) = nextInt
    }
    util.Sorting.quickSort(service_time)
    var (res, sum) = (0, 0)
    for (i <- 0 until n) {
      if (service_time(i) >= sum) {
        res += 1
        sum += service_time(i)
      }
    }
    out.println(res)
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve()
    out.close
  }
}

import java.util

/**
 * <a href="http://codeforces.com/problemset/problem/545/D"/>
 *
 * @author pvasilyev
 * @since 13 Apr 2016
 */
object Problem150 extends App {
  private val n: Int = scala.io.StdIn.readInt()
  private val ints: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  util.Arrays.sort(ints)
  val answer: Array[Int] = new Array[Int](n)
  answer(0) = 1
  var sum = ints(0)
  for (i <- 1 until n) {
    if (sum <= ints(i)) {
      sum += ints(i)
      answer(i) = answer(i - 1) + 1
    } else {
      answer(i) = answer(i - 1)
    }
  }
  println(answer(n - 1))
}

import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = new MultiTreeSet[Long]
    for (i <- 0 until n) {
      m.add(nextLong)
    }
    var waitTime = 0L
    var ans = 0L
    var current = m.first()
    while (current != 0 && !m.map.isEmpty) {
      if (m.count(current) > 0) {
        if (current >= waitTime) {
          ans += 1
//          out.print(current + " ")
          m.remove(current)
          waitTime += current
        } else {
          current = m.map.ceilingKey(waitTime)
        }
      } else {
        current = m.first()
      }
    }
    out.println(ans)
    return 0
  }
}

object _545D extends CodeForcesApp {
  import scala.collection.mutable

  override type Input = List[Int]
  override type Output = Int

  override def read(scanner: java.util.Scanner) = {
    import scanner._
    List.fill(nextInt)(nextInt).sorted
  }

  override def solve(input: Input) = {
    var t: Long = 0L
    var ans = 0

    for(i <- input) {
      //debug(input, i, t, ans)
      if(t <= i) {
        ans += 1
        t += i
      }
    }
    ans
  }

  override def format(result: Output) = super.format(result)
}

/****************************** IGNORE BELOW *********************************/
abstract class CodeForcesApp extends App {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(problem: String): String  = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  println(apply(new Scanner(System.in)))
  /********************************[ lib ]************************************/
  import scala.collection.mutable
  case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
    val cache = mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type m_=>[I, O] = Memo[I, I, O]
  def when[A](condition: Boolean)(f: => A): Option[A] = if (condition) Some(f) else None
  /******************************[ solution ]*********************************/
  type Input
  type Output
  def read(scanner: Scanner): Input
  def solve(input: Input): Output
  def format(result: Output): String = result.toString
  def timeLimitSecond = 1
}

object _545D extends CodeForcesApp {
  override type Input = List[Int]
  override type Output = Int

  override def read(scanner: java.util.Scanner) = {
    import scanner._
    List.fill(nextInt)(nextInt).sorted
  }

  override def solve(input: Input) = {
    var (ans, t) = (0, 0)
    for (i <- input if t <= i) {
      ans += 1
      t += i
    }
    ans
  }

  override def format(result: Output) = super.format(result)
}

/****************************** IGNORE BELOW *********************************/
abstract class CodeForcesApp extends App {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(problem: String): String  = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  println(apply(new Scanner(System.in)))
  /********************************[ lib ]************************************/
  import scala.collection.mutable
  case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
    val cache = mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type m_=>[I, O] = Memo[I, I, O]
  def when[A](condition: Boolean)(f: => A): Option[A] = if (condition) Some(f) else None
  /******************************[ solution ]*********************************/
  type Input
  type Output
  def read(scanner: Scanner): Input
  def solve(input: Input): Output
  def format(result: Output): String = result.toString
  def timeLimitSecond = 1
}

import scala.io.StdIn
import scala.collection.mutable.PriorityQueue

object Main {
  def main(args: Array[String]) {
    StdIn.readLine(); // ignoring

    val q = StdIn.readLine().split(" ").map(Integer.parseInt).to[PriorityQueue].reverse;

    def f : Long => Int = t => {
      if(q.isEmpty)
        0
      else {
        val v = q.dequeue();

        t <= v match {
          case true => f(t + v) + 1;
          case false => f(t);
        }
      }
    }

    println(f(0));
  }
}

import java.util.StringTokenizer

object _545D extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt).sorted.toArray

  def calc(i: Int, sum: Int, acc: Int): Int = {
    if (i >= n) acc
    else {
      calc(i + 1, sum + a(i), if (sum <= a(i)) acc + 1 else acc)
    }
  }

  println(calc(0, 0, 0))
}

import java.util

/**
 * <a href="http://codeforces.com/problemset/problem/545/D"/>
 *
 * @author pvasilyev
 * @since 13 Apr 2016
 */
object Problem150 extends App {
  private val n: Int = scala.io.StdIn.readInt()
  private val ints: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  util.Arrays.sort(ints)
  val latency: Array[Int] = new Array[Int](n)
  latency(0) = 0
  for (i <- 1 until n) {
    latency(i) = latency(i - 1) + ints(i - 1)
  }
  val answer: Array[Int] = new Array[Int](n)
  answer(0) = 1
  for (i <- 1 until n) {
    if (latency(i) > ints(i)) {
      answer(i) = answer(i - 1)
    } else {
      answer(i) = answer(i - 1) + 1
    }
  }
  println(answer(n - 1))
}

import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = new MultiTreeSet[Long]
    for (i <- 0 until n) {
      m.add(nextLong)
    }
    var waitTime = 0L
    var ans = 0L
    var current = m.first()
    while (current != 0 && !m.map.isEmpty) {
      if (m.count(current) > 0) {
        if (current >= waitTime) {
          ans += 1
          out.print(current + " ")
          m.remove(current)
          waitTime += current
        } else {
          current = m.map.ceilingKey(waitTime)
        }
      } else {
        current = m.first()
      }
    }
    out.println(ans)
    return 0
  }
}

object _545D extends CodeForcesApp {
  import scala.collection.mutable

  override type Input = List[Int]
  override type Output = Int

  override def read(scanner: java.util.Scanner) = {
    import scanner._
    List.fill(nextInt)(nextInt).sorted
  }

  override def solve(input: Input) = {
    var t = 0
    var ans = 0

    for(i <- input) {
      //debug(input, i, t, ans)
      if(t <= i) {
        ans += 1
      }
      t += i
    }
    ans
  }

  override def format(result: Output) = super.format(result)
}

/****************************** IGNORE BELOW *********************************/
abstract class CodeForcesApp extends App {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(problem: String): String  = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  println(apply(new Scanner(System.in)))
  /********************************[ lib ]************************************/
  import scala.collection.mutable
  case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
    val cache = mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type m_=>[I, O] = Memo[I, I, O]
  def when[A](condition: Boolean)(f: => A): Option[A] = if (condition) Some(f) else None
  /******************************[ solution ]*********************************/
  type Input
  type Output
  def read(scanner: Scanner): Input
  def solve(input: Input): Output
  def format(result: Output): String = result.toString
  def timeLimitSecond = 1
}

import scala.io.StdIn._

object D extends App {
  val n = readInt()
  val P = readLine().split(" ").map(_.toInt).sortWith(_ < _)

  def solve(): Int = {
    var happy = 0
    var needToWait = 0
    for (i <- 0 until P.length) {
      if (needToWait <= P(i)) happy += 1
      needToWait += P(i)

      if (needToWait > 1000000000) return happy
    }
    happy
  }

  println(solve())

}

import scala.io.StdIn._

object D extends App {
  val n = readInt()
  val P = readLine().split(" ").map(_.toInt).sortWith(_ < _)

  def solve(): Int = {
    var happy = 1
    var needToWait: BigInt = P(0)
    for (i <- 1 until P.length) {
//      println(s"consider $i $needToWait <= ${P(i)}")
      if (needToWait <= P(i)) happy += 1

      needToWait += P(i)

      if (needToWait > 1000000000) return happy
    }
    happy
  }

  println(solve())

}

import scala.io.StdIn._

object D extends App {
  val n = readInt()
  val P = readLine().split(" ").map(_.toInt).sortWith(_ < _)

  def solve(): Int = {
    var happy = 1
    var needToWait = P(0)
    for (i <- 1 until P.length) {
//      println(s"consider $i $needToWait <= ${P(i)}")
      if (needToWait <= P(i)) happy += 1

      needToWait += P(i)
    }
    happy
  }

  println(solve())
}

import scala.io.StdIn._

object D extends App {
  val n = readInt()
  val P = readLine().split(" ").map(_.toInt).sortWith(_ < _)

  def solve(): Int = {
    var happy = 1
    var needToWait: BigInt = P(0)
    for (i <- 1 until P.length) {
//      println(s"consider $i $needToWait <= ${P(i)}")
      if (needToWait <= P(i)) happy += 1

      needToWait += P(i)
    }
    happy
  }

  println(solve())

}

import scala.io.StdIn

/**
  * http://codeforces.com/problemset/problem/545/D
  **/
object DQueue {
  def main(args: Array[String]): Unit = {
    StdIn.readLine()
    val timesToServe = StdIn.readLine().split(" ").map(_.toInt)
    val (nbHappyPersons, _) = timesToServe.sorted.foldLeft((0, 0)) { case ((nbHappyPersons, accTime), timeToServe) =>
        if (accTime > timeToServe) (nbHappyPersons, accTime + timeToServe)
        else (nbHappyPersons + 1, accTime + timeToServe)
    }
    println(nbHappyPersons)
  }
}


object _842B extends CodeForcesApp {
  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._

  override def apply(io: IO): io.type = {
    val outer, _d = io.read[Double]
    val inner = outer - _d
    val sausages = io.read[Seq[(Double, Double, Double)]]

    val ans = sausages count { case (x, y, r) =>
      val d = Math.hypot(x, y)
      inner <= d - r && d + r <= outer
    }

    io.write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: A =:= B): Seq[A] = Seq(p._1, p._2.asInstanceOf[A])
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "Yes" else "No"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object BGlebAndPizza extends App {
  val Array(r, d) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val n = scala.io.StdIn.readLine.toInt
  val count = (0 until n).foldLeft(0) { (count, _) =>
    val Array(xi, yi, ri) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val di = xi * xi + yi * yi
    if (di >= (ri + r - d) * (ri + r - d) && di <= (r - ri) * (r - ri)) count + 1
    else count
  }
  println(count)
}


object B extends App {
  import scala.io.StdIn._

  val winBy = Map.apply('S' -> 'R', 'R' -> 'P', 'P' -> 'S')

  val t = readInt()

  (0 until t).foreach { _ =>
    val sn = readLine()

    val ans = winBy(sn.groupBy(identity).maxBy(_._2.size)._1).toString * sn.size

    println(ans)
  }
}

object ProblemB extends App {

  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer

  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

    def nextToken(): String = {
      while (st == null || !st.hasMoreTokens) {
        st = new StringTokenizer(in.readLine);
      }
      return st.nextToken();
    }

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  @scala.annotation.tailrec
  def gcd(a: Int, b: Int): Int = {
    if (b == 0) {
      a
    } else if (a < b) {
        gcd(b, a)
      } else {
      gcd(b, a % b)
    }
  }

  case class Step(n: Int, s: Int)

  def toPrimaryList(n: Int): List[Step] = {
    var acc = n
    var result = List[Step]()
    for (i <- 2 to math.sqrt(n).floor.toInt) {
      var count = 0
      while (acc % i == 0) {
        count = count + 1
        acc = acc / i
      }
      if (count > 0) {
        result = Step(i, count) :: result
      }
    }

    if (acc > 1) {
      result = Step(acc, 1) :: result
    }

    result
  }

  val t = in.nextInt()

  val winStrategy = Map("R" -> "S", "S" -> "P", "P" -> "R")
    .map(p => p._2 -> p._1)

  for (_ <- 1 to t) {
    val s = in.nextToken()
    val mostUsed = s.groupBy(identity).maxBy(_._2.length)._1.toString

    val result = winStrategy(mostUsed) * s.length
    println(result)
  }

}

object B {
  import InOut._
  def main(args: Array[String]): Unit = {

    def play(a: Char, b: Char): Int = {
      (a, b) match {
        case ('P', 'R') | ('R', 'S') | ('S', 'P') => 1
        case ('R', 'P') | ('S', 'R') | ('P', 'S') => 0//-1
        case _ => 0
      }
    }

    val rsp = "RSP"

    for (_ <- 1 to nextInt) {
      val s = nextLine
      val c = rsp.maxBy(c => s.map(play(c, _)).sum)
      out.println(c.toString * s.length)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

object B extends App {
  import scala.io.StdIn._

  val rps = Map.apply('S' -> "R", 'R' -> "P", 'P' -> "S")

  val t = readInt()

  (0 until t).foreach { _ =>
    val sn = readLine()

    val ans = rps(
      List('R', 'S', 'P')
        .map(s => (s, sn.count(_ == s)))
        .sortBy(_._2)(Ordering.Int.reverse)
        .head
        ._1
    ) * sn.length

    println(ans)
  }
}

import scala.io.StdIn._

object B extends App {
  val t = readInt()
  1 to t foreach { _ =>
    val A      = readLine().toCharArray
    val (x, _) = A.groupBy(identity).mapValues(_.length).maxBy(_._2)
    val answer = x match {
      case 'R' => 'P'
      case 'S' => 'R'
      case 'P' => 'S'
    }
    println(Array.fill(A.length)(answer).mkString)
  }
}

object B {
  import InOut._
  def main(args: Array[String]): Unit = {

    def play(a: Char, b: Char): Int = {
      (a, b) match {
        case ('P', 'R') | ('R', 'S') | ('S', 'P') => 1
        case ('R', 'P') | ('S', 'R') | ('P', 'S') => -1
        case _ => 0
      }
    }

    val rsp = "RSP"

    for (_ <- 1 to nextInt) {
      val s = nextLine
      val c = rsp.maxBy(c => s.map(play(c, _)).sum)
      out.println(c.toString * s.length)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

object B extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val sn = readLine()

    val ans = List('R', 'S', 'P')
      .map(s => (s, sn.count(_ == s)))
      .sortBy(_._2) //(Ordering.Int.reverse)
      .head
      ._1
      .toString * sn.length

    println(ans)
  }
}

object B extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val sn = readLine()

    val ans = List('R', 'S', 'P')
      .map(s => (s, sn.count(_ == s)))
      .sortBy(_._2)(Ordering.Int.reverse)
      .head
      ._1
      .toString * sn.length

    println(ans)
  }
}

import scala.io.StdIn._

object B extends App {

  val t = readInt()
  1 to t foreach { _ =>
    val A = readLine().toCharArray
    val answer = A.map {
      case 'P' => 'S'
      case 'S' => 'R'
      case 'R' => 'P'
    }

    println(answer.mkString)
  }
}