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,k=int(input()),0
for i in range(int((2*n)**0.5)+10):
    if i*(i-1)==2*n:
        k=i
if k==0:
    print('No')
else:
    print('Yes')
    print(k)
    c=1
    a=[[0]*k for _ in range(k)]
    for i in range(1,k):
        for j in range(1,i+1):
            a[i][j]=c
            c+=1
    ans=[[k-1]+[a[i][i] for i in range(1,k)]]
    for i in range(1,k):
        l=[k-1]
        h,w=i,1
        for j in range(1,k):
            l.append(a[h][w])
            h,w=(h,w+1) if j<i else (h+1,w)
        ans.append(l)
    for i in ans:
        print(*i)

Solution (Python):

N = int(input())


K = next(
    (
        k
        for k in range(1, N + 1)
        if k * (k + 1) // 2 == N
    ),
    0
)



ans = (
    'Yes\n{}\n{}'.format(
        K + 1,
        '\n'.join(
            '{} {}'.format(
                K,
                ' '.join(
                    map(
                        str,
                        [
                            i + j * K - j * (j + 1) // 2
                            for j in range(i)
                        ] +
                        [
                            1 + j + i * (2 * K - (i - 1)) // 2
                            for j in range(K - i)
                        ]
                    )
                )
            )
            for i in range(K + 1)
        )
    ) if K else
    'No'
)


print(ans)

Solution (Python):
N = int(input())
Ss = [[1], [1]]
while True:
    k = len(Ss)
    m = k * (k - 1) // 2
    if N < m:
        print("No")
        break
    elif N == m:
        print("Yes")
        print(k)
        for S in Ss:
            print(len(S), " ".join(map(str, S)))
        break
    S_new = []
    for i in range(k):
        x = m + 1 + i
        Ss[i].append(x)
        S_new.append(x)
    Ss.append(S_new)

Solution (Python):
import math

N = int(input())
k = math.ceil((2 * N) ** 0.5)
if N * 2 != k * (k - 1):
    print('No')
else:
    print('Yes')
    print(k)
    S = [[k - 1] 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
    for i in range(k):
        print(" ".join(map(str, S[i])))

Solution (Python):
import math
n = int(input())
if n == 1:
    print("Yes")
    print(2)
    print("1 1")
    print("1 1")
    exit()

ok = False
for i in range(2, int(math.sqrt(n*2)+1)):
    if n*2 % i == 0 and n*2 // i == i+1:
        ok = True
        size = i
        break
if ok:
    ans = [[0] * size for _ in range(size+1)]
    val = 1
    for i in range(0, size+1):
        for j in range(i, size):
            ans[i][j] = val
            val += 1
    val = 1
    for i in range(0, size):
        for j in range(i, size):
            ans[1+j][i] = val
            val += 1
    print("Yes")
    print(size+1)
    for line in ans:
        print(str(size) + " " + " ".join([str(item) for item in line]))

else:
    print("No")

Solution (Python):
n=int(input())
nn=int((n*2)**0.5)
if n*2!=nn*(nn+1):
  print("No")
else:
  print("Yes")
  print(nn+1)
  Ans=[[0]*nn for _ in range(nn+1)]
  for i in range(nn):
    for j in range(nn-i):
      Ans[i][i+j]+=nn*i-i*(i-1)//2+j+1
      Ans[i+j+1][i]+=nn*i-i*(i-1)//2+j+1
  for a in Ans:
    print(nn,*a)

Solution (Python):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())

k = ceil(sqrt(2*N))
if k*(k-1) != 2*N:
    print("No")
    exit()
print("Yes")
print(k)

S = [[]for _ in range(k+1)]
num = 1
for i in range(1,k):
    for j in range(i+1,k+1):
        S[i].append(num)
        S[j].append(num)
        num +=1
for i in range(1,k+1):
    print(k-1," ".join(map(str,S[i])))

Solution (Python):
import itertools
N = int(input())
for k in range(1000):
	if N * 2 == k * (k - 1):
		print("Yes")
		print(k)
		ans = [[] for i in range(k)]
		c = list(itertools.combinations(range(k), 2))
		for i in range(N):
			for j in c[i]:
				ans[j].append(i + 1)
		for i in ans:
			print(k - 1, end = " ")
			for j in i:
				print(j, end = " ")
			print()
		break
else:
	print("No")

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

