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: Runtime Error)

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 105;
const int oo = 1e9 + 5;

bool edge[N][N];
int sum[N];

void solve() {
	int n;
	cin >> n;
	for (int i = n - 1; i >= 2 - (n & 1); --i) {
		sum[i] += n;
		sum[n] += i;
		edge[i][n] = 1;
		edge[n][i] = 1;
	}
	for (int i = n-1; i >= 1; --i) {
		//sum[i] == sum[i+1]
		for (int j = n; j >= 1; --j) {
			if (i == j) continue;
			if (!edge[i][j] && sum[n] - sum[i] >= j && sum[j] + i <= sum[n]) {
				
				edge[i][j] = 1;
				edge[j][i] = 1;
				sum[i] += j;
				sum[j] += i;
				/**if (sum[j] > sum[n]) {
					show(sum[j]);
					show(i);
					show(j);
				}**/
			}		
		}
	}
	for (int i = 1; i <= n; ++i) {
		assert(sum[i] == sum[n]);
		/**if (sum[i] != sum[n]) {
			show(i);
			show(sum[i]);
		}**/
	}
	int cnt = 0;
	for (int i = 1; i < n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if (edge[i][j]) ++cnt;
		}
	}
	cout << cnt << '\n';
	for (int i = 1; i < n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			if (edge[i][j]) {
				cout << i <<' '<< j << '\n';
			}
		}
	}
}

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	while (tt --) {
		solve();
	}
	return 0;
}
/*
	If you only do what you can do, 
	You will never be more than you are now!
*/