import scala.annotation.tailrec
import scala.collection.immutable.IndexedSeq
import scala.collection.mutable
import scala.util._, control._
import scala.math.Ordering.Implicits._

object _629A extends CodeForcesApp {
  override type Result = Int

  override def solve(read: InputReader) = {
    val n = read[Int]
    val chocolates: IndexedSeq[(Int, Int)] = for {
      i <- 1 to n
      line = read[String]
      j <- 1 to n
      if line(j-1) == 'C'
    } yield (i, j)

    var ans = 0
    for (i <- chocolates.indices) {
      val (a1, a2) = chocolates(i)
      for (j <- chocolates.indices drop (i+1)) {
        val (b1, b2) = chocolates(j)
        if (a1 == b1 || a2 == b2) ans += 1
      }
    }

    ans
  }

  override def format(result: Result) = result.toString
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  type Result
  def solve(scanner: InputReader): Result
  def format(result: Result): String
  def apply(scanner: InputReader): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))
  def this(str: String) = this(new StringReader(str))

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

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

  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)

  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {
    val builder = cbf()
    for {_ <- 1 to n} builder += apply[A]
    builder.result()
  }

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

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

class Parser[A](val apply: InputReader => A) {
  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)
}
object Parser {
  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]
  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))
  implicit val string                                                        : Parser[String]          = new Parser(_.next())
  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)
  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)
  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)
  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))
  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)
  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))
  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))
  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))
  implicit def tuple4[A: Parser, B: Parser, C: Parser, D: Parser]            : Parser[(A, B, C, D)]    = new Parser(r => (r[A], r[B], r[C], r[D]))
  implicit def tuple5[A: Parser, B: Parser, C: Parser, D: Parser, E: Parser] : Parser[(A, B, C, D, E)] = new Parser(r => (r[A], r[B], r[C], r[D], r[E]))
}

import java.util.ArrayList
import java.util.StringTokenizer
//import scala.reflect.io.File
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object A_343_A {   var br = createBufferedReader(); var debugV = false

      //COMMENT ME !
    runTest(Test.sa2)
    debugV = true
//    file = File("C:\\temp\\google cj\\2014q\\c-small.res")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading --------------------------
    val n = readLine.int
    val arr = new Array[String](n)
    (0 until n).foreach(arr(_) = readLine.string)
//    val arr = Array.fill(n,n)(0)
//    for(i <- 0 until n) {
//      val line = readLine.string
//      for(j <- 0 until n) {
//        arr(i)(j) = if (line(j) == '.') 0 else 1
//      }
//    }
    debug("n = " + n)

    //---------------------------- parameters reading end ----------------------

    val rr = arr.map(x => soch(x.count { _ == 'C' })).sum
    var total = rr

    for(i <- 0 until n) {
      var colCount = 0
      for(j <- 0 until n) {
        if (arr(j)(i) == 'C') {
          colCount += 1
        }
      }
      total += soch(colCount)
//      total += Subsets.subsetNumber(colCount, 2)
    }

    outLn(total+"")

    finish
  }

  def soch(all:Int): Int = all - 1 match {
    case x if x < 1 => 0
    case rest => rest + soch(rest)
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) {
    resultStr.append(str).append("\n")
  }
  def finish() {
//    if (file == null) {
      println(resultStr.toString())
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
3
.CC
C..
C.C
"""

val sa2 = """
4
CC..
C..C
.CC.
.CC.
"""

}

}

import java.util.ArrayList
import java.util.StringTokenizer
//import scala.reflect.io.File
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object A_343_A {   var br = createBufferedReader(); var debugV = false

      //COMMENT ME !
    runTest(Test.sa2)
    debugV = true
//    file = File("C:\\temp\\google cj\\2014q\\c-small.res")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading --------------------------
    val n = readLine.int
    val arr = Array.fill(n,n)(0)
    for(i <- 0 until n) {
      val line = readLine.string
      for(j <- 0 until n) {
        arr(i)(j) = if (line(j) == '.') 0 else 1
      }
    }
    debug("n = " + n)

    //---------------------------- parameters reading end ----------------------

    var total = 0
    for(i <- 0 until n) {
      var rowCount = 0
      for(j <- 0 until n) {
        if (arr(i)(j) == 1) {
          rowCount += 1
        }
      }
      total += soch(rowCount)
//      total += Subsets.subsetNumber(rowCount, 2)
    }

    for(i <- 0 until n) {
      var colCount = 0
      for(j <- 0 until n) {
        if (arr(j)(i) == 1) {
          colCount += 1
        }
      }
      total += soch(colCount)
//      total += Subsets.subsetNumber(colCount, 2)
    }

    outLn(total+"")

    finish
  }

  def soch(all:Int): Int = all - 1 match {
    case x if x < 1 => 0
    case rest => rest + soch(rest)
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) {
    resultStr.append(str).append("\n")
  }
  def finish() {
//    if (file == null) {
      println(resultStr.toString())
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
3
.CC
C..
C.C
"""

val sa2 = """
4
CC..
C..C
.CC.
.CC.
"""

}

}

