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):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



MOD = 10 ** 4 + 7

N = int(input())
if N == 1:
    print("Yes")
    print(2)
    print(1, 1)
    print(1, 1)
    exit()
i = 1
K = 0
while i ** 2 <= 2 * N:
    if i * (i + 1) == 2 * N:
        K = i + 1
        break
    i += 1

if K == 0:
    print("No")
    exit()

print("Yes")
print(K)
ladder = [i for i in range(1, K - 1)]
start = 1
base = [start]
for l in ladder:
    base.append(base[-1] + l)
for i in range(K - 1):
    num = K - 1
    s = [base[i]]
    for j in range(i):
        s.append(s[0] + j + 1)
    for j in range(i + 1, K - 1):
        s.append(base[j] + i)
    print(K - 1, *s)
diagnal = [1]
for l in ladder[1:] + [K - 1]:
    diagnal.append(diagnal[-1] + l)
print(K - 1, *diagnal)

Solution (Python):
n = int(input())
kaidan = [1]
for i in range(2,int((2*n)**0.5+1)):
    kaidan.append(kaidan[-1]+i)
if not n in kaidan:
    print("No")
    exit()
print("Yes")
size = kaidan.index(n)+1
print(size+1)
hyo = [[0 for i in range(size)] for j in range(size)]
for i in range(size):
    for j in reversed(range(i+1)):
        hyo[i][j] = kaidan[i] - (i - j)
        hyo[j][i] = hyo[i][j]
kar = []
for i in range(size):
    kar.append(hyo[i][i])
hyo.append(kar)

for i in range(size+1):
    print(size,end=" ")
    print(*hyo[i])

Solution (Python):



N=int(input())
a=set()
b={}

for i in range(1000):
    if i*(i+1)%2==0:
        s= i*(i+1)//2
        if s<=10**5:
            a.add(s)
            b[s]=i
        else:
            break
            
if N not in a:
    print("No")
else:
    print("Yes")
    print(b[N]+1)
    r=[0 for _ in range(N)] 
    t=[ [] for _ in range(b[N]+1)]
    for i in range(b[N]):
        r[i] +=1
    t[0]= [i+1 for i in range(b[N])]
    print(b[N],*t[0])

    for i in range(1,b[N]+1):
        for j in range(i):
            for k,num in enumerate(t[j]):
                if r[num-1]==1:
                    t[i].append(num)
                    r[num-1]+=1
                    break
        for k in range(N):
            if r[k]==0:
                r[k] +=1
                t[i].append(k+1)
                if len(t[i])>=b[N]:
                    break
        print(b[N],*t[i])

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union























from itertools import combinations, combinations_with_replacement






def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())

    def check_k(n):
        for k in range(2, 10**3):
            if k * (k-1) > 2 * n:
                return -1
            if k * (k-1) == 2 * n:
                return k
    
    
    n = ii()
    k = check_k(n)
    if k == -1:
        print('No')
    else:
        print('Yes')
        print(k)
        num = 0
        groups = [[] for _ in range(k)]
        for pattern in combinations(range(k), r=2):
            num += 1
            a, b = pattern
            groups[a].append(num)
            groups[b].append(num)
        for g in groups:
            print(2 * n // k, end=' ')
            print(*g, sep=' ')




if __name__ == "__main__":
    main()

Solution (Python):


import sys
input=sys.stdin.readline

def main():
    N=int(input())
    m=0
    k=0
    for i in range(int(((8*N+1)**0.5-1)/2)+1):
        if i*(i+1)==2*N:
            m=i
            k=i+1
            break
    if m==0:
        print("No")
        exit()
    elif N==1:
        print("Yes")
        print(2)
        print(1,1)
        print(1,1)
    else:
        ml=[[] for i in range(k)]
        for i in range(1,k+1):
            ml[i-1].append(str(i))
            ml[i-2].append(str(i))
        for i in range(k+1,N+1):
            ml[(i-k-1)%k].append(str(i))
            l=(i-k-1)//k
            ml[(i-k-1+2+l)%k].append(str(i))
        print("Yes")
        print(k)
        for i in range(k):
            print(m, " ".join(ml[i]))
    
    
if __name__=="__main__":
    main()

Solution (Python):
n = int(input())
a = []
for i in range(1,500):
    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):

