Problem:
 Score: 500 points    Problem Statement  Does there exist an undirected graph with N vertices satisfying the following conditions?   The graph is simple and connected.  The vertices are numbered 1, 2, ..., N .  Let M be the number of edges in the graph. The edges are numbered 1, 2, ..., M , the length of each edge is 1 , and Edge i connects Vertex u_i and Vertex v_i .  There are exactly K pairs of vertices (i,\ j)\ (i < j) such that the shortest distance between them is 2 .   If there exists such a graph, construct an example.      Constraints  All values in input are integers.  2 \leq N \leq 100  0 \leq K \leq \frac{N(N - 1)}{2}         Input  Input is given from Standard Input in the following format:  N  K       Output If there does not exist an undirected graph with N vertices satisfying the conditions, print -1 .  If there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for):  M  u_1  v_1  :  u_M  v_M   If there exist multiple graphs satisfying the conditions, any of them will be accepted.        Sample Input 1 5 3      Sample Output 1 5
4 3
1 2
3 1
4 5
2 3  This graph has three pairs of vertices such that the shortest distance between them is 2 : (1,\ 4) , (2,\ 4) , and (3,\ 5) . Thus, the condition is satisfied.       Sample Input 2 5 8      Sample Output 2 -1  There is no graph satisfying the conditions.

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
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, K = MAP()

limit = sum(range(1, N-1))

if K > limit:  
	print(-1)
