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
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

    K = 0
    for i in range(1,10**3):
        if i * (i-1) // 2 == N:
            K = i
            break

    if K == 0:
        print("No")
        exit()
    
    S = [[0] * (K-1) for _ in range(K-1)]

    a = 1
    for i in range(K-1):
        for j in range(i+1):
            S[i][j] = a
            S[j][i] = a
            a += 1

    ans = []
    for s in S:
        ans.append("{} {}".format(K-1, " ".join(map(str, s))))


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

    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

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

    K = 0
    for i in range(450):
        if i * (i-1) // 2 == N:
            K = i
            break

    if K == 0:
        print("No")
        exit()
    
    S = [[0] * (K-1) for _ in range(K-1)]

    a = 1
    for i in range(K-1):
        for j in range(i+1):
            S[i][j] = a
            S[j][i] = a
            a += 1

    tri = [S[i][i] for i in range(K-1)]

    print("Yes")
    print(K)

    for s in S:
        print(K - 1, *s)
    
    print(K - 1, *tri)

    
if __name__ == "__main__":
    main()

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

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

    K = 0
    for i in range(1,10**3):
        if i * (i-1) // 2 == N:
            K = i
            break

    if K == 0:
        print("No")
        exit()
    
    S = [[0] * (K-1) for _ in range(K-1)]

    a = 1
    for i in range(K-1):
        for j in range(i+1):
            S[i][j] = a
            S[j][i] = a
            a += 1

    tri = [S[i][i] for i in range(K-1)]

    print("Yes")
    print(K)

    for s in S:
        print(K - 1, *s)
    
    print(K - 1, *tri)

    
if __name__ == "__main__":
    main()

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

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

    K = 0
    for i in range(1,450):
        if i * (i-1) // 2 == N:
            K = i
            break

    if K == 0:
        print("No")
        exit()
    
    S = [[] for _ in range(K)]

    i = 1
    k = 0
    cnt = 0
    while i <= N:
        S[k].append(i)
        i += 1
        cnt += 1
        if cnt == K - (k+1):
            k += 1
            cnt = 0

    j = 1
    k = 1
    cnt = 0
    col = 0
    while j <= N:
        S[k].append(j)
        j += 1
        k += 1
        cnt += 1
        if cnt == K - (col+1):
            col += 1
            k = col + 1
            cnt = 0

    print("Yes")
    print(K)

    for s in S:
        print(K - 1, *s)

    
if __name__ == "__main__":
    main()

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

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

    K = 0
    for i in range(1,10**3):
        if i * (i-1) // 2 == N:
            K = i
            break

    if K == 0:
        print("No")
        exit()
    
    S = [[] for _ in range(K)]

    i = 1
    k = 0
    cnt = 0
    while i <= N:
        S[k].append(i)
        i += 1
        cnt += 1
        if cnt == K - (k+1):
            k += 1
            cnt = 0

    j = 1
    k = 1
    cnt = 0
    col = 0
    while j <= N:
        S[k].append(j)
        j += 1
        k += 1
        cnt += 1
        if cnt == K - (col+1):
            col += 1
            k = col + 1
            cnt = 0

    print("Yes")
    print(K)

    for s in S:
        print(K - 1, *s)

    
if __name__ == "__main__":
    main()

Solution (Python):
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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


def main():
	N = int(input())
	M = 0
	for i in range(2, 10 ** 3):
		if i * (i - 1) == 2 * N:
			M = i - 1
			break

	if M == 0:
		print("No")
		return

	print("Yes")
	print(M + 1)

	L = []
	cnt = 1
	for i in range(M):
		l = []
		for j in range(i + 1):
			l.append(cnt)
			cnt += 1
		L.append(l)


	ans = [M]
	for i in range(M):
		ans.append(L[i][-1])
	print(*ans)

	for i in range(M):
		ans = [M]
		for j in range(i + 1):
			ans.append(L[i][j])
		for j in range(i + 1, M):
			ans.append(L[j][i])
		print(*ans)