"""
1~nまでの数字を用いて、以下の条件を満たす集合を作る。

1.1~nのそれぞれの数字はちょうど2回出現する
2.ある2つの集合を見たときに、重複する要素がちょうど1つ存在する
集合の個数・要素数は任意に決定して良い

この問題で考えるべきは、
ある2頂点に同じ要素を入れたとき、残りの要素は必ず別のものになり、
それらはまた自分と同じ要素の頂点と比べたときに必ず残りの要素が別
のものになってないといけない。

という点であり、これを達成するにはかなり厳しい制約があるはず。

まず、1.の制約より、全要素数は
2*n として求まる。
また、2.の制約より、必ず1つの頂点に頂点数-1個の要素が存在すると言える。
よって、前提として、
(2*n)%(頂点数-1) == 0
となるようなnでないと達成は不可能であり、
逆にそのようなnであれば達成可能。
頂点数はn<=10**5であることから、全探索で求めることができる。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
flag = 0
for i in range(1,n+2):
    if 2*n%i== 0: 
        tops = i
        if 2*n//tops == tops-1:
            elements = tops-1
            g = [[] for _ in range(tops)]

            mod = n
            now = 0
            now2 = 1
            for j in range(n):
                g[now].append(j+1)
                g[now2].append(j+1)
                now2 += 1
                if len(g[now]) >= elements:
                    now += 1
                    now2 = now + 1
                 

            
            flag = 1
    if flag:break

if flag:
    print("Yes")
    print(len(g))
    for i in g:
        print(len(i),*i)
else:
    print("No")

Solution (Python):
n = int(input())
t = 2*n
a = int(t**0.5)
if a*(a+1) != t:
    print("No")
    exit()

print("Yes")
print(a+1)
count = [0]*n
ans = [[] for i in range(a+1)]
now = a
p = [0]*(a+1)
for i in range(a):
    ans[i].append(i+1)
    ans[i+1].append(i+1)
    count[i] += 2
for i in range(a+1):
    if i >= 2:
        for j in range(i-1):
            while count[ans[j][p[j]]-1] ==2:
                p[j] += 1
            x = ans[j][p[j]]
            ans[i].append(x)
            count[x-1] +=1
        x = len(ans[i])
        for j in range(a-x):
            ans[i].append(now+1)
            count[now]+=1
            now += 1
    else:
        x = len(ans[i])
        for j in range(a-x):
            ans[i].append(now+1)
            count[now]+=1
            now += 1
    
for i in range(a+1):
    print(a,*ans[i])

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right


def main():
    N = int(input())
    if N == 1:
        print('Yes')
        print(2)
        print(1, 1)
        print(1, 1)
        exit()
    i = 3
    l = 2
    while i <= 10**5:
        if i == N:
            break
        else:
            l += 1
            i += l
    else:
        print('No')
        exit()

    
    ans = [[1, 2], [2, 3], [3, 1]]
    now = 3  
    M = 2  
    k = 2 * N // l
    while M < l:
        for j in range(M + 1):
            ans[j].append(now + 1 + j)
        ans.append(list(range(now + 1, now + 2 + M)))
        now += M + 1
        M += 1
    print('Yes')
    print(k)
    for i in range(k):
        print(l, *ans[i])


if __name__ == "__main__":
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from math import sqrt

deg = int(sqrt(N*2))

if N*2!=deg*(deg+1):
    print('No')
else:
    print('Yes')
    print(deg+1)
    ans = [[] for _ in range(deg+1)]
    now_len = deg
    cnt = 1
    for d in range(deg+1):
        ans[d].extend(list(range(cnt, cnt+now_len)))
        for i, c in enumerate(range(cnt, cnt+now_len), 1):
            ans[d+i].append(c)
        cnt += now_len
        now_len -= 1
    for i in range(deg+1):
        print(deg, *ans[i])

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    if N == 1:
        print('Yes')
        print(2)
        print(1,1)
        print(1,1)
        exit()
    i = 3
    l = 2
    while i <= 10**5:
        if i == N:
            break
        else:
            l += 1
            i += l
    else:
        print('No')
        exit()

    
    ans = [[1,2],[2,3],[3,1]]
    now = 3
    M = 2
    k = 2*N//l
    while M < l:
        for j in range(M+1):
            ans[j].append(now+1+j)
        ans.append(list(range(now+1,now+2+M)))
        now += M+1
        M += 1
    print('Yes')
    print(k)
    for i in range(k):
        print(l,*ans[i])



if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
if N == 1:
  print('Yes')
  print(2)
  print(1, 1)
  print(1, 1)
  quit()

S = [{1, 2}, {1, 3}, {2, 3}]
n = 3
while n < N:
  l = len(S)
  s = set()
  for i in range(l):
    n += 1
    S[i].add(n)
    s.add(n)
  S.append(s)

if n == N:
  print('Yes')
  print(len(S))
  for s in S:
    print(len(s), *s)
else:
  print('No')

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def isqrt(n):
    if n > 0:
        x = 1 << (n.bit_length() + 1) // 2
        y = (x + n // x) // 2
        while y < x:
            x = y
            y = (x + n // x) // 2
        return x
    elif n == 0:
        return 0
    else:
        raise ValueError("isqrt() argument must be nonnegative")


def main():
    N = int(readline())
    n = (isqrt(8 * N + 1) - 1) // 2
    if N != n * (n + 1) // 2:
        print('No')
        return

    it = iter(range(1, N + 1))
    G = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(i + 1):
            G[i][j] = G[j][i] = next(it)

    G.append([G[i][i] for i in range(n)])
    ans = ["{} {}".format(n, ' '.join(map(str, row))) for row in G]
    print('Yes')
    print(n + 1)
    print('\n'.join(ans))
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def isqrt(n):
    if n > 0:
        x = 1 << (n.bit_length() + 1) // 2
        y = (x + n // x) // 2
        while y < x:
            x = y
            y = (x + n // x) // 2
        return x
    elif n == 0:
        return 0
    else:
        raise ValueError("isqrt() argument must be nonnegative")


def main():
    N = int(readline())
    n = (isqrt(8 * N + 1) - 1) // 2
    if N != n * (n + 1) // 2:
        print('No')
        return

    it = iter(range(1, N + 1))
    G = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(i + 1):
            G[i][j] = G[j][i] = next(it)

    G.append([G[i][i] for i in range(n)])
    ans = ["{} {}".format(n, ' '.join(map(str, row))) for row in G]
    print('Yes')
    print(n + 1)
    print('\n'.join(ans))
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def isqrt(n):
    if n > 0:
        x = 1 << (n.bit_length() + 1) // 2
        y = (x + n // x) // 2
        while y < x:
            x = y
            y = (x + n // x) // 2
        return x
    elif n == 0:
        return 0
    else:
        raise ValueError("isqrt() argument must be nonnegative")


def main():
    N = int(readline())
    n = (isqrt(8 * N + 1) - 1) // 2
    if N != n * (n + 1) // 2:
        print('No')
        return

    it = iter(range(1, N + 1))
    G = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(i + 1):
            G[i][j] = G[j][i] = next(it)

    print('Yes')
    print(n + 1)
    for row in G:
        print(n, end=' ')
        print(*row)
    print(n, end=' ')
    print(*(G[i][i] for i in range(n)))
    return


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
L = [[] for _ in range(1000)]
l = 0
r = 1
for i in range(1, N+1):
  L[l].append(i)
  L[r].append(i)
  if(r-l == 1):
    r += 1
    l = 0
  else:
    l += 1
if(l != 0):
  print('No')
else:
  print('Yes')
  print(r)
  for i in range(r):
    print(len(L[i]), *L[i])

Solution (Python):
n = int(input())
x = (-1+(1+8*n)**0.5)/2
m = int((-1+(1+8*n)**0.5)//2)
if x != m:
    print('No')
else:
    print('Yes')
    k = 2*n//m
    print(k)
    s = [[] for i in range(k)]
    add = 1
    for i in range(m):
        for j in range(i+1, k):
            s[i].append(add)
            s[j].append(add)
            add += 1
    for i in range(k):
        print(m, ' '.join([str(j) for j in s[i]]))

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

N = int(readline())
k = -1
for i in range(1,1000):
    if i*(i-1)//2 == N:
        k = i
        print('Yes')
        break
if k == -1:
    print('No')
    exit()

print(k)
ans = [[] for i in range(k)]

import itertools

for i,(a,b) in enumerate(itertools.combinations(range(k),2),1):
    ans[a].append(i)
    ans[b].append(i)

for aaa in ans:
    print(len(aaa),*aaa)

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

N = int(readline())
k = -1
for i in range(1,1000):
    if i*(i-1)//2 == N:
        k = i
        print('Yes')
        break
if k == -1:
    print('No')
    exit()

print(k)
ans = [[] for i in range(k)]

import itertools

for i,(a,b) in enumerate(itertools.combinations(range(k),2),1):
    ans[a].append(i)
    ans[b].append(i)

for aaa in ans:
    print(len(aaa),' '.join(map(str,aaa)))

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

N = int(readline())

for i in range(1,1000):
    if i*(i-1)//2 == N:
        k = i
        print('Yes')
        break
    if i == 999:
        print('No')
        exit()

print(k)
ans = [[] for i in range(k)]

now = 1

import itertools
L = [i for i in range(k)]
for v in itertools.combinations(L,2):
    ans[v[0]].append(now)
    ans[v[1]].append(now)
    now += 1
for aaa in ans:
    print(len(aaa),' '.join(map(str,aaa)))

Solution (Python):
from itertools import combinations
n = int(input())
root = 1 + 8 * n
if int(root ** 0.5) ** 2 != root:
    print('No')
    exit()

k = (1 + int(root ** 0.5)) // 2
ans = [[] for _ in range(k)]

for i, a in enumerate(combinations(range(k), 2)):
    s, t = a
    ans[s].append(i + 1)
    ans[t].append(i + 1)
print('Yes')
print(k)
for List in ans:
    print(k - 1, *List)

Solution (Python):
l = {}
sum_n = 0
n = 1
while sum_n <= 10 ** 5:
    sum_n += n
    l[sum_n] = n
    n += 1
n = int(input())
if n not in l:
    print('No')
else:
    print('Yes')
    m = l[n]
    print(m+1)
    ans = [[m] for _ in range(m+1)]
    min_n = 1
    max_n = 1
    for i in range(1, m+1):
        max_n += i
        for j in range(min_n, max_n):
            ans[j-min_n].append(j)
            ans[i].append(j)
        min_n = max_n
    for i in ans:
        print(*i)

Solution (Python):

from itertools import combinations
from collections import defaultdict
n = int(input())

dd = defaultdict(int)
prev = 0
for i in range(1, 10**5):
    if n < prev:
        break
    dd[prev] = i
    prev += i

if dd[n]:
    print('Yes')
    print(dd[n])
    
    subarrays = [set()for _ in range(dd[n])]
    cnt = 1
    for i, j in combinations(range(dd[n]), 2):
        subarrays[i].add(cnt)
        subarrays[j].add(cnt)
        cnt += 1
    for s in subarrays:
        print(len(s), *s)

else:
    print('No')

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):
from collections import deque
N = int(input())
used1 = [0] * N
used2 = [0] * N

ans_list = [0] * 500
for i in range(1, 500):
  ans_list[i] = int(i * (i + 1) // 2)

if N in ans_list:
  print("Yes")
  k = ans_list.index(N)
  print(k + 1)
  A = [deque([]) for i in range(k)]
  for i in range(1, N + 1):
    p = int(((1 + 8 * i) ** (1/ 2) - 1.001) // 2)
    A[p].append(i)
  
  
  for i in range(k):
    print(k, end = " ")
    for j in range(i + 1):
      
      print(A[i][j], end = " ")
    for l in range(i + 1, k):
      print(A[l][i], end = " ")
    print("")
  
  print(k, end = " ")
  for i in range(k):
    print(A[i][i], end = " ")
  print("")
else:
  print("No")

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





def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))





from itertools import combinations

def main():
	n=II()

	for i in range(10**3):
		if i*(i+1)==2*n:
			break
	else:
		print("No")
		exit(0)
	k=i+1

	ans=[[] for _ in range(k)]

	for i,a in enumerate(combinations(range(k),2)):
		ans[a[0]].append(i+1)
		ans[a[1]].append(i+1)
	

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



if __name__ == "__main__":
	main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=2
    k=1
    for i in range(1,1000):
        if k==n:
            print("Yes")
            break
        if k>n:
            print("No")
            sys.exit()
        k+=s
        s+=1
    lis=[[]for _ in range(s)]
    x=1
    for i in range(s-1):
        for j in range(i+1,s):
            lis[i].append(x)
            lis[j].append(x)
            x+=1
    print(len(lis))
    for l in lis:
        print(str(len(l))+' '+' '.join(map(str,l)))

    

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=2
    k=1
    for i in range(1,1000):
        if k==n:
            print("Yes")
            break
        if k>n:
            print("No")
            sys.exit()
        k+=s
        s+=1
    lis=[[]for _ in range(s)]
    x=1
    for i in range(s-1):
        for j in range(i+1,s):
            lis[i].append(x)
            lis[j].append(x)
            x+=1
    print(len(lis))
    for l in lis:
        print(str(len(l))+' '+' '.join(map(str,l)))

    

if __name__=='__main__':
    main()

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

num_e = 1
num = num_e**2 + num_e

l = []


ok = 0

while num//2 <= 10**5:
    if num // 2 == n:
        ok = 1
        break

    num_e += 1
    num = num_e**2 + num_e

if not ok:
    print('No')
else:
    print('Yes')
    ans = [[num_e] for i in range(num_e+1)]

    num = 1
    for i in range(num_e):
        for j in range(i+1):
            ans[j].append(num)
            ans[i+1].append(num)
            num += 1
    print(num_e+1)
    for i in range(num_e+1):
        print(' '.join(map(str, ans[i])))

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

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


def main():
    N = int(input())
    if N == 1:
        print("Yes")
        print(2)
        print(*[1, 1], sep=" ")
        print(*[1, 1], sep=" ")
        return
    answer = "No"
    for i in range(1, N):
        if (2 * N) % i == 0:
            if (2 * N) // i == i + 1:
                answer = "Yes"
                cnt = i
                break
    print(answer)
    if answer == "No":
        return
    else:
        print(cnt + 1)
        answer = [[] for _ in range(cnt + 1)]
        next_num = 1
        next_place = 1
        while next_num <= N:
            for i in range(cnt + 1):
                if len(answer[i]) < cnt:
                    answer[i].append(next_num)
                    answer[next_place].append(next_num)
                    if len(answer[i]) == cnt:
                        next_place = i + 2
                    else:
                        next_place += 1
                    break
            next_num += 1

        for i in range(cnt + 1):
            ans = [cnt] + answer[i]
            print(*ans, sep=" ")


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import deque

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


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())

    for i in range(1, N + 1):
        if 2 * N == i * (i + 1):
            L = i
            break
    else:
        print("No")
        return

    ans = [[] for _ in range(L + 1)]
    used = [deque([]) for _ in range(L + 1)]
    no = deque(range(1, N + 1))

    for i in range(L + 1):
        if i == 0:
            for _ in range(L):
                j = no.popleft()
                ans[i].append(j)
                used[i].append(j)
        else:
            for j in range(i):
                k = used[j].popleft()
                ans[i].append(k)
            for _ in range(L - i):
                j = no.popleft()
                ans[i].append(j)
                used[i].append(j)

    print("Yes")
    print(L + 1)
    for a in ans:
        print(len(a), end=" ")
        print(*a, sep=" ")


if __name__ == "__main__":
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def a(i):
    return i*(i+1)//2

def main():
    n = I()
    k = -1
    for i in range(1, 10**3):
        if n == a(i):
            k = i
            break
    if k == -1:
        print("No")
        return

    print("Yes")

    print(2 * n // k)
    ans = [[] for __ in range(2 * n // k)]
    for i in range(k):
        ans[0].append(i+1)
    filled = 1
    next_to_use = [1]
    cur_max = k
    for i in range(k-1):
        remain = k
        for j in range(len(next_to_use)):
            ans[i+1].append(next_to_use[j])
            next_to_use[j] += 1
            remain -= 1
        first = True
        while remain:
            cur_max += 1
            ans[i+1].append(cur_max)
            remain -= 1
            if first:
                next_to_use.append(cur_max)
                first = False
    for i in range(k):
        ans[-1].append(ans[i][-1])

    for i in range(len(ans)):
        l = len(ans[i])
        print(str(l) + ' ' + ' '.join([str(x) for x in ans[i]]))
main()

Solution (Python):
n=int(input())
for i in range(1,1000):
  if i*(i+1)//2==n:
    D=[[0]*i for l in range(i)]
    stopcnt=i
    cnt=0
    a,b=0,0
    print('Yes')
    print(i+1)
    for j in range(n):
      D[a][j-b]=j+1
      cnt+=1
      if cnt==stopcnt:
        a+=1
        b+=stopcnt-1
        cnt=0
        stopcnt-=1
    for a in range(i):
      for b in range(a,i):
        D[b][a]=D[a][b]
    DD=[]
    for j in range(i):
      DD.append(D[j][j])
    D.append(DD)
    for j in D:
      print(len(j),*j)
    exit()
print('No')

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    ok = 10 ** 3
    ng = 0
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if N <= mid * (mid - 1) // 2:
            ok = mid
        else:
            ng = mid
    K = ok
    if not N == K * (K - 1) // 2:
        print('No')
        return

    num = 1
    ans = [[0] * (K - 1) for _ in range(K - 1)]
    for i in range(K - 1):
        for j in range(i + 1):
            ans[i][j] = ans[j][i] = num
            num += 1

    ans.append([ans[i][i] for i in range(K - 1)])
    ans = ["{} {}".format(K - 1, ' '.join(map(str, row))) for row in ans]

    print('Yes')
    print(K)
    print('\n'.join(ans))


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    K = int((1 + (8 * N + 1) ** 0.5) / 2)
    if not N == K * (K - 1) // 2:
        print('No')
        return

    num = 1
    ans = [[0] * (K - 1) for _ in range(K - 1)]
    for i in range(K - 1):
        for j in range(i + 1):
            ans[i][j] = ans[j][i] = num
            num += 1

    ans.append([ans[i][i] for i in range(K - 1)])
    ans = ["{} {}".format(K - 1, ' '.join(map(str, row))) for row in ans]

    print('Yes')
    print(K)
    print('\n'.join(ans))


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    K = int((1 + (8 * N + 1) ** 0.5) / 2)
    if not N == K * (K - 1) // 2:
        print('No')
        return

    num = 1
    ans = [[0] * (K - 1) for _ in range(K - 1)]
    for i in range(K - 1):
        for j in range(i + 1):
            ans[i][j] = ans[j][i] = num
            num += 1
    
    print('Yes')
    print(K)
    for row in ans:
        print(K - 1, *row)
    tmp = [ans[i][i] for i in range(K - 1)]
    print(K - 1, *tmp)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    K = int((1 + (8 * N + 1) ** 0.5) / 2)
    if not N == K * (K - 1) // 2:
        print('No')
        return

    ans = [[0] * (K - 1) for _ in range(K - 1)]
    for i in range(K - 1):
        n = i * (i + 1) // 2
        for j in range(i + 1):
            ans[i][j] = ans[j][i] = n + j + 1

    print('Yes')
    print(K)
    for row in ans:
        print(K - 1, *row)
    tmp = [ans[i][i] for i in range(K - 1)]
    print(K - 1, *tmp)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N = int(readline())
    K = (1 + (8 * N + 1) ** 0.5) / 2
    if not K.is_integer():
        print('No')
        return
    K = int(K)

    ans = [[] for _ in range(K)]
    num = 1
    for k in range(K):
        for l in range(k + 1, K):
            ans[k].append(num)
            ans[l].append(num)
            num += 1
    print('Yes')
    print(K)
    for row in ans:
        print(K - 1, *row)


if __name__ == '__main__':
    main()

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

flag,length=0,0
for i in range(1,10**3):
    if n==i*(i+1)//2:
        flag,length=1,i
        break
if not flag:print("No");exit()

A=[]
for i,j in enumerate(range(1,length+1)):
    num=j*(j+1)//2
    B=[]
    for k in range(i):
        B.append(num-(k+1))
    point=i+1
    B.append(num)
    for k in range(length-(i+1)):
        B.append(B[-1]+point)
        point +=1
    A.append(B)
A.append([i*(i+1)//2 for i in range(1,length+1)])

print("Yes")
print(len(A))
for i in A:
    print(length,*i)

Solution (Python):
import math

n = int(input())
num = 2 * n
tmp = int(math.sqrt(num))
if tmp * (tmp + 1) != num:
    print("No")
    exit()
print("Yes")
print(tmp + 1)
lst = [[] for _ in range(tmp + 1)]
last = 1
for i in range(tmp + 1):
    print(tmp, end = " ")
    cnt = 0
    for j in range(i):
        x = lst[j].pop()
        print(x, end = " ")
        cnt += 1
    for k in range(cnt, tmp):
        print(last, end = " ")
        lst[i].append(last)
        last += 1
        
    print()

Solution (Python):

def etrc(n1,n2,rs):
    for r in range(n1):
        rc[n2].append(rs+r)
        rc[n2+r+1].append(rs+r)

n=int(input())

x=int(((1+8*n)**0.5-1)/2)

rc=[[] for i in range(x+2)]

if n!=x*(x+1)//2:
    print("No")
else:
    print("Yes")
    print(x+1)

    rs=1
    for i in range(x):
        n1=x-i
        n2=i
        etrc(n1,n2,rs)
        rs=rs+n1

    for i in range(x+1):
        print(x, end=" ")
        for j in range(x):
            print(rc[i][j], end=" ")
        print()

Solution (Python):

def resolve():
    N = int(input())
    
    K = 0
    for i in range(1, 1000):
        if (i*(i-1)//2 == N):
            K = i
            break

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

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

if __name__ == "__main__":
    resolve()

Solution (Python):
from itertools import combinations as comb
n = int(input())
l = int((2*n)**0.5)
if 2*n == l*(l+1):
  print('Yes')
  print(l+1)
  ans = [[] for i in range(l+1)]
  for i,j in zip(range(n),comb(range(l+1),2)):
    ans[j[0]].append(i+1)
    ans[j[1]].append(i+1)
  for i in ans:
    print(l,*i,sep=' ')
else:
  print('No')