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

for i in range(10 ** 5):
    if 2 * n == i ** 2 - i:
        k = i
        print('Yes', k, sep='\n')
        break
    elif 2 * n < i ** 2 - i:
        print('No')
        exit()

num, ans = 1, [[] for _ in range(k)]
for i in range(k):
    for j in range(i + 1, k):
        ans[i].append(num)
        ans[j].append(num)
        num += 1
    print(k - 1, *ans[i])

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

for i in range(10**5):
    if 2 * n == i ** 2 - i:
        k = i
        break
    elif 2 * n < i ** 2 - i:
        print('No')
        exit()

k = int(k)
print('Yes')
print(k)
num, ans = 1, [[] for _ in range(k)]
for i in range(k):
    for j in range(i + 1, k):
        ans[i].append(num)
        ans[j].append(num)
        num += 1
    print(k - 1, *ans[i])

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

k = (1 + (1 + 8 * n)** 0.5) * 0.5
if k.is_integer():
    k = int(k)
    print('Yes')
    print(k)
    num,ans = 1,[[] for _ in range(k)]
    for i in range(k):
        for j in range(i + 1, k):
            ans[i].append(num)
            ans[j].append(num)
            num += 1
        print(k - 1, *ans[i])
else:
    print('No')

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

k = (1 + (1 + 8 * n)** 0.5) * 0.5
if k.is_integer():
    k, num = int(k), 1
    ans = [[] for _ in range(k)]
    print('Yes')
    print(k)
    for i in range(k):
        for j in range(i + 1, k):
            ans[i].append(num)
            ans[j].append(num)
            num += 1
        print(k - 1, *ans[i])
else:
    print('No')

Solution (Python):
import sys
from itertools import combinations
n = int(input())

for i in range(1, 1000):
  if n == i*(i+1)//2:
    print("Yes")
    print(i+1)
    anslist = [[] for _ in range(i+1)]
    for j, v in enumerate(combinations([int(x) for x in range(i+1)], r=2)):
      anslist[v[0]].append(j+1)
      anslist[v[1]].append(j+1)
    for ans in anslist:
      print(len(ans), *ans)
    sys.exit()

print("No")

Solution (Python):
'''
研究室PCでの解答
'''
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(ipt())
    for i in range(1,10**5):
        if i*(i+1)//2 > n:
            print("No")
            exit()
        elif i*(i+1)//2 == n:
            print("Yes")
            print(i+1)
            ans = [[] for j in range(i+1)]
            ni = 1
            for j in range(i,0,-1):
                for k in range(j):
                    ans[i-j].append(ni)
                    ans[i-k].append(ni)
                    ni += 1
            for j in ans:
                print(i," ".join(map(str,j)))
            exit()

    return None

if __name__ == '__main__':
    main()

