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 (Python):
N = int(input())

k = N*2
flag = False
tmp = 0
if N == 1:
    print("Yes")
    print(2)
    print(1, 1)
    print(1, 1)
    exit(0)
for x in range(2, int(k ** 0.5) + 1):
    if k % x == 0 and k // x == x+1:
        tmp = x
        flag = True
        break
if flag:
    print("Yes")
    print(tmp+1)
    ans = [[] for i in range(tmp+1)]
    count = 0
    for i in range(tmp+1):
        ret = [str(tmp)]
        for k in range(i):
            ret.append(ans[k][i])
        for j in range(tmp):
            if i == 0:
                count += 1
                ret.append(str(count))
            else:
                if j < tmp - i:
                    count += 1
                    ret.append(str(count))

        ans[i] = ret
    for i in range(tmp+1):
        print(" ".join(ans[i]))
else:
    print("No")

Solution (Python):
import sys
from itertools import combinations

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  

N = ri()
x = int((2 * N) ** (0.5))
if x * (x+1) == 2 * N:
    print('Yes')
else:
    print('No')
    exit()

k = x + 1 
num = 2 * N // k 
answer = [[] for _ in range(k)]
for i, (a, b) in enumerate(combinations(range(k), 2), 1):
    answer[a].append(i)
    answer[b].append(i)

print(k)
for a in answer:
    print(num, *a)

Solution (Python):
n=int(input())
y=(1+8*n)**0.5
if not y.is_integer():
    print("No")
    exit()
x=int(y)
if x%2==0:
    print("No")
    exit()
print("Yes")

k=(1+x)//2
atama=set()
atama.add(1)
now=1
for i in range(1,1000):
    now+=i
    if now<=n:
        atama.add(now)
    else:
        break
haji=set()
d={}
now=0
for i in range(1,1000):
    now+=i
    if now<=n and now not in haji:
        haji.add(now)
        d[now]=i
    else:
        break
k=len(atama)

ans=[list(atama),list(haji)]
for s in atama:
    if s==1:
        continue
    l=[s]
    while s+1 not in haji:
        l.append(s+1)
        s+=1
    s+=1
    l.append(s)
    c=d[s]
    for i in range(c,1000):
        s+=i
        if s<=n:
            l.append(s)
        else:
            break
    ans.append(l)
print(k+1)
for i in range(k+1):
    print(k,*ans[i])

Solution (Python):
N = int(input())
k = int((2*N)**0.5)+1
if 2*N==k*(k-1):
    print("Yes")
    A = [[0 for _ in range(k+1)] for _ in range(k+1)]
    cnt = 1
    for i in range(1,k):
        for j in range(i+1,k+1):
            A[i][j] = cnt
            A[j][i] = A[i][j]
            cnt += 1
    S = [[] for _ in range(k+1)]
    for i in range(1,k+1):
        for j in range(1,k+1):
            if i!=j:
                S[i].append(A[i][j])
    print(k)
    for i in range(1,k+1):
        print(k-1,*S[i])
else:
    print("No")

Solution (Python):
n = int(input())
l, r = 0, 10 ** 4
while r - l > 1:
    m = (l + r) // 2
    if m * (m - 1) // 2 <= n:
        l = m
    else:
        r = m
if l * (l - 1) // 2 != n:
    print('No')
else:
    print('Yes')
    print(l)
    a = [[] for _ in range(l)]
    t = 1
    for i in range(l):
        for j in range(i + 1, l):
            a[i].append(t)
            a[j].append(t)
            t += 1
    for x in a:
        print(len(x), end=' ')
        print(' '.join(map(str, x)))

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    for k in range(1000):
        if (k*k-k) % 2 == 0 and (k*k-k) // 2 == N:
            break
    else:
        print('No')
        return

    c = 1
    S = [set() for _ in range(k)]
    for i in range(k):
        for j in range(i+1, k):
            S[i].add(c)
            S[j].add(c)
            c += 1
    print('Yes')
    print(k)
    for s in S:
        print(len(s), ' '.join(map(str, s)))