import java.util.ArrayList
import java.util.StringTokenizer
import scala.reflect.io.File
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object A_343_A {

  def main(args: Array[String]): Unit = {

    //COMMENT ME !
//    is = new ByteArrayInputStream(Test.sa2.trim.getBytes("ISO-8859-1"))
//    debugV = true
//    file = File("C:\\temp\\google cj\\2014q\\c-small.res")

    //---------------------------- parameters reading --------------------------
//    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val arr = Array.fill(n,n)(0)
    for(i <- 0 until n) {
      val line = readLine.string
      for(j <- 0 until n) {
        arr(i)(j) = if (line(j) == '.') 0 else 1
      }
    }
    //---------------------------- parameters reading end ----------------------

    var total = 0
    for(i <- 0 until n) {
      var rowCount = 0
      for(j <- 0 until n) {
        if (arr(i)(j) == 1) {
          rowCount += 1
        }
      }
      total += soch(rowCount)
//      total += Subsets.subsetNumber(rowCount, 2)
    }

    for(i <- 0 until n) {
      var colCount = 0
      for(j <- 0 until n) {
        if (arr(j)(i) == 1) {
          colCount += 1
        }
      }
      total += soch(colCount)
//      total += Subsets.subsetNumber(colCount, 2)
    }

    println(total+"")
  }

  def soch(all:Int): Int = all - 1 match {
    case x if x < 1 => 0
    case rest => rest + soch(rest)
  }

  //============================ service code ======================

  val br = createBufferedReader(System.in)

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()

  }

  def createBufferedReader(in: InputStream): BufferedReader = {
    val bis = new BufferedInputStream(in);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
3
.CC
C..
C.C
"""

val sa2 = """
4
CC..
C..C
.CC.
.CC.
"""

}

}

import scala.io.Source

object CF343_A extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt

  val rows = new Array[Int](100)
  val cols = new Array[Int](100)

  for(r <- 0 to n-1) {
      val line = in.next()
      for(c <- 0 to n-1) {
         if(line.charAt(c) == 'C') {
           cols(c) += 1
           rows(r) += 1
         }

      }
  }

  var res = 0

  for(i <- 0 to n-1) {
    if(2 <= rows(i)) res += combination(rows(i), 2)
    if(2 <= cols(i)) res += combination(cols(i), 2)
  }

  println(res)

  def combination(n: Int, r: Int): Int = {
    if(r == 0)
      1
    else if(n == 0)
      0
    else {
      var res = 0
      res += combination(n-1, r)
      res += combination(n-1, r-1)
      res
    }
  }

}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val rows = Array.ofDim[Int](n)
  val res = (1 to n).foldLeft(0l) {
    case (acc, _) =>
      val str = in.next()
      val count = str.count(_ == 'C')
      str.indices.foreach{i => if (str(i) == 'C') rows(i) += 1}
      acc + count * (count - 1) / 2
  } + rows.foldLeft(0l){
    case(acc, count) => acc + count * (count - 1) / 2
  }
  println(res)

}

object A629 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = Array.fill(n)(read)
    val row = Array.fill(n)(0)
    val col = Array.fill(n)(0)
    for(i <- 0 until n; j <- 0 until n) {
      if(in(i)(j) == 'C') {
        row(i) += 1
        col(j) += 1
      }
    }
    val res = (row++col).foldLeft(0L){case (sum, i) => sum + (i.toLong*(i.toLong-1))/2}
    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))
    }
  }

}

/**
 * @author pvasilyev
 * @since 23 Apr 2016
 */
object Problem155 extends App {

  val n: Int = scala.io.StdIn.readInt()
  val cake = Array.ofDim[Char](n, n)
  for (i <- 0 until n) {
    cake(i) = scala.io.StdIn.readLine().toCharArray
  }
  var answer = 0

  for (i <- 0 until n) {
    var inRow = 0
    for (j <- 0 until n) {
      if (cake(i)(j) == 'C') {
        inRow += 1
      }
    }
    if (inRow >= 2) {
      answer += inRow * (inRow - 1) / 2
    }
  }
  for (j <- 0 until n) {
    var inCol = 0
    for (i <- 0 until n) {
      if (cake(i)(j) == 'C') {
        inCol += 1
      }
    }
    if (inCol >= 2) {
      answer += inCol * (inCol - 1) / 2
    }
  }
  println(answer)
}

object A {
  def main(args: Array[String]) {
    var arr = Array.ofDim[Char](128,128)
    var cnt = -1
    var n = 0
    for (ln <- io.Source.stdin.getLines) {
        if (cnt == -1) {
	    n = ln.trim.toInt
	}
        else {
	   for ( i <- 0 until ln.trim.length) {
		arr(cnt)(i) = ln(i)
	   }
	}
	cnt = cnt + 1
    }
    var res = 0
    for ( i <- 0 until n){
        var C = 0
	for (j<- 0 until n){
	    if(arr(i)(j)=='C'){
		C = C + 1
	    }
	}
        res = res + C*(C-1)/2
    }
    for ( j <- 0 until n){
        var C = 0
	for (i<- 0 until n){
	    if(arr(i)(j)=='C'){
		C = C + 1
	    }
	}
        res = res + C*(C-1)/2
    }
    println(res)
  }
}

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

object _629A extends CodeForcesApp {
  override type Result = Int

  override def solve(read: InputReader) = {
    val n = read[Int]
    val (rows, cols) = (Array.ofDim[Int](n+1), Array.ofDim[Int](n+1))

    for {
      i <- 1 to n
      line = read[String]
      j <- 1 to n
      if line(j-1) == 'C'
    } {
      rows(i) += 1
      cols(j) += 1
    }

    def nc2(i: Int) = (i*(i-1))/2

    rows.map(nc2).sum + cols.map(nc2).sum
  }

  override def format(result: Result) = result.toString
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  type Result
  def solve(scanner: InputReader): Result
  def format(result: Result): String
  def apply(scanner: InputReader): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))
  def this(str: String) = this(new StringReader(str))

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

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

  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)

  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {
    val builder = cbf()
    for {_ <- 1 to n} builder += apply[A]
    builder.result()
  }

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

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

class Parser[A](val apply: InputReader => A) {
  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)
}
object Parser {
  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]
  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))
  implicit val string                                                        : Parser[String]          = new Parser(_.next())
  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)
  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)
  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)
  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))
  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)
  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))
  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))
  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))
  implicit def tuple4[A: Parser, B: Parser, C: Parser, D: Parser]            : Parser[(A, B, C, D)]    = new Parser(r => (r[A], r[B], r[C], r[D]))
  implicit def tuple5[A: Parser, B: Parser, C: Parser, D: Parser, E: Parser] : Parser[(A, B, C, D, E)] = new Parser(r => (r[A], r[B], r[C], r[D], r[E]))
}

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

object _629A extends CodeForcesApp {
  override type Result = Int

  override def solve(read: InputReader) = {
    val n = read[Int]
    val chocolates = for {
      i <- 0 until n
      line = read[String]
      j <- 0 until n if line(j) == 'C'
    } yield (i, j)

    var ans = 0
    for {
      ((x1, y1), i) <- chocolates.zipWithIndex
      (x2, y2) <- chocolates drop (i + 1) if x1 == x2 || y1 == y2
    } ans += 1
    ans
  }

  override def format(result: Result) = result.toString
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  type Result
  def solve(scanner: InputReader): Result
  def format(result: Result): String
  def apply(scanner: InputReader): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))
  def this(str: String) = this(new StringReader(str))

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

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

  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)

  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {
    val builder = cbf()
    for {_ <- 1 to n} builder += apply[A]
    builder.result()
  }

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

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

class Parser[A](val apply: InputReader => A) {
  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)
}
object Parser {
  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]
  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))
  implicit val string                                                        : Parser[String]          = new Parser(_.next())
  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)
  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)
  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)
  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))
  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)
  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))
  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))
  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))
  implicit def tuple4[A: Parser, B: Parser, C: Parser, D: Parser]            : Parser[(A, B, C, D)]    = new Parser(r => (r[A], r[B], r[C], r[D]))
  implicit def tuple5[A: Parser, B: Parser, C: Parser, D: Parser, E: Parser] : Parser[(A, B, C, D, E)] = new Parser(r => (r[A], r[B], r[C], r[D], r[E]))
}

import java.util.Scanner

object Main{
  def main (args: Array[String]){
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    sc.nextLine()

    var cake = new Array[String](n)
    for(i <- 0 until n)
      cake(i) = sc.nextLine()

    //
    var ans = BigInt(0)

    for(i <- 0 until n){
      val s = cake(i)

      var cnt = 0
      for(e <- s)
        if(e == 'C')
          cnt += 1

      if(cnt >= 2)
        ans += (cnt * (cnt-1)) / 2
    }

    for(i <- 0 until n){
      var cnt = 0
      for(j <- 0 until n)
        if(cake(j)(i) == 'C')
          cnt += 1

      if(cnt >= 2)
        ans += (cnt * (cnt-1)) / 2
    }

    println(ans)
  }
}

/**
 * Created by aborisenko on 21.02.16.
 */

import io.StdIn._

object Main extends App {
  def a629 (){
    val n = readInt()
    var arr: Array[String] = new Array[String](n)

    for( i <- 0 to n-1)
      arr(i) = readLine()

    var arr1: Array[Long] = Array.fill[Long](n)(0)
    var arr2: Array[Long] = Array.fill[Long](n)(0)

    for( i <- 0 to n-1)
      for( j <- 0 to n-1) {
        arr1(i) += (if( arr(i)(j) == 'C') 1 else 0)
        arr2(j) += (if( arr(i)(j) == 'C') 1 else 0)
      }

    def f(n: Long): Long = {
      if(n <= 1) 0 else n-1 + f(n-1)
    }

    var sum: Long = 0

    for( i <- 0 to n-1) {
      sum = f(arr1(i)) + sum
      sum = f(arr2(i)) + sum
    }

    println(sum)
  }

  a629()
}

import java.util.ArrayList
import java.util.StringTokenizer
import scala.reflect.io.File
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object A_343_A {
    var br = createBufferedReader(); var debugV = false

      //COMMENT ME !
    runTest(Test.sa2)
    debugV = true
//    file = File("C:\\temp\\google cj\\2014q\\c-small.res")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading --------------------------
    val n = readLine.int
    val arr = Array.fill(n,n)(0)
    for(i <- 0 until n) {
      val line = readLine.string
      for(j <- 0 until n) {
        arr(i)(j) = if (line(j) == '.') 0 else 1
      }
    }
    debug("n = " + n)

    //---------------------------- parameters reading end ----------------------

    var total = 0
    for(i <- 0 until n) {
      var rowCount = 0
      for(j <- 0 until n) {
        if (arr(i)(j) == 1) {
          rowCount += 1
        }
      }
      total += soch(rowCount)
//      total += Subsets.subsetNumber(rowCount, 2)
    }

    for(i <- 0 until n) {
      var colCount = 0
      for(j <- 0 until n) {
        if (arr(j)(i) == 1) {
          colCount += 1
        }
      }
      total += soch(colCount)
//      total += Subsets.subsetNumber(colCount, 2)
    }

    println(total+"")
  }

  def soch(all:Int): Int = all - 1 match {
    case x if x < 1 => 0
    case rest => rest + soch(rest)
  }

  //============================ service code ======================

//  var inst = System.in

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()

  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
//    inst = new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1"))
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
3
.CC
C..
C.C
"""

val sa2 = """
4
CC..
C..C
.CC.
.CC.
"""

}

}