Solution (Python):
ntok = {3: 3, 6: 4, 10: 5, 15: 6, 21: 7, 28: 8, 36: 9, 45: 10, 55: 11, 66: 12, 78: 13, 91: 14, 105: 15,
        120: 16, 136: 17, 153: 18, 171: 19, 190: 20, 210: 21, 231: 22, 253: 23, 276: 24, 300: 25, 325: 26, 351: 27,
        378: 28, 406: 29, 435: 30, 465: 31, 496: 32, 528: 33, 561: 34, 595: 35, 630: 36, 666: 37, 703: 38, 741: 39,
        780: 40, 820: 41, 861: 42, 903: 43, 946: 44, 990: 45, 1035: 46, 1081: 47, 1128: 48, 1176: 49, 1225: 50,
        1275: 51, 1326: 52, 1378: 53, 1431: 54, 1485: 55, 1540: 56, 1596: 57, 1653: 58, 1711: 59, 1770: 60, 1830: 61,
        1891: 62, 1953: 63, 2016: 64, 2080: 65, 2145: 66, 2211: 67, 2278: 68, 2346: 69, 2415: 70, 2485: 71, 2556: 72,
        2628: 73, 2701: 74, 2775: 75, 2850: 76, 2926: 77, 3003: 78, 3081: 79, 3160: 80, 3240: 81, 3321: 82, 3403: 83,
        3486: 84, 3570: 85, 3655: 86, 3741: 87, 3828: 88, 3916: 89, 4005: 90, 4095: 91, 4186: 92, 4278: 93, 4371: 94,
        4465: 95, 4560: 96, 4656: 97, 4753: 98, 4851: 99, 4950: 100, 5050: 101, 5151: 102, 5253: 103, 5356: 104,
        5460: 105, 5565: 106, 5671: 107, 5778: 108, 5886: 109, 5995: 110, 6105: 111, 6216: 112, 6328: 113, 6441: 114,
        6555: 115, 6670: 116, 6786: 117, 6903: 118, 7021: 119, 7140: 120, 7260: 121, 7381: 122, 7503: 123, 7626: 124,
        7750: 125, 7875: 126, 8001: 127, 8128: 128, 8256: 129, 8385: 130, 8515: 131, 8646: 132, 8778: 133, 8911: 134,
        9045: 135, 9180: 136, 9316: 137, 9453: 138, 9591: 139, 9730: 140, 9870: 141, 10011: 142, 10153: 143, 10296: 144,
        10440: 145, 10585: 146, 10731: 147, 10878: 148, 11026: 149, 11175: 150, 11325: 151, 11476: 152, 11628: 153,
        11781: 154, 11935: 155, 12090: 156, 12246: 157, 12403: 158, 12561: 159, 12720: 160, 12880: 161, 13041: 162,
        13203: 163, 13366: 164, 13530: 165, 13695: 166, 13861: 167, 14028: 168, 14196: 169, 14365: 170, 14535: 171,
        14706: 172, 14878: 173, 15051: 174, 15225: 175, 15400: 176, 15576: 177, 15753: 178, 15931: 179, 16110: 180,
        16290: 181, 16471: 182, 16653: 183, 16836: 184, 17020: 185, 17205: 186, 17391: 187, 17578: 188, 17766: 189,
        17955: 190, 18145: 191, 18336: 192, 18528: 193, 18721: 194, 18915: 195, 19110: 196, 19306: 197, 19503: 198,
        19701: 199, 19900: 200, 20100: 201, 20301: 202, 20503: 203, 20706: 204, 20910: 205, 21115: 206, 21321: 207,
        21528: 208, 21736: 209, 21945: 210, 22155: 211, 22366: 212, 22578: 213, 22791: 214, 23005: 215, 23220: 216,
        23436: 217, 23653: 218, 23871: 219, 24090: 220, 24310: 221, 24531: 222, 24753: 223, 24976: 224, 25200: 225,
        25425: 226, 25651: 227, 25878: 228, 26106: 229, 26335: 230, 26565: 231, 26796: 232, 27028: 233, 27261: 234,
        27495: 235, 27730: 236, 27966: 237, 28203: 238, 28441: 239, 28680: 240, 28920: 241, 29161: 242, 29403: 243,
        29646: 244, 29890: 245, 30135: 246, 30381: 247, 30628: 248, 30876: 249, 31125: 250, 31375: 251, 31626: 252,
        31878: 253, 32131: 254, 32385: 255, 32640: 256, 32896: 257, 33153: 258, 33411: 259, 33670: 260, 33930: 261,
        34191: 262, 34453: 263, 34716: 264, 34980: 265, 35245: 266, 35511: 267, 35778: 268, 36046: 269, 36315: 270,
        36585: 271, 36856: 272, 37128: 273, 37401: 274, 37675: 275, 37950: 276, 38226: 277, 38503: 278, 38781: 279,
        39060: 280, 39340: 281, 39621: 282, 39903: 283, 40186: 284, 40470: 285, 40755: 286, 41041: 287, 41328: 288,
        41616: 289, 41905: 290, 42195: 291, 42486: 292, 42778: 293, 43071: 294, 43365: 295, 43660: 296, 43956: 297,
        44253: 298, 44551: 299, 44850: 300, 45150: 301, 45451: 302, 45753: 303, 46056: 304, 46360: 305, 46665: 306,
        46971: 307, 47278: 308, 47586: 309, 47895: 310, 48205: 311, 48516: 312, 48828: 313, 49141: 314, 49455: 315,
        49770: 316, 50086: 317, 50403: 318, 50721: 319, 51040: 320, 51360: 321, 51681: 322, 52003: 323, 52326: 324,
        52650: 325, 52975: 326, 53301: 327, 53628: 328, 53956: 329, 54285: 330, 54615: 331, 54946: 332, 55278: 333,
        55611: 334, 55945: 335, 56280: 336, 56616: 337, 56953: 338, 57291: 339, 57630: 340, 57970: 341, 58311: 342,
        58653: 343, 58996: 344, 59340: 345, 59685: 346, 60031: 347, 60378: 348, 60726: 349, 61075: 350, 61425: 351,
        61776: 352, 62128: 353, 62481: 354, 62835: 355, 63190: 356, 63546: 357, 63903: 358, 64261: 359, 64620: 360,
        64980: 361, 65341: 362, 65703: 363, 66066: 364, 66430: 365, 66795: 366, 67161: 367, 67528: 368, 67896: 369,
        68265: 370, 68635: 371, 69006: 372, 69378: 373, 69751: 374, 70125: 375, 70500: 376, 70876: 377, 71253: 378,
        71631: 379, 72010: 380, 72390: 381, 72771: 382, 73153: 383, 73536: 384, 73920: 385, 74305: 386, 74691: 387,
        75078: 388, 75466: 389, 75855: 390, 76245: 391, 76636: 392, 77028: 393, 77421: 394, 77815: 395, 78210: 396,
        78606: 397, 79003: 398, 79401: 399, 79800: 400, 80200: 401, 80601: 402, 81003: 403, 81406: 404, 81810: 405,
        82215: 406, 82621: 407, 83028: 408, 83436: 409, 83845: 410, 84255: 411, 84666: 412, 85078: 413, 85491: 414,
        85905: 415, 86320: 416, 86736: 417, 87153: 418, 87571: 419, 87990: 420, 88410: 421, 88831: 422, 89253: 423,
        89676: 424, 90100: 425, 90525: 426, 90951: 427, 91378: 428, 91806: 429, 92235: 430, 92665: 431, 93096: 432,
        93528: 433, 93961: 434, 94395: 435, 94830: 436, 95266: 437, 95703: 438, 96141: 439, 96580: 440, 97020: 441,
        97461: 442, 97903: 443, 98346: 444, 98790: 445, 99235: 446, 99681: 447}

