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 in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;

namespace abc131_e
{
    class Program
    {
        static void Main(string[] args)
        {
            var items = Console.ReadLine().Split(' ');
            // 頂点数
            var n = int.Parse(items[0]);
            // 長さ2のペア
            var k = int.Parse(items[1]);

            // a_b   :aとbは長さ1
            // a_._b :aとbは長さ2
            // つまり、こんな感じのグラフになる
            // .        1 0 0
            // ._.      2 0 1
            // ./_.     3 1 2
            // .//_.    4 3 3
            // ./_/_.   5 4
            // .//_._.  5 4
            // .///_.   5 6 4
            // .///_.   i+1 i-1+i-2+...+2+1 i

            // すべての頂点を一直線に連結する
            var lines = new List<line>();
            lines.Add(new line { u = 1, v = 2 });
            for (int p = 2; p < n; p++)
            {
                lines.Add(new line { u = p, v = p + 1 });
            }
            // kは辺の数-1。この時のkが最小
            var kk = lines.Count - 1;

            // 辺を付け替えて、kを調整する
            var star = new List<line>();
            while (kk < k && lines.Count > 0)
            {
                // 末尾の辺を1に付け替える
                var line = lines[lines.Count - 1];
                lines.Remove(line);
                line.u = 1;
                star.Add(line);
                // 末尾の辺が減ったので、kも1減る
                kk -= 1;
                // 1に辺が増えたので、1に連結している点の数-1増える(1-2のみlにいることに注意)
                kk += star.Count;
            }
            lines.AddRange(star);

            var m = kk != k ? -1 : lines.Count;
            Console.WriteLine($"{m}");
            for (int i = 0; i < m; i++)
            {
                Console.WriteLine($"{lines[i].u} {lines[i].v}");
            }
        }
    }
    struct line
    {
        public int u;
        public int v;
    }
}