if __name__ == '__main__':
	main()

Solution (Python):
N = int(input())
exist = False
num = None
for K in range(1, N+1):
    if K * (K + 1) // 2 == N:
        exist = True
        num = K
        break

if not exist:
    print("No")
else:
    print("Yes")
    print(num + 1)
    res = [[] for _ in range(num + 1)]
    tot = 1
    for k in range(num, 0, -1):
        for i in range(k):
            res[num - k].append(tot + i)
            res[num - k + i + 1].append(tot + i)
        tot += k

    for i in range(num + 1):
        ans = []
        ans.append(len(res[i]))
        ans += res[i]
        print(" ".join(map(str, ans)))

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()

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







if __name__ == '__main__':
    resolve()

Solution (Python):
n=int(input())
for i in range(1,1000):
    if i*(i+1)==n*2:
        print("Yes")
        k=i+1
        print(k)
        break
else:
    print("No")
    quit()
ans=[[0]*(k-1) for i in range(k)]
x=1
for i in range(k-1,0,-1):
    for j in range(i):
        ans[-i-1][-j-1]=x
        ans[-i+j][-i]=x
        x+=1
for i in ans:
    print(k-1," ".join(map(str,i)))

Solution (Python):




















N=int(input())
num=0
flag=0

for i in range(2,1000):
    if 2*N==i*(i-1):
        num=i
        flag=1
        break
if flag==0:
    print("No")
else:
    l=[[] for _ in range(num)]
    cnt=1
    for i in range(num):
        for j in range(i+1,num):
            l[i].append(cnt)
            l[j].append(cnt)
            cnt=cnt+1
    print("Yes")
    print(num)
    for i in range(num):
        print(num-1,*l[i],sep=" ")

Solution (Python):
N=int(input())
num=0
flag=0
for i in range(2,1000):
    if 2*N==i*(i-1):
        num=i
        flag=1
        break
if flag==0:
    print("No")
else:
    l=[[] for _ in range(num)]
    cnt=1
    for i in range(num):
        for j in range(i+1,num):
            l[i].append(cnt)
            l[j].append(cnt)
            cnt=cnt+1
    print("Yes")
    print(num)
    for i in range(num):
        print(num-1,*l[i],sep=" ")

Solution (Python):
n=int(input())
f=0
for i in range(1,n+2):
	if i*(i-1)//2==n:
		f=1
		break
if f==0:
	print("No")
	exit()
print("Yes")
print(i)
k=i
cnt=0
s=[[-1]*k for _ in range(k)]
for i in range(k):
	for j in range(k):
		if i<j:
			s[i][j]=cnt
			cnt+=1
ans=[[]for _ in range(k)]
for i in range(k):
	for j in range(k):
		if s[i][j]!=-1:
			ans[i].append(s[i][j]+1)
			ans[j].append(s[i][j]+1)
for x in ans:
	print(k-1,*x)

Solution (Python):
MOD = 10 **9 + 7
INF = 10 ** 10

def main():
    N = int(input())
    K = 0
    for i in range(2,N + 2):
        if i*(i - 1)//2 == N:
            K = i
            break
    if K == 0:
        print('No')
        return
    ans = [[0] * (K - 1) for _ in range(K)]

    before = 1
    for i in range(K - 1):
        for j in range(i,K - 1):
            ans[i][j] = before
            ans[j + 1][i] = before
            before += 1
    print('Yes')
    print(K)
    for i in range(K):
        print(len(ans[i]),*ans[i])
if __name__ == '__main__':
    main()

Solution (Python):
def sol():
    N = int(input())
    D = 0

    for d in range(1, int((2 * N)**0.5) + 100):
        if d * (d - 1) == 2 * N:
            D = d
            break

    if D == 0:
        print('No')
        return

    print('Yes')
    mx = 1
    ans = []
    for d in range(D):
        line = []
        for _ in range(D - d - 1):
            line.append(mx)
            mx += 1
        ans.append(line)
    for i in range(D):
        line = ans[i]
        for j in range(i):
            line.append(ans[j][-i])
    print(len(ans))
    for a in ans:
        print(len(a), end=' ')
        print(*a)