n = int(input())

if n==1:
        print("Yes")
        print(2)
        print(1,1)
        print(1,1)
        exit()

if n not in ntok:
    print("No")
    exit()

k = ntok[n]
ans = [[] for _ in range(k)]
a = 0
for i in range(k):
    for j in range(i):
        a += 1
        ans[i].append(a)
        ans[j].append(a)

print("Yes")
print(k)
for s in ans: print(len(s),*s)

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

for i in range(N + 1):
    if i * (i + 1) // 2 == N:
        M = i
        print('Yes')
        print(M + 1)
        res = [[] for _ in range(M + 1)]
        for i in range(M + 1):
            res[i].append(M)
        cnt = 1
        for k in range(M):
            for i in range(M - k):
                res[k].append(cnt + i)
            for i in range(M - k):
                res[k + i + 1].append(cnt)
                cnt += 1
        for r in res:
            print(*r)
        break
else:
    print('No')

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

"""
N = 2
 No
N = 3
 1,2. 2,3. 3,1
N = 4
 No
N = 5
 No
N = 6
 1,2,4 1,3,6 4,5,6 2,3,5

個数がN(Nー1)でしょうと言うのは考察を諦めない力
全ての部分集合の長さって同じじゃね？って気付けるかどうか。。。
あとは６で具体的に構築できるかどうか勝負かな。
"""

def solve(k):
  print("Yes")
  print(k)
  G = []
  for i in range(1,k+1):
    G = calcG(i-1,G)
  for g in G:
    print(str(len(g)) + " " + " ".join(map(str,g)))
    
def calcG(i,G):
  st = i*(i-1) // 2 + 1
  en = i*(i+1) // 2
  
  new = list(range(st,en+1))
  for j in range(len(G)):
    G[j].append(new[j])
  G.append(new)
  return G

for i in range(2,1000):
  if i*(i-1)//2 == N:
    solve(i)
    exit(0)

print("No")

Solution (Python):
n = int(input())
t = int((n*2)**(0.5))
if t*(t+1)//2!=n:
    print("No")
    quit()
l = [[] for _ in range(t+1)]
ind = 1
for i in range(t,0,-1):
    for j in range(i):
        l[t-i].append(j+ind)
    for j in range(i):
        l[t-i+1+j].append(j+ind)
    ind += i
