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 (GCC 5.4.1) (judge verdict: Accepted)

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

int can (i32 n, i32 k, i32 *a) {
  i32 p = n * (n + 1) / 2 / k;
  i32 i,j;
  for (i = 1; i <= n; ++i) a[i] = i;
  i32 d = 1;
  for (i = n; i >= 1; --i) {
    if (a[i] <= 0) continue;
    i32 sum = i;
    a[i] = -d;
    for (j = i - 1; j >= 1 && sum < p; --j) {
      if (a[j] <= 0) continue;
      if (j + sum <= p) {
	sum += j;
	a[j] = -d;
      }
    }
    if (sum < p) return 0;
    d++;
  }
  return 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 sum = n * (n + 1) / 2;
  i32 *a = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 k = 2; k <= sum; ++k) {
    if (sum % k != 0) continue;
    if (can (n, k, a)) {
      break;
    }
  }
  i32 i, j;
  i32 cnt = 0;
  for (i = 1; i <= n; ++i) {
    for (j = i + 1; j <= n; ++j) {
      if (a[i] != a[j]) {
	cnt++;
      }
    }
  }
  printf("%" PRIi32 "\n", cnt);
  for (i = 1; i <= n; ++i) {
    for (j = i + 1; j <= n; ++j) {
      if (a[i] != a[j]) {
	printf("%" PRIi32 " %" PRIi32 "\n", i, j);
      }
    }
  }
}

int main (void) {
  run ();
  return 0;
}