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):
def check(n):
    i = 1
    while n > 0:
        n -= i
        if n == 0:
            return i
        i += 1
    return 0


N = int(input())
K = check(N)
if K == 0:
    print("No")
    exit()

print("Yes")
print(K + 1)
ans = [[] for _ in range(K + 1)]
cur = 0
nxt = K
for k in range(K):
    ans[k] += range(cur + 1, cur + K - k + 1)
    for i in range(K - k):
        ans[i + k + 1].append(i + cur + 1)
    cur += nxt
    nxt -= 1

[print(K, *row) for row in ans]

Solution (Python):
import itertools

n = int(input())
triangle = [0,0]
now = 0
num = 1
while now < n:
  now += num
  triangle.append(now)
  num += 1
if n in triangle:
  print("Yes")
  K = triangle.index(n)
  print(K)
  ans = [list() for i in range(K)]
  for k,v in enumerate(itertools.combinations(range(K),2),1):
    for i in v:
      ans[i].append(k)
  for i in ans:
    print(K-1,*i)
else:
  print("No")

Solution (Python):

"""
if N = K(K + 1)/2 -> Yes
construct a triangle(e.g. N = 10, K = 4):
    1 0 0 0
    2 3 0 0
    4 5 6 0
    7 8 9 10
the answer will be:
  {each row until 0 + column straight down from there}
    {1 2 4 7}
    {2 3 5 8}
    {4 5 6 9}
    {7 8 9 10}
  {diagonal line}
    {1 3 5 10}
"""
def main():
    N = int(input())
    K = int((N * 2) ** 0.5)
    if K * (K + 1) / 2 != N:
        print("No")
        return
    row, cur, cnt = [], 1, 1
    while cur + cnt - 1 <= N:
        row.append(list(range(cur, cur + cnt)) + [0] * (K - cnt))
        cur += cnt
        cnt += 1
    col = [list(c) for c in zip(*row)]
    ans, diag = [], []  
    for i, (r, c) in enumerate(zip(row, col)):
        diag.append(r[i])
        ans.append(r[:i] + c[i:])
    ans.append(diag)
    print("Yes", K + 1, sep="\n")
    for a in ans:
        print(K, end=" ")
        print(" ".join(map(str, a)))


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
k=0
for i in range(1,n+1):
  if (i*(i+1))//2==n:
    k=i
    break
else:
  k=-1
if k==-1:
  print('No')
else:
  arr=[[k] for _ in range(k+1)]
  tmp=0
  tk=0
  while k-tk>0:
    for i in range(tmp+1,tmp+k+1-tk):
      arr[tk].append(i)
    for i in range(tk+1,k+1):
      arr[i].append(tmp+i-tk)
    tmp+=(k-tk)
    tk+=1
  print('Yes')
  print(k+1)
  for row in arr:
    print(*row)

Solution (Python):
N = int(input())
for i in range(2000):
    if i*(i-1)//2 == N:
        c = 1
        X = [[] for _ in range(i)]
        for j in range(i):
            for k in range(j+1, i):
                X[j].append(c)
                X[k].append(c)
                c += 1
        print("Yes")
        print(len(X))
        for x in X:
            print(len(x), *x)
        break
else:
    print("No")

Solution (Python):
N=int(input())
K=-1
for k in range(2,2+int((2*N)**0.5)):
    if k*(k-1)==2*N:
        K=k
if K==-1:
    print("No")
else:
    print("Yes")
    print(K)
    ans=[[] for i in range(K)]
    now=1
    for i in range(K-1):
        for j in range(i+1,K):
            ans[i].append(now)
            ans[j].append(now)
            now+=1
    for L in ans:
        print(str(len(L))+" "+" ".join(map(str,L)))

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

can_be_ans = False
for k in range(1, 10 ** 5):
    if 2 * N == k * (k - 1):
        can_be_ans = True
        break
    elif 2 * N < k * (k - 1):
        break
        
if not can_be_ans:
    print("No")