print("Yes")
print(t+1)
for i in range(t+1):
    print(t,*l[i])

Solution (Python):
N = int(input())
k = 1
n = 0
while n < N:
    n += k
    k += 1
if n!=N:
    print('No')
    exit()
print('Yes')
print(k)
ans = [[] for _ in range(k)]
v = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(v)
        ans[j].append(v)
        v += 1
for row in ans:
    print(*([len(row)] + row))

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


def get_node_count(n):
    sum = 0
    for i in range(10**6):
        sum += i
        if sum == n:
            return i+1
        if sum > n:
            return False


def main():
    n = int(input())
    k = get_node_count(n)
    if not k:
        print("No")
        return

    nodes = [[] for _ in range(k)]
    edges = []
    dup_num = 1
    for from_ in range(k-1):
        for to in range(from_+1, k):
            edge = (from_, to, dup_num)
            edges.append(edge)
            dup_num += 1

    for from_, to, num in edges:
        nodes[from_].append(num)
        nodes[to].append(num)

    print("Yes")
    print(k)
    for node in nodes:
        print(k-1, *node)


if __name__ == "__main__":
    main()

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

m=-1

for i in range(3,1000,2):
    if i*i==8*n+1:
        m=(1+i)//2

if m==-1:
    print('No')
    exit(0)

cnt=1
s=[[0] for _ in range(m+1)]

for i in range(1,m+1):
    for j in range(i+1,m+1):
        s[i][0]+=1
        s[j][0]+=1

        s[i].append(cnt)
        s[j].append(cnt)

        cnt+=1

print('Yes')
print(m)
for i in range(1,m+1):
    print(' '.join([str(c) for c in s[i]]))

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

for k in range(1,10**9):
  if N==k*(k+1)//2:
    break
  elif N<k*(k+1)//2:
    print("No")
    sys.exit(0)
  
print("Yes")
print(k+1)

cnt=1
set_list=[set() for _ in range(k+1)]
for i in range(k+1):
  for j in range(i+1,k+1):
    
    set_list[i].add(cnt)
    set_list[j].add(cnt)
    cnt+=1

  
for i in range(k+1):
  print(k,*set_list[i])

Solution (Python):
N=int(input())
if N==1:
    print("Yes")
    print(2)
    print(1,1)
    print(1,1)
    exit()

for i in range(2,1000):
    if i*(i+1)//2==N:
        print("Yes")
        print(i+1)
        L=[]
        cnt=1
        for j in range(i+1):
            l=[]
            for k in range(len(L)):
                l.append(L[k][len(L)-1])
            while len(l)<i:
                l.append(cnt)
                cnt+=1
            L.append(l)
        for i in range(len(L)):
            print(len(L[i]),*L[i])
        exit()
        
    elif i*(i+1)//2>N:
        print("No")
        exit()

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def gg(n):
	for i in range(n+1):
		
		if 2*n == i*(i+1):
			return i+1
		if 2*n < i*(i+1):
			return -1
	return -1

def main():
	n = int(input())
	
	
	g_num = gg(n)
	if g_num == -1:
		return 'No'
	print('Yes')
	print(g_num)
	n_num = g_num-1
	ggg=[]
	ggg.append(list(range(1, n_num+1)))
	next=n_num+1
	for ig in range(g_num-1):
		next_group=[]
		for ip, g in enumerate(ggg):
			next_group.append(g[len(ggg)-1])
		while len(next_group) < n_num:
			next_group.append(next)
			next+=1
		ggg.append(next_group)
	for g in ggg:
		print(n_num, *g)
	
		
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
n = int(input())
ans = True
for k in range(1, 500):
    if n == k * (k - 1) / 2:
        ans = False
        break
if ans:
    print('No')
    exit()
print('Yes')
print(k)
val = 1
ans_list = [[] for _ in range(k)]
for i in range(k - 1):
    for j in range(i + 1, k):
        ans_list[i].append(val)
        ans_list[j].append(val)
        val += 1
for a in ans_list:
    print(*([len(a)] + a))

Solution (Python):
n = int(input())
k = 1
t = 0
while t < n:
    t += k
    k += 1

if t != n:
    print("No")
    exit(0)

print("Yes")
print(k)

a = [[] for _ in range(k)]
val = 1
for i in range(k-1):
    for j in range(i+1,k):
        a[i].append(val)
        a[j].append(val)
        val += 1