import java.util.Scanner

object Main{
  def main (args: Array[String]){
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    sc.nextLine()

    var cake = new Array[String](n)
    for(i <- 0 until n)
      cake(i) = sc.nextLine()

    //
    var ans = BigInt(0)

    for(i <- 0 until n){
      val s = cake(i)

      var cnt = 0
      for(e <- s)
        if(e == 'C')
          cnt += 1

      if(cnt >= 2)
        ans += (BigInt(2) to cnt).product / 2
    }

    for(i <- 0 until n){
      var cnt = 0
      for(j <- 0 until n)
        if(cake(j)(i) == 'C')
          cnt += 1

      if(cnt >= 2)
        ans += (BigInt(2) to cnt).product / 2
    }

    println(ans)
  }
}

/**
 * Created by aborisenko on 21.02.16.
 */

import io.StdIn._

object Main extends App {
  def a629 (){
    val n = readInt()
    var arr: Array[String] = new Array[String](n)

    for( i <- 0 to n-1)
      arr(i) = readLine()

    var arr1: Array[Long] = Array.fill[Long](n)(0)
    var arr2: Array[Long] = Array.fill[Long](n)(0)

    for( i <- 0 to n-1)
      for( j <- 0 to n-1) {
        if( arr(i)(j) == 'c') {
          arr1(i) += 1
          arr2(j) += 1
        }
      }

    def f(n: Long): Long = {
      if(n < 2) 1 else n * f(n-1)
    }

    var sum: Long = 0

    for( i <- 0 to n-1) {
      sum = (if(arr1(i) < 2) 0 else f(arr1(i) - 1)) + sum
      sum = (if(arr2(i) < 2) 0 else f(arr2(i) - 1)) + sum
    }

    println(sum)
  }

  a629()
}

/**
 * Created by aborisenko on 21.02.16.
 */

import io.StdIn._

object Main extends App {
  def a629 (){
    val n = readInt()
    var arr: Array[String] = new Array[String](n)

    for( i <- 0 to n-1)
      arr(i) = readLine()

    var arr1: Array[Long] = Array.fill[Long](n)(0)
    var arr2: Array[Long] = Array.fill[Long](n)(0)

    for( i <- 0 to n-1)
      for( j <- 0 to n-1) {
        if( arr(i)(j) == 'C') {
          arr1(i) += 1
          arr2(j) += 1
        }
      }

    def f(n: Long): Long = {
      if(n < 2) 1 else n * f(n-1)
    }

    var sum: Long = 0

    for( i <- 0 to n-1) {
      sum = (if(arr1(i) < 2) 0 else f(arr1(i) - 1)) + sum
      sum = (if(arr2(i) < 2) 0 else f(arr2(i) - 1)) + sum
    }

    println(sum)
  }

