#define PROBLEM_NAME "intset"
#define TEST_STR "%03d"
#include "gentools.h"

#include <cstring>
#include <set>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <functional>
#include <algorithm>

#ifdef WIN32
#define INT64 "%I64d"
#else
#define INT64 "%lld"
#endif

#ifdef DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif


using namespace std;

const int MAXN = 1000000;
int n, l, m;

void do_nothing (void) {
}

void open_test (void) {
  n = l = m = -1;
}

void close_test (void) {
}

void log_test (void) {
  //fprintf (flog, "n = %d", n);
}

void shuffle_test (void) {
  do_nothing ();
}

void verify_test (void) {
  assert (n <= MAXN);
  assert (m >= 1 && l >= 1);
  assert (m <= n && l <= n);
}

void output_test (void) {
  ofstream o (cur_test_str);
  o << n << " " << l << " " << m << endl;
}

void gen_random (int n, int seed) {
  START_TEST ("gen_random(n:%d, seed:%d)", n, seed);
  ::n = n;
  l = rndvalue (1, n);
  m = rndvalue (1, n);
  END_TEST ();
}

void test (int n, int l, int m, string s = "") {
  START_TEST ("n = %d, l = %d, m = %d. %s", n, l, m, s.c_str ());
  ::n = n;
  ::l = l;
  ::m = m;
  END_TEST ();
}

void gen_samples (void) {
  test (4, 1, 2, "first example");
}

void gen_small (void) {
  int t;
  for (t = 1; t <= 3; t++) {
    gen_random (20, t);
  }
  for (t = 1; t <= 3; t++) {
    gen_random (100, 10+t);
  }
}

void gen_medium () {
  int t;
  for (t = 1; t <= 5; t++) {
    gen_random (1000, 20+t);
  }
  for (t = 1; t <= 3; t++) {
    gen_random (10000, 30+t);
  }
  test (65536, 128, 1024);

  for (t = 1; t <= 3; t++) {
    gen_random (100000, 30+t);
  }
}

void gen_large (void) {
  int t;

  for (t = 1; t <= 5; t++) {
    gen_random (MAXN, 3000+t);
  }
  
  test (1000000, 1, 500000, "P{k==0} = 1/2");
  test (1000000, 1000000, 1000000, "P{k==MAXN} = 1.0");
  test (1000000, 64940, 503611, "Vasya wins with probability <= 0.5 + 5e-6");
  test (1000000, 992072, 994136, "max answer from stress2 selection");
  test (1000000, 3184, 23659, "min answer from stress2 selection");
}

void stress (void) {
  for (int n = 1; n <= 10; n++) {
    for (int l = 1; l <= n; l++) {
      for (int m = l; m <= n; m++) {
        test (n, l, m);
      }
    }
  }
}

void stress2 (void) {
  for (int t = 1; t <= 999; t++) {
    gen_random (MAXN, t);
  }
}

int main (int argc, char * argv []) {
  init_gen (argc, argv);
  //stress2 ();
  gen_samples ();
  gen_small ();
  gen_medium ();
  gen_large ();
  
  exit_gen ();

  return 0;
}