def main():
    N = read_int()
    (slv(N))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

for i in range(10 ** 5) :
  if i * (i + 1) // 2 == N :
    print('Yes')
    print(i + 1)
    ret = [[] for _ in range(i + 1)]
    cur = 1
    for j in range(i + 1) :
      for _ in range(i - j) :
        ret[j].append(cur)
        cur += 1
    for j in range(1, i + 1) :
      for k in range(j) :
        ret[j].append(ret[k][i-j])
    for j in range(i + 1) :
      print(i, *ret[j])
    
    break
else :
  print('No')

Solution (Python):
N=int(input())
cN=N

d=1
while N%2==0:
  N//=2
  d+=1

k=-1
for i in range(1,int(N**0.5)+1):
  if N%i==0:
    if abs(i*(2**d)-N//i)==1:
      k=max(i*(2**d),N//i)
      break
    elif abs((N//i)*(2**d)-i)==1:
      k=max((N//i)*(2**d),i)
      break

if k==-1:
  print("No")
else:
  print("Yes")
  print(k)
  S=[[] for _ in range(k)]
  n=0
  for j in range(k):
    for i in range(1,k-j):
      S[j].append(n+i)
      S[i+j].append(n+i)
    n+=i
  
  for i in range(k):
    print(k-1," ".join(map(str,S[i])))

Solution (Python):
n=int(input())
count=1
index=1
while count<n:
  index+=1
  count+=index
if count!=n:
  print("No")
elif n==1:
  print("Yes")
  print(2)
  print("1 1")
  print("1 1")
else:
  print("Yes")
  print(index+1)
  l=[]
  now=1
  num=1
  while now<n:
    l.append(now)
    now+=num
    num+=1
  for i in range(index):
    l1=[str(index)]
    l1.append(str(l[i]))
    num=l[i]
    count1=0
    while count1<i:
      num+=1
      count1+=1
      l1.append(str(num))
    for j in range(1+i,index):
      num+=j
      l1.append(str(num))
    print(" ".join(l1))
  l1=[str(index),str(l[0])]
  num=0
  for j in range(2,index+1):
    num+=j
    l1.append(str(l[0]+num))
  print(" ".join(l1))

Solution (Python):
def chk(k):
  if k*(k-1)//2 != n:
    return False
  l=[[] for i in range(k)];x=1
  for i in range(k):
    for j in range(i+1,k):
      l[i].append(x);l[j].append(x);x+=1
  print("Yes\n"+str(k))
  for i in range(k):
    print(len(l[i]),' '.join(map(str,l[i])))
  return True
  
n=int(input());flag=False
for i in range(1,1000):
  if chk(i):
    flag=True
    exit()
if not flag:
  print("No")

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
f = 0
if N == 1:
  print("Yes")
  print(2)
  print(1, 1)
  print(1, 1)
  exit(0)
for i in range(1, N + 1):
  if i * (i + 1) == 2 * N:
    f = i + 1
    break
if f:
  print("Yes")
  print(f)
  res = [set() for _ in range(f + 1)]
  table = [0] * (N + 1)
  for i in range(N):
    res[i % f + 1].add(i + 1)
    table[i + 1] = 1
  for i in range(1, f + 1):
    for j in range(f - len(res[i]) - 1):
      for k in res[(i + j) % f + 1]:
        if table[k] < 2:
          res[i].add(k)
          table[k] += 1
          break
    print(len(res[i]), *sorted(res[i]))
else:
  print("No")

Solution (Python):
def main():
    n=int(input())
    for k in range(1,450):
        if k*(k+1)==2*n:
            print("Yes")
            print(k+1)
            break
    else:
        print("No")
        return 0
    ans=[]
    cnt=1
    for i in range(k+1):
        ans.append([])
        for j in range(i):
            ans[i].append(ans[j][i-1])
        for j in range(i,k):
            ans[i].append(cnt)
            cnt+=1
    for i in ans:
        print(len(i),*i)
main()

Solution (Python):
N = int(input())

def judge(n):
    n *= 2
    for d in range(1,n):
        if n == d*(d+1):
            return True, d
    return False, -1



flag, k = judge(N)
if not flag:
    print("No")
    exit()

print("Yes")
print(k+1)

l = [[] for _ in range(k+1)]
c = 1
for i in range(k+1):
    for j in range(i+1, k+1):
        l[i].append(c)
        l[j].append(c)
        c += 1

for line in l:
    print(k, end = " ")
    print(*line)

Solution (Python):
N = int(input())
"""
どの部分集合の共通する要素も一つだけで、各数字（１～N）は２回ずつしか出現しないことから、部分集合の数をｋとすると、
(1)と(2)の共通が１、(1)と(3)の共通が２、～、(k-1)と(k)の共通がN、のように表現でき、この中で１～Nが２回ずつ出現している。
ある部分集合がほかのk-1この部分集合と共通の値を一個ずつもつので、部分集合の要素数はk-1となる。
１～Nまで２回ずつ出てくる＆ｋ個の部分集合の要素がそれぞれ（ｋ－１）であることから、２N＝k(k-1)となる。
ｋが決まれば、上記の(1)と(2)の共通が１で～みたいな置き方をしていくだけでそれぞれの集合が決まる。
Nは10^5までなので、ｋが１０００程度の範囲までで、２N＝k(k-1)を満たすｋがあるか調べていけばよい。

公式開設動画が非常にわかりやすかった：https://www.youtube.com/watch?v=wwCqOcWkVh4
"""
k = 0
while N != k*(k-1)//2:
    k += 1
    if k == 1000:
        break

if k == 1000:
    print("No")
else:
    ans = [[] for _ in range(k)]
    cnt = 0
    for i in range(k):
        for j in range(i+1,k):
            ans[i].append(cnt+1)
            ans[j].append(cnt+1)
            cnt += 1

    print("Yes")
    print(k)
    for a in ans:
        print(k-1, *a)

Solution (Python):
N = int(input())

k = 0
while N != k*(k-1)//2:
    k += 1
    if k == 1000:
        break

if k == 1000:
    print("No")
else:
    ans = [[] for _ in range(k)]
    cnt = 0
    for i in range(k):
        for j in range(i+1,k):
            ans[i].append(cnt+1)
            ans[j].append(cnt+1)
            cnt += 1

    print("Yes")
    print(k)
    for a in ans:
        print(k-1, *a)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

N = I()

ansCandi = []
for i in range(1,1000):
    a = (i+1)*i/2
    ansCandi.append(a)

if N not in ansCandi:
    print("No")
else:
    a = ansCandi.index(N)+1
    A = [[0] * (a+1) for _ in range(a+1)]


    k = int(1)
    for i in range(a+1):
        for j in range(i+1,a+1):
            A[i][j] = k
            A[j][i] = k
            k += 1

    print("Yes")
    print(a+1)

    for v in A:
        v.remove(0)
        v.insert(0,a)

    for v in A:
        print(*v)

Solution (Python):
N = int(input())

if N == 1:
    print('Yes')
    print(2)
    print(1, 1)
    print(1, 1)
else:
    r = int((N*2)**0.5)
    if N*2 == r*(r+1):
        print('Yes')
        print(r+1)
        ans = []

        if r % 2 == 0:
            for i in range(r//2):
                ans.append([j+1+i*(r+1) for j in range(r+1)])
            for i in range(r//2):
                c = [j+1+i*(r+1) for j in range(r+1)]
                ans.append(c[i+1:]+c[:i+1])

        else:
            for i in range(r//2):
                ans.append([j+1+i*(r+1) for j in range(r+1)])

            m = N % (r+1)

            for i in range(r//2):
                c = [j+1+m+i*(r+1) for j in range(r+1)]
                ans.append(c[i+1:]+c[:i+1])

            l = [i+1 for i in range(N)]
            ans.append(l[-m:]+l[:m])

            

        for i in zip(*ans):
            print(r, *i)

    else:
        print('No')

Solution (Python):

"""
if N = K(K + 1)/2 -> Yes
construct a triangle(e.g. N = 10, K = 4):
    1 0 0 0
    2 3 0 0
    4 5 6 0
    7 8 9 10
the answer will be:
  {each row until 0 + column straight down from there}
    {1 2 4 7}
    {2 3 5 8}
    {4 5 6 9}
    {7 8 9 10}
  {diagonal line}
    {1 3 5 10}
"""
def main():
    N = int(input())
    K = int((N * 2) ** 0.5)
    if K * (K + 1) / 2 != N:
        print("No")
        return
    row, cur, cnt = [], 1, 1
    while cur + cnt - 1 <= N:
        row.append(list(range(cur, cur + cnt)) + [0] * (K - cnt))
        cur += cnt
        cnt += 1
    col = [list(c) for c in zip(*row)]
    ans, diag = [], []  
    for i, (r, c) in enumerate(zip(row, col)):
        diag.append(r[i])
        ans.append(r[:i] + c[i:])
    ans.append(diag)
    print("Yes", K + 1, sep="\n")
    for a in ans:
        print(K, end=" ")
        print(" ".join(map(str, a)))


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N = int(input())
    K = int((N * 2) ** 0.5)
    if K * (K + 1) / 2 != N:
        print("No")
        return
    row, cur, cnt = [], 1, 1
    while cur + cnt - 1 <= N:
        row.append(list(range(cur, cur + cnt)) + [0] * (K - cnt))
        cur += cnt
        cnt += 1
    col = [list(c) for c in zip(*row)]
    ans, diag = [], []  
    for i, (r, c) in enumerate(zip(row, col)):
        diag.append(r[i])
        ans.append(r[:i] + c[i:])
    ans.append(diag)
    print("Yes", K + 1, sep="\n")
    for a in ans:
        print(K, end=" ")
        print(" ".join(map(str, a)))


if __name__ == "__main__":
    main()

Solution (Python):
import sys


N = int(input())


k = 0

while k*(k+1) <= 2 * N:

    if k * (k+1) == 2 * N:

        lis = [ [] for i in range(k+1) ]
        now = 1

        for i in range(k):

            for j in range(k-i):

                lis[i].append(now)
                lis[i+1+j].append(now)
                now += 1
        print ("Yes")
        print (k+1)
        for i in range(k+1):
            print (k," ".join(map(str,lis[i])))
        sys.exit()

    k += 1

print ("No")

Solution (Python):
N = int(input())
hoge = 0
M = 1
while True:
    hoge += M
    if hoge == N:
        print("Yes")
        break
    if hoge > N:
        print("No")
        exit()
    M += 1
print(M+1)

ans = []
hoge = 1
for i in range(M):
    ans.append([])
    for j in range(i+1):
        ans[-1].append(hoge)
        hoge += 1
for i in range(M):
    print(M,end = " ")
    for j in range(i+1):
        print(ans[i][j],end = " ")
    for j in range(i+1,M):
        print(ans[j][i],end=" ")
    print()
print(M,end=" ")
for i in range(M):
    print(ans[i][i],end=" ")
print()

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



N = I()

d = defaultdict(int)
for i in range(2,10**5):
    if i*(i-1)//2 > 10**5:
        break
    d[i*(i-1)//2] = i

if d[N]==0:
    print('No')
    exit()

k = d[N]
group = [[] for _ in range(k)]
val = 1
now = 0
while val<=N:
    for i in range(val,N+1):
        if len(group[now])==k-1:
            break
        else:
            group[now].append(i)
    for i in range(now+1,k):
        group[i].append(val)
        val += 1
    now += 1

print('Yes')
print(k)
for i in range(k):
    print(k-1,*group[i])

Solution (Python):
n = int(input())

a = [0]
for i in range(1,10**5):
    a.append(a[-1]+i)
    if a[-1] >= n:
        break

if n != a[-1]:
    print('No')
    exit()

print('Yes')

k = len(a)
print(k)

s = [[] for _ in [0]*k]

cnt = 1
for i in range(1,k):
    ind = 0
    while cnt <= a[i]:
        s[i].append(cnt)
        s[ind].append(cnt)
        cnt += 1
        ind += 1

for i in range(k):
    print(len(s[i]),end=' ')
    for e in s[i]:
        print(e,end=' ')
    print('')

Solution (Python):
import sys
N = int(input())

K = 1
while K * (K-1) // 2 < N:
  K += 1

if K * (K-1) // 2 != N:
  print("No")
  sys.exit(0)

vs = [ [] for _ in range(K) ]
k = 0
for i in range(K):
  for j in range(K):
    if i <= j: continue
    vs[i].append(k)
    vs[j].append(k)
    k += 1

print('Yes')
print(K)
for v in vs:
  print(len(v), end="")
  print(" ", end="")
  print(" ".join([str(x+1) for x in v]))

Solution (Python):
N = int(input())
S = []
hoge = 1
i = 0
while hoge <= N:
    S.append([])
    i += 1
    for j in range(i):
        S[-1].append(hoge)
        hoge += 1

if S[-1][-1] == N:
    print("Yes")
else:
    print("No")
    exit()

N = len(S)
print(N+1)

for i in range(N):
    print(N,end = " ")
    x,y = 0,i
    for j in range(i+1):
        x = j
        print(S[y][x],end=" ")
    for j in range(i+1,N):
        y = j
        print(S[y][x],end=" ")
    print()
print(N,end = " ")
for i in S:
    print(i[-1],end = " ")
print()

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    g = 1
    tmp = 1
    while tmp < N:
        g += 1
        tmp += g
    if tmp != N:
        print("No")
        return
    ans = [list() for i in range(g+1)]
    i, j = 0, 0
    for count in range(N):
        if i == j:
            ans[i].append(count+1)
            ans[-1].append(count+1)
            i += 1
            j = 0
        else:
            ans[i].append(count+1)
            ans[j].append(count+1)
            j += 1
    print("Yes")
    print(g+1)
    for i in range(g+1):
        print(len(ans[i]), end=" ")
        for j in range(len(ans[i])-1):
            print(ans[i][j], end=" ")
        print(ans[i][-1])

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())

x = (1+(1+8*N)**0.5)/2
if x.is_integer():
  print('Yes')
  x = int(x)
  print(x)
  S = [[] for _ in range(x)]
  e = 1
  for i in range(x):
    for j in range(i+1,x):
      S[i].append(e)
      S[j].append(e)
      e += 1
  for s in S:
    print(len(s),*s)
else:
  print('No')

Solution (Python):
from math import sqrt
n = int(input())
a = 1+8*n
b = int(sqrt(a))
if b**2 != a or b%2==0:
    print("No")
    exit()
else:
    k = (1 + b)//2
    s = [[] for i in range(k)]
    cur = 1
    for i in range(k):
        for j in range(k-i-1):
            s[i].append(cur)
            s[i+j+1].append(cur)
            cur += 1
    print("Yes")
    print(k)
    for i in range(k):
        res = "{} ".format(len(s[i])) + " ".join(map(str, s[i]))
        print(res)

Solution (Python):
n=int(input())
p=int((2*n)**0.5)
if n!=((p+1)*p)//2:
    print("No")
else:
    t=[[]for i in range(p+1)]
    c=1
    for i in range(1,p+1):
        for j in range(i):
            t[i].append(c)
            t[j].append(c)
            c+=1
    print("Yes")
    print(p+1)
    for i in t:
        i=[len(i)]+i
        print(*i)

Solution (Python):

N = int(input())

flag = 0
for i in range(2*N):
    I = i+1
    if I*(I+1) == 2*N:
        k = I+1
        flag = 1
        break
        
if flag == 0:
    print("No")
else:
    print("Yes")
    print(k)
    ans = [[] for i in range(k)]
    now = 0
    for i in range(k-1):
        loop = 1+i
        for j in range(loop):
            now+=1
            if j == 0:
                ans[0].append(now)
            if j == loop-1:
                ans[-1].append(now)
            if j > 0 and j < loop-1:
                ans[j].append(now)
            if i != 0:
                ans[i].append(now)
            
    for a in ans:
        print(len(a),end=" ")
        print(*a)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lst = [3]
tmp = 3
if n == 1:
    print('Yes')
    print(2)
    print(1,1)
    print(1,1)
    quit()
for _ in range(500):
    x = lst[-1] + tmp
    lst.append(x)
    tmp += 1
if n not in lst:
    print('No')
else:
    print('Yes')
    x = lst.index(n) + 3
    print(x)
    lst = [[] for _ in range(x-1)]
    tmp = 0
    cnt = 0
    for i in range(1,n+1):
        lst[tmp].append(i)
        if cnt == tmp:
            tmp += 1
            cnt = 0
            continue
        cnt += 1
    ans = [[] for _ in range(x)]
    tmp = 0
    for i in range(x-1):
        for j in range(tmp):
            ans[i].append(lst[tmp][j])
        for j in range(tmp,x-1):
            ans[i].append(lst[j][tmp])
        tmp += 1
    for i in range(x-1):
        ans[-1].append(lst[i][-1])
    for i in range(x):
        print(x-1,*ans[i])

Solution (Python):
n = int(input())

i = 1
cnt = 1
flag = False
while True:
    cnt += 1
    if i == n:
        flag = True
        break
    if i > n:
        break
    i += cnt


if not flag:
    print("No")
    exit()

print("Yes")
print(cnt)
li = [[] for i in range(cnt)]
num = 1
for i in range(cnt):
    tmp_num = num
    for _ in range(cnt - i - 1):
        li[i].append(tmp_num)
        tmp_num += 1
    for j in range(i+1, cnt):
        li[j].append(num)
        num += 1
for li2 in li:
    print(len(li2), *li2)

Solution (Python):
n = int(input())

i = 1
cnt = 1
flag = False
while True:
    cnt += 1
    if i == n:
        flag = True
        break
    if i > n:
        break
    i += cnt

if not flag:
    print("No")
    exit()

print("Yes")
print(cnt)
li = [[] for i in range(cnt)]
num = 1
for i in range(cnt):
    tmp_num = num
    for _ in range(cnt - i - 1):
        li[i].append(tmp_num)
        tmp_num += 1
    for j in range(i+1, cnt):
        li[j].append(num)
        num += 1
for li2 in li:
    print(len(li2), *li2)

Solution (Python):
N = int(input())

K = -1
for k in range(N+1):
    if k*(k-1)//2 == N:
        K = k
        break
    elif k*(k-1)//2 > N:
        break

if N == 1:
    print('Yes')
    print(2)
    print(1, 1)
    print(1, 1)
elif K == -1:
    print('No')
else:
    print('Yes')
    print(K)
    n = 0
    S = [[] for _ in range(K)]
    for i in range(K):
        for j in range(i+1, K):
            n += 1
            S[i].append(n)
            S[j].append(n)
    for s in S:
        print(len(s), ' '.join([str(a) for a in s]))

Solution (Python):
from numpy import*;p=print;i=int;n=i(input());c=i(sqrt(n*2))
if c*c+c-n*2:p('No')
else:a=eye(c+1,c,0,i);t=triu_indices(c);a[t]=a[1:].T[t]=r_[:n]+1;p('Yes');p(c+1);[p(c,*r)for r in a]

Solution (Python):
import numpy as N;p=print;i=int;n=i(input());c=i(N.sqrt(n*2))
if c*c+c-n*2:p('No')
else:a=N.eye(c+1,c,0,i);t=N.triu_indices(c);a[t]=a[1:].T[t]=N.arange(n)+1;p('Yes');p(c+1);[p(c,*r)for r in a]

Solution (Python):
import numpy as N;p=print;i=int;n=i(input());c=i(N.sqrt(n*2))
if c**2+c-n*2:p('No')
else:a=N.zeros((c+1,c),i);t=N.triu_indices(c);a[t]=a[1:].T[t]=N.arange(n)+1;p('Yes');p(c+1);[p(c,*r)for r in a]

Solution (Python):
import numpy as N;p=print;n=int(input());c=int(N.sqrt(n*2))
if c**2+c-n*2:p('No')
else:a=N.zeros((c+1,c));t=N.triu_indices(c);a[t]=a[1:].T[t]=N.arange(n)+1;p('Yes');p(c+1);[p(c,*map(int,r))for r in a]

Solution (Python):
import numpy as N
p=print
n=int(input())
c=int(N.sqrt(n*2))
if c**2+c-n*2:p('No')
else:a=N.zeros((c+1,c));t=N.triu_indices(c);a[t]=a[1:].T[t]=N.arange(n)+1;p('Yes');p(c+1);[p(c,*map(int,r))for r in a]

Solution (Python):
import numpy as N
p=print
n=int(input())
c=int(N.sqrt(n*2))
if c**2+c-n*2:p('No');exit()
a=N.zeros((c+1,c))
t=N.triu_indices(c)
a[t]=a[1:].T[t]=N.arange(n)+1
p('Yes')
p(c+1)
for r in a:p(c,*map(int,r))

Solution (Python):
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())

cnt = math.ceil(math.sqrt(N * 2))
if cnt * (cnt - 1) != N * 2:
    print('No')
    exit()

ans = np.zeros((cnt, cnt - 1), dtype=int)
ans[np.triu_indices(cnt - 1)] = np.arange(1, N + 1)
ans[1:].T[np.triu_indices(cnt - 1)] = np.arange(1, N + 1)
print('Yes')
print(cnt)
for r in ans:
    print(cnt - 1, *r)

Solution (Python):
import math
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())

cnt = math.ceil(math.sqrt(N * 2))
if cnt * (cnt - 1) != N * 2:
    print('No')
    exit()

ans = np.zeros((cnt, cnt - 1), dtype=int)
ans[np.triu_indices(cnt - 1)] = np.arange(1, N + 1)
ans[1:] = np.maximum(ans[:-1].T, ans[1:])
print('Yes')
print(cnt)
for r in ans:
    print(cnt - 1, *r)

Solution (Python):
N = int(input())


M = (8 * N + 1)**0.5

if M.is_integer():
    M = (int(M) - 1) // 2
    print('Yes')
    print(M + 1)
    setNum = [[] for _ in range(N + 1)]
    for s in range(1, M + 2):
        ans = [M]
        V = set()
        for i in range(1, N + 1):
            if len(ans) > M:
                break
            if len(setNum[i]) >= 2:
                continue
            elif len(setNum[i]) == 0:
                ans.append(i)
                setNum[i].append(s)
            elif not setNum[i][0] in V:
                ans.append(i)
                setNum[i].append(s)
                V.add(setNum[i][0])
        print(*ans)
else:
    print('No')

Solution (Python):
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())


def solve(N):
    count = math.ceil(math.sqrt(N * 2))
    if count * (count - 1) != N * 2 or N == 2:
        return []

    ans = [[] for _ in range(count)]
    a = 1
    for i in range(count):
        for j in range(count - 1 - len(ans[i])):
            ans[i].append(a)
            ans[i + 1 + j].append(a)
            a += 1

    return ans


ans = solve(N)
if ans:
    print('Yes')
    cnt = len(ans)
    print(cnt)
    for r in ans:
        print(cnt - 1, *r)
else:
    print('No')

Solution (Python):
def comb(arr, k):
    n = len(arr)
    def dfs(curr,cnt,tmp):
        ret = []
        if cnt==0:
            return [tmp]
        for i in range(curr,n-cnt+1):
            ret += dfs(i+1,cnt-1,tmp+[arr[i]])
        return ret
    return dfs(0,k,[])

from math import *
N=int(input())
k1 = int(sqrt(2*N))
k2 = k1+1
if k1*k2 == 2*N:
    print("Yes")
    print(k2)
    ans = [[] for _ in range(k2)]
    for i, (i1, i2) in enumerate(comb(list(range(k2)), 2)):
        ans[i1].append(i+1)
        ans[i2].append(i+1)
    
    for arr in ans:
        print(" ".join([str(v) for v in [k1]+arr]))
else:
    print("No")

Solution (Python):
N=int(input())
x=1
while x*(x-1)//2<N:
    x+=1
if x*(x-1)//2>N:
    print('No')
else:
    print('Yes')
    print(x)
    a=[[] for i in range(x)]
    from itertools import combinations
    y=1
    for i,j in combinations(range(x),2):
        a[i].append(y)
        a[j].append(y)
        y+=1
    for l in a:
        print(x-1,*l)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import itertools

N = int(input())
k = 1
while k * (k+1) // 2 <= N:
    k += 1

if k * (k-1) // 2 == N:
    S = [[] for _ in range(k)]
    for i,(a,b) in enumerate(itertools.combinations(range(k),2),1):
        S[a].append(i)
        S[b].append(i)
    print('Yes')
    print(k)
    for se in S:
        print(len(se), *se)
else:
    print('No')

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def num__grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
solve = (1 + (1 + 8 * n) ** 0.5) / 2
if int(solve) != solve:
    print("No")
else:
    print("Yes")
    k = int(solve)
    ansli = [[] for _ in range(k)]

    cnt = 1
    dec = 0
    i = 1
    while i <= n:
        if cnt <= k - 1 - dec:
            ansli[dec].append(i)
            cnt += 1
            i += 1
        else:
            cnt = 1
            dec += 1

    cnt = 1
    up = 1
    i = 1
    while i <= n:
        if cnt <= k - 1:
            ansli[cnt].append(i)
            cnt += 1
            i += 1
        else:
            up += 1
            cnt = up

    print(k)
    for i in range(k):
        print(len(ansli[i]), " ".join(map(str, ansli[i])))

Solution (Python):
def calc(N):
    n = 0
    for i in range(1,N+1):
        n+=i
        if n>=N:break
    if n!=N:
        print("No")
        return
    print("Yes")
    print(i+1)
    S = [list(range(1,i+1))]
    print(i,*S[0])
    m = i
    for j in range(1,i+1):
        S.append([])
        for s in S[:-1]:
            S[-1].append(s.pop())
        S[-1].extend(range(m+1,m+1+i-j))
        m = max(S[-1])
        print(i,*S[-1])
def main():
    N=int(input())
    calc(N)
main()

Solution (Python):
n=int(input())
k=0
for i in range(1,n+1):
  if (i*(i+1))//2==n:
    k=i
    break
else:
  k=-1
if k==-1:
  print('No')
else:
  arr=[[k] for _ in range(k+1)]
  tmp=0
  tk=0
  while k-tk>0:
    for i in range(tmp+1,tmp+k+1-tk):
      arr[tk].append(i)
    for i in range(tk+1,k+1):
      arr[i].append(tmp+i-tk)
    tmp+=(k-tk)
    tk+=1
  print('Yes')
  print(k+1)
  for row in arr:
    print(*row)

Solution (Python):
from itertools import combinations

N = int(input())
k = 1
while k**2 - k < 2*N: k += 1
if k**2 - k != 2*N: print('No')
else:
    print('Yes')
    print(k)
    sets = [[] for _ in range(k)]
    n = 1
    for i, j in combinations(range(k), 2):
        sets[i].append(n)
        sets[j].append(n)
        n += 1
    for S in sets: print(len(S), *S)