print('Yes')
s = 1
ans = [[] for i in range(K)]
for k in range(K - 1, 0, -1):
    for i in range(k):
        ans[K - k - 1].append(s + i)
        ans[K - k + i].append(s + i)
    s += k

print(K)
for i in range(K):
    ans[i].insert(0, len(ans[i]))
    print(*ans[i])

Solution (Python):
n=int(input())
if n==1:
    print('Yes')
    print(2)
    print(1,1)
    print(1,1)
    exit()
if n==2:
    print('No')
    exit() 
a=[[1]]
i=1
for j in range(1,n):
    a.append(list(range(i,i+j)))
    if n==i+j-1:
        break
    elif i+j>n:
        print('No')
        exit()
    i+=j
print('Yes')
m=len(a)
for i in range(m-1):
    for j in range(i+1+(i<1),m):
        a[i].append(a[j][i])
print(m)
for b in a:
    print(len(b),*b)

Solution (Python):
n=int(input())
if n==1:
    print('Yes')
    print(2)
    print(1,1)
    print(1,1)
    exit()
if n==2:
    print('No')
    exit() 
a=[[1]]
i=1
for j in range(1,n):
    a.append(list(range(i,i+j)))
    if n==i+j-1:
        break
    elif i+j>n:
        print('No')
        exit()
    i+=j
print('Yes')
m=len(a)
for i in range(m-1):
    for j in range(i+1+(i<1),m):
        a[i].append(a[j][i])
print(m)
for b in a:
    print(len(b),*b)

