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
#include <cstdio>

int main ()
{
  unsigned n;
  scanf ("%u", &n);
  int b = 0;
  int p = 0;
  int w = 0;
  for (unsigned m=n; m>0; m/=2)
  {
    b ++;
    p += m%2;
    w += b>1? 2: 1;
  }
  w += p;
  printf ("%i\n", w);
  if (!n) return 0;
  for (int i=0, j=0; i<b-1; i++) if ((n>>i)%2)
  printf ("%i %i\n"               , p+2*i+1        , ++j+1           );
  printf ("%i %i\n"               , n>1? w-2: w    , n>1? w-1: -1    );
  for (int i=1; i<b; i++)
  printf ("%1$i %2$i\n%1$i %2$i\n", i>1? p+2*i-3: w, i>1? p+2*i-2: -1);
  printf ("%i %i\n"               , -1             , -1              );
  return 0;
}