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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
#include<bits/stdc++.h>

using namespace std;
int n,x,i,dl,position,jedynki,k;
int tab[200][2];
bool poz[50];
int main ()
{
    ios_base::sync_with_stdio(false);
    cin>>k;
    position=k;
    while (position>0)
    {
        dl++;
        if (position%2==1)
        {
            poz[dl]=true;
            jedynki++;
        }
        position/=2;
    }
    //cout<<"jedynki="<<jedynki<<'\n';
    //cout<<"dl="<<dl<<'\n';
    if (k==1)
    {
        tab[1][0]=2;
        tab[1][1]=-1;
        x=2;
    }
    else
    {

        tab[1][0]=2;
        tab[2][0]=3;
        tab[2][1]=4;
        x=3;
        for (i=3;i<=dl;i++)
        {
            tab[x][0]=x+2;
            tab[x][1]=x+3;
            tab[x+1][0]=x+2;
            tab[x+1][1]=x+3;
            x+=2;
        }
        x+=2;
        tab[1][1]=x;
        //cout<<"x="<<x<<'\n';
        position=dl-1;

        while (poz[position]==false && position>0)
        {
            position--;
        }
        if (poz[position]==true)
        {
            tab[x][0]=x+1;
            tab[x][1]=x+2;
            tab[x+1][0]=2*(dl-position)+1;
            x++;
            position--;
        }

        while (position>0)
        {
            while (poz[position]==false && position>0)
            {
                position--;
            }
            if (position<=0)
            {
                break;
            }
            if (tab[x][1]==0)
            {
                tab[x][1]=2*(dl-position)+1;
            }
            else
            {
                tab[x+1][0]=x+2;
                tab[x+1][1]=x+3;
                x+=2;
                tab[x][0]=2*(dl-position)+1;
            }
            position--;
        }
        x+=2;
        tab[2*dl][0]=x;
        tab[2*dl-1][0]=x;
    }
    cout<<x<<'\n';
    for (i=1;i<=x;i++)
    {
        if (tab[i][0]==0)
        {
            tab[i][0]=-1;
        }
        if (tab[i][1]==0)
        {
            tab[i][1]=-1;
        }
        cout<<tab[i][0]<<" "<<tab[i][1]<<'\n';
    }
    return 0;
}