for aa in a:
    print(*([len(aa)] + aa))

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

Solution (Python):
N = int(input())
MAX = 450
A = [[1],[1]] 

size = 0
for i in range(1,MAX):
  if i*(i+1)//2 == N:
    size = i+1
    break
if size == 0:
  print("No")
  exit()
now = 2
while now < size:
  start = now*(now-1)//2+1
  last = [start+i for i in range(now)]
  for j in range(len(A)):
    A[j].append(last[j])
  A.append(last)
  now += 1
print("Yes")
print(len(A))

for x in A:
  x.insert(0,len(A)-1)
  print(*x)

Solution (Python):
import sys
n=int(input())
for i in range(10000):
  if (i*(i-1))//2==n:
    ans=i
    break
  if i==9999:
    print('No')
    sys.exit()
t=[]
print('Yes')
print(ans)
for i in range(ans):
  t.append([])
current=1
i=1
while i<=n:
  for j in range(current,ans):
    t[j].append(str(i))
    t[current-1].append(str(i))
    i+=1
  current+=1
for i in range(ans):
  print(len(t[i]))
  print(' '.join(t[i]))

Solution (Python):
N = int(input())
k = 1
n = 0
while n < N:
    n += k
    k += 1
if n!=N:
    print('No')
    exit()
print('Yes')
print(k)
ans = [[] for _ in range(k)]
v = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(v)
        ans[j].append(v)
        v += 1
