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

if N == 1:
    print('Yes')
    print(2)
    print('1 1')
    print('1 1')
    
elif N == 3:
    print('Yes')
    print(3)
    print('2 1 2')
    print('2 2 3')
    print('2 3 1')
    
elif N == 2:
    print('No')

else:
    k = int((2*N)**0.5)+1
    if k * (k-1) != 2*N:
        print('No')
    else:
        print('Yes')
        print(k)
        
        counter = 1
        node = []
        for i in range(k):
            for j in range(i+1,k):
                node.append([counter,i,j])
                counter += 1
        nd = [[] for _ in range(k)]
        for n in node:
            nd[n[1]].append(n[0])
            nd[n[2]].append(n[0])
        for i in range(k):
            ans = str(k-1)
            for j in nd[i]:
                ans += ' {}'.format(j)
            print(ans)

Solution (Python):
n=int(input())
j=False
k=-1
for i in range(1,1000):
    if i*(i+1)//2==n:
        j=True
        k=i
if j:
    print("Yes")
    print(k+1)
    res=[[0 for _ in range(k)] for _ in range(k+1)]
    t=1
    for i in range(k):
        for j in range(i,k):
            res[i][j]=t+j
        t+=k-i-1
    res=[[res[i][j] for i in range(k)] for j in range(k)]
    res.insert(0,[0 for _ in range(k)])
    t=1
    for i in range(k):
        for j in range(i,k):
            res[i][j]=t+j
        t+=k-i-1
    for t in res:
        t=list(map(str,t))
        print(str(k)+" "+" ".join(t))
else:
    print("No")

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


yess = {1:2}
for i in range(3, 500):
  n = i * (i-3) // 2 + i
  yess[n] = i

if N not in yess:
  print('No')
  exit()

print('Yes')
if N == 1:
  print(2)
  print(1, 1)
  print(1, 1)
  exit()


k = yess[N]
ss = [set() for _ in range(k)]
n = 1
for i in range(k):
  for j in range(i+1, k):
    ss[i].add(n)
    ss[j].add(n)
    n += 1

print(k)
for s in ss:
  print(len(s), ' '.join(map(str, s)))

