Problem:
Score : 700 points

Problem Statement

You are given an integer N.
Build an undirected graph with N vertices with indices 1 to N that satisfies the following two conditions:

The graph is simple and connected.

There exists an integer S such that, for every vertex, the sum of the indices of the vertices adjacent to that vertex is S.

It can be proved that at least one such graph exists under the constraints of this problem.

Constraints

All values in input are integers.

3 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

In the first line, print the number of edges, M, in the graph you made. In the i-th of the following M lines, print two integers a_i and b_i, representing the endpoints of the i-th edge.

The output will be judged correct if the graph satisfies the conditions.

Sample Input 1

3

Sample Output 1

2
1 3
2 3

For every vertex, the sum of the indices of the vertices adjacent to that vertex is 3.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

///in the name of Allah the most beneficent the most merciful.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 998244353
//#define mod2 20071027
//#define MOD 998244353
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=110, M=1000005;
ll n, a[N];
vector<pair<ll, ll>>edge;
bool ok(ll s)
{
    memz(a);
    edge.clear();
//    cout<<"s "<<s<<endl;
    for(ll i=n;i>=1;i--)
    {
        ll baki=s-a[i],doom=0;
//        cout<<"baki1 "<<baki<<endl;
        if(baki<0) return 0;
        vector<ll>v;
        for(ll j=1;baki>0 && j<i;j++)
        {
            if(baki>=j)
            {
                baki-=j;
                v.pb(j);
            }
            else
            {
                ll d = j-baki;
                doom = d;
                baki=0;
                v.pb(j);
                break;
            }
        }
//        cout<<"baki2 "<<baki<<endl;
        if(baki!=0) return 0;
        for(auto u:v)
        {
            if(u!=doom)
            {
                a[u]+=i;
                a[i]+=u;
                edge.pb({i,u});
            }
        }
    }
    return 1;
}
int main()
{

    in1(n);
    ll l = n, r = (n*(n-1))/2,f=0;
    for(ll s=r; s>=l;s--)
    {
        if(ok(s))
        {
            printf("%lld\n", (ll)edge.size());
            for(auto u:edge)
            {
                printf("%lld %lld\n", u.first, u.second);
            }
            return 0;
        }
    }
    return 0;
}
/*

*/