for row in ans:
    print(*([len(row)] + row))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    N = n * 2
    for i in range(1, int(pow(N, 0.5)) + 1):
        if N % i == 0 and abs(N // i - i) == 1:
            x, y = i, N // i
            print("Yes")
            print(y)
            break
    else:
        print("No")
        exit()

    res = [[0] * x for _ in range(y)]
    num = 1
    left = 0
    while left < y:
        for i in range(left, x):
            res[left][i] = num
            res[i + 1][left] = num
            num += 1
        left += 1

    for i in res:
        print(x, *i)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():
    N = in_n()

    for i in range(1, N + 1):
        if i * (i + 1) == N * 2:
            X = i
            break
    else:
        print('No')
        exit()

    ans = [[] for _ in range(X + 1)]
    ans[0] = [t for t in range(1, X + 1)]
    non_used = deque(range(X + 1, N + 1))
    used = [deque(range(1, X + 1))]

    for i in range(1, X + 1):
        for u in used:
            ans[i].append(u.popleft())

        size = len(ans[i])
        t = []
        for j in range(X - size):
            t.append(non_used.popleft())

        if t:
            ans[i] += t
            used.append(deque(t))

    print('Yes')
    print(X + 1)
    for a in ans:
        print(' '.join(map(str, [X] + a)))


if __name__ == '__main__':
    main()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




from itertools import combinations
P = []
for i in range(500):
  P.append(i*(i+1)//2)
N = I()
if N not in P:
  print("No")
  exit()
else:
  W = P.index(N)
  H = W+1
  ans = [[] for i in range(H)]
  i = 1
  for a,b in combinations(range(H), 2):
    ans[a].append(i)
    ans[b].append(i)
    i += 1
  print("Yes")
  print(H)
  for a in ans:
    print(W,*a)

Solution (Python):
from itertools import combinations as cb
import sys

N = int(input())

k = (1 + int((1 + 8 * N) ** 0.5)) // 2

if k * (k - 1) // 2 != N:
    print('No')
    sys.exit()

print('Yes')
print(k)

x = list(cb(range(k), 2))
dp = [[] for i in range(k)]
for i,(a,b) in enumerate(x):
    dp[a].append(i+1)
    dp[b].append(i+1)
for r in dp:
    print(len(r), *r)

Solution (Python):
from collections import deque
N=int(input())
if N==1:
    print("Yes")
    print(2)
    print(1,1)
    print(1,1)
    exit()




size=None
for i in range(1,N):
    if i*(i+1)==N*2:
        size=i
        groups=i+1
if size is None:
    print("No")
    exit()

ans=[[] for _ in range(groups)]
first=deque(list(range(1,N+1)))



for i in range(groups):
    to_idx=i+1
    while len(ans[i])<size:
        x=first.popleft()
        ans[i].append(x)
        
        ans[to_idx].append(x)
        to_idx+=1

print("Yes")
print(len(ans))
for s in ans:
    print(len(s), *s)

Solution (Python):
n = int(input())
A = []
for i in range(1, int(n ** .5 + 3) * 2):
    A.append(i * (i - 1) // 2)

if n in A:
    print("Yes")
    x = A.index(n) + 1
    ans = [[] for _ in range(x)]
    now = 1
    l = 0
    while l < x:
        for i in range(x - l - 1):
            ans[l].append(now)
            ans[l + 1 + i].append(now)
            now += 1
        l += 1
    print(x)
    for i in range(x):
        print(x - 1, *ans[i])
        
else:
    print("No")

Solution (Python):
n=int(input())
for m in range(1,n+1):
  if m*(m+1)//2==n:break
else:
  print('No')
  exit()
a=[]
k=1
for i in range(m):
  b=[0]*m
  for j in range(i+1):
    b[j]=k
    k+=1
  a.append(b)
ans=[]
for i in range(m):
  b=[m]
  for j in range(i+1):
    b.append(a[i][j])
  for k in range(j+1,m):
    b.append(a[k][j])
  ans.append(b)
b=[m]
for i in range(m):
  b.append(a[i][i])
ans.append(b)
print('Yes')
print(len(ans))
for i in ans:
  print(*i)

Solution (Python):
n = int(input())
if n == 1:
    print('Yes')
    print(2)
    print("1 1")
    print("1 1")
    exit()
t = [3]
cnt = 3
while t[-1]+cnt <= n:
    t.append(t[-1]+cnt)
    cnt += 1
if t[-1] != n:
    print('No')
    exit()
print('Yes')
try:
    n_cols = t[-1]-t[-2]
except:
    print(3)
    print("2 1 2")
    print("2 3 1")
    print("2 2 3")
    exit()
print(n_cols+1)
t_len = len(t)
t2 = [i+1 for i in t]
t3 = [0 for i in t]
for col in range(n_cols+1):
    out = str(n_cols)
    if col <=2:
        if col == 0:
            out += " 1 2"
        elif col == 1:
            out += " 1 3"
        elif col == 2:
            out += " 2 3"
    else:
        idx = t[col-3]+1
        while idx <= t[col-2]:
            out += " " + str(idx)
            idx += 1
    for i in range(t_len-1):
        if t2[i] != t[i+1]+1:
            out += " " + str(t2[i])
            t2[i] += 1
    print(out)

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


k = 0 
for i in range(1,N+1):
  if N==(i*(i+1))//2:
    k = i
    break
if not k:
  print("No")
  exit()

S = [ [0]*k for _ in range(k+1) ]

base,span = 1,k
for i in range(k):
  S[i][i:i+span+1] = list(range(base, base+span))

  for j in range(span):
    S[i+j+1][j] = base+j

  base,span = base+span,span-1




print("Yes")
print(k+1)
for s in S:
  print(" ".join([ str(s) for s in [k]+s ]))

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

"""
k組ある，
ある組から見て，残りの(k-1)組と被りが1つずつあるから要素数はk-1

"""

def main():
    mod=10**9+7
    N=I()

    k=0
    for i in range(N+5):
        ii=i*(i-1)
        if ii==2*N:
            k=i
            break
    if k==0:
        print("No")
        exit()
    
    ans=[[]for _ in range(k)]
    now=1
    import itertools
    
    for ite in itertools.combinations(range(k),2):
        i=ite[0]
        j=ite[1]
        ans[i].append(now)
        ans[j].append(now)
        now+=1
        
    print("Yes")
    print(k)
    for i in range(k):
        print(len(ans[i]),' '.join(map(str, ans[i])))
        
        
            
            
            
 
        

main()

Solution (Python):
from itertools import combinations as cb   
n = int(input())

k = 0
for i in range(1,1000):
    if i*(i-1)//2 == n:
        k = i
if k == 0:
    print("No")
    exit()

print("Yes")
print(k)
x = list(cb([i for i in range(k)], 2))
dp = [[] for i in range(k)]
for i,(a,b) in enumerate(x):
    dp[a].append(i+1)
    dp[b].append(i+1)
for r in dp:
    print(len(r), *r)

Solution (Python):
n = int(input())
for i in range(1, 1000):
    if i*(i+1)//2>n:
        print('No')
        exit(0)
    if i*(i+1)//2==n:
        break
q = list(range(n, 0, -1))
ans = []
for j in range(i+1):
    tmp = []
    for k in ans:
        tmp.append(k[j-1])
    for _ in range(i-j):
        tmp.append(q.pop())
    ans.append(tmp)
print('Yes')
print(i+1)
for j in ans:
    tmp = [i]+j
    print(*tmp)

Solution (Python):
n = int(input())
if n==1:
    print('Yes')
    print(2)
    print(1, 1)
    print(1, 1)
    exit(0)
for i in range(2, 1000):
    if i*(i+1)//2>n:
        print('No')
        exit(0)
    if i*(i+1)//2==n:
        break
q = list(range(n, 0, -1))
ans = []
for j in range(i+1):
    tmp = []
    for k in ans:
        tmp.append(k[j-1])
    for _ in range(i-j):
        tmp.append(q.pop())
    ans.append(tmp)
print('Yes')
print(i+1)
for j in ans:
    tmp = [i]+j
    print(*tmp)

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

i = 1
K = []
while(1):
    k = i * (i+1) // 2
    if k > 10**5:
        break
    K.append(k)
    i+=1
if not N in K:
    print ('No')
    exit()
print ('Yes')
S = [[],[]]
i = 0

for n in range(1,N+1):
    S[i].append(n)
    S[-1].append(n)
    i+=1
    if n in K:
        if n==N:
            break
        i = 0
        S.append([])
print(len(S))
for s in S:
    print(str(len(s)) + ' ' + ' '.join(map(str,s)))

Solution (Python):
n=int(input())
n2=n*2
key=[0,0]
for i in range(1,int(n2**0.5)+3):
  if n2%i==0:
    if i*(i+1)==n2:
      key=[i,i+1]
      break
if key==[0,0]:
  print('No')
  exit()
print('Yes')
a,b=key
print(b)
ans=[[0]*a for _ in range(b)]
cnt=1
for i in range(b):
  for j in range(a):
    if j<i:
      ans[i][j]=ans[j][i-1]
    else:
      ans[i][j]=cnt
      cnt+=1
for x in ans:
  print(len(x),' '.join(map(str,x)))

Solution (Python):
N=int(input())
X=0
for i in range(1,1000):
  X+=i
  if X==N:
    P=[[] for j in range(i+1)]
    X=0
    for j in range(i):
      for k in range(i-j):
        P[j].append(k+X+1)
      for k in range(i-j):
        P[k+j+1].append(k+X+1)
      X+=i-j
    print('Yes')
    print(i+1)
    for j in range(i+1):
      print(len(P[j]),end=' ')
      print(*P[j])
    exit()
print('No')

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
for k in range(1,n+3):
    if k*(k-1)//2==n:
        print("Yes")
        print(k)
        size = (k-1)//2

        l = [set() for _ in range(k)]
        ind  = 1
        for i in range(k):
            for j in range(i+1,k):
                l[i].add(ind)
                l[j].add(ind)
                ind += 1
                    
        for i in range(k):
            print(len(l[i]), " ".join(map(str, l[i])))
        break
else:
    print("No")

Solution (Python):
N = int(input())
for k in range(1, N + 2):
    sn = k - 1
    if k * sn != 2 * N:
        continue

    print("Yes")
    print(k)
    s = [[0] * sn for _ in range(sn)]
    for i in range(sn):
        s[i][i] = s[i-1][i-1] + (i + 1)
        for j in range(i + 1, sn):
            s[i][j] = s[i][j-1] + j
            s[j][i] = s[i][j]
    s.append([s[i][i] for i in range(sn)])
    for x in s:
        print(sn, " ".join(map(str, x)))
    break
else:
    print("No")

Solution (Python):
N = int(input())
K = 0
for i in range(1, 500):
    if i * (i + 1) == 2 * N:
        K = i
        break
if K == 0:
    print("No")
    exit()

A = [[0] * K for _ in range(K)]
count = 1
for i in range(K):
    for j in range(i + 1):
        A[i][j] = count
        count += 1

print("Yes")
print(K + 1)
ans = []
for i in range(K):
    tmp = A[i][:i + 1]
    for y in range(i + 1, K):
        tmp.append(A[y][i])
    ans.append(tmp)
ans.append([A[i][i] for i in range(K)])
for a in ans:
    print(K, *a)