#include <iostream>
#include <string>

using namespace std;

#define PRINT(arg)  #arg "=" << arg << ", "
#define PRINTN(arg)  #arg "=" << arg << endl

#define CINE(arg)  { cin >> arg; if (!cin) { cerr << "CINE failed reading var >" #arg "< in file >" __FILE__ "< at line >" << __LINE__ << "<."  << endl; exit(2);}}

#define CINE3(a,b,c) CINE(a);CINE(b);CINE(c)
#define CINE4(a,b,c,d) CINE(a);CINE(b);CINE(c);CINE(d)

#define CINE8(a,b,c,d,e,f,g,h) CINE(a);CINE(b);CINE(c);CINE(d);CINE(e);CINE(f);CINE(g);CINE(h)


#define GETLINE(string)  { getline(cin,string); if (!cin) { cerr << "GETLINE failed reading string " #string  << " in file " __FILE__ " at line " << __LINE__  << endl; exit(1);}}


//#define NEWA(var,type,size) {  e=1; }

//#define NEWA(var,type,size) { if(0==(var=new type [(size)])) e=1; }

#define NEWA(var,type,size) { try  { if(0==(var=new type [(size)])) throw;} catch (...)  { cerr << "NEWA failed on " #var "=new " #type "[" #size "=" << (size) << "]" << endl; exit(1); }}



int read2(char * const buffer,const int len) { 
  cin.read(buffer,len); 
  if (!cin) { 
    cerr << "READ failed reading cin at position " << cin.tellg() 
	 << " into buffer with len=" << len;
    return 0;
  } 
  if (cin.gcount()!=len) { 
    cerr << "READ returned only " << cin.gcount() 
	 << " chars when reading cin at position " << cin.tellg() 
	 << " into buffer with len=" << len;
    return 0;
  }
  return 1;
}


void die(const char *msg)
{	std::cerr << "ERROR: " << msg << endl;
 exit(1);
}

int print_env() {
  char *now;
  time_t secs;

  secs = time(NULL);
  now = ctime(&secs);
  cerr << "\n***** Starting at " << now << "*****" << endl;

  cerr << "File: " << __FILE__ << ", compiled: " << __DATE__ << ' ' 
       << __TIME__ << ", GNU compiler " << __GNUC__ << '.' << __GNUC_MINOR__;

#ifdef __GNUC_PATCHLEVEL__
  cerr   << '.' << __GNUC_PATCHLEVEL__;
#endif
  cerr << ", version " << __VERSION__ << ", "; 
#ifndef __OPTIMIZE__
  cerr << "NOT ";
#endif
  cerr << " optimized." << endl;
}