sol()

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    k=1
    while k <= N*2:
        if k*(k-1)==2*N: break
        k+=1
    else:
        print('No')
        return
    print('Yes')
    print(k)
    ans=[[] for _ in range(k)]
    v=1
    for i in range(k):
        for j in range(i+1,k):
            ans[i].append(v)
            ans[j].append(v)
            v+=1
    for a in ans:
        print(len(a),*a)

if __name__ == '__main__':
    main()

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

k = 0
for i in range(1, 2*n+1):
    if i*(i-1) == 2*n:
        k = i


if not k:
    print('No')
    exit()

S = [[] for _ in range(k)]
import itertools
C = list(itertools.combinations(range(k),2))
for i in range(n):
    j = i+1
    c1, c2 = C[i]
    S[c1].append(j)
    S[c2].append(j)

print('Yes')
print(k)
for i in range(k):
    print(len(S[i]), *S[i])

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

tmp = 0
flag = True
for k in range(N + 1):
    tmp += k
    if tmp == N:
        break
    if tmp > N:
        flag =False
        break

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


G = [[] for _ in range(k + 1)]

count = 1
for i in range(k):
    for j in range(i + 1, k + 1):
        G[i].append(count)
        G[j].append(count)
        count += 1

print ('Yes')
print (k + 1)
for tmp in G:
    print (len(tmp), *tmp, sep = ' ')

Solution (Python):
N = int(input())
k = 2
while 1:
    if k*(k-1)//2 == N: break
    if k*(k-1)//2 > N:
        print('No')
        exit()
    k += 1

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

Solution (Python):
from itertools import combinations
N = int(input())
k = 2
while (k*(k-1))//2<N:
    k += 1
if (k*(k-1))//2!=N:
    print("No")
else:
    print("Yes")
    S = {i:[] for i in range(1,k+1)}
    cnt = 1
    for x in combinations(range(1,k+1),2):
        S[x[0]].append(cnt)
        S[x[1]].append(cnt)
        cnt += 1
    print(k)
    for i in range(1,k+1):
        print(len(S[i]),*S[i])

Solution (Python):
n=int(input())
m=-1
for i in range(2,10**5):
  if n==i*(i-1)//2:
    m=i
    break
if m==-1:print("No");exit()
print("Yes")
ans=[[]for _ in range(m)]
for i in range(m-1):
  if i==0:x=1
  else:x=ans[0][i]
  for j in range(m-1):
    ans[i].append(x)
    if i<=j:x+=j+1
    else:x+=1
x=1
for j in range(m-1):
  ans[-1].append(x)
  x+=j+2
print(m)
for i in ans:
  print(m-1,end=" ")
  print(*i)

Solution (Python):
n = int(input())
flag = 0
a = 0
for i in range(1, 1000):
    if n == a:
        flag = 1
        ans = i-1
        break
    else:
        a += i

if flag == 0:
    print("No")
else:
    print("Yes")
    print(ans+1)
    ans = [[] for j in range(ans+1)]

    l = 1
    c = len(ans)-1
    s = -1
    for i in range(len(ans)):
        for j in range(len(ans)-c-1):
            ans[i].append(ans[j][s])
        for j in range(c):
            ans[i].append(l)
            l += 1
        c -= 1
        s += 1

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

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

k = -1
for i in range(1, 10 ** 5 + 1):
    if i * (i - 1) == 2 * n:
        k = i
        break

if k == -1:
    print('No')
else:
    ans = [[] for _ in range(k)]
    print('Yes')
    print(k)
    tmp = 1
    for i in range(k):
        for j in range(i+1, k):
            ans[i].append(tmp)
            ans[j].append(tmp)
            tmp += 1

    for i in range(k):
        print(len(ans[i]), *ans[i])

Solution (Python):























