// random test case generator. The lenght of the intervals is either 1 or 2 with equal probability if tiny_intervals is true,
// otherwise it is geometrically distributed with parameter p. (i.e biased towards shorter intervals - the smaller p is, the more biased it is)

#include <iostream>
#include <random>
#include <cstdlib>
#include <cassert>
#include <set>

using namespace std;

int main(int argc, char *argv[]) {
    int N, seed, tiny_intervals;
    double p;
    assert(argc == 5);
    N = atoi(argv[1]);
    tiny_intervals = (atoi(argv[2]));
    p = atof(argv[3]);
    seed = atoi(argv[4]);

    mt19937 engine(seed);
    uniform_int_distribution<int> dist1(0, 2*N-2);

    set<pair<int,int> > pairs;
    
    cout << N << endl;
    for (int i = 0; i < N; i++) {
      int l, r;
      do {
        l = dist1(engine);
        if(tiny_intervals){
          if(dist1(engine) % 2 == 0 || l == 2*N-2) {
            r = l + 1;
          } else {
              r = l + 2;
          }
        }
        else{
            geometric_distribution<int> dist2(p);
            r = dist2(engine) + l +1;
        }
      }
      while (r >= 2*N || pairs.count({l, r}) > 0);
      pairs.insert({l, r});
      cout << l << " " << r << endl;
    }

    return 0;
}