else:
    print("Yes")
    print(k)
    s_grid = [[0 for i in range(k - 1)] for j in range(k)]
    for i in range(1, k + 1):
        for j in range(k - i):
            s_grid[i - 1][i - 1 + j] = (i - 1) * k - i * (i - 1) // 2 + 1 + j
            s_grid[i + j][i - 1] = (i - 1) * k - i * (i - 1) // 2 + 1 + j
            
    for row in s_grid:
        print(k - 1, end=" ")
        print(" ".join(map(str, row)))

Solution (Python):
N=int(input())
chk = (2*N)**(1/2)
k = chk//1
if N  != k*(k+1)//2:
    print("No")
else:
    print("Yes")
    k = int(k)
    print(k+1)
    ans_list = [[0 for i in range(k)] for j in range(k+1)]
    W1 = 0
    H1 = 0
    W2 = 0
    H2 = 1
    for i in range(N):
        ans_list[H1][W1] = i+1
        ans_list[H2][W2] = i+1
        if H1 == W1 :
            H1 = 0
            W1 =W1+1
            H2 = W1+1
            W2 = 0
        else:
            H1 += 1
            W2 += 1
    for i in range(k+1):
        print(str(k)+" "+" ".join(str(n) for n in ans_list[i]))

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())
sk = int((2*n)**0.5)
km = sk + 1
if (n !=sk*km//2):
  print ("No")
else:
  print ("Yes")
  print (km)
  li = [[] for i in range(km)]
  
  c = 1
  for i in range(sk):
      for j in range(1+i,sk+1):
          li[i].append(c)
          li[j].append(c)
          c+=1
  [ print ( str(sk)+" "+" ".join([ str(_p) for _p in it ]) )   for it in li]

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
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 II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import Counter

def main():
    N = II()
    ks = {}
    for i in range(1, 1000):
        ks[i * (i - 1) // 2] = i
    if N not in ks.keys():
        print('No')
        return 0
    print('Yes')
    k = ks[N]
    print(k)
    sets = [[k - 1] for i in range(k)]
    cnt = 1
    for i in range(k):
        for j in range(i):
            sets[i].append(cnt)
            sets[j].append(cnt)
            cnt += 1
    for i in range(k):
        print(*sets[i])

    return 0

main()

Solution (Python):
def calc(n):
    if n == 2:
        return [[1], [1]], 1
    lis, val = calc(n - 1)
    for i, l in enumerate(lis):
        l.append(val + 1 + i)
    lis.append(list(range(val + 1, val + n)))
    return lis, val + n - 1

N = int(input())
base = 1
n = 4
while ((base // 2) < N) and (N != 1):
    base = (n - 1) * (n - 2)
    n += 1
if base == (N * 2) or (N == 1):
    lis,_ = calc(n - 2)
    length = len(lis[0])
    k = len(lis)
    print('Yes')
    print(k)
    [print(length, ' '.join(map(str, l))) for l in lis] 
else:
    print('No')

Solution (Python):

"""
Created on Tue Apr 16 22:14:05 2019

@author: Yamazaki Kenichi
"""
import sys

N = int(input())
n = ((8*N+1)**0.5 - 1)/2
if n % 1 != 0:
    print('No')
    sys.exit()
else:
    n = int(n)
    print('Yes')
    print(n+1)

S = [[n] + [-1 for i in range(n)] for i in range(n+1)]

tmp = 1
for i in range(1,n+1):
    for j in range(i):
        S[j][i] = tmp
        S[i][j+1] = tmp
        tmp += 1
for i in range(n+1):
    print(' '.join(map(str,S[i])))

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

answer = {(i-1)*i//2:i for i in range(2,500)}

from itertools import combinations


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

else:
  print('Yes')

  k = answer[N]
  S = [set() for _ in range(k)]
  for i, c in enumerate(combinations(S,2)):
    for s in c:
      s.add(i+1)

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

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



creatable = []
for n in range(1, N + 1):
    num = n * (n + 1) // 2
    if num > N:
        break
    creatable.append(num)



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



K = creatable.index(N) + 2
ans = [[] for i in range(K)]
for n, (c1, c2) in enumerate(combinations(range(K), 2), start=1):
    ans[c1].append(n)
    ans[c2].append(n)



print('Yes')
print(K)
for a in ans:
    print(len(a), ' '.join(map(str, a)))

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

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

m = s = 1
while s < N:
    m += 1
    s += m
if s != N:
    print('No')
    exit()

k = m+1
print('Yes')
print(k)
ans = [[] for i in range(k)]
n = 1
for i in range(k-1):
    for j in range(i+1,k):
        ans[i].append(n)
        ans[j].append(n)
        n += 1

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

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left
from itertools import combinations

n = ni()

cands = []
for i in range(1,10**5):
    cand = (i+1)*i // 2
    if cand > 10**5:
        break
    cands.append((i+1)*i // 2)
    
if not n in cands:
    print('No')

else:
    setnum = bisect_left(cands, n) + 2
    sets = list(combinations([i for i in range(1,setnum+1)], 2))
    grid = [[] for _ in range(setnum)]
    for i, (set1, set2) in enumerate(sets):
        grid[set1-1].append(i+1)
        grid[set2-1].append(i+1)
    
    print('Yes')
    print(setnum)
    for row in grid:
        print(len(row), *row)

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())
a=-1
for k in range(450):
  if N==k*(k-1)//2:
    a=k
    break
if a==-1:
  print("No")
  exit()
else:
  print("Yes")
List=[]
s=0
for i in range(a-1):
  List.append(list(range(1+s,a-i+s)))
  s=a-i+s-1
ans=[[] for i in range(a)]
for i in range(a):
  if i<a-1:
    for j in List[i]:
      ans[i].append(str(j))
  for k in range(i):
    ans[i].append(str(List[k][i-k-1]))
print(a)
for b in ans:
  print(str(a-1)+" "+" ".join(b))

Solution (Python):
n=int(input())
k=int((n*2)**0.5+1)
if k*(k-1)!=n*2:
    print('No')
    exit()
print('Yes')
a=1
b=[[] for i in range(k)]
for i in range(k):
    for j in range(i+1,k):
        b[i].append(a)
        b[j].append(a)
        a+=1
print(k)
for i in b:print(k-1,*i)

Solution (Python):
N = int(input())
t = [2,1]
h = [[1],[1]]
while t[1]<=N:
    if t[1]==N:
        print("Yes")
        print(t[0])
        [print(len(h[i])," ".join([str(j) for j in h[i]])) for i in range(len(h))]
        break
    else:
        [h[i].append(t[1]+1+i) for i in range(len(h))]
        h.append([t[1]+1+i for i in range(len(h))])
        t[1]+=t[0]
        t[0]+=1
else:
    print("No")

Solution (Python):
N = int(input())
t = [2,1]
h = [[1],[1]]
while t[1]<=N:
    if t[1]==N:
        print("Yes")
        print(t[0])
        [print("{0} {1}".format(len(h[i])," ".join([str(j) for j in h[i]]))) for i in range(len(h))]
        break
    else:
        [h[i].append(t[1]+1+i) for i in range(len(h))]
        h.append([t[1]+1+i for i in range(len(h))])
        t[1]+=t[0]
        t[0]+=1
else:
    print("No")
    exit()

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):
from itertools import combinations
import sys
N=int(input())
flag=True
for k in range(1000):
    s=(k*(k+1))//2
    if s==N:
        flag=False
        break
if flag:
    print('No')
    sys.exit()
table=[[k] for i in range(k+1)]
s=1
for elem in combinations(range(k+1),2):
    table[elem[0]].append(s)
    table[elem[1]].append(s)
    s+=1
print('Yes')
print(k+1)
for i in range(k+1):
    print(' '.join(map(str,table[i])))

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

cnt = 0
fitn = 0
while(fitn < n):
    cnt += 1
    fitn += cnt
    
    if(fitn > n):
        print("No")
        exit()


numofrow = cnt + 1
ans = []
for i in range(numofrow):
    ans.append([])

idx = 1
for i in range(numofrow):
    for j in range(i+1,numofrow):
        ans[i].append(idx)
        ans[j].append(idx)
        idx += 1


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

Solution (Python):
N = int(input())
H = list(range(N))
T = []

ctr = 0
L = 0
while ctr < N:
    L += 1
    ctr += L

if ctr != N:
    print('No')
    
else:
    print('Yes')
    print('{0}'.format(L+1))
    T = [[0 for _ in range(L)] for _ in range(L+1)]
    for i in range(L):
        for j in range(L-i):
            T[i][i+j] = int(i*L-i*(i-1)/2+j+1)
            T[i+j+1][i] = int(i*L-i*(i-1)/2+j+1)
    for i in range(L+1):
        print(L,*T[i])

Solution (Python):

from fractions import math
import decimal
from collections import defaultdict

N = int(input())

nlen = decimal.Decimal(1+decimal.Decimal(math.sqrt(1+8*N)))
if nlen%2==0:
    nlen = int(nlen//2)
    print("Yes")
    
    print(nlen)
    E = defaultdict(list)
    e = 1
    for i in range(nlen):
        for j in range(i+1,nlen):
            E[i].append(str(e))
            E[j].append(str(e))
            e+=1
    for i in range(nlen):
        print(len(E[i])," ".join(E[i]))
    
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):
    print(k,end="")
    for s in table[i]:
        if s==0:
            continue
        print('',s,end='')
    print('')

Solution (Python):
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]

    if N==1:
        print "Yes"
        print 2
        print 1, 1
        print 1, 1
        exit()
    x = 3
    idx = 1
    accept_set = set([x])
    is_accept = False
    while x <= N:
        if N == x:
            is_accept = True
            break
        x += (idx + 2)
        accept_set.add(x)
        idx += 1

    
    if is_accept == False:
        print "No"
        exit()


    base = idx + 1
    row_num = base + 1
    col_num = base

    res = [[0 for i in range(col_num)] for j in range(row_num)]
    count = 1
    for i in range(row_num):
        for j in range(i, col_num):
            res[i][j] = count
            count += 1
        for k in range(col_num - i):
            res[i + k + 1][i] = res[i][k + i]

    print "Yes"
    print base + 1
    for i in range(row_num):
        print base,
        for j in range(col_num):
            print res[i][j],
        print
        




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):
from math import sqrt, floor
from itertools import combinations
from collections import defaultdict
N = int(input())

ans_root = sqrt(1 + 8 * N)
if (1 + 8 * N) - floor(ans_root) ** 2 > 1e-6:
    print("No")
    exit(0)

k = floor((1 + ans_root) // 2)
result = defaultdict(list)
for i, (flag1, flag2) in enumerate(combinations(range(k), 2), start=1):
    result[flag1].append(str(i))
    result[flag2].append(str(i))

print("Yes")
print(k)
for value in result.values():
    print(len(value), " ".join(value))

Solution (Python):
from math import sqrt, floor
from itertools import combinations
from collections import defaultdict
N = int(input())

ans_root = sqrt(1 + 8 * N)
if (1 + 8 * N) - floor(ans_root) ** 2 > 1e-6:
    print("No")
    exit(0)

k = floor((1 + ans_root) // 2)
result = defaultdict(list)
for i, (flag1, flag2) in enumerate(combinations(range(k), 2), start=1):
    result[flag1].append(str(i))
    result[flag2].append(str(i))

print("Yes")
print(k)
for value in result.values():
    print(len(value), " ".join(value))

Solution (Python):
N = int(input())
Nlist = [k*(k-1)//2 for k in range(10**3)]
if N not in Nlist:
    print('No')
    exit()
print('Yes')
k = Nlist.index(N)
S = [[0]*i for i in range(k)]
S[0] = [i+1 for i in range(k-1)]
for i in range(k-1):
    S[i+1] = [S[j][i] for j in range(i+1)]
    S[i+1] += [S[i][k-2]+j+1 for j in range(k-1-(i-1))]
print(k)
S = [[str(S[i][j]) for j in range(k-1)] for i in range(k)]
for i in range(k):
    print(' '.join([str(k-1)]+S[i]))

Solution (Python):
from itertools import combinations

n = int(input())
m = 1
while m * (m+1) // 2 <= n:
    m += 1
m -= 1
if m * (m+1) // 2 == n:
    print("Yes")
    k = n*2 // m
    print(k)
    ans = [[] for i in range(k)]
    c = tuple(i for i in range(k))
    for i, comb in enumerate(combinations(c, 2)):
        ans[comb[0]].append(i+1)
        ans[comb[1]].append(i+1)
    for i in ans:
        print(m, *i)

else:
    print("No")

Solution (Python):
import sys, math
sys.setrecursionlimit(10**6)

def b(n):
	i = 1
	while(True):
		if i * (i+1) == n*2:
			return i
		elif i * (i+1) > n*2:
			return 0
		else:
			i += 1

def main():
	n = int(input())
	ref = b(n)
	if ref == 0:
		print("No")
	else:
		print("Yes")
		s = [[] for i in range(ref+1)]
		k = 1
		for i in range(ref):
			for j in range(i+1,ref+1):
				s[i] += [k]
				s[j] += [k]
				k+=1
		print(ref + 1)
		for i in range(ref+1):
			print(str(ref) + " " + " ".join(map(str,s[i])))
	return

main()

Solution (Python):
import sys

n=int(input())

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

def sss(n):
    if n==2:
        return [[1,2],[1,3],[2,3]]
    N=n*(n+1)//2
    ss=[[i for i in range(N-n+1,N+1)]]
    j=N-n+1
    for i in sss(n-1):
        i.append(j)
        ss.append(i)
        j+=1

    return ss
    

ok=0
for i in range(1000):
    if n == (i+2)*(i+3)//2:
        ok=1
        k = i+3
        gen = k-1
        break




if ok==0:
    print("No")

else:
    print("Yes")
    print(k)
    
    for i in sss(gen):
        print(*([len(i)]+i))

Solution (Python):


import math
import sys
import itertools
import numpy as np



n =int(input())

k=0
for i in range(2,1000):
    a = i *(i-1) // 2
    if n == a:
        k = i
        break

if k >= 2:
    print("Yes")
else:
    print("No")

if k >= 1:
    print(k)
    m = [[0]*(k-1) for ii in range(k)]


    t = 1
    for i in range(0,k):
        print(k-1, end=" ")
        for j in range(0,i):
            m[i][j]=m[j][i-1]
            print(m[i][j], end=" ")
        for j in range(i,k-1):
            m[i][j]=t
            t = t + 1
            print(m[i][j], end=" ")
        print("")

Solution (Python):
N=int(input())
K=-1
for i in range(1,N+2):
    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):
N = int(input())

c = N*2
import math
cl, cr = math.ceil(math.sqrt(c)), math.floor(math.sqrt(c))
if cl==cr+1 and cl*cr==c:
  k = cl
  print('Yes')
  ans = [[] for _ in range(k)]
  print(k)
  num = 1
  for i in range(k-1):
    for j in range(i+1, k):
      ans[i].append(num)
      ans[j].append(num)
      num += 1
  for arr in ans:
    print(len(arr), *arr, sep=' ')
else:
  print('No')

Solution (Python):
N = int(input())
n = N*2
k = 1
while k * (k+1) < n:
	k += 1
if k * (k+1) != n:
	print('No')
	exit()
ans = [[0 for i in range(k)] for j in range(k+1)]
n = 1
for i in range(k+1):
	for j in range(i, k):
		ans[i][j] = n
		ans[j+1][i] = n
		n += 1
print('Yes')
print(k+1)
for a in ans:
	print(' '.join([str(k)] + [str(i) for i in a]))

Solution (Python):
n = int(input())
lis = []
cou = 0
num = 1
while n > cou:
  cou += num
  num += 1
  lis.append(cou)
  if cou > n:
    print("No")
    exit()
  if n == cou:
    break
print("Yes")
print(len(lis)+1)
lis.sort(reverse=True)
ans = [[str(len(lis))] for i in range((len(lis)+1))]
nu = 1
num = len(lis)
for i in range(num):
  for k in range(i+1,num+1):
    ans[i].append(str(nu))
    ans[k].append(str(nu))
    nu += 1
for i in range(num+1):print(" ".join(ans[i]))

Solution (Python):
import math

def mk(n):
    if (n == 1):
        return [[1], [1]]
    else:
        y = (n*(n-1)) // 2 + 1
        p = mk(n-1)
        for i in range(0,n):
            p[i].append(y+i)
        p.append([a+y for a in range(n)])
        return p


m = int(input())
x = math.floor(math.sqrt(2*m))
if (not x*(x+1) == 2*m):
    print("No")
else:
    print("Yes")
    print(x+1)
    p = mk(x)
    for i in range(x + 1):
        print(x," ", end="")
        for e in p[i]:
            print(e," ", end="")
        print()

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

for i in range(1, n+1, 1):
    if(n*2 % i == 0):
        j = n*2 // i
        if(i+1 == j): break
    if(i >= j):
        print("No")
        exit()

ans = [i*[0] for k in range(j)]

for k in range(i):
    ans[0][k] = k+1

for l in range(j-2):
    count = 1
    for k in range(i):
        if(l >= k):
            ans[l+1][k] = ans[k][l]
        else:
            ans[l+1][k] = ans[l][-1] + count
            count += 1

for k in range(i):
    ans[-1][k] = ans[k][-1]

print("Yes")
print(j)
for k in range(j):
    print("%d %d" %(i, ans[k][0]), end="")
    for l in range(1, i, 1):
        print(" %d" %(ans[k][l]), end="")
    print()

Solution (Python):
n=int(input())
if n==1:
  print('Yes')
  print('2')
  print('1 1')
  print('1 1')
  exit()
a=1
while ((a+1)*(a+2))//2<=n:
  if n==((a+1)*(a+2))//2:
    print('Yes')
    x=a+2
    print(x)
    break
  a+=1
else:
  print('No')
  exit()
b=[]
for i in range(1,n+1):
  b+=[i]
b=b+b

l=[[] for i in range(x)]
for i in range(x):
  if i==0:
    for j in range(x-1):
      l[i].append(b.pop())
    print(x-1,*l[i])
  else:
    for j in range(i):
      l[i].append(l[j].pop())
    for j in range(x-1-i):
      l[i].append(b.pop())
    print(x-1,*l[i])

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

S = {}
s = 0
n = 1
while s <= N:
    S[s] = n
    s += n
    n += 1

if N not in S.keys():
    print("No")
else:
    print("Yes")
    k = S[N]
    res = [[] for i in range(k)]

    num = k - 1
    now = 1
    for i in range(k - 1):
        num = k - 1 - i
        res[i] += [now + p for p in range(num)]
        for r in range(num):
            res[i + r + 1].append(now + r)

        now += num

    print(k)
    for l in res:
        print("{0} {1}".format(str(k - 1), " ".join(map(str, l))))

Solution (Python):
import itertools
import sys
N, = [int(i) for i in input().split(' ')]

yn = "No"

if N in []:
    pass
else:
    for i in range(pow(10, 4)):
        c = i * (i-1) // 2
        if c > N:
            break
        elif c == N:
            yn = "Yes"
            k = i
            break

if yn == "No":
    print(yn)
else:
    print(yn)
    print(k)
    co = 1
    d = [[] for i in range(k)]
    for x in itertools.combinations(range(k), 2):
        d[x[0]].append(str(co))
        d[x[1]].append(str(co))
        co += 1
    
    for i in range(k):
        print(N*2//k, " ".join(d[i]))

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

isok = False
SUM = 0
e = 0
for i in range(1,100001):
    SUM += i
    if SUM==N:
        isok = True
        e = i
        break
    elif SUM>N:
        break
        
if isok:
    print("Yes")
    print(e+1)
    OUTPUT = [[i for i in range(1,e+1)] for j in range(e+1)]
    DIFF_SUM = e-1
    DIFF = e-1
    for j in range(1,e+1):
        for i in range(e+1-j): OUTPUT[j+i][j-1] = OUTPUT[j-1][i+j-1]
        
        for i in range(j,e): OUTPUT[j][i] += DIFF_SUM
        DIFF -= 1
        DIFF_SUM += DIFF
        
    for o in OUTPUT:
        print(e," ".join([str(i) for i in o]))
    
else:
    print("No")

Solution (Python):
import math

n = int(input())
k = round((1 + math.sqrt(1 + 8 * n)) / 2)

if k * (k - 1) == 2 * n:
    print("Yes")
    ss = [[0 for j in range(k - 1)] for i in range(k)]

    cnt = 1
    for i in range(1, k):
        for j in range(k - i):
            ss[i - 1][i + j - 1] = cnt
            ss[i + j][i - 1] = cnt
            cnt += 1

    print(k)
    for s in ss:
        print(k - 1, " ".join([str(i) for i in s]))
else:
    print("No")

Solution (Python):
N = int(input())
S = {i*(i+1): (i, i+1) for i in range(1, 10**5)}

if N * 2 in S:
    a, b = S[N * 2]
    print('Yes')
    print(b)
    R = [[0]*a for _ in range(b)]
    cnt = 1
    for i in range(a):
        for j in range(i,a):
            R[i][j] = cnt
            cnt += 1
    for i in range(1, a):
        for j in range(i):
            R[i][j] = R[j][i]
    for i in range(a):
        R[-1][i] = R[i][i]
    for x in R:
        print(a, *x)
else:
    print('No')

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import combinations

n = ni()

cnt = 2
nc2 = []

while cnt*(cnt-1)//2 <= 2*10**5:
    nc2.append(cnt*(cnt-1)//2)
    cnt += 1
    
sets = -1
if n in nc2:
    sets = nc2.index(n)+2
    
    
if sets == -1:
    print("No")

else:
    print("Yes")
    print(sets)
    anss = [[] for _ in range(sets)]
    combis = list(combinations(range(sets),2))
    
    for num, (i,j) in enumerate(combis):
        anss[i].append(num + 1)
        anss[j].append(num + 1)
        
    for ans in anss:
        print(len(ans), *ans)

Solution (Python):





"""
Tenka1-2018 C
"""

n = int(input())
m = -1
for i in range(1, 500):
    if i*(i-1)//2 == n:
        m = i
if m is -1:
    print('No')
    exit()

alili = [[] for i in range(m)]
for j in range(1, m):
    tmp = (2*m-j)*(j-1)//2
    for i in range(1, m-j+1):
        i2 = tmp+i
        alili[j-1].append(i2)
        alili[j-1+i].append(i2)


print('Yes')
print(m)
for j in range(m):
    print(m-1, " ".join(map(str, alili[j])))

Solution (Python):

N=int(raw_input())
flag=True
n=0
for i in range(1,10**3+1):
    if i*(i+1)/2==N:
        n=i
        flag=False
        break

if flag:
    print "No"
else:
    print "Yes"
    set_num=n+1
    set_size=n
    print set_num
    num=1
    for i in range(set_num):
        num1=num
        ans = str(set_size)+" "
        for j in range(set_size):
            ans+=str(num1)+" "
            if j+1<i:
                num1+=1
            elif j+1==i:
                num1+=j+2
            else:
                num1+=j+1
        print ans[:-1]
        num+=i

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

    c = 1
    while c * c <= 8 * n + 1:
        if c * c == 8 * n + 1:
            break
        c += 1
    else:
        print("No")
        exit()

    k, cnt = (c+1) // 2, 1
    ans = [set() for i in range(k)]
    for i in range(k):
        for j in range(i+1, k):
            ans[i].add(cnt)
            ans[j].add(cnt)
            cnt += 1

    print("Yes")
    print(k)
    for i in range(k):
        print(len(ans[i]), end=" ")
        for j in ans[i]:
            print(j, end=" ")
        print()


if __name__ == '__main__':
    main()

Solution (Python):
import sys

N = int(input())

for i in range(1, N + 1):
    if i * (i + 1) // 2 == N:
        K = i
        break
else:
    print('No')
    sys.exit(0)

anss = [[] for _ in range(K + 1)]
x = 1
iAns = 0
for i in reversed(range(1, K + 1)):
    anss[iAns].append(x)
    anss[-1].append(x)
    for j in range(1, i):
        anss[iAns].append(x + j)
        anss[iAns + j].append(x + j)
    x += i
    iAns += 1

print('Yes')
print(K + 1)
for ans in anss:
    print(len(ans), ' '.join(map(str, ans)))

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

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

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

print('Yes')
print(k)

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

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