Solution (Python):
import itertools
N = int(input())
X = int(((8 * N + 1)**0.5 - 1) // 2)
if N != X * (X + 1) // 2:
    print('No')
    exit()
index = 0
ans = [[X] for _ in range(X + 2)]
for i, j in itertools.combinations(range(1, X + 2), 2):
    index += 1
    ans[i] += [index]
    ans[j] += [index]
print('Yes')
print(X + 1)
[print(*_) for _ in ans[1:]]

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

L=[]
for i in range(1,10**5):
    if (i*(i+1)//2)>10**5:
        break
    else:
        L.append(i*(i+1)//2)

if N not in L:
    print("No")
    exit()
print("Yes")
for i in range(448):
    if N==i*(i+1)//2:
        print(i+1)
        break
L=[i+1 for i in range(i)]
ans=str(i)
for j in L:
    ans+=" "+str(j)
print(ans)
A=[[a+1]for a in range(i)]

cnt=i+1
for a in range(1,i+1):
    for b in range(i):
        if cnt>(((i)*(i+1))//2):
            break
        A[b%(i)].append(cnt)
        A[(b+a)%(i)].append(cnt)
        cnt+=1

for a in range(i):
    ANS=str(i)
    for j in A[a]:
        ANS+=" "+str(j)
    print(ANS)

Solution (Python):
import math


def main():
    N = int(input())
    x = math.floor(math.sqrt(N*2))
    if x * (x+1) != N*2:
        print("No")
        return
    print("Yes")
    print(x+1)
    s = [[] for _ in range(x+1)]
    counter = 1
    for i in range(x+1):
        for j in range(i+1, x+1):
            s[i].append(counter)
            s[j].append(counter)
            counter += 1
    for i in range(x+1):
        print(len(s[i]), *s[i])


if __name__ == "__main__":
    main()

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

def printCompleteGraph(n):
    edge = [(u, v) for u in range(n)
                   for v in range(u + 1, n)
                   if u != v]
    name = {e: i+1 for i, e in enumerate(edge)}
    for u in range(n):
        e = [name[(min(u, v), max(u, v))] for v in range(n) if u != v]
        print(len(e), ' '.join(map(str, e)))

for n in range(2, max(N, 2) + 1):
    if n * (n - 1) // 2 == N:
        print('Yes')
        print(n)
        printCompleteGraph(n)
        exit()
print('No')

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

def calc_n(K):
  for n in range(1, int(K/2)+2):
    if n*(n+1)/2 == K:
      return n
  return "No"

N = calc_n(K)
if not isinstance(N, int):
  print(N)
else:
  print("Yes")
  print(N+1)
  last = [i for i in range(1, N+1)]
  count = 2
  first_set = [str(i) if i == 1 else str(sum(last[:i-1])+1) for i in range(1, N+1)]
  print(N, " ".join(first_set))
  last_set = [str(sum(last[:i])) for i in range(1,N+1)]
  print(N, " ".join(last_set))
  while count != N+1:
    first_number = sum(last[:count-1])+1
    other_set = [i for i in range(first_number, first_number+count)]
    other_set.extend([first_number+count*(i+1)-1+sum(last[:i-1]) for i in range(1, N-count+1)])
    count += 1
    other_set = [str(i) for i in other_set]
    print(N, " ".join(other_set))

Solution (Python):
N = int(input())
flag = False
k = 0
if N == 1:
  print('Yes')
  print(2)
  print(1,1)
  print(1,1)
  exit()
for i in range(N+1):
    if i*(i-1)/2 == N:
        flag = True
        k = i
        break
if flag == False:
    print('No')
else:
    L = []
    cnt = 0
    dot = 1
    for j in range(k-1):
        M = []
        while cnt < j+1:
            M.append(dot)
            cnt += 1
            dot += 1
        L.append(M)
        cnt = 0
    ans = []
    for i in range(k-1):
      S = L[i]
      for j in range(i+1,k-1):
        S += [L[j][i]]
      ans.append(S)
    T = []
    for i in range(k-1):
      T.append((i+1)*(i+2)//2)
    ans.append(T)
    print('Yes')
    print(k)
    for i in range(len(ans)):
      ans[i] = [k-1]+ans[i]
      for j in range(len(ans[i])):
        if j != len(ans[i])-1:
          print(ans[i][j],end = ' ')
        else:
          print(ans[i][j],end = '')
      print()

Solution (Python):
import itertools
N = int(input())
k = int((2 * N) ** 0.5) + 1
if (k-1) * k == 2 * N:
    print('Yes')
    print(k)
    S = [[] for _ in range(k)]
    n = 1
    for i, j in itertools.combinations(range(k), 2):
        S[i].append(str(n))
        S[j].append(str(n))
        n += 1
    for s in S:
        print(len(s), ' '.join(s))
else:
    print('No')

Solution (Python):

ans_data = []

def get_num_shugou(num):
    num_shuugou = -1
    for i in range(1, num + 2):
        if 2 * num == i * (i - 1):
            num_shuugou = i
            break
        elif 2 * num < i * (i - 1):
            break
    return num_shuugou

def get_piramid(num_shuugou):
    piramid = [[1]]
    for i in range(num_shuugou - 2):
        data = [piramid[-1][-1] + j + 1 for j in range(len(piramid) + 1)]
        piramid.append(data)
    return piramid


def data_append(now_list):
    print('{} {}'.format(len(now_list), ' '.join(list(map(str, now_list)))))


def make_data(high, width, piramid, now_list_kari, down_flg):
    now_list = now_list_kari.copy()
    now_list.append(piramid[high][width])

    if len(now_list) == len(piramid):
        data_append(now_list)
        return

    if down_flg:
        make_data(high + 1, width, piramid, now_list, down_flg)

    elif width == len(piramid[high]) - 1:
        down_flg = 1
        make_data(high + 1, width, piramid, now_list, down_flg)
    else:
        make_data(high, width + 1, piramid, now_list, down_flg)


def write_shugou(num_shuugou):
    piramid = get_piramid(num_shuugou)

    now_list = [piramid[i][-1] for i in range(len(piramid))]
    data_append(now_list)
    for i in range(num_shuugou - 1):
        make_data(i, 0, piramid, [], 0)

def main():
    num = int(input())
    num_shuugou = get_num_shugou(num)
    if num_shuugou == -1:
        print('No')
    else:
        print('Yes')
        print(num_shuugou)
        write_shugou(num_shuugou)



if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
k = (2*n+0.25)**(1/2)+1/2
if k-int(k) == 0:
    print("Yes")
    k = int(k)
    print(k)
    bset = [[] for i in range(k)]
    now = 1
    for i in range(k-1):
        for j in range(i+1,k):
            bset[i].append(now)
            bset[j].append(now)
            now += 1
    length = len(bset[0])
    for i in bset:
        print(length," ".join(list(map(str,i))))
else:
    print("No")

Solution (Python):
n = int(input())
k = (2*n+0.25)**(1/2)+1/2
if k-int(k) == 0:
    print("Yes")
    k = int(k)
    print(k)
    bset = [[] for i in range(k)]
    now = 1
    for i in range(k-1):
        for j in range(i+1,k):
            bset[i].append(now)
            bset[j].append(now)
            now += 1
    length = len(bset[0])
    for i in bset:
        print(length," ".join(list(map(str,i))))
else:
    print("No")

Solution (Python):
N=int(input())
if N==1:
    print("Yes")
    print(2)
    print(1,"",1)
    print(1,"",1)
    quit()
find=False
for i in range(2,N+1):
    if i*(i-1)==2*N:
        find=True
        k=i
        break
if not find:
    print("No")
    quit()
S=2*N//k


list=[[] for i in range(k)]
par1=0
par2=1
for _ in range(k-1):
    num=S-len(list[par1])
    for j in range(num):
        list[par1].append(par2+j)
    for i in range(S-par1):
        list[par1+1+i].append(par2+i)
    
    par2+=S-par1
    par1+=1
print("Yes")
print(k)
for i in range(k):
    print(str(S)+" "+" ".join(map(str,list[i])))

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,random
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
tmp = 0
cnt = 0
while True:
    cnt += 1
    tmp += cnt
    if N == tmp:
        break
    elif N < tmp:
        print('No')
        sys.exit()

print('Yes')
print(cnt+1)
M = cnt

B = [1]
Bs = 1
for k in range(M,1,-1):
    Bs += k
    B.append(Bs)
B.sort()


S =[[] for _ in range(M+1)]
for i in range(1,N+1):
    ind = bisect.bisect_right(B,i)
    
    S[ind-1].append(i)
    S[ind+(i-B[ind-1])].append(i)

for i in range(M+1):
    print (' '.join(map(str,[M]+S[i])))

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

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

s = [[] for _ in range(k+1)]
num = 0
for i in range(1, k):
    for j in range(i):
        num += 1
        s[i].append(num)
        if j == i-1:
            s[k].append(num)
        else:
            s[j+1].append(num)
print("Yes")
print(k)
for i in range(1, k+1):
    print(k-1, *s[i])

Solution (Python):


"""
参考：https://img.atcoder.jp/tenka1-2018/editorial.pdf
　　　https://ferin-tech.hatenablog.com/entry/2018/10/29/135010
　　　https://babcs2035.hateblo.jp/entry/2018/11/03/143845
　　　https://naoyat.hatenablog.jp/entry/tenka1-2018-vc
　　　https://atcoder.jp/contests/tenka1-2018-beginner/submissions/3996670
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

cnt = 1
add = 2
while cnt < N:
    cnt += add
    add += 1

if cnt == N:
    
    c = add - 1
    ans = list2d(add, c, 0)
    k = 1
    for i in range(add):
        for j in range(i, c):
            ans[i][j] = k
            ans[j+1][i] = k
            k += 1
    print('Yes')
    print(add)
    for i in range(add):
        print(c, *ans[i])
else:
    print('No')

Solution (Python):


import sys


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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()

x = -1
for i in range(500):
    if N == i * (i + 1) // 2:
        x = i

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

print('Yes')
print(x + 1)
num = [i + 1 for i in range(N)]
S = [[0] * x for _ in range(x + 1)]
k = 0
for i in range(x):
    for j in range(i, x):
        S[i][j] = num[k]
        S[j + 1][i] = num[k]
        k += 1

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

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

def isTriangular(n):
    i = 1
    while( (i*(i+1))//2 <= n) :
        if (i*(i+1))//2 == n:
            return True
        i+=1
    return False


def solve(n):
    if not isTriangular(n):
        print("No")
        return
    i = 1
    jump = 2
    ans = [[1],[1]]
    while ans[-1][-1] != n:
        next_ind = list(range(ans[-1][-1]+1, ans[-1][-1]+jump+1))
        for i in range(len(next_ind)):
            ans[i].append(next_ind[i])
        ans.append(next_ind)
        i+=jump
        jump += 1
    print("Yes")
    print(len(ans))
    for x in ans:
        p_str = ""
        p_str += str(len(x))
        for b in x:
            p_str += " " 
            p_str += str(b)
        print(p_str)
solve(n)

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 pf(s): return print(s, flush=True)


def main():
    n = I()
    t = -1
    for i in range(1, 10**3):
        if i * (i+1) // 2 == n:
            t = i + 1
            break
    if t < 0:
        return 'No'
    a = [[] for _ in range(t)]
    k = 0
    for i in range(t):
        for j in range(i+1, t):
            k += 1
            a[i].append(k)
            a[j].append(k)
    r = ['Yes', str(len(a))]
    for c in a:
        r.append('{} {}'.format(len(c), ' '.join(map(str, c))))

    return '\n'.join(r)


print(main())

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


res = [[]]
cnt = 1
num = 1
for i in range(r):
    l = list(range(cnt,cnt+num))
    res.append(l)
    for j,k in enumerate(l):
        res[j] += [k]
    cnt += num
    num += 1

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

Solution (Python):
n = int(input())
k = int((n*2)**.5) + 1

if (k - 1) * k / 2 == n:
  print('Yes')
  print(k)
else:
  print('No')
  exit()

t = [1] * (k - 1)

for i in range(1, k - 1):
  t[i] = t[i-1] + i

for i in range(k-1):
  s = (t[max(i, j)] + min(i, j) for j in range(k-1))
  print(k-1, *s)
print(k - 1, *(t[j] + j for j in range(k-1)))

Solution (Python):
import math
n = int(input())
m = int(math.sqrt(8 * n + 1))

if m * m != 8 * n + 1:
  print("No")
else:
  k = int((m + 1) / 2)
  S = [[] for h in range(k)]
  l = 1
  for i in range(k - 1):
    for j in range(i + 1, k):
      S[i].append(l)
      S[j].append(l)
      l += 1
  print("Yes")
  print(k)
  s = "{} " * k
  t = s.rstrip(" ")
  for p in range(k):
    print(t.format(k - 1, *S[p]))

Solution (Python):
import math

n = int(input())

flag = False

if n == 1:
    print('Yes')
    print(2)
    print(1, 1)
    print(1, 1)
    

    

else:
    for i in range(int(math.sqrt(2*n)+1)):
        if i * (i + 1) == 2 * n:
            k = i
            flag = True
            break
    if flag:
        print('Yes')
        print(k + 1)
        lll = []
        mem = 1
        for j in range(k+1):
            s = []
            
            for l in range(k):
                if l >= j:
                    s.append(mem)
                    mem += 1
                else:
                    s.append(lll[l][j-1])

            lll.append(s)
            print(k, ' '.join(map(str, s)))


    else:
        print('No')

Solution (Python):
from math import sqrt
from itertools import combinations
n = int(input())
a = int(sqrt(2*n))
if n-a*(a+1)//2: print("No")
else:
	print("Yes")
	print(a+1)
	x,y,m = [[str(a)] for i in range(a+1)],[i for i in range(a+1)],1
	for i,j in combinations(y,2):
		x[i].append(str(m))
		x[j].append(str(m))
		m+=1
	for i in x: print(" ".join(i))

Solution (Python):
n = input()
state = 0
for k in range(448):
    if n * 2 == k * (k + 1):
        state = 1
        print "Yes"
        print k + 1
        break
if state == 1:
    arr = [[0 for j in range(k)] for i in range(k + 1)]
    number = 1
    for p in range(k):
        temp = number
        for s in range(p+1):
            
            arr[s][p] = number
            number += 1
        number = temp
        for t in range(p+1):
            
            arr[p+1][t] = number
            number += 1

    for a in arr:
        print len(a),
        for b in a:
            print b,
        print
else:
    print "No"

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

k=2
while(2*n > k*(k-1)):
    k+=1

if(2*n!=k*(k-1)):
    print("No")
else:
    print("Yes")
    print(k)
    tmp=0
    result=[[0]*(k-1) for i in range(k)]
    for i in range(k):
        for j in range(i):
            result[i][j]=result[j][i-1]
        for l in range(k-i-1):
            tmp+=1
            result[i][i+l]=tmp
        
    for j in range(k):
        print("{} ".format(k-1),end="")
        for i in range(k-2):
            print("{} ".format(result[j][i]),end="")
        print(result[j][k-2])

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

ss = [[1], [1]]
n = 2

for i in range(1, N):
    l = i + 1
    ss = [ss[i] + [n + i] for i in range(l)]
    ss += [[n + i for i in range(l)]]
    n += l
    if n - 1 >= N:
        break

if n - 1 == N:
    print("Yes")
    print(len(ss))
    for r in ss:
        print(len(r), *r)
else:
    print("No")

Solution (Python):
N = int(input())
a = [[ i*(i+1)//2 + j + 1 for j in range(i+1)] for i in range(540)]

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

if k*(k-1)//2 == N:
    print('Yes')
    print(k)
    for i in range(k-1):
        print(str(k-1), end='')
        for j in range(i+1):
            print(' '+str(a[i][j]), end='')
        for j in range(i+1, k-1):
            print(' '+str(a[j][i]), end='')
        print('')
    print(str(k-1), end='')
    for i in range(k-1):
        print(' '+str(a[i][i]), end='')
    print('')
else :
    print('No')

Solution (Python):
N = int(input())
if N == 1:
    print("Yes")
    print(2)
    print(1, 1)
    print(1, 1)
elif N == 2:
    print("No")
else:
    for i in range(N):
        if N == i * (i+1)/2:
            Ans = []
            ans =[1]
            for j in range(i-1):
                ans.append(ans[-1]+j+2)
            Ans.append(ans)
            ini, level = 1, 1
            for j in range(1, i+1):
                ans = [ini + k for k in range(level)]
                step, wide, temp = i-j, level, ini+level-1
                while step > 0:
                    ans.append(temp+wide)
                    temp += wide
                    step -= 1
                    wide += 1
                Ans.append(ans)
                ini += level
                level += 1
            print("Yes")
            print(len(Ans))
            for j in range(len(Ans)):
                print(i, " ".join(map(str, Ans[j])))      
            break
    else:
        print("No")

Solution (Python):
N = int(input())
if N == 1:
    print('Yes')
    print('2')
    print('1 1')
    print('1 1')
    exit()
for subs in range(2, N):
    n = N - subs
    if n == subs*(subs-1) // 2:
        print("Yes")
        print(subs+1)
        print(subs, end='')
        for i in range(1, subs+1):
            print(' ', end='')
            print(i, end='')
        print()
        li = [[] for _ in range(subs)]
        num = subs+1
        for i in range(len(li)):
            for j in range(i+1, subs):
                li[i].append(num)
                li[j].append(num)
                num += 1
        for ll in range(len(li)):
            print(len(li[ll])+1, end=' ')
            print(ll+1, end='')
            for kk in li[ll]:
                print(' ' + str(kk), end='')
            print()
        exit()
print("No")

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

for k in range(1000):
    temp = k * (k - 1) // 2
    if n == temp:
        print('Yes')
        print(k)
        res = [[] for _ in range(k)]
        p = 1
        for i in range(k):
            for j in range(i + 1, k):
                res[i].append(p)
                res[j].append(p)
                p += 1
        for x in res:
            print(' '.join(map(str, [k - 1] + x)))
        break
    elif n < temp:
        print('No')
        break

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

k = 2
while True:
    t = k * (k - 1) // 2
    if t >= n:
        break
    else:  
        k += 1

if t == n:
    m = [[None for _ in range(k - 1)] for _ in range(k - 1)]
    v = 1
    for r in range(k - 1):
        for c in range(r + 1):
            m[r][c] = v
            v += 1

    print('Yes')
    print(k)

    for i in range(k - 1):
        s = list()
        for c in range(i + 1):
            s.append(m[i][c])

        cnt = len(s)
        j = 0
        while cnt < k - 1:
            s.append(m[i + 1 + j][i])
            j += 1
            cnt += 1

        s = [k - 1] + s
        print(*s)

    s = list()
    cnt = 0
    j = 0
    while cnt < k - 1:
        s.append(m[j][j])
        j += 1
        cnt += 1

    s = [k - 1] + s
    print(*s)

else:
    print('No')

Solution (Python):
def d_crossing(N):
    """
    S_k は、どの2つの部分集合の共通部分の要素数が1であり、1からNのどの要素も
    ちょうど2回しか使われないため、各集合の要素数はいずれもk-1である。
    また、要素数の和を考えると、 2N=k(k-1) ⇔ N=k(k-1)/2 である。

    逆に、1からk(k-1)/2までの数を三角形に並べたあと、対称行列になるように
    行列を構成すると、各行(列でも可)または対角成分を要素とした集合を部分集合とすれば
    条件を満たせる。
    (例: N=6)
    1         1 2 4
    2 3   <=> 2 3 5
    4 5 6     4 5 6
    として、{1, 2, 4}, {2, 3, 5}, {4, 5, 6}, {1, 3, 6} を部分集合とすればよい。
    """

    
    k = 2
    while True:
        tmp = k * (k - 1)
        if tmp > 2 * N:
            return 'No'
        elif tmp == 2 * N:
            ans = ['Yes']
            break
        k += 1

    ans.append(str(k))
    
    matrix = [[0] * (k - 1) for _ in range(k - 1)]
    cnt = 1
    for r in range(k - 1):
        for c in range(r + 1):
            matrix[c][r] = matrix[r][c] = cnt
            cnt += 1
    
    for r in matrix:
        ans.append('{0} {1}'.format(k - 1, ' '.join(map(str, r))))
    
    tmp = [matrix[j][j] for j in range(k - 1)]
    ans.append('{0} {1}'.format(k - 1, ' '.join(map(str, tmp))))
    
    ans = '\n'.join(ans)
    return ans

N = int(input())
print(d_crossing(N))

Solution (Python):
def d_crossing(N):
    
    k = 2
    while True:
        tmp = k * (k - 1)
        if tmp > 2 * N:
            return 'No'
        elif tmp == 2 * N:
            ans = ['Yes']
            break
        k += 1

    ans.append(str(k))
    matrix = [[0] * (k - 1) for _ in range(k - 1)]
    cnt = 1
    for r in range(k - 1):
        for c in range(r + 1):
            matrix[c][r] = matrix[r][c] = cnt
            cnt += 1
    for r in matrix:
        ans.append('{0} {1}'.format(k - 1, ' '.join(map(str, r))))
    tmp = []
    for j in range(k - 1):
        tmp.append(matrix[j][j])
    ans.append('{0} {1}'.format(k - 1, ' '.join(map(str, tmp))))
    ans = '\n'.join(ans)
    return ans

N = int(input())
print(d_crossing(N))

Solution (Python):
import math
N = int(input())
ans = ""

for i in range(1, int(math.sqrt(2*N)+1)):
    if i*(i+1) == 2*N:
        k = i
        break
else:
    print("No")
    exit()

for i in range(k+1):
    if i == 0:
        ans += str(k) + " " + " ".join(map(str, range(1, k+1))) + "\n"
        ans_list = [0, k]
    else:
        ans_list = [i+1 for i in ans_list]
        ans += str(k) + " " + " ".join(map(str, ans_list[:-1]+\
        list(range(ans_list[-1], ans_list[-1]+k-i)))) + "\n"
        ans_list = ans_list[:-1] + [ans_list[-1]-1]
        ans_list.append(ans_list[-1]+k-i)


print("Yes"+"\n{}\n".format(k+1)+ans[:-1])

Solution (Python):

import sys
N=int(input())
a=[s+1 for s in range(N)]
flag=0
if N==1:
    print("Yes")
    print("2")
    print("1 1")
    print("1 1")
    sys.exit()

for i in range(N+1):
    if i*(i-1)//2==N: 
        flag=1
        print("Yes")
        print(i)
        b=[[] for t in range(i)]
        c=1
        u=0
        for s in reversed(range(0,i)):
            for t in range(s):
                b[i-s-1].append(c)
                b[i-s+c-u-1].append(c)
                c+=1
            u+=s
        for x in range(i):
            print(i-1,' '.join(map(str, b[x])))
if flag==0:
    print("No")

Solution (Python):
from math import sqrt, ceil

def tostr(a):
    return ' '.join(map(str, a))

N = int(input())
k = ceil(sqrt(N*2))

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

print('Yes')
print(k)
M = k - 1

a = [1]
for i in range(M-1):
    a.append(a[-1] + i + 2)
print(M, tostr(a))

for i in range(M):
    a = [int(i*(i+1)/2) + 1]
    a += list(range(a[-1]+1, a[-1]+i+1))
    
    for j in range(i+1, M):
        a.append(a[-1] + j)
    print(M, tostr(a))

Solution (Python):
import math
import itertools

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

    for i in range(2, 500):
        tmp = combination_count(i, 2)
        if N < tmp:
            print('No')
            return
        elif N == tmp:
            print('Yes')
            array = [x+1 for x in range(i)]
            accum = [[] for x in range(i)]
            for idx, (i, j) in enumerate(itertools.combinations(array, 2)):
                accum[i-1].append(idx + 1)
                accum[j-1].append(idx + 1)
            print(len(accum))
            for item in accum:
                txt = str(len(item)) + " " + " ".join([str(x) for x in item])
                print(txt)
            return
        else:
            continue

    return


main()