  a629()
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next()
  val (f, s, t) = in.next().split(' ').map(_.toInt).sorted.reverse.foldLeft(0, 0, 0) {
    case((a, b, c), el) if a <= b && a <= c => (a + el, b, c)
    case((a, b, c), el) if b <= a && b <= c => (a, b + el, c)
    case((a, b, c), el) if c <= a && c <= b => (a, b, c + el)
  }
  val sorted = List(f, s, t).sorted
  val res = sorted(2) - sorted(1) - sorted(0) + 1
  if (res >= 0)
    println(res)
  else
    println(0)
}

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

object _667B extends CodeForcesApp {
  override def apply(io: IO) = {
    val rods = io[List[Long]].sorted
    val p = rods.scanLeft(0L)(_ + _)
    val s = rods.scanRight(0L)(_ + _)
    val (l, r) = (p zip s) minBy {case (a, b) => (a - b).abs}
    io += (l - r).abs + 1
  }
}
/****************************[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
  }
  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 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 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[I] = new {
    def apply[O](f: I => O): I => O = new mutable.HashMap[I, O]() {
      override def apply(key: I) = getOrElseUpdate(key, f(key))
    }
  }
  @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 newLine: String = "\n"
}
/***********************************[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(): this.type = {
    println()
    this
  }

  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 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()
      }
    }
  }
}


object D {
  import InOut._

  def main(args: Array[String]): Unit = {}

  val n, k = nextInt
  val mn   = nextInts(n).sorted(Ordering.Int.reverse)
  val ck   = nextInts(k)

  val (ans, _, _) = ck.reverse.zipWithIndex
    .foldLeft((0, 0, 0d)) {
      case ((b, j, g), (c, i)) =>
        var t = mn.indexWhere(_ < (k - i), j)
        if (t < 0) t = n

        val h = g + t - j

        (b max math.ceil(h / c).toInt, t, h)
    }

  val kv = collection.mutable.Map.empty[Int, List[Int]]

  mn.zipWithIndex.foreach {
    case (m, i) =>
      val k = i % ans
      val v = m :: kv.getOrElse(k, Nil)

      kv += (k -> v)
  }

  out.println(ans)
  kv.foreach {
    case (_, vs) =>
      out.println(s"${vs.length} ${vs.mkString(" ")}")
  }
  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
  }
}

import scala.collection.mutable

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

  val n, k = nextInt
  val ms = nextInts(n)
  val cs = nextInts(k)

  val lastBigger = mutable.Map.empty[Int, Int]
  var prev = -1
  var prevM = -1
  for (i <- 0 until k) {
    if (prev != cs(i)) {
      prev = cs(i)
      prevM = i
    }
    lastBigger(i) = prevM
  }

  val counts = new java.util.TreeMap[Int, Int]
  for (m <- ms) {
    counts.put(m, counts.getOrDefault(m, 0) + 1)
  }

  var resBuilders = mutable.ArrayBuffer.empty[mutable.ArrayBuilder.ofInt]
  while (!counts.isEmpty) {
    resBuilders += new mutable.ArrayBuilder.ofInt
    var lim = Int.MaxValue
    val it = counts.keySet().iterator
    //val removeBuilder = new mutable.ArrayBuilder.ofInt
    var used = 0
    var current = counts.lastKey()
    while (current > 0) {
      val value = counts.get(current)
      lim = cs(current - 1) - used
      if (lim > 0) {
        val take = value min lim
        used += take
        if (value == take) {
          counts.remove(current)
        } else {
          counts.put(current, value - take)
        }
        var i = 0
        while (i < take) {
          resBuilders.last += current
          i += 1
        }
        current = counts.lowerKey(current)
      } else {
        current = lastBigger(current)
      }
    }
//    var i = 0
//    val remove = removeBuilder.result()
//    while (i < remove.length)  {
//      counts.remove(remove(i))
//      i += 1
//    }
  }

  val res = resBuilders.map(_.result())

  out.println(res.size)
  res.foreach { r =>
    out.print(r.length)
    out.println(r.mkString(" ", " ", ""))
  }

  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
  }
}

import scala.collection.mutable

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

  val n, k = nextInt
  val ms = nextInts(n)
  val cs = nextInts(k)

  val counts = mutable.TreeMap.empty[Int, Int].withDefaultValue(0)
  for (m <- ms) {
    counts(m) += 1
  }

  var resBuilders = mutable.ArrayBuffer.empty[mutable.ArrayBuilder.ofInt]
  while (counts.nonEmpty) {
    resBuilders += new mutable.ArrayBuilder.ofInt
    var lim = Int.MaxValue
    val it = counts.iterator
    val removeBuilder = new mutable.ArrayBuilder.ofInt
    while (it.hasNext && lim > 0) {
      val (key, value) = it.next()
      lim = lim min cs(key - 1)
      val take = value min lim
      counts(key) -= take
      if (value == take) {
        removeBuilder += key
      }
      var i = 0
      while (i < take) {
        resBuilders.last += key
        i += 1
      }
      lim -= take
    }
    val remove = removeBuilder.result()
    for (r <- remove) {
      counts.remove(r)
    }
  }

  val res = resBuilders.map(_.result())

  out.println(res.size)
  res.foreach { r =>
    out.print(r.length)
    out.println(r.mkString(" ", " ", ""))
  }

  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
  }
}

import scala.collection.mutable

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

  val n, k = nextInt
  val ms = nextInts(n)
  val cs = nextInts(k)

  val counts = mutable.TreeMap.empty[Int, Int].withDefaultValue(0)
  for (m <- ms) {
    counts(m) += 1
  }

  var resBuilders = mutable.ArrayBuffer.empty[mutable.ArrayBuilder.ofInt]
  while (counts.nonEmpty) {
    resBuilders += new mutable.ArrayBuilder.ofInt
    var lim = Int.MaxValue
    val it = counts.iterator
    val updates = mutable.ArrayBuffer.empty[(Int, Int)]
    while (it.hasNext && lim > 0) {
      val (key, value) = it.next()
      lim = lim min cs(key - 1)
      val take = value min lim
      counts(key) -= take
      updates += ((key, value - take))
      var i = 0
      while (i < take) {
        resBuilders.last += key
        i += 1
      }
      lim -= take
    }
    for ((k, v) <- updates) {
      if (v == 0) {
        counts.remove(k)
      } else {
        counts(k) = v
      }
    }
  }

  val res = resBuilders.map(_.result())

  out.println(res.size)
  res.foreach { r =>
    out.print(r.length)
    out.println(r.mkString(" ", " ", ""))
  }

  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 D extends App {
  val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val mn          = scala.io.StdIn.readLine().split(" ").map(_.toInt).sorted(Ordering.Int.reverse)
  val ck          = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val ans = ck.reverse.zipWithIndex
    .foldLeft((mn, 0d, 0)) {
      case ((mn, g, b), (c, i)) =>
        val mm = mn.dropWhile(_ >= (k - i))
        val t  = g + mn.length - mm.length

        (mm, t, b.max((t / c).toInt))
    }
    ._3

  val kv = collection.mutable.Map.empty[Int, List[Int]]

  mn.zipWithIndex.foreach {
    case (m, i) =>
      val k = i % ans
      val v = m :: kv.getOrElse(k, Nil)

      kv += (k -> v)
  }

  println(ans)

  kv.foreach {
    case (_, vs) =>
      println(s"${vs.length} ${vs.mkString(" ")}")
  }
}

object D {
  import InOut._

  def main(args: Array[String]): Unit = {}

  val n, k = nextInt
  val mn   = nextInts(n).sorted(Ordering.Int.reverse)
  val ck   = nextInts(k)

  val (ans, _, _) = ck.reverse.zipWithIndex
    .foldLeft((0, 0, 0d)) {
      case ((b, j, g), (c, i)) =>
        val t = mn.indexWhere(_ < (k - i), j)

        val h = g + (if (t < 0) n - j else t - j)

        (b max math.ceil(h / c).toInt, t, h)
    }

  val kv = collection.mutable.Map.empty[Int, List[Int]]

  mn.zipWithIndex.foreach {
    case (m, i) =>
      val k = i % ans
      val v = m :: kv.getOrElse(k, Nil)

      kv += (k -> v)
  }

  out.println(ans)
  kv.foreach {
    case (_, vs) =>
      out.println(s"${vs.length} ${vs.mkString(" ")}")
  }
  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 D extends App {

  private def greater(mn: List[Int], k: Int): List[Int] = {
    @scala.annotation.tailrec
    def go(mn: List[Int], i: Int, gk: List[Int]): List[Int] =
      if (i == 0) gk
      else {
        val mm = mn.dropWhile(_ >= i)
        val g  = gk.head + (mn.length - mm.length)

        go(mm, i - 1, g :: gk)
      }

    go(mn, k, List(0))
  }

  private def boxes(ck: Seq[Int], gk: Seq[Int]): Int = {
    @scala.annotation.tailrec
    def go(ck: Seq[Int], gk: Seq[Int], b: Int): Int =
      ck match {
        case Seq() => b
        case _     => go(ck.tail, gk.tail, b.max(math.ceil(gk.head.toDouble / ck.head).toInt))
      }

    go(ck, gk, 0)
  }

  private def put(mn: List[Int], b: Int): collection.mutable.Map[Int, List[Int]] = {
    val kv = collection.mutable.Map.empty[Int, List[Int]]

    mn.zipWithIndex.foreach {
      case (m, i) =>
        val k = i % b
        val v = m :: kv.getOrElse(k, Nil)

        kv += (k -> v)
    }

    kv
  }

  val Array(n, k) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val mn          = scala.io.StdIn.readLine().split(" ").map(_.toInt).sorted(Ordering.Int.reverse).toList
  val ck          = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val gk = greater(mn, k)

  println(s"gk: ${gk.mkString(" ")}")
  println(s"ck: ${ck.mkString(" ")}")

  val b = boxes(ck, gk)

  val ans = put(mn, b).values.toList

  println(ans.length)
  ans.foreach(t => println(s"${t.length} ${t.mkString(" ")}"))
}

object D {
  import InOut._

  def main(args: Array[String]): Unit = {}

  val n, k = nextInt
  val mn   = nextInts(n)
  val ck   = nextInts(k)

  val ans = ck.reverse.zipWithIndex
    .foldLeft((mn, 0d, 0)) {
      case ((mn, g, b), (c, i)) =>
        val mm = mn.dropWhile(_ >= (k - i))
        val t  = g + mn.length - mm.length

        (mm, t, b.max(math.ceil(t / c.toInt).toInt))
    }
    ._3

  val kv = collection.mutable.Map.empty[Int, List[Int]]

  mn.zipWithIndex.foreach {
    case (m, i) =>
      val k = i % ans
      val v = m :: kv.getOrElse(k, Nil)

      kv += (k -> v)
  }

  out.println(ans)
  kv.foreach {
    case (_, vs) =>
      out.println(s"${vs.length} ${vs.mkString(" ")}")
  }
  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
  }
}


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

object C {

  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)
    }
    return st.nextToken
  }

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

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

  class MultiTreeSet[T <: Comparable[T]] {
    val map = new util.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 w = nextInt
    val h = nextInt
    val n = nextInt
    val hor = new TreeSet[Int]()
    val vert = new TreeSet[Int]()
    val hCuts = new MultiTreeSet[Integer]
    val vCuts = new MultiTreeSet[Integer]
    hCuts.add(h)
    vCuts.add(w)
    hor.add(0)
    hor.add(h)
    vert.add(0)
    vert.add(w)
    for (i <- 0 until n) {
      val dir = next.toCharArray.apply(0)
      if (dir == 'H') {
        val pos = h - nextInt
        val lo = hor.lower(pos)
        val hi = hor.higher(pos)
        hCuts.remove(hi - lo)
        hCuts.add(hi - pos)
        hCuts.add(pos - lo)
        hor.add(pos)
      } else {
        val pos = nextInt
        val lo = vert.lower(pos)
        val hi = vert.higher(pos)
        vCuts.remove(hi - lo)
        vCuts.add(hi - pos)
        vCuts.add(pos - lo)
        vert.add(pos)
      }
      out.println(vCuts.last().toLong * hCuts.last().toLong)
    }
    return 1
  }

  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.io._
import java.util
import java.util._

object C {

  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)
    }
    return st.nextToken
  }

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

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

  class MultiTreeSet[T <: Comparable[T]] {
    val map = new util.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 w = nextInt
    val h = nextInt
    val n = nextInt
    val hor = new TreeSet[Int]()
    val vert = new TreeSet[Int]()
    val hCuts = new MultiTreeSet[Integer]
    val vCuts = new MultiTreeSet[Integer]
    hCuts.add(h)
    vCuts.add(w)
    hor.add(0)
    hor.add(h)
    vert.add(0)
    vert.add(w)
    for (i <- 0 until n) {
      val dir = next.toCharArray.apply(0)
      if (dir == 'H') {
        val pos = h - nextInt
        val lo = hor.lower(pos)
        val hi = hor.higher(pos)
        hCuts.remove(hi - lo)
        hCuts.add(hi - pos)
        hCuts.add(pos - lo)
        hor.add(pos)
      } else {
        val pos = nextInt
        val lo = vert.lower(pos)
        val hi = vert.higher(pos)
        vCuts.remove(hi - lo)
        vCuts.add(hi - pos)
        vCuts.add(pos - lo)
        vert.add(pos)
      }
      out.println(vCuts.last() * hCuts.last())
    }
    return 1
  }

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


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, K = nl()
    val x = (K - 1) / N + 1

    out.println(x)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }
}

import scala.io.StdIn

object Problem1036a {
  def main(args: Array[String]): Unit = {
    val vals = StdIn.readLine().split(" ").map(_.toLong)
    val n = vals(0)
    val k = vals(1)

    println(solve(n, k))
  }

  def solve(n: Long, k: Long): Long = {
    (k - 1) / n + 1
  }
}

object Main {
import java.io._
import java.util.Scanner

import collection.mutable.HashMap
import scala.collection.{SortedSet, mutable}
import scala.util.Random
  protected val EPS = 1e-11

  private def default = (
    new StreamTokenizer(new InputStreamReader(System.in)),
    new Scanner(System.in),
    new PrintWriter(System.out)
  )

  val (in, ins, out) = {
    try {
      if (sys.props.contains("xDx")) {
        (
          new StreamTokenizer(new FileReader("input.txt")),
          new Scanner(new FileReader("input.txt")),
          new PrintWriter(new FileWriter("output.txt"))
        )
      } else {
        default
      }
    } catch {
      case _: Throwable => default
    }
  }

  private def nextInt = {
    in.nextToken
    in.nval.toInt
  }

  private def nextLong = {
    in.nextToken
    in.nval.toLong
  }

  private def nextDouble = {
    in.nextToken
    in.nval
  }

  private def nextString = {
    in.nextToken
    in.sval
  }

  private def nextChar = {
    in.nextToken
    in.ttype.toChar
  }

  def main(args: Array[String]): Unit = {
    try {
      new Run().run()
    } catch {
      case e: Throwable =>
        throw new RuntimeException(e)
    } finally out.close()
  }

  class Run {
    import collection.breakOut
    def run(): Unit = {
        val n = ins.nextLong
        val k = ins.nextLong
        println((k + n - 1)/n)
    }

  }

}

import scala.io.StdIn

object Problem1036a {
  def main(args: Array[String]): Unit = {
    val vals = StdIn.readLine().split(" ").map(_.toInt)
    val n = vals(0)
    val k = vals(1)
    println(k / n)
  }
}


import sun.management.counter.Counter

import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object Solution extends App {

  //=====Solution=========
  val testNumber = readInt()
  1.to(testNumber).foreach { _ =>
    val Array(characterHealth, characterDamage) = readLongs().map(BigInt(_))
    val Array(monsterHealth, monsterDamage) = readLongs().map(BigInt(_))
    val Array(coins, weaponBonus, armourBonus) = readLongs().map(BigInt(_))

    def remainingLifeWithBonuses(weaponCoins: BigInt): BigInt =
      remainingLife(
        characterHealth + (coins - weaponCoins) * armourBonus,
        characterDamage + weaponCoins * weaponBonus
      )

    def remainingLife(characterHealth: BigInt, characterDamage: BigInt): BigInt = {
      val roundNumber = (monsterHealth-1) / characterDamage + 1
      val answer = characterHealth - (roundNumber - 1) * monsterDamage
      answer
    }

    val answer = 0.to(coins.toInt).map(c => remainingLifeWithBonuses(c) > 0).reduce(_ || _)
    if (answer) println("YES") else println("NO")

  }

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

object KillTheMonsters extends App {
def count(hc: Long, dc: Long, hm: Long, dm: Long, k: Long, w: Long, a: Long): String =
    if ((0L to k).exists{ na => (1.0 * hm / (dc + na * w)).ceil <= (1.0 * (hc + (k - na) * a) / dm).ceil }) "YES" else "NO"

  val lines = io.Source.stdin.getLines
  val t = lines.next.toInt
  (1 to t).foreach{_ =>
    val fl = lines.next.split(" ")
    val hc = fl(0).toLong
    val dc = fl(1).toLong
    val sl = lines.next.split(" ")
    val hm = sl(0).toLong
    val dm = sl(1).toLong
    val tl = lines.next.split(" ")
    val k = tl(0).toLong
    val w = tl(1).toLong
    val a = tl(2).toLong
    println(count(hc, dc, hm, dm, k, w, a))
  }
}

import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.math._, BigDecimal._

object cf1633c {
  def main(args: Array[String]): Unit = {
    var t = readInt()
    while(t > 0) {
      t -= 1
      var Array(hC, dC) = readLine.split(" ").map(BigInt(_))
      var Array(hM, dM) = readLine.split(" ").map(BigInt(_))
      var Array(k, w, a) = readLine.split(" ").map(BigInt(_))
      var possible = false
      for(K <- BigInt(0) to k) {
        if(check(hC + K * a, dC + (k - K) * w, hM, dM)) {
          possible = true
        }
      }
      if(possible == true) {
        println("YES")
      }
      else {
        println("NO")
      }
    }
  }

  def check(hC: BigInt, dC: BigInt, hM: BigInt, dM: BigInt): Boolean = {
    var req_t = (BigDecimal(hM) / BigDecimal(dC)).setScale(0, RoundingMode.CEILING)
    if(BigDecimal(hC) > BigDecimal(dM) * (req_t - 1)) {
      return true
    }
    return false
  }
}

object KillTheMonsters extends App {
  def count(hc: Int, dc: Int, hm: Int, dm: Int, k: Int, w: Int, a: Int): String =
    if ((0 to k).exists(na => hm / (dc + na * w) - 1 < (hc + (k - na) * a) / dm)) "YES" else "NO"

  val lines = io.Source.stdin.getLines
  val t = lines.next.toInt
  (1 to t).foreach{_ =>
    val fl = lines.next.split(" ")
    val hc = fl(0).toInt
    val dc = fl(1).toInt
    val sl = lines.next.split(" ")
    val hm = sl(0).toInt
    val dm = sl(1).toInt
    val tl = lines.next.split(" ")
    val k = tl(0).toInt
    val w = tl(1).toInt
    val a = tl(2).toInt
    println(count(hc, dc, hm, dm, k, w, a))
  }
}

object KillTheMonsters extends App {
  def count(hc: Int, dc: Int, hm: Int, dm: Int, k: Int, w: Int, a: Int): String =
    if ((0 to k).exists(na => hm / (dc + na * w) < 1 + (hc + (k - na) * a) / dm)) "YES" else "NO"

  val lines = io.Source.stdin.getLines
  val t = lines.next.toInt
  (1 to t).foreach{_ =>
    val fl = lines.next.split(" ")
    val hc = fl(0).toInt
    val dc = fl(1).toInt
    val sl = lines.next.split(" ")
    val hm = sl(0).toInt
    val dm = sl(1).toInt
    val tl = lines.next.split(" ")
    val k = tl(0).toInt
    val w = tl(1).toInt
    val a = tl(2).toInt
    println(count(hc, dc, hm, dm, k, w, a))
  }
}

object KillTheMonsters extends App {
  def count(hc: Int, dc: Int, hm: Int, dm: Int, k: Int, w: Int, a: Int): String =
    if ((0 to k).exists(na => hm / (dc + na * w) + 1 <= (hc + (k - na) * a) / dm)) "YES" else "NO"

  val lines = io.Source.stdin.getLines
  val t = lines.next.toInt
  (1 to t).foreach{_ =>
    val fl = lines.next.split(" ")
    val hc = fl(0).toInt
    val dc = fl(1).toInt
    val sl = lines.next.split(" ")
    val hm = sl(0).toInt
    val dm = sl(1).toInt
    val tl = lines.next.split(" ")
    val k = tl(0).toInt
    val w = tl(1).toInt
    val a = tl(2).toInt
    println(count(hc, dc, hm, dm, k, w, a))
  }
}

object KillTheMonsters extends App {
  def count(hc: Int, dc: Int, hm: Int, dm: Int, k: Int, w: Int, a: Int): String =
    if ((0 to k).exists(na => hm / (dc + na * w) <= (hc + (k - na) * a) / dm)) "YES" else "NO"

  val lines = io.Source.stdin.getLines
  val t = lines.next.toInt
  (1 to t).foreach{_ =>
    val fl = lines.next.split(" ")
    val hc = fl(0).toInt
    val dc = fl(1).toInt
    val sl = lines.next.split(" ")
    val hm = sl(0).toInt
    val dm = sl(1).toInt
    val tl = lines.next.split(" ")
    val k = tl(0).toInt
    val w = tl(1).toInt
    val a = tl(2).toInt
    println(count(hc, dc, hm, dm, k, w, a))
  }
}

import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object cf1633c {
  def main(args: Array[String]): Unit = {
    var t = readInt()
    while(t > 0) {
      t -= 1
      var Array(hC, dC) = readLine.split(" ").map(BigInt(_))
      var Array(hM, dM) = readLine.split(" ").map(BigInt(_))
      var Array(k, w, a) = readLine.split(" ").map(BigInt(_))
      var possible = false
      for(K <- BigInt(0) to k) {
        if(check(hC + K * a, dC + (k - K) * w, hM, dM)) {
          possible = true
        }
      }
      if(possible == true) {
        println("YES")
      }
      else {
        println("NO")
      }
    }
  }

  def check(hC: BigInt, dC: BigInt, hM: BigInt, dM: BigInt): Boolean = {
    var req_t = (hM.toFloat / dC.toFloat).ceil
    if(hC.toFloat > dM.toFloat * (req_t - 1)) {
      return true
    }
    return false
  }
}

import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object cf1633c {
  def main(args: Array[String]): Unit = {
    var t = readInt()
    println(t)
    while(t > 0) {
      t -= 1
      var Array(hC, dC) = readLine().split(" ").map(_.toInt)
      var Array(hM, dM) = readLine().split(" ").map(_.toInt)
      var Array(k, w, a) = readLine().split(" ").map(_.toInt)
      var possible = false
      for(K <- 0 to k) {
        println(K)
        if(check(hC + K * a, dC + (k - K) * w, hM, dM)) {
          possible = true
        }
      }
      if(possible == true) {
        println("YES")
      }
      else {
        println("NO")
      }

    }
  }

  def check(hC: Int, dC: Int, hM: Int, dM: Int): Boolean = {
    var req_t = (hM*1.0 / dC).ceil
    if(hC > dM * (req_t - 1)) {
      return true
    }
    return false
  }
}

import sun.management.counter.Counter

import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object Solution extends App {

  //=====Solution=========
  val testNumber = readInt()
  1.to(testNumber).foreach { _ =>
    val Array(characterHealth, characterDamage) = readLongs().map(BigInt(_))
    val Array(monsterHealth, monsterDamage) = readLongs().map(BigInt(_))
    val Array(coins, weaponBonus, armourBonus) = readLongs().map(BigInt(_))

    def remainingLifeWithBonuses(weaponCoins: BigInt): BigInt =
      remainingLife(
        characterHealth + (coins - weaponCoins) * armourBonus,
        characterDamage + weaponCoins * weaponBonus
      )

    def remainingLife(characterHealth: BigInt, characterDamage: BigInt): BigInt = {
      val roundNumber = (monsterHealth-1) / characterDamage + 1
      val answer = characterHealth - (roundNumber - 1) * monsterDamage
      answer
    }

    def search(l: BigInt, r: BigInt): Boolean =
      if (r - l <= 1) remainingLifeWithBonuses(l) > 0 || remainingLifeWithBonuses(r) > 0
      else {
        val medium = (r + l) / 2
        if (remainingLifeWithBonuses(medium - 1) > remainingLifeWithBonuses(medium + 1)) {
          search(l, medium)
        } else {
          search(medium, r)
        }
      }

    val answer = search(0, coins)
    if (answer) println("YES") else println("NO")

  }

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object Solution extends App {

  //=====Solution=========
  val testNumber = readInt()
  1.to(testNumber).foreach { _ =>
    val Array(characterHealth, characterDamage) = readLongs()
    val Array(monsterHealth, monsterDamage) = readLongs()
    val Array(coins, weaponBonus, armourBonus) = readLongs()

    def remainingLifeWithBonuses(weaponCoins: Long): Long =
      remainingLife(
        characterHealth + (coins - weaponCoins) * armourBonus,
        characterDamage + weaponCoins * weaponBonus
      )

    def remainingLife(characterHealth: Long, characterDamage: Long): Long = {
      val roundNumber = (monsterHealth-1) / characterDamage + 1
      val answer = characterHealth - (roundNumber - 1) * monsterDamage
      answer
    }

    def search(l: Long, r: Long): Boolean =
      if (r - l <= 1) remainingLifeWithBonuses(l) > 0 || remainingLifeWithBonuses(r) > 0
      else {
        val medium = (r + l) / 2
        if (remainingLifeWithBonuses(medium - 1) > remainingLifeWithBonuses(medium + 1)) {
          search(l, medium)
        } else {
          search(medium, r)
        }
      }

    val answer = search(0, coins)
    if (answer) println("YES") else println("NO")

  }

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}


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

import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new CVK17A(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class CVK17A(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val m = ni()

    g = Array.fill[ListBuffer[Int]](n)(new ListBuffer[Int]())

    REP(m) { _ =>
      val u = ni()
      val v = ni()

      g(u-1) += v-1
      g(v-1) += u-1
    }

    marked = Array.fill[Int](n)(-1)
    var id = 0
    var yes = true
    var prev = 0
    REP(n) { i =>
     if(marked(i) == -1) {
       marked(i) = id
       counter +=1
       val x = countEdges(i)
       val y = (counter - prev).toLong
//       out.println(i + " " + x + " " + y + " " + i + " " + (y * (y-1)))
       yes = yes & (x == (y * (y-1)))
       id += 1
       prev = counter
     }
    }
    if(yes) {
      out.println("YES")
    } else out.println("NO")
  }

  var g: Array[ListBuffer[Int]] = _
  var marked: Array[Int] = _
  var counter = 0

  def countEdges(u: Int): Long = {
    var stack = List.empty[Int]
    stack = u :: stack
    var count = 0L
    while (stack.nonEmpty) {
      val v = stack.head
      stack = stack.drop(1)
      count += g(v).size
      g(v).foreach { f =>
        if (marked(f) == -1) {
          marked(f) = marked(v)
          counter += 1
          stack = f :: stack
        }
      }
    }
    count
  }
}

//package solutions

import java.io.PrintWriter
import java.util.Scanner

import scala.util.control.Breaks

/**
  * @author traff
  */

