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 解():
    iN = int(input())

    

    iK = int((2 * iN) ** 0.5)
    if 2 * iN != iK * (iK +1 ) :
        print("No")
    else:
        print("Yes")
        print(iK+1)
        oAns = []
        iStart = 1
        for i in range(iK):
            oRes = [iK]
            oRes.extend(list(range(iStart,iStart+i+1)))
            iLast = oRes[-1]
            for k in range(i+1,iK):
                iLast += k
                oRes.append(iLast)
            oAns.append(" ".join([str(_) for _ in oRes]))
            iStart += i +1
        oRes = [iK]
        iStart = 0
        for i in range(0,iK):
            iStart += i +1
            oRes.append(iStart)
        oAns.append(" ".join([str(_) for _ in oRes]))
        print("\n".join(oAns))
解()

Solution (Python):
N, = map(int, raw_input().split())
r = "No"
for l in range(1,1000):
  if 2*N==l*(l+1):
    r = "Yes"
    break
print r
if r=="Yes":
  k = l+1
  S = []
  for i in range(k):
    S.append([])
  x = 1
  for i in range(k-1):
    for j in range(l-i):
      S[i].append(x)
      S[i+1+j].append(x)
      x += 1
  print k
  for i in range(k):
    print " ".join([str(l)] + map(str, S[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([])
offset = 0
finishrow = 0
while(finishrow != numofrow):
    for i in range(cnt-finishrow):
        ans[finishrow].append(i+1+offset)
    finishrow += 1    
    for i in range (numofrow-finishrow):
        ans[i+finishrow].append(i+1+offset)
    
    offset += numofrow-finishrow

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

Solution (Python):
N = int(input())
K = (((8 * N + 1) ** (1/2) + 1) / 2)

def recursive(k):
    if k == 2:
        return [[1], [1]]
    else:
        before = recursive(k - 1)
        r = [_ for _ in range(1 + (k - 2) * (k - 1) // 2, 1 + k * (k - 1) // 2)]
        return ([before[_] + [r[_]] for _  in range(len(r))] + [r])

if K.is_integer():
    K = int(K)
    print('Yes')
    print(K)
    [print(K - 1, ' '.join(map(str, ary))) for ary in recursive(K)]
else:
    print('No')

Solution (Python):
import numpy as np
N = int(input().strip('\n'))
k2 = 1+np.sqrt(1+8*N)
if k2%2==0:
    k=int(k2/2)
    print('Yes')
    print(k)
    yel = [1]
    red = [1]
    for i in range(1,k-1):
        yel.append(yel[i-1]+1+i)
        red.append(red[i-1]+i)
    yel = np.array(yel).astype('int32')
    red = np.array(red).astype('int32')
    print(k-1,*yel)
    print(k-1,*red)
    for i in range(1,k-1):
        fs = np.arange(red[i],red[i]+i).astype('int32')
        sc = red[i:]+i
        fs = np.concatenate((fs,sc))
        print(k-1,*fs)
else:
    print('No')

Solution (Python):
n=int(input())
k=2
while n>=k*(k-1)/2:
    if n==k*(k-1)/2:
        print('Yes')
        print(k)
        a=list([] for i in range(k))
        t=1
        for i in range(0,k):
            for j in range(1,k-i):
                a[i].append(t)
                a[i+j].append(t)
                t+=1
        for i in range(k):
            print(str(k-1)+" "+" ".join(map(str,a[i])))
        exit()
    else:
        k+=1
print('No')

Solution (Python):
import math
N=int(input())*2
q=int(math.sqrt(N))
if-~q*q!=N:print("No");exit()
S=[list(range(1,q+1))]
S+=[[j]for j in S[0]]
l=q
for i in range(1,q):
	r=list(range(l+1,l+1+q-i))
	S[i]+=r
	for j in range(q-i):S[i+j+1]+=[r[j]]
	l=r[-1]
print("Yes")
print(len(S))
for s in S:print(len(s)," ".join(map(str,s)))

Solution (Python):
import math
N=int(input())
q=int(math.sqrt(N*2))
if N*2!=q*q+q:print("No");exit()
S=[list(range(1,q+1))]
S+=[[j]for j in S[0]]
last=q
for i in range(1,q):
	r=list(range(last+1,last+1+q-i))
	S[i]+=r
	for j in range(q-i):S[i+j+1]+=[r[j]]
	last=r[-1]
print("Yes")
print(len(S))
for s in S:print(len(s)," ".join(map(str,s)))

Solution (Python):
import math
N=int(input())
q=int(math.sqrt(N*2))
if N*2!=q*q+q:print("No");exit()
S=[list(range(1,q+1))]
for j in range(1,q+1):S.append([j])
last=q
for i in range(1,q):
	r=list(range(last+1,last+1+q-i))
	S[i]+=r
	for j in range(q-i):S[i+j+1]+=[r[j]]
	last=r[-1]
print("Yes")
print(len(S))
for s in S:print(len(s)," ".join(map(str,s)))

Solution (Python):
def 解():
    iN = int(input())

    

    iK = int((2 * iN) ** 0.5)
    if 2 * iN != iK * (iK +1 ) :
        print("No")
    else:
        print("Yes")
        print(iK+1)
        aD = [ [0] * iK for _ in range(iK)]
        iMaxCol = 0
        iRow = 0
        iCol = 0
        for i in range(1,iN+1):
            aD[iRow][iCol] = i
            if iCol == iMaxCol:
                iMaxCol += 1
                iRow += 1
                iCol = 0
            else:
                iCol += 1

        oAns = []
        iRC = 0
        iStartCol = 0
        iStartRow = 0
        for i in range(iK):
            aTmp = []
            aTmp.append(iK)
            for j in range(iK):
                if iRC == 0:
                    aTmp.append(aD[iStartRow][j])
                else:
                    aTmp.append(aD[j][iStartCol])
                if j == iStartCol:
                    iRC = 1
            oAns.append(" ".join([str(_) for _ in aTmp]))
            iStartCol += 1
            iStartRow += 1
            iRC = 0
        aTmp = []
        aTmp.append(iK)
        for i in range(iK):
            aTmp.append(aD[i][i])

        oAns.append(" ".join([str(_) for _ in aTmp]))
        print("\n".join(oAns))
解()

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

def f(limit):
    i = 1
    j = 2
    while True:
        if i > limit:
            break
        yield i
        i += j
        j += 1

def h1(l, n):
    s = 0
    for i in range(n):
        yield l[s:s+i+1]
        s += i+1

def h2(p, l):
    if not l:
        return
    for pp, ll in zip(p, l):
        ll.append(pp)
    h2(l[0], l[1:])

l = list(f(10**5))

if N in l:
    print("Yes")

    n = l.index(N)+1
    print(N*2//n)

    t = list(h1(list(range(1, N+1)), n))
    t.reverse()
    t.append([])

    h2(t[0], t[1:])

    for i in t:
        print(len(i), " ".join(str(j) for j in i))
else:
    print("No")

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

k = 1

while 2*N >= k*(k-1):
    if 2*N == k*(k-1):
        print('Yes')
        print(k)

        S = [[0 for i in range(k-1)] for j in range(k)]

        for lis in range(k-1):
            S[0][lis] = lis + 1

        num_max = k - 1
        for history in range(1, k):
            num_max += k - 1 - history
            for bef_list in range(history):
                S[history][bef_list] = S[bef_list][history - 1]
            for new_list in range(k - history - 1):
                S[history][new_list + history] = num_max - new_list
            S[history].sort()

        for i in range(k):
            print(k-1, end=' ')
            for j in range(k-1):
                print(S[i][j], end=' ')
            print('')

        exit()

    k += 1

print('No')

Solution (Python):
N = int(input())
alist=[]
if N ==1:
    print("Yes")
    print("2")
    print("1 1")
    print("1 1")
    exit()
if N==2:
    print("No")
    
    
    
    exit()

for i in range(2000):
    if i*(i+1)/2 > 100000:
        break
    else:
        alist.append(int(i*(i+1)/2) )



if N in alist:
    print("Yes")
else:
    print("No")
    exit()

tate=alist.index(N)+1
yoko=alist.index(N)

s=[]
tmp=[]
cnt=1
for j in range(tate):
    stmp=[]
    ntmp=[]
    for l in range(len(tmp)):
        
        stmp.append(tmp[l].pop(0))
        
    for m in range(yoko-len(stmp)):
        stmp.append(cnt)
        ntmp.append(cnt)
        
        cnt=cnt+1
    
    s.append(stmp)
    
    tmp.append(ntmp)
    tmp2=[x for x in tmp if x ]
    tmp=tmp2

print(len(s))

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

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

yn=1
a=2
while True:
    if n==yn:
        print('Yes')
        break
    elif yn>n:
        print('No')
        exit()
    else:
        yn+=a
        a+=1

a-=1
k=n*2//a
s=[[a] for i in range(k)]

l = [0]*n

for i in range(a):
    s[0].append(i+1)
    l[i]+=1

for i in range(1,k):
    for j in range(i):
        s[i].append(s[j][i])
    while len(s[i]) - 1 != s[i][0]:
        for m in range(s[i-1][-1]-1,n):
            if l[m] == 0:
                s[i].append(m + 1)
                l[m] += 1
                if len(s[i]) - 1 == s[i][0]:
                        break
        if len(s[i]) - 1 != s[i][0]:
            for m in range(s[i-1][-1]-1,n):
                if l[m] == 1:
                    s[i].append(m + 1)
                    l[m] += 1
                    if len(s[i]) - 1 == s[i][0]:
                        break
        break

print(k)

for i in range(len(s)):
    for j in range(len(s[i])):
        if j==len(s[i])-1:
            print(s[i][j])
        else:
            print(s[i][j], end=' ')

Solution (Python):
def run(N):
    ret = []
    if N == 1:
        ret.append('Yes')
        ret.append(2)
        ret.append([[1, 1], [1, 1]])
    elif N < 3:
        ret.append('No')
    else:
        for i in range(3, N+1):
            if N * 2 < i * (i-1):
                ret.append('No')
                break
            elif N * 2 == i * (i-1):
                ret.append('Yes')
                ret.append(i)
                S = []
                for j in range(1, i+1):
                    '''
                    j列の1行目は、1列目のj行目
                    j列の2行目は、2列目のj行目
                    j列のk行目は、k列目のj行目
                    j列のj行目以降は、j-1列目の最後の行の数+1から1ずつ増加
                    '''
                    tmp = [i-1]
                    for k in range(1, i):
                        if k < j:
                            tmp.append(S[k-1][j-1])
                        else:
                            if j < 2:
                                tmp.append(k-j+1)
                            else:
                                tmp.append(S[j-2][i-1]+k-j+1)
                    S.append(tmp)
                ret.append(S)
    return ret


def main():
    N = int(input())
    ret = run(N)
    print(ret[0])
    if len(ret) > 1:
        k = ret[1]
        print(k)
        for s in ret[2]:
            s = [str(si) for si in s]
            print(' '.join(s))


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations as comb


def comb2(a):
    return a * (a - 1) // 2


n = int(input())

numS = 2
while True:
    if n < comb2(numS):
        print("No")
        exit()
    elif n == comb2(numS):
        break
    numS += 1

lenS = n * 2 // numS

print("Yes")
print(numS)
ans = {}
for i, room in enumerate(comb(range(numS), 2)):
    
    for a in room:
        if a not in ans:
            ans[a] = [str(i + 1)]
        else:
            ans[a].append(str(i + 1))


for ansS in ans.values():
    print(str(lenS) + " " + " ".join(ansS))

Solution (Python):
from math import sqrt
N=int(input())
q=int(sqrt(N*2))
if N*2!=q*q+q:print("No")
else:
    S=[list(range(1,q+1))]
    for j in range(1,q+1):S.append([j])
    last = q
    for i in range(1,q):
        r = list(range(last+1,last+1+q-i))
        S[i] += r
        for j in range(q-i):
            S[i+j+1] += [r[j]]
        last = r[-1]
    print("Yes")
    print(len(S))
    for s in S: print(len(s), " ".join(str(i)for i in s))

Solution (Python):

N = int(input())

ans_len = 0
ans_num = 0
zero = []
for i in range(1,N+1):
    temp = i * (i+1) // 2
    zero.append(temp)
    if temp == N:
        ans_len = i+1
        ans_num = i
        break

ans_list = [[] for _ in range(ans_len)]

if N in zero:
    print('Yes')
else:
    print('No')
    exit()


low_idx = 0
up_idx = 1
for i in range(1,N+1):
    ans_list[low_idx].append(i)
    ans_list[up_idx].append(i)
    if i in zero:
        low_idx = 0
        up_idx += 1
    else:
        low_idx += 1


print(len(ans_list))
for a in ans_list:
    print(len(a)," ".join([str(x) for x in a]))


"""
1 2 3 4 5  6  7
2 4 6 8 10 12 14 16 18 20
2   3      4           5
1   2      3           4
0 1 0 1 2  0  1  2  3  0

12
13
23

1347
1258
2369
456 10
789 10

124
135
236
456

"""

Solution (Python):
def search(n):
    for i in range(1, 3*n):
        if i*(i-1) == 2*n:
            return i
    return 0


n = int(input())

nodes = search(n)
if nodes != 0:
    print("Yes")
    print(nodes)
    out = [[] for i in range(nodes)]
    index = [int(i) for i in range(nodes)]
    counter = 1
    for i in range(len(index)):
        for j in range(index[i]):
            out[j].append(counter)
            out[i].append(counter)
            counter += 1
    for i in range(len(out)):
        str1 = str(out[i])
        table = str1.maketrans({
            ',': '',
            '[': '',
            ']': '',
        })
        str1 = str1.translate(table)
        print(("{} {}".format(len(out[i]), str1)))
else:
    print("No")

Solution (Python):

import numpy as np
n = int(input())


a = np.ones((2,1)).astype(np.int)
a[-1][-1]+len(a)
i = 1
while(1):
    if len(a)>=500:
        break
    if n==a[-1][-1]:
        print ("Yes")
        print (len(a))
        for line in a:
            print (i," ".join(line.astype(np.str).tolist()))
        exit()
    i+=1
    temp = int((1/2)*i*(i+1))
    add = np.array((list(range(temp-i+1,temp+1))))

    a = np.c_[a,add]
    a = np.r_[a,add.reshape(1,-1)]
print ("No")

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

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

print(ans)
if ans == 'Yes':
    print(k)
    psum = (k-1)*k//2
    tops = []
    for i in range(k):
        ntop = psum - (k-1-i)*(k-i)//2 + 1
        tops.append(ntop)
    for i in range(k):
        print(k-1, end=" ")
        
        for j in range(i):
            print(tops[j]+(i-j-1), end=" ")
        
        for j in range(k-1-i):
            print(tops[i]+j, end=" ")
        print('')

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

m = 0
i = 1
while True:
    m += i
    if m == n:
        print('Yes')
        print(i+1)
        break
    elif m > n:
        print('No')
        exit()
    i += 1

ans = [[1], [1]]
max_ = 0
if i == 1:
    print('1 1')
    print('1 1')
else:
    max_a = 1
    for i_ in range(1, i):
        adds = list(range(max_a+1, max_a+1+len(ans)))
        for j, add in enumerate(adds):
            ans[j].append(add)
        ans.append(adds)
        max_a = adds[-1]
    for a in ans:
        print(str(len(a))+' '+' '.join(map(str, a)))

Solution (Python):
import numpy
N = int(input())
i = int(numpy.sqrt(2*N))

if i * (i+1) == 2 * N:
    print('Yes')
    print(i+1)
    S = [[] for k in range(i+1)]
    k = 1
    for now in range(0, i+1):
        for now2 in range(now+1, i+1):
            S[now].append(k)
            S[now2].append(k)
            k += 1
    for j in range(i+1):
        print(i, end = ' ')
        values = map(str, S[j])
        print(' '.join(values))
else:
    print('No')

Solution (Python):
a = int(input())
if a == 1:
	print("Yes")
	print(2)
	print(1, 1)
	print(1,1)
elif a == 3:
	print("Yes")
	print(3)
	print(2,1,2)
	print(2,3,1)
	print(2,2,3)
elif (int((2*a) ** 0.5)**2  + int((2*a) ** 0.5))  == 2*a:
	print ("Yes")
	t = int((2*a) ** 0.5)
	print(t + 1)
	print(str(t) +' ' +  ' '.join([str(i) for i in list(range(1, t + 1))]))
	now = t + 1
	for i in range(1, t + 1):
		left = ' '.join([str(i + (2*t - j - 1)*j //2) for j in list(range(i))])
		right = ' '.join([str(j) for j in list(range(now, now + t - i))])
		now = now + t - i
		print(str(t) +' ' + left + ' ' + right)
else:
	print("No")

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

s = 0
i = 1

while s <= n:
    s += i
    if s == n:
        break
    i += 1
    
else:
    print('No')
    exit()

print('Yes')
print(i+1)
A = [[] for i in range(i+1)]
N = [i for i in range(n+1)]

m = i
j = 1

for a in range(i+1):
    A[a] += N[j:j+m]
    for k in range(a+1, i+1):
        A[k] += [j]
        j += 1
    print(i, *A[a])
    m -= 1

Solution (Python):

import math, sys

N = int(input())



k = 1
while True:
    if k * (k + 1) // 2 == N:
        break
    elif k * (k + 1) // 2 > N:
        print("No")
        sys.exit()
    else:
        k += 1

print("Yes")
mat = [[None] * (k + 1) for i in range(k + 1)]
idx = 1
for i in range(k + 1):
    for j in range(k + 1):
        
        if i == j: continue
        
        if mat[i][j] == None:
            mat[i][j] = idx
            mat[j][i] = idx
            idx += 1

print(k + 1)
for i in range(k + 1):
    print(k, end="")
    for val in mat[i]:
        if val != None:
            print(" ", end="")
            print(val, end="")
    print("")

Solution (Python):

N = int(input())

now = 0
all_now = []

for i in range(N):
    now = now+(i+1)
    all_now.append(now)
    if N==now:
        f=1
        break
    elif N<now:
        f=-1
        break
    
all_now = all_now[2:i+1]
now_num = 0
re_num = 3

if f<0:
    print('No')
else:
    print('Yes')
    print(i+2)
    
    ans = [[]]*(i+2)
    
    if N ==1:
        ans[0] = 1
        ans[1] = 1
        print('1 1')
        print('1 1')
    else:
        ans[0] = [1, 2]
        ans[1] = [1, 3]
        ans[2] = [2, 3]
        
        k = 0
        
        for j in range(4, N+1):
            if j>all_now[now_num]:
                k = 0
                re_num = re_num+1
                now_num = now_num+1
                
            ans[k] = ans[k] + [j]
            ans[re_num] = ans[re_num] + [j]
            k = k+1
        
        for j in range(i+2):
            ans2 = [str(len(ans[j]))]
            for k1 in range(len(ans[j])):
                ans2 = ans2 + [str(ans[j][k1])]
            print(' '.join(ans2))

Solution (Python):
from itertools import combinations

n = int(input())
yes = [i*(i-1)//2 for i in range(2, 448)]
if n in yes:
    print('Yes')
    len_s = yes.index(n) + 1
    print(len_s+1)
    res = [[] for _ in range(len_s+1)]
    for i, v in enumerate(combinations(range(len_s+1), 2)):
        res[v[0]].append(str(i+1))
        res[v[1]].append(str(i+1))
    for r in res:
        print(' '.join([str(len_s)] + r))        
else:
    print('No')

Solution (Python):
import numpy as np
N = int(input())
k = 1
while k*k < 2*N:
    k += 1
if k*(k - 1) != 2*N:
    print('No')
else:
    print('Yes')
    print(k)
    S = np.zeros([k, k-1], dtype=int)
    max = int(0)
    for i in range(k-1):
        S[i, i:] = list(range(max+1, max+k-i))
        S[i+1:, i] = S[i, i:]
        max += k-i-1
    for i in range(k):
        print(' '.join(map(str, np.insert(S[i], 0, k-1))))

Solution (Python):
N=int(input())
k=2
while N>=(k-1)*k/2:
    if N==(k-1)*k/2:
        print("Yes")
        print(k)
        a=list([] for i in range(k))
        t=1
        for i in range(0,k):
            for n in range(1,k-i):
                a[i].append(t)
                a[i+n].append(t)
                t+=1
        for i in range(k):
            print(str(k-1)+" "+" ".join(map(str,a[i])))
        exit()
    else:
        k+=1
print("No")

Solution (Python):
def main():

	n = int(input())

	num = 0
	sum = 0
	while sum <= n:
		if sum == n:
			print("Yes")
			break
		else:
			num += 1
			sum += num
	else:
		print("No")
		return
	
	Ss = []
	for i in range(num+1):
		Ss.append([])
	
	insert = 0
	for i in range(1,num+1)[::-1]:
		key = num - i
		for j in range(1,i+1):
			insert += 1
			Ss[key].append(insert)
			Ss[key+j].append(insert)
	
	print(len(Ss))
	for i in range(len(Ss)):
		ans = ""
		ans += str(len(Ss[i])) + " "
		ans += ' '.join(map(str, Ss[i]))
		print(ans)




if __name__ == '__main__':
	main()

Solution (Python):
import math
N=int(input())
kf = (math.sqrt(8*N+1)+1)/2
k = int(kf)
if k!=kf:
    print("No")
else:
    print("Yes")
    print(k)
    for i in range(1,k+1):
        print(k-1, end=' ')
        elements = []
        for j in range((i-1)*(i-2)//2+1,i*(i-1)//2+1):
            elements.append(j)
        for q in range(i+1,k+1):
            elements.append(i + (q-1)*(q-2)//2)
        last = elements.pop()
        for e in elements:
            print(e, end=' ')
        print(last)

Solution (Python):
import sys
from math import sqrt, ceil

N = int(input())
k = ceil(sqrt(2 * N))
if k * (k - 1) != 2 * N:
    print("No")
    sys.exit()

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

print("Yes")
print(k)
for i in range(1, k + 1):
    print(len(S[i]), " ".join(map(str, S[i])))

Solution (Python):
import math
n = int(input())
s = (-1+math.sqrt(1+8*n))/2
if (int(s)!=s):
    print("No")
else:
    print("Yes")
    s = int(s)
    print(s+1)
    A = []
    w = 1
    for i in range(s+1):
        print(s, end=" ")
        for j in range(len(A)):
            print (A[j][i-j-1], end=" ")
        A.append([])
        for j in range(s-len(A)+1):
            print(w, end=" ")
            A[i].append(w)
            w+=1
        print()

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

d = {}
k = 1
while k*(k-1)/2 < 10**5:
    d[int(k*(k-1)/2)] = k
    k += 1

if N not in d.keys():
    print("No")

else:
    print("Yes")
    k = d[N]
    output = [[] for _ in range(k)]
    print(k)

    comb_list = list(itertools.combinations(list(range(k)), 2))
    for n, comb in zip(range(1, N+1), comb_list):
        output[comb[0]].append(n)
        output[comb[1]].append(n)

    length = len(output[0])
    for l in output:
        print(length, *l)

Solution (Python):
from math import sqrt

x = int(input())
n = (sqrt(8*x+1) - 1) / 2
if int(n) == n:
  n = int(n)
  a = [[1], [1]]
  for i in range(2, n+1):
    ti = i*(i+1)//2
    b = list(range(ti+1-i,ti+1))
    for j, v in enumerate(b):
      a[j].append(v)
    a.append(b)
  print("Yes")
  print(len(a))
  for b in a:
    print(len(b), *b)
else:
  print("No")

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

flag=0
for i in range(int(N^(1//2))+1):
    if N*2==i*(i+1):
        flag=1
        d=i
        break
if flag==0:
    print('No')
    exit(0)

ls=[[0 for _ in range(d)] for _ in range(d+1)]
for i in range(d):
    ls[0][i]=i+1

for j in range(1,d+1):
    for i in range(j):
        ls[j][i]=ls[j-i-1][j-1]
    for i in range(d-j):
        ls[j][i+j]=i+max(ls[j-1])+1
print('Yes')
print(d+1)
for i in range(len(ls)):
    print(d, end=' ')
    for j in ls[i]:
        print(j, end=' ')
    print()

Solution (Python):
N=int(input())
num=0
ans='No'
for i in range(1,10**3):
    if i*(i+1)>2*N:
        break
    elif i*(i+1)==2*N:
        num=i
        ans='Yes'
        break
print(ans)
if ans=='Yes':
    print(num+1)
    arr=[[num] for i in range(num+1)]
    n=1
    for i in range(num+1):
        j=1
        while len(arr[i]) != num+1:
            arr[i].append(n)
            arr[i+j].append(n)
            j+=1
            n+=1
    
    for a in arr:
        print(a[0],end='')
        for x in a[1:]:
            print(' {}'.format(x),end='')
        print('')

Solution (Python):
import sys
N = int(input())
s = 0
i = 1
x = 0
while s<=N:
  s += i
  if s==N:
    x = i
  i += 1
if x == 0:
  print('No')
  sys.exit()
print('Yes')
print(x+1)
anslis = []
i,j = 0,1
while len(anslis)<=x:
  anslis.append([x])
n = 1
while n <= N:
  anslis[i].append(n)
  anslis[j].append(n)
  if j < x:
    j += 1
  else:
    i += 1
    j = i+1
  n += 1
i = 0
for arrays in anslis:
  print(" ".join(map(str, arrays)))

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

k = int((n * 2) ** 0.5) + 1
if k * (k - 1) != 2 * n:
    print('No')
else:
    print('Yes')
    print(k)
    arr = [list() for _ in range(k)]

    num = 1
    tar1, tar2 = 0, 1
    while True:
        arr[tar1].append(num)
        arr[tar2].append(num)
        if num == n:
            break
        else:
            num += 1
        if len(arr[tar1]) == k - 1:
            tar1 += 1
            tar2 = tar1 + 1
        else:
            tar2 += 1
    for i in range(k):
        print(k - 1, *arr[i])

Solution (Python):
def solve(n):
    k= -1
    for i in range(1000):
        if i * (i-1) == 2 * n:
            k =i
            print("Yes")
            break
        elif i*(i-1)  > 2*n:
            print("No")
            return
    ans = [[-1 for i in range(k-1)] for i in range(k)]
    c = 1
    print(k)
    for i in range(k):
        for j in range(k-i-1):
            ans[i][i+j] = c
            ans[i+j+1][i] = c
            c += 1

    for i in range(k):
        print(k-1 ,end = "")
        for j in ans[i]:
            print(" " + str(j),end = "")
        print()

solve(int(input()))

Solution (Python):
import sys

N=int(input())

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


U=N 
L=0 
flag=False

while U-L>1:
    x=(U+L)//2
    if N==x*(x+1)//2:
        print("Yes")
        flag=True
        break
    elif N<x*(x+1)//2:
        U=x
    else:
        L=x
        
if not flag: print("No")
else:
    print(x+1)
    
    data=[[0]*x for _ in range(x+1)]
    for i in range(x):
        data[0][i]=i+1
    head=x+1
    for i in range(1,x+1):
        for j in range(i):
            data[i][j]=data[j][i-1]
        for j in range(i,x):
            data[i][j]=head
            head+=1
            
    for i in range(x+1):
        print(x,end=' ')
        for d in data[i][:-1]:
            print(d,end=' ')
        print(data[i][-1])

Solution (Python):
n = int(input())
f = 0
for k in range(1,1000):
    if k*(k-1)//2 == n:
        f = 1
        break
if f == 0:
    print("No")
    exit()
else:
    print("Yes")
    print(k)
l = [[]]*k
a = 1
for i in range(1,k):
    for j in range(0,i):
        l[j] = l[j]+[str(a)]
        l[i] = l[i]+[str(a)]
        a += 1
for i in range(k):
 print(k-1, " ".join(l[i]))

Solution (Python):
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


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

n = getN()

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

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

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

if varn != 0:
    print("Yes")
    print(varn)
    for i in range(varn):
        print(varn-1, " ".join(map(str, vars[i])))

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()

k = -1

for i in range(10000):
    if i * (i - 1) / 2 == N:
        k = i
        break

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

print "Yes"
print k

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

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

for i in range(k):
    print k - 1, ' '.join(map(str, E[i]))