Solution (Python):
from math import sqrt
N = int(input())
flg = False
g = 0
for i in range(1,int(sqrt(2*N))+1):
    if (2*N) % i == 0:
        if abs(i - (2*N//i)) == 1:
            flg = True
            g = (2*N//i)
            break

if not flg:
    print("No")
    exit(0)


print("Yes")
print(g)
e = 2*N//g
output = [[] for _ in range(g)]

k = 0
l = 1
for i in range(1,N+1):
    output[k].append(i)
    output[l].append(i)
    l += 1
    if l == g:
        k += 1
        l = k + 1

for i in range(g):
    print(e , end=" ")
    print(*output[i])

Solution (Python):
N = int(input())
a = 0
flag = True
for i in range(500):
    a += i+1
    if N == a:
        flag = False
        l = [[] for j in range(i+2)]
        b = i+1
        c = 0
        d = i+1
        for j in range(N):
            l[c].append(j+1)
            l[c + d - b + 1].append(j+1)
            if b > 1:
                b -= 1
            else:
                b = d - 1
                c = c + 1
                d = d - 1

        print("Yes")
        print(i+2)
        for j in range(i+2):
            print(i+1,' '.join(map(str, l[j])))
        break

if flag:
    print("No")

Solution (Python):
N=int(input())
if N==1:
    print("Yes")
    print(2)
    print(1,1)
    print(1,1)
    exit()
K=-1
for i in range(1,N+1):
    if i*(i-1)==2*N:
        K=i
        break
if K==-1:
    print("No")
    exit()
else:
    print("Yes")
print(K)
L=[[] for i in range(K)]
t=1
X=[[0 for i in range(K-1)] for i in range(K)]
for i in range(K):
    for j in range(i):
        L[i].append(L[j][-1])
        L[j].pop()
    for j in range(K-1-i):
        L[i].append(t)
        t+=1
    for j in range(K-1):
        X[i][j]=L[i][j]
for i in range(K):
    S=str(K-1)
    for j in range(K-1):
        S=S+" "+str(X[i][j])
    print(S)

Solution (Python):
from collections import defaultdict

n = int(input())

for i in range(2, 450):
    if n == i * (i - 1) // 2:
        break
else:
    print("No")
    exit()

num_apexes = i

edge_dict = defaultdict(list)

for i in range(num_apexes):
    for j in range(num_apexes):
        if i == j:
            continue
        edge_dict[i].append(j)

used = set([])
sets = defaultdict(list)
count = 1
for s in edge_dict.keys():
    for e in edge_dict[s]:
        if (s, e) in used or (e, s) in used:
            sets[s].append(str(count))
            sets[e].append(str(count))
            count += 1
        else:
            used.add((e, s))

print('Yes')
print(num_apexes)
for i in sets.keys():
    words = [str(len(sets[i])),] + sets[i]
    print(' '.join(words))

Solution (Python):

N = int(input())

ruiseki = 0
a = 0
enable = False
while ruiseki < N:
	a += 1
	ruiseki += a
	if ruiseki == N:
		enable = True

ans = []
if enable:
	if N == 1:
		ans = [[1],[1]]
	else:
		ans = [[1,2],[2,3],[1,3]]
		ruiseki = 3
		for i in range(a-2):
			tmp = []
			for ans_raw in ans:
				ruiseki += 1
				ans_raw.append(ruiseki)
				tmp.append(ruiseki)
			ans.append(tmp)

if enable:
	print('Yes')
	print(a+1)
	for ans_raw in ans:
		print(str(len(ans_raw)) + ' ' + ' '.join(map(str,ans_raw)))
else:
	print('No')

Solution (Python):
import sys
N=int(input())
flag=True
for k in range(1000):
    s=(k*(k+1))//2
    if N==s:
        flag=False
        break
if flag:
    print('No')
    sys.exit()
table=[[0]*(k+1) for i in range(k+1)]
s=1
for j in range(k+1):
    for i in range(j):
        table[j][i]=table[i][j]
    for i in range(j+1,k+1):
        table[j][i]=s
        s+=1
print('Yes')
print(k+1)
for i in range(k+1):
    table[i].remove(0)
    l=str(k)+' '
    l+=' '.join(map(str,table[i]))
    print(l)

Solution (Python):
N = int(input())
k = 2
while k * (k - 1) // 2 < N:
  k += 1
if k * (k - 1) // 2 == N:
  print('Yes')
  print(k)
  V = [[] for i in range(k)]
  idx = 1
  for i in range(k - 1):
    for j in range(i + 1, k):
      V[i].append(idx)
      V[j].append(idx)
      idx += 1
  for i in range(k):
    print(' '.join([str(x) for x in [k - 1] + V[i]]))
else:
  print('No')

Solution (Python):
import math


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

    a = int(math.sqrt(2 * N))

    if N != a * (a + 1) / 2:
        print('No')
        return

    k = a + 1
    n = a

    S = [[] for i in range(k)]

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

    print('Yes')
    print(k)
    for Si in S:
        print(str(n) + ' ' + ' '.join(map(str, Si)))

if __name__ == '__main__':
    main()

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

import sys

if N==1:
    print("Yes")
    print(2)
    print(1,1)
    print(1,1)
    sys.exit()


ANSLIST=[]


ANS=0
x=2
while ANS<=10**5:
   ANS= (1+x)*x//2
   ANSLIST.append(ANS)
   x+=1

if N in ANSLIST:
    print("Yes")
    x=ANSLIST.index(N)+2

    print(x+1)
    ANS=[[] for i in range(x+1)]


    LIST=[]
    y=1
    z=x
    while z>=0:
        LIST.append(y)
        y+=z
        z-=1

    

    for j in range(x):
        for k in range(x-j):
            ANS[j].append(LIST[j]+k)
            ANS[j+k+1].append(LIST[j]+k)

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


else:
    print("No")

Solution (Python):

OK = []
i = 1
while True:
    OK.append(i*(i+1)//2)
    if OK[-1] > 10**5:
        break
    i += 1
N = int(input())

if N in OK:
    print("Yes")
    W = OK.index(N) + 1
    S = [[] for _ in range(W+1)]
    j = 0
    L = list(range(1, N+1))
    l = 1
    for i, w in enumerate(range(W, 0, -1)):
        for s in range(l, l+w):
            S[i].append(s)
        l = l+w
    l = 1
    for i, w in enumerate(range(W, 0, -1)):
        for j, s in enumerate(range(l, l+w)):
            S[i+1+j].append(s)
        l = l+w
    print(len(S))
    for s in S:
        print(len(s), *s)
else:
    print("No")

Solution (Python):
from math import sqrt
from itertools import combinations

n = int(input())
if int(sqrt(2 * n)) * (int(sqrt(2 * n)) + 1) != 2 * n:
	print("No")
else:
	print("Yes")
	k = int(sqrt(2 * n)) + 1
	print(k)
	ans = [[] for _ in range(k)]
	num = 1
	for p in combinations(range(k), r=2):
		
		ans[p[0]].append(num)
		ans[p[1]].append(num)
		num += 1
	for i in range(k):
		ans[i] = [k-1] + ans[i]
		print(*ans[i])

Solution (Python):
n = int(input())
r = int((n*2)**.5)
if r*(r+1)!=n*2:
    print('No')
    exit()



res = [[] for i in range(r+1)]
tmp = 0
for i in range(r-1):
    
    
    for k in range(tmp,r-i+tmp):
        res[i].append(k+1)
        res[i+k-tmp+1].append(k+1)
    
    
    tmp += r-i
res[-2].append(n)
res[-1].append(n)

print('Yes')
print(len(res))
for l in res:
    print(len(l),*l)

Solution (Python):
def main():

    N = int(input())

    k=0
    while True:
        t=k*(k+1)//2
        if t==N:
            break
        if t>N:
            print("No")
            return
        k+=1

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

    sets=[list() for j in range(k+1)]
    x=0
    y=1
    for i in range(1,N+1):
        sets[x].append(i)
        sets[y].append(i)
        x+=1
        if y==x:
            y+=1
            x=0

    
    for s in sets:
        u=" ".join(str(ss) for ss in s)
        print("{} {}".format(len(s), u))

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
for i in range(1,100000):
  if n == i*(i+1)//2:
    k = i+1
    break
else:
  print("No")
  exit()
print("Yes")
print(k)
a = [[] for i in range(k)]
moto = list(range(1,n+1))
moto = moto[::-1]
for i in range(k):
  for j in range(i):
    a[i].append(a[j][i-1])
  while len(a[i]) != k-1:
    a[i].append(moto.pop())
for i in a:
  print(k-1,*i)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
MAXK = int(N + 10)
ll = [k for k in range(MAXK) if k * (k - 1) == N * 2]
if len(ll) == 0:
  print('No'); exit()

K = ll[0]

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

assert(cnt == N + 1)
print("Yes")
print(K)
for s in S:
  print(len(s), " ".join(str(c) for c in s))

Solution (Python):

import numpy as np

def main():
	n = int(input())
	m = find_n(n)
	
	tmp_st = 1
	if m == -1:
		print("No")
	else:
		ans = np.zeros((m + 1, m))
		for i in range(m):
			tmp_ary = np.array([i for i in range(tmp_st, tmp_st + m - i)])
			tmp_st += m - i
			ans[i, i:] = tmp_ary
			ans[i + 1:, i] = tmp_ary

		print("Yes")
		print(m + 1)
		for i in range(m + 1):
			print(str(m) + " " + " ".join([str(int(x)) for x in ans[i,]]))

			

def find_n(m):
	i = 1
	while True:
		if m == i * (i + 1) / 2:
			return i
		elif i * (i + 1) / 2 > m:
			return -1
		i += 1

if __name__ == '__main__':
	main()

Solution (Python):
from math import sqrt
from itertools import combinations
N = int(input())

k = round((1+sqrt(1+8*N))/2)

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

print('Yes')
print(k)

S = [list() for _ in range(k)]

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

for s in S:
  print(len(s),' '.join(map(str,s)))

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

k=int(sqrt(2*n))+1

if(k*(k-1)==2*n):
    res=[[0 for _ in range(k-1)] for _ in range(k)]
    num=[0 for _ in range(k)]
    for i,pair in enumerate(combinations(range(k),2)):
        for a in pair:
            res[a][num[a]]=i+1
            num[a]+=1

    print('Yes')
    print(k)
    for row in res:
        print(k-1,end=' ')
        for e in row:
            print(e,end=' ')
        print('')
else:
    print('No')

Solution (Python):

import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    
     
N, = getIntList()


T = 2*N

for i in range(1, 1000000000000):
    if i* (i+1) == T:
        break
    if i*(i+1) > T:
        print('No')
        sys.exit()

g = i

res = [ [] for i in range(g+1) ]
ac = 1
for i in range(g+1):
    for j in range(i+1, g+1):
        res[i].append(ac)
        res[j].append(ac)
        ac+=1

print('Yes')
print(len(res))
for x in res:
    print(len(x), end = ' ')
    for y in x:
        print(y,end = ' ')
    print()

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

r = int((N*2)**0.5)-1

if (r+1)*(r+2)//2!=N:
    print("No")
    exit()
cnt = 1
L = [[] for i in range(r+2)]
for i in range(1, r+2):
    for j in range(i+1, r+3):
        L[i-1].append(cnt)
        L[j-1].append(cnt)
        cnt += 1
print("Yes")
print(r+2)
for i in range(r+2):
    print(r+1, *L[i])

Solution (Python):
def check(n):
    i = 1
    while n > 0:
        n -= i
        if n == 0:
            return i
        i += 1
    return False


def solve(n):
    s = check(n)
    if s == False:
        print('No')
        return
    buf = [[s] + [0] * s for _ in range(s + 1)]
    t = s
    u = 1
    for i in range(s):
        buf[i][i + 1:i + t + 1] = list(range(u, u + t))
        for j in range(t):
            buf[i + j + 1][i + 1] = u + j
        u += t
        t -= 1
    print('Yes')
    print(s + 1)
    print('\n'.join(' '.join(map(str, b)) for b in buf))


n = int(input())
solve(n)

Solution (Python):
import math

N = int(input())
k = int(math.sqrt(N * 2)) + 1
if k * (k-1) == N*2:
    print("Yes")
    print(str(k))
    print_list = []
    used = 0
    for i in range(k):
        if i == 0:
            single_list = [str(k-1)] + [str(a+1) for a in range(k-1)]
            print(" ".join(single_list))
            print_list.append(single_list)
            used = k-1
        else:
            single_list = [str(k-1)] + [a[i] for j, a in enumerate(print_list)] + [str(a + used + 1) for a in range(k-1-i)]
            print(" ".join(single_list))
            print_list.append(single_list)
            used += k-1-i
else:
    print("No")

Solution (Python):
N = int(input())
a = int(((8*N+1)**(1/2)+1)/2+0.5)
if a*(a-1) != 2*N:
    print ("No")
    
else:
    m = N * 2 // a
    X = [[m] for i in range(a)]
    print ("Yes")
    print (a)
    k = 0
    for i in range(a-1):
        for j in range(i+1, a):
            k += 1
            X[i].append(k) 
            X[j].append(k) 
    for x in X:
        print (" ".join(map(str, x)))

Solution (Python):

"""
edge is an integer from 1 to N
it's a complete graph
"""

import sys

input=sys.stdin.readline
mii=lambda:map(int,input().split())

n=int(input())

sz=2
while sz*(sz-1)<n*2:
    sz+=1

if sz*(sz-1)==n*2:
    
    out=[[] for _ in range(sz)]
    num=1
    for i in range(sz):
        for j in range(i):
            out[i].append(num)
            out[j].append(num)
            num+=1
    print("Yes")
    print(len(out))
    for p in out:
        print("%d %s"%(len(p)," ".join(map(str,p))))
else:
    print("No")

Solution (Python):
n=int(input())
for i in range(500):
    if i*(i-1)//2==n:
        print("Yes")
        print(i)
        l=[[] for i in range(i)]
        a=1
        for j in range(i-1):
            for k in range(j+1,i):
                l[j].append(a)
                l[k].append(a)
                a+=1
        for j in range(i):
            print(i-1,end=" ")
            for k in range(i-1):
                print(l[j][k],end=" ")
            print("")
        n=0
        break
if n>0:
    print("No")

Solution (Python):
N = int(input())
r = 0
for i in range(2000):
    if N == i*(i-1) // 2:
        r = i
        
if r == 0:
    print("No")
else:
    print("Yes")
    res_list = [["0"]*(r-1) for _ in range(r)]
    ind_list = [0]*r
    k = 0
    for i in range(r):
        for j in range(i+1, r):
            k += 1
            res_list[i][ind_list[i]] = str(k)
            res_list[j][ind_list[j]] = str(k)
            ind_list[i] += 1
            ind_list[j] += 1
    print(r)
    for i in range(r):
        print(" ".join([str(r-1)] + res_list[i]))

Solution (Python):
N = int(input())
yes_set = []
k = 1
while k * (k + 1) < 2 * N:
    k += 1
if k * (k + 1) != 2 * N:
    print("No")
    quit()
ans = []
x = 1
for i in range(k + 1):
    row = []
    for j in range(i):
        row.append(ans[j][i - 1])
    for j in range(k - i):
        row.append(x)
        x += 1
    ans.append(row)
print("Yes")
print(k + 1)
for row in ans:
    print("{} {}".format(k, ' '.join(map(str, row))))

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

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

if N != K*(K-1)//2:
    print("No")
    exit(0)
print("Yes")
S = [[] for i in range(K)]

print(K)

v = 1
for i in range(K):
    for j in range(i+1, K):
        S[i].append(v)
        S[j].append(v)
        v += 1
for s in S:
    print(len(s), *s)

Solution (Python):
from sys import stdout
def main():
    n = int(raw_input())
    k = 1
    while k * (k - 1) / 2 < n:
        k += 1
    if k * (k - 1) / 2 != n:
        print "No"
        return
    ans = [[n * 2 / k] for _ in xrange(k)]
    c = 0
    for i in xrange(k):
        for j in xrange(i + 1, k):
            c += 1
            ans[i].append(c)
            ans[j].append(c)
    stdout.write('Yes\n')
    stdout.write(str(k) + '\n')
    for l in ans:
        stdout.write(' '.join(map(str, l)))
        stdout.write('\n')
main()