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):
'''
https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    N = int(input())
    for i in range(10**3):
        if i*(i-1) == N*2:
            res = i
            break
    else:
        print('No')
        exit()

    s = [[] for _ in range(res)]
    num = 1

    for a,b in combinations(range(res), 2):
        s[a].append(num)
        s[b].append(num)
        num += 1

    print('Yes')
    print(res)
    for i in s:
        print('{} {}'.format(res-1, ' '.join(map(str, i))))

if __name__ == '__main__':
    main()

Solution (Python):
'''
https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    N = int(input())
    for i in range(10**3):
        if i*(i-1) == N*2:
            res = i
            break
    else:
        print('No')
        exit()

    s = [[] for _ in range(res)]
    num = 1

    for a,b in combinations(range(res), 2):
        s[a].append(num)
        s[b].append(num)
        num += 1

    print('Yes')
    print(res)
    for i in s:
        print('{} {}'.format(res-1, ' '.join(map(str, i))))

if __name__ == '__main__':
    main()

Solution (Python):
import math
n = int(input())
x = (-1+math.sqrt(1+8*n))/2
if not x.is_integer():
  print ('No')
  exit (0)
x = int(x)
ans = []
k = 1
for i in range(x+1):
  a = []
  for j in range(x):
    if j >= i:
      a.append(k)
      k +=1
    else:
      a.append(ans[j][i-1])
  ans.append(a)
print ('Yes')
print (x+1)
for i in range(x+1):
  print (x,*ans[i])

Solution (Python):
def issquare(n):
    f = (0,0,1,1,0,1,1,1,1,0,1,1,1,1,1,1)
    if f[n & 0xf]:
         return False
    l, r = 1, n
    while l <= r:
        m  = l + (r - l) // 2
        m2 = m * m
        if m2 < n:
            l = m + 1
        elif m2 > n:
            r = m - 1
        else:
            return True
    return False        

def istriangular(n):
    return issquare(1+8*n)

N = int(input())

if istriangular(N):
    print('Yes')
    n = int((1+8*N)**0.5-1) // 2
    k = n + 1
    print(k)
    base = 1
    for i in range(n):
        s = [n]
        base += i
        add = 0
        for j in range(n):
            s.append(base + add)
            if j < i:
                add += 1
            else:
                add += j + 1
        print(*s)
    s = [n, 1]
    for i in range(2, n+1):
        s.append(s[-1]+i)
    print(*s)
