Under construction

Still being built. Things may change

△

Interview

Time limit1sMemory limit1024 MB

Summary
Given N, build a tree on N vertices that minimizes the sum of distances over all vertex pairs, then print that minimum and the edges.
Level

Easy3 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Given a tree with NN vertices, build a tree that minimizes the sum of distances between all pairs of vertices. The vertices are numbered from 11 to NN.

That is, the tree should minimize ∑1≤i<j≤Ndist(i,j)\sum_{1 \leq i < j \leq N} \textrm{dist}(i, j), where dist(i,j)\textrm{dist}(i, j) is the distance between vertices ii and jj.

Input

The first line contains the number of vertices NN. (2≤N≤100 0002 \leq N \leq 100\,000)

Output

On the first line, print the minimum possible sum of distances between all pairs of vertices.

From the second line, print N−1N-1 lines describing the edges of the tree. Each line contains the two vertex numbers connected by an edge, separated by a space. If several trees satisfy the condition, print any one of them.

Examples1

  1. Example 1

    Input
    3
    
    Expected output
    4
    2 1
    1 3