Problem:
Score : 500 points

Problem Statement

You are given an integer N. Determine if there exists a tuple of subsets of \{1,2,...N\}, (S_1,S_2,...,S_k), that satisfies the following conditions:

Each of the integers 1,2,...,N is contained in exactly two of the sets S_1,S_2,...,S_k.

Any two of the sets S_1,S_2,...,S_k have exactly one element in common.

If such a tuple exists, construct one such tuple.

Constraints

1 \leq N \leq 10^5

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If a tuple of subsets of \{1,2,...N\} that satisfies the conditions does not exist, print No.
If such a tuple exists, print Yes first, then print such subsets in the following format:

k
|S_1| S_{1,1} S_{1,2} ... S_{1,|S_1|}
:
|S_k| S_{k,1} S_{k,2} ... S_{k,|S_k|}

where S_i={S_{i,1},S_{i,2},...,S_{i,|S_i|}}.

If there are multiple such tuples, any of them will be accepted.

Sample Input 1

3

Sample Output 1

Yes
3
2 1 2
2 3 1
2 2 3

It can be seen that (S_1,S_2,S_3)=(\{1,2\},\{3,1\},\{2,3\}) satisfies the conditions.

Sample Input 2

4

Sample Output 2

No

Solution in Scala (2.11.7) (judge verdict: Accepted)

object Main extends App {
  val N = scala.io.StdIn.readInt

  getSkew(1, Nil) match {
    case Nil => println("No")
    case skew => print(calc(skew))
  }

  def calc(skew: List[Int]): List[List[Int]] = {
    val n = skew.size
    val line = 1 :: skew.init.map(_ + 1)
    skew :: (0 until n).toList.map{i =>
      Stream.from(line(i)).take(i) ++: line.drop(i).map(_ + i)
    }
  }

  def print(list: List[List[Int]]): Unit = {
    println("Yes")
    println(list.size)
    list.foreach(l => println((l.size :: l).mkString(" ")))
  }

  @scala.annotation.tailrec
  def getSkew(n: Int, skew: List[Int]): List[Int] = sum(n) match {
    case N => (N :: skew).reverse
    case s if s < N => getSkew(n + 1, s :: skew)
    case _ => Nil
  }

  def sum(n: Int): Int = (n + 1) * n / 2
}