N = int(input())
if N == 1:
  print("Yes")
  print(2)
  print(1,1)
  print(1,1)
  exit(0)
  
X = -1
for x in range(2,449):
  if (x * (x - 1) % 2) == 0 and (x * (x - 1) // 2) == N:
    X = x
    break
else:
  print("No")
  exit(0)
  

num = 1
ans = [set() for i in range(X)]
for i in range(len(ans)-1):
  for j in range(i+1,len(ans)):
    ans[i].add(num)
    ans[j].add(num)
    num += 1
    
print("Yes")
print(X)
for a in ans:
  print(len(a),*a)

Solution (Python):









N = int(input())
if N == 1:
  print("Yes")
  print(2)
  print(1,1)
  print(1,1)
  exit(0)
  
X = -1
for x in range(2,449):
  if (x * (x - 1) % 2) == 0 and (x * (x - 1) // 2) == N:
    X = x
    break
else:
  print("No")
  exit(0)
  

num = 1
ans = [[] for i in range(X)]
for i in range(len(ans)-1):
  for j in range(i+1,len(ans)):
    ans[i].append(num)
    ans[j].append(num)
    num += 1
    
print("Yes")
print(X)
for a in ans:
  print(len(a),*a)

Solution (Python):
def main():
    n = int(input())
    x = 2
    while (x-1)*x//2 < n:
        x += 1
    if (x-1)*x//2 == n:
        print("Yes")
        ans = [[] for _ in range(x)]
        y = 1
        for i in range(x-1):
            for j in range(i+1, x):
                ans[i].append(y)
                ans[j].append(y)
                y += 1
        print(x)
        for i in range(x):
            print(len(ans[i]), end=" ")
            for j in range(len(ans[i])):
                print(ans[i][j], end="")
                if j < len(ans[i])-1:
                    print(" ", end="")
                else:
                    print("")
    else:
        print("No")

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
num = 8*n+1
import math
a=int(math.sqrt(num))
ok=False
for i in [a-2,a-1,a,a+1,a+2]:
    if i**2 == num:
        ok=True
if not ok:
    print("No")
    exit()
print("Yes")
k=1+(a-1)//2
print(k)

from collections import defaultdict
ans=defaultdict(list)

i=0
j=1
for now in range(1,n+1):
    ans[i].append(now)
    ans[j].append(now)
    j+=1
    if j==k:
        i+=1
        j=i+1
        if i==k:
            break

for lis in ans.values():
    print(k-1,end=" ")
    print(*lis)

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

r = []
c = 1
i = 1
while i <= n:
    r.append([])
    for j in range(1, c+1):
        r[-1].append(i)
        i += 1
    c += 1

if i == n+1:
    print('Yes')
    print(c)
    for j in range(c-1):
        result = [c-1]
        result.extend(r[j])
        for x in range(j+1, c-1):
            result.append(r[x][j])
        print(*result)
    result = [c-1]
    for x in range(c-1):
        result.append(r[x][x])
    print(*result)
else:
    print("No")

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

r = []
c = 1
i = 1
while i <= n:
    r.append([])
    for j in range(1, c+1):
        r[-1].append(i)
        i += 1
    c += 1

if i == n+1:
    print('Yes')
    print(c)
    for j in range(c-1):
        result = [c-1]
        result.extend(r[j])
        for x in range(j+1, c-1):
            result.append(r[x][j])
        print(*result)
    result = [c-1]
    for x in range(c-1):
        result.append(r[x][x])
    print(*result)
else:
    print("No")

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
k = int(0.5+(2*N)**0.5)
if k*(k+1) == 2*N:  
	print("Yes")
	print(k+1)
	ans = [[] for _ in range(k+1)]
	for i, (x, y) in enumerate(combinations(range(k+1), 2)):
		ans[x].append(i+1)
		ans[y].append(i+1)
	for l in ans:
		print(k, *l)
else:
	print("No")

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

def gen_set(k):
    s = [[0] * k for _ in range(k + 1)]

    for i in range(k + 1):
        if i == 0:
            s[i][0] = 1
            for j in range(1, k):
                s[i][j] = s[i][j - 1] + j    
        elif 1 <= i < k:
            s[i][0] = s[0][i]
            for j in range(1, k):
                if j <= i:
                    
                    s[i][j] = s[i][j - 1] + 1
                else:
                    
                    s[i][j] = s[i][j - 1] + j
        else:
            
            s[i][0] = s[0][0]
            for j in range(1, k):
                s[i][j] = s[i][j - 1] + j + 1

    return s


x = 0
k = 0
while x < N:
    k += 1
    x += k

if x == N:
    s = gen_set(k)
    print("Yes")
    print(k + 1)
    for t in s:
        print(k, *t)
else:
    print("No")

Solution (Python):
n = int(input())
k = int((n*2)**(1/2))-1
for i in range(10):
    if (k+i)*(k+i-1)==n*2:
        k+=i
        break
if k*(k-1)!=n*2:
    print("No")
    exit()
print("Yes")
print(k)
tri = []

for i in range(1,k):
    tri.append([j for j in range(i*(i-1)//2+1,i*(i+1)//2+1)])
for i in range(k-1):
    print(k-1,end = " ")
    print(*tri[i],end=" ")
    for j in range(i+1,k-1):
        print(tri[j][i],end=" ")
    print()
print(k-1,end=" ")    
for i in range(k-1):
    print(tri[i][-1],end = " ")

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

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import itertools

n = ni()
k = -1

for i in range(1,10**7):
    if i*(i-1)//2 > n:
        break
    elif i*(i-1)//2 == n:
        k = i

if k == -1:
    print('No')
    exit()

print('Yes')
print(k)

a = list(itertools.combinations(range(k), 2))
ans = [[] for i in range(k)]

for i in range(len(a)):
    x,y = a[i]
    ans[x].append(i+1)
    ans[y].append(i+1)

for l in ans:
    print(str(k-1) + ' ' + (' '.join([str(u) for u in l])))

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

a = 0
s = []
fl = 0
for i in range(1,500):
    a += i
    s.append(a)
    
for i in range(len(s)):
    if s[i] == n:
        fl = 1
        leng = i+1
        
if fl == 0:
    print("No")
    sys.exit()
    
print("Yes")
print(leng+1)
ans = [[] for _ in range(leng)]
a = 0

for i in range(leng):
    while True:
        a += 1
        ans[i].append(a)
        if len(ans[i]) == i+1:
            break
            
for j in range(leng-1,-1,-1):
    a = ans[j][len(ans[j])-1]
    for k in range(leng-1-j):
        a += (k + j + 1)
        ans[j].append(a)
        
sime = s[:leng]
nn = len(ans[0])

for i in range(leng):
    print(nn,*ans[i])
    
print(nn,*sime)

Solution (Python):
n=int(input())
d=int((1+8*n)**(1/2))
if d**2!=(1+8*n) or d%2==0:
    print("No");exit()
k=(1+d)//2
print("Yes")
print(k)
haba=1
cnt=1
ret=[[] for i in range(k)]
while cnt<=n:
    for s in range(k-haba):
        ret[s].append(cnt)
        ret[s+haba].append(cnt)
        cnt+=1
    haba+=1
for i in ret:
    print(len(i),*i)

Solution (Python):
from math import sqrt
n = int(input())
k = (1+sqrt(1+8*n))/2
if k.is_integer():
    print('Yes')
    k = int(k)
    ans = [set() for _ in range(k)]
    i = 1
    for j in range(k-1):
        for l in range(j+1,k):
            ans[j].add(i)
            ans[l].add(i)
            i += 1
    print(k)
    for a in ans:
        print(k-1,' '.join(map(str,a)))
else:
    print('No')

Solution (Python):
n=int(input())
qi=0
for i in range(1000):
    if i*(i+1) ==n*2:
        qi=i
if qi==0 : 
    print("No")
    exit()
print("Yes")
print(qi+1)
from itertools import combinations as com
A=[[] for i in range(qi+1)]
now=1
for i,j in com([i for i in range(qi+1)],2):
    A[i].append(now) ; A[j].append(now)
    now+=1

for i in range(qi+1):
    print(qi, *A[i])

Solution (Python):
n=int(input())
qi=0
for i in range(1000):
    if i*(i+1) ==n*2:
        qi=i
if qi==0 : 
    print("No")
    exit()
print("Yes")
print(qi+1)
from itertools import combinations as com
A=[[] for i in range(qi+1)]
now=1
for i,j in com([i for i in range(qi+1)],2):
    A[i].append(now) ; A[j].append(now)
    now+=1

for i in range(qi+1):
    print(qi, *A[i])

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

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

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

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

Solution (Python):
N = int(input())
M = 1
while M*(M+1)//2 < N:
    M += 1
if M*(M+1)//2 != N:
    print('No')
    exit()
M += 1
S = [[] for i in range(M)]
k = 1
print('Yes')
print(M)
for i in range(M):
    for j in range(i+1, M):
        S[i].append(k)
        S[j].append(k)
        k += 1
for i in range(M):
    print(M-1, *S[i])

Solution (Python):
def is_square(N):
    i = 0
    while i**2 < N:
        i += 1
    if i**2 == N:
        return i
    return None


N = int(input())
r = is_square(8*N+1)
if r is None:
    print("No")
else:
    print("Yes")
    k = (r-1)//2
    size = k+1
    print(size)
    length = k
    ans = [[-1]*length for _ in range(size)]
    used = set()
    cur_max = 0
    for i in range(0, size):
        for j in range(i):
            ans[i][j] = ans[j][i-1]
        for k in range(i, length):
            ans[i][k] = cur_max+1
            cur_max += 1
    for a in ans:
        print("{} {}".format(length, " ".join(map(str, a))))

Solution (Python):
def main():
    N=int(input())
    flag=0
    tmp=0
    a=0
    for tmp in range(1,1000):
        if tmp*(tmp-1)//2==N:
            flag=1
            break
    if flag==0:
        print('No')
        exit()
    else:
        print('Yes')
        print(tmp)
    lst=[[]]*tmp
    for i in range(1,tmp):
        for j in range(i):
            a+=1
            lst[i]=lst[i]+[str(a)]
            lst[j]=lst[j]+[str(a)]
    for i in range(tmp):
        print(tmp-1, " ".join(lst[i]))

main()

Solution (Python):
n = int(input())
m = int((n*2)**0.5)
if m*(m+1)!=n*2:
    print('No')
else:
    print('Yes')
    print(m+1)
    ans = [[0]*m for _ in range(m+1)]
    for i in range(m+1):
        for j in range(m):
            if i==0 and j==0:
                ans[i][j] = 1
            elif i==j:
                ans[i][j] = ans[i-1][j-1] + m-i + 1
            else:
                if i>j:
                    if i==j+1:
                        ans[i][j] = ans[i-1][j]
                    else:
                        ans[i][j] = ans[i-1][j] + 1
                else:
                    ans[i][j] = ans[i][j-1] + 1
    for a in ans:
        print(len(a), *a)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n = II()
    k = 0
    tmp = 0
    while tmp < n:
        k += 1
        tmp += k
    if tmp == n:
        print("Yes")
        ans = [[]]
        x = 1
        for i in range(k):
            tmp = []
            for j in range(i+1):
                ans[j].append(x)
                tmp.append(x)
                x += 1
            ans.append(tmp)
        print(len(ans))
        for ai in ans:
            print(len(ai), *ai)
    else:
        print("No")
    return



if __name__ == '__main__':
    solve()

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

Solution (Python):
N=int(input())
triangle=[(i*(i-1))//2 for i in range(0,2*N+1)]
if not N in triangle:
    print('No')
else:
    print('Yes')
    k=triangle.index(N)
    print(k)
    count=0
    S=[[] for i in range(0,k)]
    for i in range(0,k):
        if i==0:
            S[i]=[j for j in range(1,k)]
            count=k-1
        else:
            for j in range(0,i):
                S[i].append(S[j][i-1])
            for j in range(0,k-1-i):
                S[i].append(count+1)
                count+=1
        print(k-1,*S[i])

Solution (Python):
N = int(input())
for i in range(1,N+2):
  if i*(i-1)//2==N:
    print('Yes')
    ans = [[] for i in range(i)]
    cnt = 0
    p = 0
    q = 1
    while cnt<N:
      cnt += 1
      ans[p].append(cnt)
      ans[q].append(cnt)
      if q==i-1:
        p += 1
        q = p+1
      else:
        q += 1
    print(len(ans))
    for a in ans:
      print(len(a),*a)
    break
else:
  print('No')

Solution (Python):
n = int(input())
i = 1
m = 0
while True:
    m += i
    if m == n:
        k = i + 1
        c = 1
        break
    elif m > n:
        c = 0
        break
    i += 1
if c == 1:
    print("Yes")
    print(k)
    dp = [[0 for _ in range(k - 1)] for _ in range(k)]
    m = 0
    for i in range(k):
        for j in range(k - 1):
            if i <= j:
                m += 1
                dp[i][j] = m
            else:
                if i == j + 1:
                    dp[i][j] = dp[i - 1][j]
                else:
                    dp[i][j] = dp[i - 1][j] + 1
    for i in range(k):
        print(k - 1, end = " ")
        s = map(str, dp[i])
        print(" ".join(s))
else:
    print("No")

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    l = 1
    r = n
    while r > l+1:
        m = (l+r) >> 1
        if m*(m+1) >> 1 <= n:
            l = m
        else:
            r = m
    if l*(l+1) >> 1 < n:
        print("No")
        return
    print("Yes")
    f = [[1]]
    for i in range(l-1):
        a = f[-1][-1]+1
        f += [list(range(a,a+i+2))]
    k = l+1
    ans = [[i[-1] for i in f]]
    for i in range(l):
        p = f[i][:i]
        p += [f[j][i] for j in range(i,l)]
        ans += [p]
    print(k)
    for i in ans:
        print(len(i),*i)
    return


if __name__ == "__main__":
    solve()

Solution (Python):



def main():
    from itertools import combinations

    N = int(input())

    
    
    

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

    if not cond:
        print('No')
        return

    sets = tuple(set() for _ in range(k))
    for common_component, (set_idx_1, set_idx_2) in enumerate(combinations(range(k), r=2), start=1):
        sets[set_idx_1].add(common_component)
        sets[set_idx_2].add(common_component)

    print('Yes')
    print(k)
    for set_ in sets:
        print(len(set_), *set_)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from collections import deque
    from decimal import Decimal, getcontext

    getcontext().prec = 1000

    N = int(input())

    
    
    

    sq = Decimal(N * 8 + 1).sqrt()
    cond = sq % 2 == 1  

    if not cond:
        print('No')
        return
    k = int((1 + sq) // 2)  
    print('Yes')
    print(k)

    deqs = []
    it = iter(range(1, N + 1))
    for _ in range(k):
        print(k - 1, end=' ')
        t = []
        for deq in deqs:
            x = deq.popleft()
            t.append(x)
        u = []
        for _ in range(k - 1 - len(t)):
            x = next(it)
            u.append(x)
        t.extend(u)
        print(*t) 
        deqs.append(deque(u))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    
 
    
    
 
    N = int(input())
    for i in range(10**3):
        if i*(i-1) == N*2:
            res = i
            break
    else:
        print('No')
        exit()
 
    s = [[] for _ in range(res)]
    num = 1
 
    for a,b in combinations(range(res), 2):
        s[a].append(num)
        s[b].append(num)
        num += 1
 
    print('Yes')
    print(res)
    for i in s:
        print('{} {}'.format(res-1, ' '.join(map(str, i))))
 
if __name__ == '__main__':
    main()