else:  
	edge = list(combinations(range(1, N+1),2))
	if K == 0:
		print(N*(N-1)//2)
		for u, v in edge:
			print(u, v)
	else:	
		rem = []
		count = 0
		for i in edge:
			if i[1] != N:
				rem.append(i)
				count += 1
				if count == K:
					break
		for i in rem:
			edge.remove(i)

		print(N*(N-1)//2 - K)
		for u, v in edge:
			print(u, v)

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,K = map(int,input().split())
if N*(N-1)//2-K<N-1:
    print(-1)
    exit()
else:
    print(N*(N-1)//2-K)
    edge=[[1]*(N) for i in range(N)]
    for i in range(N):
        edge[i][i]=0
    for i in range(N-1):
        for j in range(i+1,N-1):
            if K>0:
                edge[i][j]=0
                K -=1
    for i in range(N)[::-1]:
        for j in range(0,i):
            edge[i][j]=0
    for i in range(N):
        for j in range(N):
            if edge[i][j]:
                print(i+1,j+1)

Solution (Python):
from collections import Counter
def check(n, k):
    if k > (n-1)*(n-2)//2 :
        return False
    return True

def solve():
    N, K = map(int, input().split())
    if not check(N, K):
        print(-1)
        return
    
    Ans = []
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            Ans.append((i, j))
    dim = [N-1]*(N+1)
    for _ in range(K):
        for i, j in Ans:
            if i != 1:
                Ans.remove((i, j))
                dim[i] -= 1
                dim[j] -= 1
                break
    
    print(len(Ans))
    for a in Ans:
        print(*a)
solve()

Solution (Python):
N, K = map(int, input().split())

import math
max_n = sum([a for a in range(N-2+1)])


import sys

sys.setrecursionlimit(20000)

if N == 2 and K != 0:
    print(-1)
elif max_n >= K:
    non_edges = []
    for a in range(2, N+1):
        for b in range(a+1, N+1):
            if len(non_edges) == K:
                break
            non_edges.append((a, b))
    
    edges = []
    for a in range(1, N+1):
        for b in range(a+1, N+1):
            if (a, b) in non_edges:
                pass
            else:
                edges.append((a, b))
    
    print(len(edges))
    for a, b in edges:
        print(a, b)
else:
    print(-1)

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 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 main():
    N, K = LI()
    tot_M = (N-1)*N/2
    M = tot_M - K
    if M < N - 1:
        print(-1)
        return
    print(int(M))
    cnt = 0
    for ix in range(N-1):
        print("1 {}".format(ix+2))
        cnt += 1

    for ix in range(2, N+1):
        for jx in range(ix+1, N+1):
            if cnt >= M:
                return
            print("{} {}".format(ix, jx))
            cnt += 1
            
main()

Solution (Python):
N, K = map(int, input().split())

if (N-1)*(N-2)/2 < K:
    print(-1)
else:
    diff = int(((N-1)*(N-2)/2 - K))
    print(N-1+diff)
    for i in range(1, N):
        start = 1
        end = i+1
        print(str(start) + " " + str(end))
    cnt = 0
    isEnd = False
    for i in range(1, N):
        start = i+1
        if isEnd:
            break
        for j in range(i+1, N):
            if cnt == diff:
                isEnd = True
                break
            end = j +1
            print(str(start) + " " + str(end))
            cnt += 1

Solution (Python):
n,k=map(int, input().split())
a=(n-1)*(n-2)//2
from itertools import permutations, combinations,combinations_with_replacement,product
moto=list(range(2,n+1))
ku=list(combinations(moto,2))

if k>a:
    print(-1)
else:
    print(n-1+a-k)
    for j in range(n-1):
        print(1,j+2)
    for j in range(a-k):
        print(*ku[j])

Solution (Python):
import itertools
import sys
N,K=map(int,input().split())
Max = (N-1) * (N-2) // 2
Hen = N * (N-1)//2
if K>Max:
    print(-1)
    sys.exit()
rinsetsu = [[True]*N for i in range(N)]

OnetoN = range(1,N)
c = itertools.combinations(OnetoN,2)
if K!=0:
    for n,(a,b) in enumerate(c,start = 1):
        rinsetsu[a][b] = 0
        rinsetsu[b][a] = 0
        if n == K:break
print(Hen-K)
for i in range(N):
    for j in range(i):
        if i!=j and rinsetsu[i][j]:
            print(i+1,j+1)
3

Solution (Python):
N,K =  list(map(int,input().split(" ")))
co = 1/2 * (N-2)*(N-1)
co = int(co)
if K > co:
    print(-1)
    exit()
edges = []
diff = co - K
for i in range(2,N+1):
    edges.append((1,i))

co = 0

flag = False
for i in range(2,N+1):
    for j in range(i+1,N+1):
        if co == diff:
            flag = True
            break
        edges.append((i,j))
        co += 1
    if flag:
        break

M = len(edges)
print(M)
for edge in edges:
    a,b = edge
    print(a,b)

Solution (Python):
N,K =map(int,input().split())
ans = []

if K > (N-1)*(N-2)//2:
    print(-1)
else:
    for i in range(N-1):
        ans.append([i+1,N])
    maco = (N-1)*(N-2)//2 -K
    count = 0
    s =False
    for i in range(N-1):
        i += 1
        if s:
            break
        for j in range(i-1):
            j+= 1
            if count == maco:
                s = True
            if s:
                break
            ans.append([i,j])
            count += 1
    print(N-1+count)
    anstr ="\n".join(["{} {}".format(i,j)for i,j in ans])
    print(anstr)

Solution (Python):
N, K = map(int, input().split())

ans = []

if N == 2 and K > 0:
    ans = []
elif (1+N-2)*(N-2)//2 < K:
    ans = []
else:
    for i in range(2, N+1):
        ans.append([1, i])
    cnt = (1+N-2)*(N-2)//2

    for u in range(2, N):
        if cnt == K:
            break
        for v in range(u+1, N+1):
            if cnt == K:
                break
            ans.append([u, v])
            cnt -= 1

if ans:
    print(len(ans))
    for u, v in ans:
        print(u, v)
else:
    print(-1)

Solution (Python):
def check():
    N,K = map(int,input().split())

    
    m_list = []
    for i in range(2,N+1):
        m_list.append([1,i])

    saidai = int((N-1)*(N-2)/2)

    if K > saidai:
        return False

    herasu = saidai - K

    if herasu == 0:
        return m_list

    cnt = 0
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            m_list.append([i,j])
            cnt += 1
            if cnt == herasu:
                return m_list

result = check()
if result == False:
    print(-1)
else:
    print(len(result))
    for a,b in result:
        print(a,b)

Solution (Python):
n,k = map(int,input().split())
r = (n-1)*(n-2)//2 - k
if r < 0:
  print(-1)
else:
  print(n-1+r)
  for i in range(1,n):
    print(1,i+1)
  for i in range(1,n):
    r -= n-i-1
    if r >= 0:
      for j in range(i+1,n):
        print(i+1,j+1)
    else:
      for j in range(i+1,r+n):
        print(i+1,j+1)
      break

Solution (Python):

import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, K: int):
    g = [[1] * N for _ in range(N)]
    for i in range(N):
        g[i][i] = 0

    k = K
    for i in range(N):
        if k == 0:
            break
        for j in range(N - 1):
            if j <= i:
                continue

            g[i][j] = 0
            g[j][i] = 0
            k -= 1
            if k == 0:
                break

    if 0 < k:
        return '-1'

    ret = []
    for i in range(N):
        for j in range(N):
            if j <= i:
                continue

            if g[i][j] != 0:
                ret.append('{} {}'.format(i+1, j+1))
    ret = [str(len(ret))] + ret
    return '\n'.join(ret)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    result = solve(N, K)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
N , K = map(int,input().split())
max_K = (N - 1) * (N - 2) // 2
if K > max_K:
	print(-1)
else:
	ans = []
	temp_K = max_K
	for i in range(N - 1):
		ans.append([1,2+i])
	if temp_K == K:
		print(len(ans))
		for ans_ in ans:
			print(ans_[0],ans_[1])
	else:
		i = 2
		while temp_K > K:
			j = i + 1
			while temp_K > K and j <= N:
				temp_K -= 1
				ans.append([i,j])
				j += 1
			i += 1
		print(len(ans))
		for ans_ in ans:
			print(ans_[0],ans_[1])

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,k = get_nums_l()

edges = []

edges.append((1, 2))

right = min(k, n-2) 
for i in range(right):
    edges.append((2, i+3))

kumi = right + (right*(right-1)//2)

if(kumi < k):
    print(-1)
    exit()

over = kumi - k
count = 0
if over > 0:
    for i in range(right):
        for j in range(i+1, right):
            count += 1
            edges.append((i+3, j+3))
            if count >= over:
                break
        if count >= over:
            break

amari = n - (right+2)

for i in range(amari):
    for j in range(right+2):
        edges.append((j+1, i+right+3))

for i in range(amari-1):
    for j in range(i+1, amari):
        edges.append((i+right+3, j+right+3))

print(len(edges))
for e in edges:
    print(" ".join(map(str,(e))))

Solution (Python):
N,K= map(int,input().split())
import math
import itertools

f = 1

if len(list(itertools.combinations(range(1,N),2))) < K:
    f = 0

if f == 0:
    print(-1)

if f!=0:
    ans_list = []
    kumi = list(itertools.combinations(range(2,N+1), 2))
    kumilen = len(kumi)
    
    for i in range(2,N+1):
        ans_list.append((1,i))
    for i in range(0,kumilen-K):
        ans_list.append(kumi[i])
    
    print(len(ans_list))
    for i in range(len(ans_list)):
        print(ans_list[i][0],ans_list[i][1])

Solution (Python):
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
n,k=map(int,input().split())
isExist=True

if k > (n-2)*(n-1)//2:
    isExist=False
if isExist:
    side=cmb(n,2)-k
    print(side)
    cnt=0
    for i in range(n):
        for j in range(i+1,n):
            if cnt>=k or j==n-1:
                print(i+1,j+1)
            else:
                cnt+=1
else:
    print(-1)

Solution (Python):
from itertools import combinations
N, K = map(int, input().split())

def solve():
    uni = []  
    for i in range(N-1):
        v = i + 2
        uni.append((1, v))
    f = (N - 1) * (N - 2) // 2

    for edge in combinations(range(2, N+1), 2):
        if f == K:
            break
        uni.append(edge)
        f -= 1
    
    return len(uni), uni
    

if K > (N - 1) * (N - 2) // 2:
    print(-1)
else:
    M, G = solve()
    print(M)
    for g in G:
        print(g[0], g[1])

Solution (Python):
n, k = map(int, input().split())
if k > (n -1) * (n - 2) // 2:
    print(-1)
else:
    m = (n - 1) + ((n - 1) * (n - 2) // 2 - k)
    print(m)
    for i in range(n - 1):
        print(i + 1, n)
    e = m - n + 1
    j = 1
    while e > 0:
        if e <= n - j - 1:
            for i in range(e):
                print(j, j + i + 1)
            e = 0
        else:
            for i in range(n - j - 1):
                print(j, j + i + 1)
            e -= (n - j - 1)
            j += 1

Solution (Python):
N, K=map(int, input().split())
if K>(N-1)*(N-2)//2:
    print("-1")
    exit(0)
l=[]
for i in range(2,N+1):
    l.append((1,i))
s=(N-1)*(N-2)//2-K

a=2
b=3

for i in range(s):
    l.append((a,b))
    if b+1<=N:
        b+=1
    else:
        a+=1
        b=a+1
print(len(l))
for i in range(len(l)):
    print(l[i][0], l[i][1])

Solution (Python):
N,K=map(int,input().split())


if K>((N-2)*(N-1))//2:
  print(-1)
else:
  M=N-1
  M+=((N-2)*(N-1))//2-K
  print(M)
  for i in range(2,N+1):
    print(1,i)
  count=N-1
  for j in range(2,N+1):
    for k in range(j+1,N+1):
      if count==M:
        exit()
      else:
        print(j,k)
        count+=1

Solution (Python):
n,k = map(int, input().split())
max_connect = (n-1)*(n-2)//2
if k > max_connect:
    print(-1)
else:
    print(n+max_connect - k -1)
    for i in range(n-1):
        print(i+1,n)

    end = max_connect - k
    cnt = 0
    cntflg = end > 0
    for i in range(n-1):
        for j in range(i+1,n-1):
            if cntflg:
                print(i+1,j+1)
                cnt += 1
            if cnt == end:
                cntflg = False

Solution (Python):
import itertools
N, K = map(int, input().split())
ans = []
max_K = sum([i for i in range(N-1)])
if K > max_K:
    print(-1)
else:
    M = N-1
    for i in range(2, N+1):
        ans.append([str(1), str(i)])
    count = 0
    if K == max_K:
        print(M)
        for a in ans:
            print(' '.join(a))
    else:
        for c in itertools.combinations([str(i) for i in range
        (2, N+1)], 2):
            ans.append([c[0], c[1]])
            count += 1
            if max_K - count == K:
                break
        M += count
        print(M)
        for a in ans:
            print(' '.join(a))

Solution (Python):
N, K = map(int, input().split())

if K > (N-1)*(N-2)//2:
    print(-1)
    exit()

left = (N-1)*(N-2)//2 - K
ans = []

for i in range(N-1):
    ans.append((1, i+2))

now = N - 1
tmp = N
while left > 0:
    left -= 1
    ans.append((now, tmp))
    if tmp == N:
        now = now - 1
        tmp = now
    tmp += 1
print(len(ans))

for a, b in ans:
    print(a, b)

Solution (Python):
n, k = map(int, input().split())
if k > (n - 1) * (n - 2) // 2:
    print(-1)
else:
    edges = []
    e = n * (n - 1) // 2 - k
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            if e > 0:
                edges.append((a, b))
                e -= 1
    print(len(edges))
    for e in edges:
        print(e[0], e[1])

Solution (Python):
N,K = (int(i) for i in input().split())
onon = 2
hoge = 3
if (N-1) * (N-2) // 2 < K:
    print(-1)
else:
    print(N-1 +((N -1) * (N-2) // 2 - K))
    for i in range(N-1):
        print("1" + " " + str(i+2))
    for i in range((N -1) * (N-2) // 2 - K):
        print(str(onon) + " " + str(hoge))
        hoge += 1
        if hoge > N:
            hoge = onon + 2
            onon += 1

Solution (Python):
from collections import Counter
from operator import itemgetter
import math
num1 = 2
num2 = 3
chk = 0
N,K =map(int,input().split())
if K > (N-1)*(N-2)//2:
	print(-1)
else:
	left = (N-1)*(N-2)//2 - K
	print(left+N-1)
	for i in range(2,N+1):
		print("1"+" "+str(i))

	for i in range(left):
			if N >= num2 :
				if chk == 1:
					num2 += 1
					chk = 0
				print(str(num1) + " " + str(num2))
				num2 += 1
			else:
				num1 +=1
				num2 = num1+1
				print(str(num1) + " " + str(num2))
				chk = 1

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    s = S()
    for i in range(3):
        if s[i] == s[i + 1]:
            print("Bad")
            return
    print("Good")
    return


def B():
    n, l = LI()
    lis = [l + i for i in range(n)]
    s = sum(lis)
    a = inf
    for i in lis:
        if abs(a) > abs(i):
            a = i
    print(s-a)
    return


def C():
    def gcd(a, b):
        a, b = max(a, b), min(a, b)
        while b:
            a, b = b, a % b
        return a
    def lcm(a, b):
        return a * b // gcd(a, b)
    a, b, c, d = LI()
    x = b // c - (a-1) // c
    y = b // d - (a-1) // d
    z = b // lcm(c , d) - (a-1) // lcm(c , d)
    print(b-a+1-(x+y-z))
    return


def D():
    n = II()
    ab = LIR(n)
    ab.sort(key=lambda x: x[1])
    now = 0
    for a, b in ab:
        now += a
        if now <= b:
            continue
        print("No")
        return
    print("Yes")
    return


def E():
    n, k = LI()
    if k > (n - 1) * (n - 2) / 2:
        print(-1)
        return
    d = (n - 1) * (n - 2) // 2 - k
    a = [[] for i in range(n)]
    for i in range(n):
        if i != 1:
            a[i].append(1)
            a[1].append(i)
    l = 0
    m = 2
    while d > 0:
        a[l].append(m)
        m += 1
        d -= 1
        if m == n:
            l += 1
            m = l + 1
            if l == 1:
                l = 2
                m = 3
    aa = 0
    ans = []
    for num,i in enumerate(a):
        for l in i:
            if num < l:
                aa += 1
                ans.append((num+1,l+1))
    print(aa)
    for x, y in ans:
        print(x, y)
    return


def F():
    n = II()
    xy = LIR(n)
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    E()

Solution (Python):
N,K = map(int,input().split())

calc = N-2
for i in range(3,N) :
    calc += (N-i)

if calc < K :
    print(-1)


else :
    ans = []
    ans.append([1,2])
    for i in range(3,N+1) :
        ans.append([2,i])
    
    cnt = calc - K
    
    
    for i in range(3,N+1) :
        if cnt > 0 :
        
            ans.append([1,i])
            cnt -= 1
        else :
            break
    
    for i in range(3,N) :
        if not cnt > 0 :
            break
        for j in range(i+1,N+1) :
            if not cnt > 0 :
                break
            
            ans.append([i,j])
            cnt -= 1

    M = len(ans)

    print(M)
    for a in ans :
        print(*a)

Solution (Python):
words = lambda t : list(map(t, input().split()))
n,k = words(int)

max_m = sum(range(1,n-1))
if k > max_m:
    print(-1)
else:
    g = []
    for i in range(n):
        for j in range(i+1,n):
            g.append((i,j))
    
    for i in range(k):
        g.pop(-1)

    print(len(g))
    for a,b in g:
        print(a+1,b+1)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N,K=LI()

if K > (N-1)*(N-2)//2:
    print(-1)
    exit()

out = []
for i in range(N-1):
    out.append((1, 2+i))

cnt = 0
for i in range(2, N+1):
    for j in range(i+1, N+1):
        if cnt < ((N-1)*(N-2)//2-K):
            cnt += 1
            out.append((i, j))

print(len(out))
for li in out:
    print(li[0],li[1])

Solution (Python):


def f(N, K):
    m = (N-1)*(N-2)//2
    if K > m:
        print(-1)
        return

    print(N-1+m-K)

    for i in range(2, N+1):
        print(1, i)

    k2 = m - K
    for i in range(2, N+1):
        for j in range(i+1, N+1):
            if k2 <= 0:
                return

            print(i, j)
            k2 -= 1

def main():
    N, K = map(int, input().split())
    f(N, K)
    



if __name__ == '__main__':
    main()

Solution (Python):
import itertools as it
n,k=map(int,input().split())
d=(n-1)*(n-2)//2-k
if d<0:
    print(-1)
    exit()
print(n-1+d)
for i in range(1,n):
    print(i,n)
p=[x for x in range(1,n)]
for a,b in it.combinations(p,2):
    if d == 0:
        break
    print(a,b)
    d-=1

Solution (Python):
N, K = map(int, input().split())

if K > (N - 1) * (N - 2) // 2 :
    print(-1)
else :
    t = (N - 1) * (N - 2) // 2 - K
    print(N + t - 1)
    for i in range(1, N) :
        print(i, N)

    i, j = 1, 2
    while t > 0 :
        print(i, j)
        
        j += 1
        if j == N :
            i, j = i + 1, i + 2
        t -= 1

Solution (Python):
from math import sqrt, factorial
from fractions import gcd
from sys import setrecursionlimit
from itertools import combinations
from string import ascii_lowercase as abc
from operator import itemgetter
setrecursionlimit(10000000)

def inpl(): return list(map(int, input().split()))
N, K = inpl()
if K > (N-1)*(N-2)//2:
    print(-1)
else:
    ans = ["{} {}".format(i, N) for i in range(1, N)]
    cnt = (N-1)*(N-2)//2
    for a, b in combinations(range(1, N), r=2):
        if cnt == K:
            break
        else:
            ans.append("{} {}".format(a, b))
            cnt -= 1
    print(len(ans))
    print(*ans, sep="\n")

Solution (Python):
n, k = map(int, raw_input().split())

s = (n - 1) * (n - 2) / 2

if k > s:
    print -1
    exit(0)

ans = []
for i in xrange(2, n + 1):
    ans.append([1, i])

for i in xrange(2, n + 1):
    for j in xrange(2, i):
        if s > k:
            s -= 1
            ans.append([i, j])
print len(ans)
for x in ans:
    print x[0], x[1]

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict
import itertools

n, k = LI()
graph = [[] for i in range(n)]
kumis = list(itertools.combinations(list(range(2, n+1)), 2))
m = (n-1) * (n-2) // 2

if m < k:
    print(-1)
else:
    print(m - k + n - 1)
    for i in range(n+1):
        if i in (0, 1):
            continue
        else:
            print(1, i)
    for i in range(m - k):
        print(kumis[i][0], kumis[i][1])

Solution (Python):
def main():
     n,k=map(int,input().split())
     if n*(n-1)//2-k<n-1:
          print(-1)
     else:
          cnt=0
          lim=int(n*(n-1)/2-k)
          print(lim)
          for i in range(1,n):
               if cnt==lim:
                    break
               for j in range(i+1,n+1):
                    print(i,j)
                    cnt+=1
                    if cnt==lim:
                         break
     
if __name__=='__main__':
     main()

Solution (Python):
[N,K] = list(map(int,input().split()))

if K>(N-1)*(N-2)/2:
    output =-1
    print(output)
else:
    output = []
    for i in range(2,N+1):
        output.append([1,i])
    count = int((N-1)*(N-2)/2)
    small = 2
    large = 3
    while (count!=K)and(count>0):
        output.append([small,large])
        count += -1
        large += 1
        if large > N:
            small += 1
            large = small+1

    print(len(output))
    for i in range(len(output)):
        print("{0} {1}".format(output[i][0], output[i][1]))

Solution (Python):
N, K = [int(elem) for elem in input().split()]

if K > (N - 2) * (N - 1) // 2:
    print(-1)
    exit(0)

num_edges_to_delete = K
available_edges = N * (N - 1) // 2 - K

center_node = N
trivial_edges = [(i, j) for i in range(1, N) for j in range(i + 1, N)]

print(available_edges)
for u, v in trivial_edges[num_edges_to_delete:]:
    print(u, v)

for u in range(1, N):
    print(u, center_node)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
from sys import exit
n, k = getList()

if k > (n-1) * (n-2) // 2:
    print(-1)
    exit()

if k <= n:
    var = []
    for i in range(1, n):
        for j in range(i+1, n+1):
            var.append((i, j))

    for i in range(1, k+1):
        try:
            var.remove((i, i+1))
        except:
            pass

    if k == n:
        var.remove((1, n))

    print(len(var))
    for v in var:
        print(v[0], v[1])
    exit()


def build_hub(lis, hub):
    for l in lis:
        print(l, hub)

def kanzen(beg, end):
    for i in range(beg, end):
        for j in range(i+1, end+1):
            print(i, j)


rui = []
for i in range(1, n):
    rui.append(i*(i-1)//2)


for i, ru in enumerate(rui):
    if k <= ru:
        use_hub = i + 1
        already = ru
        break

rem_var = n - use_hub


ans_num = (use_hub * rem_var) + (rem_var * (rem_var-1) // 2) + (ru - k)
print(ans_num)

for i in range(rem_var):
    build_hub(range(1, use_hub+1), n-i)

kanzen(use_hub+1, n)

for i in range(ru-k):
    print(i+1, i+2)

"""
1,3,6,10,15,21,,,
"""

Solution (Python):
import itertools
n, k=map(int, input().split())
benchmark=((n-1)*(n-2))//2
seq=[]
for i in range(n-1):
    seq.append(i+2)

if k<=benchmark:
    m=(n-1)+(benchmark-k)
    count=benchmark-k
    print(m)
    for i in range(n-1):
        print("1 {}".format(i+2))
    combi_list=list(itertools.combinations(seq, 2))
    for i in range(count):
        print("{} {}".format(combi_list[i][0], combi_list[i][1]))

else:
    print(-1)

Solution (Python):
import itertools
N, K = map(int, input().split())
if K > (N-1)*(N-2)//2:
    print(-1)
else:
    print(N-1+(N-1)*(N-2)//2-K)
    for i in range(N-1):
        print(i+1, N)
    A = list(itertools.combinations(range(1,N),2))
    for i in range((N-1)*(N-2)//2-K):
        print(*A[i])

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K = MAP()
    M = (N - 1)*(N - 2)/2
    if K > M:
        print(-1)
        exit()
    ng =  N * (N - 1)/2 - K
    print(int(ng))
    count = 0
    for i in range(1, N):
        for j in range(i+1, N + 1):
            print(i, j)
            count += 1
            if count == ng:
                exit()

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

n, k = map(int, input().split())

if (n-2) * (n - 1) // 2 < k:
    print(-1)
else:
    graph = list(itertools.combinations(list(range(1, n + 1)), 2))
    idx = (n - 1) + (n-2) * (n - 1) // 2 - k
    print(idx)
    for i in range(idx):
        print(graph[i][0], graph[i][1])

Solution (Python):
import math


def main():
  n, k = map(int, input().split())

  if n == 2:
    if k == 0:
      print(1)
      print(1, 2)
    else:
      print(-1)

    return

  v = math.factorial(n - 1) // math.factorial(n - 3) // 2

  if k > v:
    print(-1)
    return

  nodes = [(0, i) for i in range(1, n)]
  s = 1
  d = 2

  while v > k:
    nodes.append((s, d))
    d += 1
    v -= 1

    if d == n:
      s += 1
      d = s + 1

  print(len(nodes))

  for s, d in nodes:
    print(s + 1, d + 1)


if __name__ == '__main__':
  main()

Solution (Python):
import itertools

N, K = map(int, raw_input().split())

def foo(N, K):
    
    if K > (N-1)*(N-2)/2:
        print -1
        return
    edges = [(1, j) for j in range(2, N+1)]
    count = (N-1)*(N-2)/2
    it = itertools.combinations(range(2, N+1), 2)

    while count > K:
        edges.append(next(it))
        count -= 1
    print len(edges)
    for i, j in edges:
        print i, j

foo(N, K)

Solution (Python):
N,K = map(int,input().split())
A = int((N-1)*(N-2)//2)
if K > A:
    print(-1)
else:
    R = A - K
    Edge = []
    M = N-1+R
    for i in range(N-1):
        Edge.append([i+1,N])
    count = 0
    c = 0
    while(count < R):
        a = int(c//N + 1)
        b = c % N +1
        c += 1
        if a <= b:
            continue
        Edge.append([a,b])
        count += 1
    print(M)
    for edge in Edge:
        print(edge[0],edge[1])