#include <iostream>
#include <vector>
#include <cassert>
#include <cstdlib>

using namespace std;

long int randNumber ( long int min, long int max ){
  if (max==min) return min;
  long int toReturn = lrand48()%(max-min+1) + min;
  return toReturn;
}

vector<long int> differentRandNumbers ( uint total, long int min, long int max ){
  vector<long int> toReturn;
  if (total==0) return toReturn;
  
  assert(max>min);

  vector<long int> available(max-min+1);
  for (uint i=0;i<available.size();i++) available[i]=min+i;   

  uint left = total;

  while (toReturn.size()<total){
    long int n = randNumber(1,max-min+1);
    long int nAvailableFound=0;

    for (uint i=0;i<available.size();i++){
      if (available[i]!=-1) nAvailableFound++;
      if (nAvailableFound==n){
	toReturn.push_back(available[i]);      
	available[i]=-1;
	left--;
	break;
      }
    }
  }

  return toReturn;
}

int main ( int argc, char **argv ){

  if (argc!=5){
    cout << "Syntax is:" << endl << argv[0] << " nCars nSlots nBrands nAttributes" << endl;
    exit(1);
  }
  
  int nCars = atoi(argv[1]);
  int nSlots = atoi(argv[2]);
  int nBrands = atoi(argv[3]);
  int nAttributes = atoi(argv[4]);
  
  if (nCars>nSlots) {
    cout << "nSlots should be greater than nCars" << endl;
    exit(1);
  }
  if (nAttributes<=1){
    cout << "nAttributes should be greater than 1" << endl;
    exit(1);
  }
  
  cout << nCars << " " << nSlots << " " << nBrands << " " << nAttributes << " 0" << endl;
  srand48((unsigned)time(0)); 
  for (int i=1;i<=nCars;i++){

    long int brand = randNumber(1,nBrands);

    long int best = randNumber(1,nAttributes);
    long int worst = randNumber(1,nAttributes);
    while (worst==best) worst = randNumber(1,nAttributes);

    long int lengthList = randNumber(0,nSlots/5);
    vector<long int> forbiddenSlots = differentRandNumbers(lengthList,1,nSlots);

    cout << brand << " " << best << " " << worst << " ";
    for (uint i=0;i<forbiddenSlots.size();i++) cout << forbiddenSlots[i] << " ";
    cout << 0 << endl;

  }

}