else:
    print('No')

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
n=int(input())
D=defaultdict(int)
i=1
while i*(i+1)//2<=10**5:
  D[i*(i+1)//2]=i
  i+=1
if D[n]==0:
  print("No")
else:
  print("Yes")
  k=D[n]+1
  print(k)
  A=[[0]*(k) for _ in range(k)]
  for i in range(k):
    A[i][0]=k-1
  D=dict()
  D[1]=1*k+1
  for i in range(2,n+1):
    d1,d2=D[i-1]//k,D[i-1]%k
    if d2==k-d1:
      D[i]=(d1+1)*k+1
    else:
      D[i]=d1*k+d2+1
  for i in range(1,n+1):
    d1,d2=D[i]//k,D[i]%k
    A[d1-1][d1+d2-1]=i
    A[d1+d2-1][d1]=i
  for a in A:
    print(*a)

Solution (Python):

import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N =INT()
    size = 0
    for i in range(1,10**3):
        if i*(i+1)//2 == N:
            size = i 
            break
    else:
        print("No")
        return
    
    k = size + 1
    answer = [[] for _ in range(k)]

    start = 1
    for i in range(k):
        answer[i] = list(range(start,start+size-i))
        start += size-i
    
    for i in range(k-1):
        for j in range(i+1,k):
            answer[j].append(answer[i][j-i-1])
    
    print("Yes")
    print(k)
    for i in range(k):
        print(size,*answer[i])
    return

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
N = int(input())
if N==1:
    print("Yes")
    print(2)
    print(1,1)
    print(1,1)
elif N==2:
    print("No")
elif N==3:
    print("Yes")
    print(3)
    print(2,1,2)
    print(2,1,3)
    print(2,2,3)
else:
    flg = 0
    for i in range(4,int((3*N)**0.5)+2):
        if N==(i*(i-1))//2:
            flg=1
            K = i
            break
    if flg==0:
        print("No")
    else:
        S = {i:[] for i in range(K)}
        for j,x in enumerate(combinations(range(K),2)):
            j += 1
            i0,i1 = x[0],x[1]
            S[i0].append(j)
            S[i1].append(j)
        print("Yes")
        print(K)
        for i in range(K):
            print(len(S[i]),*S[i])

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

for k in range(1,n + 2):
    if k * (k - 1)  == 2 * n:
        print("Yes")
        break
    if k * (k - 1) > 2 * n:
        print("No")
        exit()

print(k)
answer = [[] for _ in range(k)]

num = [[i,j] for i in range(k) for j in range(i+1,k)]

for i,st in enumerate(num):
    s,t = st
    answer[s].append(i + 1)
    answer[t].append(i + 1)

for ans in answer:
    print(k-1,*ans)

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

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

P = [0]
p = 1
for i in range(10**3):
    P.append(P[-1] + p)
    p += 1

i = 1
while P[i] < n:
    i += 1
if P[i] > n:
    print("No")
else:
    print("Yes")
    m = i+1
    S = [[] for i in range(m)]
    for i in range(m):
        s = 1 if i==0 else 1+P[i-1]
        for j in range(m-1):
            S[i].append(s)
            if j < i-1:
                s += 1
            elif j == i-1:
                s += i+1
            else:
                s += j+1
    print(m)
    for i in range(m):
        print(m-1, " ".join([str(j) for j in S[i]]))

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

Solution (Python):
from itertools import combinations
n = int(input())
i = 1
plus = 1
flg = False
while i <= n:
    if i == n:
        flg = True
        break
    plus += 1
    i += plus
if flg:
    print("Yes")
    res = {i : [] for i in range(plus+1)}
    for i, combi in enumerate(combinations(range(plus + 1), 2), 1):
        res[combi[0]].append(str(i))
        res[combi[1]].append(str(i))
    print(plus + 1)
    for i, val in res.items():
        print(str(plus) + " " + " ".join(val))
else:
    print("No")

Solution (Python):
from itertools import combinations
n = int(input())
k = 0
for i in range(2*n+1):
  if i * (i - 1) == 2 * n:
    k = i
    break
if k:
  ans = [[k-1] for _ in range(k)]
  i = 1
  for a, b in combinations(range(k), 2):
    ans[a].append(i)
    ans[b].append(i)
    i += 1
  print('Yes')
  print(k)
  for ansi in ans:
    print(' '.join(list(map(str, ansi))))
else:
  print('No')

Solution (Python):
from math import floor
import numpy as np

N = int(input())
K = floor((N * 2) ** 0.5)
if K * (K + 1) // 2 != N:
    print('No')
    exit()
else:
    print('Yes')
    print(K + 1)

grid = np.ones((K, K), np.int64)
grid[1:, 0] = np.arange(1, K)
grid[:, 0] = np.cumsum(grid[:, 0])
grid = np.cumsum(grid, axis=1).astype(str)
answer = []
k = str(K)
answer.append([k] + np.diag(grid).tolist())
answer.append([k] + grid[:, 0].tolist())
for i in range(1, K):
    answer.append([k] + grid[i, :i].tolist() + grid[i:, i].tolist())

print('\n'.join(map(' '.join, answer)))

Solution (Python):
from math import floor
import numpy as np

N = int(input())
K = floor((N * 2) ** 0.5)
if K * (K + 1) // 2 != N:
    print('No')
    exit()
else:
    print('Yes')
    print(K + 1)

grid = np.ones((K, K), np.int64)
grid[1:, 0] = np.arange(1, K)
grid[:, 0] = np.cumsum(grid[:, 0])
grid = np.cumsum(grid, axis=1)
answer = []
answer.append([K] + np.diag(grid).tolist())
answer.append([K] + grid[:, 0].tolist())
for i in range(1, K):
    answer.append([K] + grid[i, :i].tolist() + grid[i:, i].tolist())

for i in answer:
    print(' '.join(map(str, i)))

Solution (Python):
N=int(input())
stock=[N-i for i in range(N)]

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

N*=2
n=-int(-N**0.5//1)
if N/n==N//n and (n-N//n)==1:
    yoko=N//n
else:
    print("No")
    exit()

ans=[[0 for j in range(yoko)]for i in range(n)]

for i in range(N-1):
    for j in range(i,yoko):
        temp=stock.pop(-1)
        ans[i][j]=temp
        ans[j+1][i]=temp

print("Yes")
print(len(ans))
for item in ans:
    print(len(item), *item)

Solution (Python):
n=int(input())
if int((2*n)**(1/2))*int((2*n)**(1/2)+1)==2*n:
  a=int((2*n)**(1/2))
  print("Yes")
  print(a+1)
  A=[[] for i in range(a+1)]
  x=0
  for i in range(a):
    for j in range(a-i):
      x=x+1
      A[i].append(x)
  B=[[] for i in range(a+1)]
  x=0
  for i in range(a):
    for j in range(a-i):
      x=x+1
      B[i].append(x)
  C=[[] for i in range(a+1)]
  for i in range(a):
    for j in range(a-i):
      C[a-j].append(B[i][j])
  D=[[] for i in range(a+1)]
  for i in range(a+1):
    D[i]=A[i]+C[i]
  for i in range(a+1):
    print(a,end=" ")
    for j in range(a):
      print(D[i][j],end=" ")
    print()
else:
  print("No")

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

n1 = 8*N+1
a = int(n1**0.5)

if N==1:
    print("Yes")
    print(2)
    print(1, 1)
    print(1, 1)
elif n1==a**2:
    n = (-3+a)//2
    d = [[0]*(n+1) for _ in range(n+2)]
    d[0][0] = 1
    d[0][1] = 2
    d[1][0] = 2
    d[1][1] = 3
    d[2][0] = 3
    d[2][1] = 1
    for i in range(1, n):
        v = 4+((i-1)*(i+4)//2)
        c = 2+i

        for j in range(c):
            d[c][j] = v+j
            d[j][c-1] = v+j

    print("Yes")
    print(n+2)
    for i in range(n+2):
        print(n+1, *d[i], sep=" ")
else:
    print("No")

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

n1 = 8*N+1
a = int(n1**0.5)

if N==1:
    print("Yes")
    print(2)
    print(1, 1)
    print(1, 1)
elif N>=3 and n1==a**2:
    n = (-3+a)//2
    if (-3+a)%2:
        print("No")
    else:
        d = [[0]*(n+1) for _ in range(n+2)]
        d[0][0] = 1
        d[0][1] = 2
        d[1][0] = 2
        d[1][1] = 3
        d[2][0] = 3
        d[2][1] = 1
        for i in range(1, n):
            v = 4+((i-1)*(i+4)//2)
            c = 2+i

            for j in range(c):
                d[c][j] = v+j
                d[j][c-1] = v+j

        print("Yes")
        print(n+2)
        for i in range(n+2):
            print(n+1, *d[i], sep=" ")
else:
    print("No")

Solution (Python):
def main():
    N=int(input())
    for k in range(1000):
        if k*(k-1)//2==N:
            print("Yes")
            print(k)
            break
        if k*(k-1)//2>N:
            print("No")
            return
    S=[[0]*(k-1) for _ in range(k)]
    a=1
    for i in range(k-1):
        for j in range(k-i-1):
            S[j][i]=a
            S[k-i-1][i+j]=a
            a+=1
    for s in S:
        print(len(s), *s)

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
k=int((n*2)**0.5)
if (k*(k+1))//2==n:
  print('Yes')
  print(k+1)
else:
  print('No')
  exit()
s=[[] for _ in range(k+1)]
t=1
for i in range(1,k+1):
  for j in range(i):
    s[i].append(t)
    s[j].append(t)
    t+=1
for i in s:
  print(len(i),*i)

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

n = int((2*N)**0.5)
if n*(n+1) == 2*N:
    print("Yes")
    print(n+1)
    S = [[] for _ in range(n+1)]
    num = 1
    for i in range(n+1):
        j = i+1
        while len(S[i]) < n:
            S[i].append(str(num))
            S[j].append(str(num))
            num += 1
            j += 1
    for i in range(n+1):
        print(n, " ".join(S[i]))
    
else:
    print("No")

Solution (Python):
N = int(input())
flg = 0
k = 0
while k * (k - 1) <= 2 * N:
  if k * (k - 1) == 2 * N:
    flg = 1
    break
  else:
    k += 1
if flg == 0:
  print("No")
else:
  print("Yes")
  print(k)
  S = [[k-1] for _ in range(k)]
  cnt = 1
  for i in range(k-1):
    for j in range(i+1, k):
      S[i].append(cnt)
      S[j].append(cnt)
      cnt += 1
  for i in range(k):
    for j in range(k):
      if j == k:
        print(S[i][j])
      else:
        print(S[i][j], end = ' ')
    print()

Solution (Python):

n = int(input())
k = int((2*n)**.5)
if k*(k+1)//2 != n:
  print('No')
  exit()
ans = [[x for x in range(k)]]
now = k
for j in range(k):
  tmp = []
  for i in range(j+1):
    tmp.append(ans[i][j])
  for i in range(j+1,k):
    tmp.append(now)
    now += 1
  ans.append(tmp)
print('Yes')
print(k+1)
for x in ans:
  print(k,' '.join(list(map(lambda y:str(y+1),x))))

Solution (Python):
n=int(input())
l=[i*(i-1)//2 for i in range(2,450)]
if n in l:
  print('Yes')
  k=l.index(n)+1
  print(k+1)
  x=[[k] for _ in range(k+1)]
  p=1
  for i in range(k):
    for j in range(k-i):
      x[i].append(p+j)
      x[i+j+1].append(p+j)
    p=p+k-i
  for i in x:
    print(*i)
else:
  print('No')

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


e=0
v=1
while e<=10**5:
    if e==N: break
    e+=v
    v+=1
else:
    print('No')
    exit()
print('Yes')



subsets=[set() for _ in range(v)]
k=1
for i in range(v):
    for j in range(i+1,v):
        subsets[i].add(k)
        subsets[j].add(k)
        k+=1

print(v)
for s in subsets:
    S=[len(s)]+list(s)
    print(' '.join(map(str,S)))

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    k = int((N*2)**(1/2))
    if N*2 != k*(k+1):
        print("No")
    else:
        print("Yes")
        l = [[0 for _ in range(k)] for _ in range(k+1)]
        for i in range(k):
            for j in range(k-i):
                if i == 0:
                    l[i][j] = j+1
                    l[j+1][i] = j+1
                else:
                    l[i][i+j] = 1+(k+1)*i-i*(i+1)//2+j
                    l[i+j+1][i] = 1+(k+1)*i-i*(i+1)//2+j
        print(k+1)
        for i in range(k+1):
            print(k,*l[i])

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
for l in range(1, 10**3):
  if l*(l-1)//2 == n:
    print("Yes")
    print(l)
    S = [[] for _ in range(l)]
    now = 0
    count = 1
    for j in range(l-1):
      for k in range(l-1-j):
        S[now].append(count)
        S[now+1+k].append(count)
        count += 1
      now += 1
    for s in S:
      print(l-1, *s)
    break
else:
  print("No")

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
for i in range(1,10**5):
    tmp = i*(i+1)//2
    if n == tmp:
        k = i+1
        break
    elif n < tmp:
        print('No'); quit()
res = [[0 for j in range(k-1)]for i in range(k)]
cnt = 1
for i in range(k):
    for j in range(k-1-i):
        res[i][j] = cnt
        cnt += 1

cnt = 1
for j in range(k-1)[::-1]:
    for i in range(k):
        if res[i][j]: continue
        res[i][j] = cnt
        cnt += 1

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

Solution (Python):
n=int(input())
l=[]
s=0
for i in range(n+2):
  l.append(s)
  s+=i+1
if n not in l:
  print('No')
else:
  k=l.index(n)+1
  ans=[[] for i in range(k)]
  c=0
  for i in range(k):
    for j in range(i+1,k):
      ans[i].append(c+1)
      ans[j].append(c+1)
      c+=1
  print('Yes')
  print(k)
  for i in range(k):
    print(k-1,*ans[i])

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
for k in range(n+5):
    m = k*(k-1)//2
    
    if m>n:
        break
    if m<n:
        continue
    cnt = 1
    s = [ [] for i in range(k) ]
    for i in range(k-1):
        for j in range(i+1,k):
            s[i].append(cnt)
            s[j].append(cnt)
            cnt += 1
    print('Yes')
    print(k)
    for i in range(k):
        printn(k-1)
        for j in s[i]:
            printn(' ' + str(j))
        print('')
    exit()
print('No')

Solution (Python):
n = int(input())
for i in range(10**3):
    if n == i*(i+1)//2:
        x = i
        break
else:
    print("No")
    exit()
ans = [[] for i in range(x+1)]
app = 0
for i in range(1,x+1):
    for j in range(i):
        app += 1
        ans[j].append(app)
    ans[i].extend([k for k in range(i*(i-1)//2+1,i*(i+1)//2+1)])
print("Yes")
print(x+1)
for ansarr in ans:
    print(x, *ansarr, sep = " ")

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

K = int((2 * N) ** 0.5) + 1
if K * (K - 1) // 2 != N:
    print("No")
    quit()

print("Yes")
print(K)

A = [[] for _ in range(K - 1)]

cur = 1
for i in range(K - 1):
    for _ in range(i + 1):
        A[i].append(cur)
        cur += 1

for i in range(K - 1):
    T = A[i]
    cur = len(T) - 1
    for j in range(cur + 1, K - 1):
        T.append(A[j][cur])
    print(len(T), *T)

T = [A[i][i] for i in range(K - 1)]
print(len(T), *T)

Solution (Python):
def grid(N):
    n = 0
    while n * (n + 1) < N * 2:
        n += 1

    if n * (n + 1) != N * 2:
        print("No")
        return

    S = [[0]*n for _ in range(n+1)]
    cnt = 1
    for i in range(n+1):
        for j in range(n):
            if i <= j:
                S[i][j] = cnt
                cnt += 1
            else:
                S[i][j] = S[j][i-1]
    print("Yes")
    print(len(S))
    for s in S:
        print(n, end=" ")
        print(*s, sep=" ")


if __name__ == "__main__":
    N = int(input())
    grid(N)

Solution (Python):

n=int(input())
flag=False
index=0
for i in range(1000):
    if i*(i+1)//2==n:
        flag=True
        index=i
        break
if flag:
    print("Yes")
    print(i+1)
    uselist=[[1],[1]]
    if index==1:
        print(1,1)
        print(1,1)
    else:
        def plus(N):
            base=(N)*(N-1)//2
            for k in range(1,N+1):
                uselist[k-1].append(base+k)
            uselist.append([base+i+1 for i in range(N)])

     
        
        for k in range(2,index+1):
            plus(k)
        for some in uselist:
            print(index,*some)
            
else:
    print("No")

Solution (Python):
n=int(input())
l=[]
s=0
for i in range(n+2):
  l.append(s)
  s+=i+1
if n not in l:
  print('No')
else:
  k=l.index(n)+1
  ans=[[] for i in range(k)]
  c=0
  for i in range(k):
    for j in range(i+1,k):
      ans[i].append(c+1)
      ans[j].append(c+1)
      c+=1
  print('Yes')
  print(k)
  for i in range(k):
    print(k-1,*ans[i])

Solution (Python):
N = int(input())
"""
どの部分集合の共通する要素も一つだけで、各数字（１～N）は２回ずつしか出現しないことから、部分集合の数をｋとすると、
(1)と(2)の共通が１、(1)と(3)の共通が２、～、(k-1)と(k)の共通がN、のように表現でき、この中で１～Nが２回ずつ出現している。
ある部分集合がほかのk-1この部分集合と共通の値を一個ずつもつので、部分集合の要素数はk-1となる。
１～Nまで２回ずつ出てくる＆ｋ個の部分集合の要素がそれぞれ（ｋ－１）であることから、２N＝k(k-1)となる。
ｋが決まれば、上記の(1)と(2)の共通が１で～みたいな置き方をしていくだけでそれぞれの集合が決まる。
Nは10^5までなので、ｋが１０００程度の範囲までで、２N＝k(k-1)を満たすｋがあるか調べていけばよい。

公式開設動画が非常にわかりやすかった：https://www.youtube.com/watch?v=wwCqOcWkVh4
"""
k = 0
while N != k*(k-1)//2:
    k += 1
    if k == 1000:
        break

if k == 1000:
    print("No")
else:
    ans = [[] for _ in range(k)]
    cnt = 0
    for i in range(k):
        for j in range(i+1,k):
            ans[i].append(cnt+1)
            ans[j].append(cnt+1)
            cnt += 1

    print("Yes")
    print(k)
    for a in ans:
        print(k-1, *a)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    N*=2
    size = -1
    group_num = -1
    for i in range(2,N+2):
        if i*(i-1)==N:
            group_num = i
            size = i-1
            break
    if size == -1:
        print("No")
        return 
    
    ans = [[-1]*size for _ in range(group_num)]

    now = 0
    for i in range(group_num):
        for j in range(size):
            if j<i:
                ans[i][j] = ans[j][i-1]
            else:
                now += 1
                ans[i][j] = now

        
    print("Yes")
    print(group_num)
    for a in ans:
        print(size,*a)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
tmp=1
while 1:
    if 2*n==(tmp+1)*tmp:
        break
    if 2*n<(tmp+1)*tmp:
        print("No")
        exit()
    tmp+=1
print("Yes")
print(tmp+1)
ans=[[] for i in range(tmp)]
a=1
for i in range(tmp):
    for j in range(i+1):
        ans[i].append(a)
        a+=1

for i in range(tmp):
    b=str(tmp)
    flag=-1
    for j in range(tmp):
        if flag==-1:
            b+=" "+str(ans[i][j])
        else:
            b+=" "+str(ans[i+j-flag][i])
        if j+1==len(ans[i]):
            flag=j
    print(b)
b=str(tmp)
for i in range(tmp):
    b+=" "+str(ans[i][-1])
print(b)

Solution (Python):
n=int(input())
if int((2*n)**(0.5))*int((2*n)**(0.5)+1)==2*n:
  print('Yes')
  k=int((2*n)**(0.5)+1)
  print(k)
  l=[]
  for i in range(k):
    if i==0:l.append([j+1 for j in range(k-1)]);lused=k-1
    else:
      addl=[]
      for j in range(i):
        addl.append(l[j][i-1])
      for j in range((k-1)-i):
        addl.append(lused+1)
        lused+=1
      l.append(addl)
  for i in l:print(2*n//k,*i)
else:print("No")

Solution (Python):
def main():
    n=int(input())
    m=int((2*n)**0.5)
    if m*(m+1)==n*2:
        print("Yes")
        m+=1
        print(m)
    else:
        print("No")
        exit()
    
    ans=[[m-1] for i in range(m)]
    c=1
    for i in range(m):
        for j in range(i+1,m):
            ans[i].append(c)
            ans[j].append(c)
            c+=1
    for i in ans:
        print(" ".join(map(str,i)))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n=int(input())
    m=int((2*n)**0.5)
    if m*(m+1)==n*2:
        print("Yes")
        m+=1
        print(m)
    else:
        print("No")
        exit()
    
    ans=[[m-1] for i in range(m)]
    c=1
    for i in range(m):
        for j in range(i+1,m):
            ans[i].append(c)
            ans[j].append(c)
            c+=1
    for i in ans:
        print(" ".join(map(str,i)))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n=int(input())
    m=int((2*n)**0.5)
    if m*(m+1)==n*2:
        print("Yes")
        m+=1
        print(m)
    else:
        print("No")
        exit()
    
    ans=[[m-1] for i in range(m)]
    c=1
    for i in range(m):
        for j in range(i+1,m):
            ans[i].append(c)
            ans[j].append(c)
            c+=1
    for i in ans:
        print(*i)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
for i in range(10**3):
    if n == i*(i+1)//2:
        x = i
        break
else:
    print("No")
    exit()
ans = [[] for i in range(x+1)]
app = 0
for i in range(1,x+1):
    for j in range(i):
        app += 1
        ans[j].append(app)
    ans[i].extend([k for k in range(i*(i-1)//2+1,i*(i+1)//2+1)])
print("Yes")
print(x+1)
for ansarr in ans:
    print(x, *ansarr, sep = " ")

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

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

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

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


for i in range(k - 1):
    for j in range(k - 1 - i):
        lst[i].append(tmp)
        lst[i + j + 1].append(tmp)
        tmp += 1

print (k)    
for i in lst:
    print (len(i), *i, sep = ' ')

Solution (Python):
def main():
	n = int(input())
	l = []
	i = 1
	while n > 0:
		n -= i
		t = i * (i - 1) // 2
		l += [list(range(t + 1, t + i + 1))]
		i += 1
	if n < 0:
		print("No")
		exit()
	print("Yes")
	i -= 1
	ans = [i + 1] + [i] + [l[j][-1] for j in range(i)]
	for j in range(i):
		ans += [i] + l[j] + [l[k][j] for k in range(j + 1, i)]
	print(" ".join(map(str, ans)))
	
if __name__=="__main__":
	main()

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

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

Solution (Python):
def examA():
    S = SI()
    if len(S)==3:
        ans = S[::-1]
    else:
        ans = S
    print(ans)
    return

def examB():
    A, B, K = LI()
    for i in range(K):
        if i%2==0:
            B +=A//2
            A //=2
        else:
            A +=B//2
            B //=2
    print(A,B)
    return

def examC():
    N = I()
    A = [I() for _ in range(N)]
    A.sort()
    A1 = A[:N//2]; A2 = A[N//2:]
    ans = 0; cur = 0
    for i in range(len(A2)):
        if i<len(A1):
            cur +=(A2[i]-A1[i])
        if i-1>=0:
            cur +=(A2[i]-A1[i-1])
    if N%2==1:
        cur += (A2[-1] - A2[1])
    ans = max(ans,cur)


    if N%2==1:
        A1 = A[:1+(N//2)]; A2 = A[1+(N//2):]
        cur = 0
        for i in range(len(A1)):
            if i < len(A2):
                cur += (A2[i] - A1[i])
            if i - 1 >= 0:
                cur += (A2[i-1] - A1[i])
        cur +=(A1[-2]-A1[0])
        ans = max(ans, cur)

    print(ans)
    return

def examD():
    N = I()
    ansCandi = []
    for i in range(1, 1000):
        a = (i + 1) * i / 2
        ansCandi.append(a)
    if N not in ansCandi:
        print("No")
    else:
        a = ansCandi.index(N) + 1
        A = [[0] * (a + 1) for _ in range(a + 1)]
    
        k = int(1)
        for i in range(a + 1):
            for j in range(i + 1, a + 1):
                A[i][j] = k
                A[j][i] = k
                k += 1

        print("Yes")
        print(a + 1)
        for v in A:
            v.remove(0)
            v.insert(0, a)
        for v in A:
            print(*v)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
k = 0
for i in range(1, N + 2):
  if i * (i - 1) == N * 2:
    k = i
    break
if k == 0:
  print("No")
  exit(0)
res = [[] for _ in range(k + 1)]
p = 1
print("Yes")
print(k)
for i in range(2, k + 1):
  for j in range(1, i):
    res[i].append(p)
    res[j].append(p)
    p += 1
for i in range(1, k + 1):
  print(str(len(res[i])) + " " + " ".join(list(map(str, res[i]))))

Solution (Python):
N = int(input())
k = int((2*N)**0.5)+1
if k*(k-1)==2*N:
    print('Yes')
    print(k)
    S = [[0 for j in range(k-1)] for i in range(k)]
    sx,sy = 0,0
    n = 1
    while sx<k:
        for i in range(k-1-sx):
            S[sx][sy+i] = n+i
            S[sx+1+i][sy] = n+i
        n += k-1-sx
        sx += 1
        sy += 1
    for s in S:
        print(len(s),*s)
else:
    print('No')

Solution (Python):
n = int(input())
k = int((n*2)**.5)
if k*(k+1)//2 != n:
  print("No")
  exit()
print("Yes")
print(k+1)
l = [set() for _ in range(k+1)]
t = 0
for i in range(k):
  for j in range(i+1):
    t += 1
    l[i].add(t)
    l[j].add(t)
  l[-1].add(t)
for x in l:
  print(k," ".join(map(str,x)))