object SolTaskB extends App {
  override def main(args: Array[String]): Unit = {
    val out = new PrintWriter(System.out)

    run(new Scanner(System.in), out)

    out.close()
  }

  def run(s: Scanner, out: PrintWriter): Unit = {
    val n = s.nextInt()
    val m = s.nextInt()

    var t: Array[Int] = (0 until n).toArray

    var rank: Array[Int] = Array.fill(n)(1)

    def find(i: Int): Int = {
      if (i == t(i)) {
        i
      } else {
        t(i) = find(t(i))
        t(i)
      }
    }

    def union(i: Int, j: Int): Unit = {
      if (rank(i) > rank(j)) {
        t(i) = t(j)
        rank(i) += rank(j)
      } else {
        t(j) = t(i)
        rank(j) += rank(i)
      }
    }

    val c = Array.fill(n + 1)(0)

    for (i <- 1 to m) {
      var a = s.nextInt()
      var b = s.nextInt()

      if (b > a) {
        val t = a
        a = b
        b = t
      }

      if (find(a - 1) != find(b - 1)) {
        union(find(a - 1), find(b - 1))
      }

      c(a) += 1
      c(b) += 1
    }

    var cnt = Array.fill(n)(0)

    for (i <- 1 to n) {
      cnt(find(i-1)) += 1
    }

    Breaks.breakable {
      for (i <- 1 to n) {
        if (c(i) != (cnt(find(i-1)) - 1)) {
          out.write("NO")
          Breaks.break()
        }
      }

      out.write("YES")
    }
  }
}

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

