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

using namespace std;

int main(int argc, char *argv[]) {
  int N, seed;
  double p;
  assert(argc == 4);
  N = atoi(argv[1]); // may create slightly less than N intervals to avoid equal pairs
  p = atof(argv[2]); 
  seed = atoi(argv[3]);

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

  set<int> ls;

  while(ls.size() < N){
    ls.insert(dist1(engine)); 
  }

  cout << N << endl;
  for(int l : ls){
    int r;
    do {
      geometric_distribution<int> dist2(p);
      r = dist2(engine) + l + 1;
    } while (r >= 2*N);
    cout << l << " " << r << endl;
  }

  return 0;
}