1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>

using namespace std;

int v[120][2], S = 1;

void doubleNum()
{
  for (int i = 0; i < S; i++)
    for (int j = 0; j < 2; j++)
      if (v[i][j] == S - 1)
        v[i][j] = S + 1;

  v[S - 1][0] = v[0][0];
  v[S - 1][1] = v[0][1];
  v[S][0] = S - 1;
  v[0][0] = S - 1;
  v[0][1] = S;
  S += 2;
}

void incrementNum()
{
  for (int i = 0; i < S; i++)
    for (int j = 0; j < 2; j++)
      if (v[i][j] == S - 1)
        v[i][j] = S;

  v[S - 1][0] = v[0][0];
  v[S - 1][1] = v[0][1];
  v[0][0] = S - 1;
  v[0][1] = S;
  ++S;
}

void genDag(int num)
{
  /*if (num == 2)
  {
    v[0][0] = 1;
    v[0][1] = 2;
    v[1][0] = 2;
    S = 3;
    return;
  }
  if (num == 3)
  {
    v[0][0] = 1;
    v[0][1] = 2;
    v[1][0] = 2;
    v[1][1] = 3;
    v[2][0] = 3;
    S = 4;
    return;
  }*/
  if (num <= 1)
  {
    v[0][0] = 1;
    S = 2;
    return;
  }
  genDag(num / 2);
  doubleNum();
  if (num & 1)
    incrementNum();
}

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < 100; i++)
    v[i][0] = v[i][1] = -2;
  genDag(n);
  cout << S << '\n';
  for (int i = 0; i < S; i++)
    cout << v[i][0] + 1 << ' ' << v[i][1] + 1 << '\n';
}