import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new CVK17A(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class CVK17A(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val m = ni()

    g = Array.fill[ListBuffer[Int]](n)(new ListBuffer[Int]())

    REP(m) { _ =>
      val u = ni()
      val v = ni()

      g(u-1) += v-1
      g(v-1) += u-1
    }

    marked = Array.fill[Int](n)(-1)
    var id = 0
    var yes = true
    var prev = 0
    REP(n) { i =>
     if(marked(i) == -1) {
       marked(i) = id
       counter +=1
       val x = countEdges(i)
       val y = (counter - prev).toLong
//       out.println(x + " " + y + " " + i + " " + (y * (y-1)))
       yes = yes & (x == (y * (y-1)))
       id += 1
       prev = counter
     }
    }
    if(yes) {
      out.println("YES")
    } else out.println("NO")
  }

  var g: Array[ListBuffer[Int]] = _
  var marked: Array[Int] = _
  var counter = 0

  def countEdges(u: Int): Long = {
    var stack = List.empty[Int]
    stack = u :: stack
    var count = 0L
    while (stack.nonEmpty) {
      val v = stack.head
      stack = stack.drop(1)
      count += g(u).size
      g(v).foreach { f =>
        if (marked(f) == -1) {
          marked(f) = marked(v)
          counter += 1
          stack = f :: stack
        }
      }
    }
    count
  }
}

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

import scala.collection.mutable.ListBuffer
import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new CVK17A(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class CVK17A(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val m = ni()

    g = Array.fill[ListBuffer[Int]](n)(new ListBuffer[Int]())

    REP(m) { _ =>
      val u = ni()
      val v = ni()

      g(u-1) += v-1
      g(v-1) += u-1
    }

    marked = Array.fill[Int](n)(-1)
    var id = 0
    var yes = true
    var prev = 0
    REP(n) { i =>
     if(marked(i) == -1) {
       marked(i) = id
       counter +=1
       val x = countEdges(i)
       val y = counter - prev
//       out.println(x + " " + y + " " + i + " " + (y * (y-1)))
       yes = yes & (x == (y * (y-1)))
       id += 1
       prev = counter
     }
    }
    if(yes) {
      out.println("YES")
    } else out.println("NO")
  }

  var g: Array[ListBuffer[Int]] = _
  var marked: Array[Int] = _
  var counter = 0

  def countEdges(u: Int): Int = {
    var count = g(u).size
    g(u).foreach { f =>
      if(marked(f) == -1) {
        counter += 1
        marked(f) = marked(u)
       count += countEdges(f)
      }
    }
    count
  }
}