#include <stdio.h>
#define ROADSTORE 50000000
/*
#define BITSWIDE  21
#define DEPTH     3
#define PERIOD    2
#define XMOVE     1
#define YMOVE     0
#define CLEARUP   -5
#define CLEARAT   1
#define BUFFERIGHT 4
#define NOSYM     1
#define EVENSYM   0
#define ODDSYM    0
#define FLIP      1
#define ASYMFORCE 0
#define ASYMROW   0
*/
#define MAXCONSTACK  16
#define MAXCPRSTACK  16
#define MAXPROSTACK  16
#define MAXDEPTH  20
#define MAXPERIOD 8
#define EXRIGHT   0
#define EXLEFT    0
#define FACTDEPTH 7
#define NUMFACTS  13
#define DN        ((PERIOD + 1)*NUMFACTS)
#define UP        (-DN)
#define UR        NUMFACTS
#define DL        (-UR)
#define RT        (DN + UR)
#define LT        (-RT)
 
main(argc, argv)
int argc;
char *argv[];
{
int BITSWIDE, DEPTH, PERIOD, XMOVE, YMOVE, CLEARUP, SLOWER, VERYSLOW;
int CLEARAT, BUFFERIGHT, NOSYM, EVENSYM, ODDSYM, FLIP, ASYMFORCE, ASYMROW;
int INTREE, TREEOUT, MEMCOMP, HYPEROW;
static char line[500], ljunk[10];
unsigned c, xscreen, yscreen;
unsigned r0, cr0, xr0, xr0loc, checkend, clearsum;
unsigned newval, oldval, valimit, valinc;
unsigned t0, t1, t2, t3, t4, t5;
unsigned firsttry, numtries, numtriesb, numhits, rownum, trownum, numprints;
unsigned noway3l, noway3r, noway0l, noway0r;
unsigned noway1l, noway1r, noway2l, noway2r;
unsigned gt1, gt2, lt2, lt1;
unsigned gt1l, gt1r, lt2l, lt2r;
unsigned gt1ll, gt1rr, lt2ll, lt2rr;
unsigned gt2l, gt2r, lt1l, lt1r;
unsigned nomid, nomidl, nomidr;
unsigned totnw4;
unsigned ostuff0, ostuff1, ostuff2, ostuff3, ostuff4, ostuff5, ostuff6;
unsigned contra, contries, contriesb, conmissq, conmissqb, contrits, contritsb, contramisses, contramissesb;
unsigned advtodo, props;
unsigned *forcntpnt;
unsigned *newfacts, *oldfacts, *noway, *sumnw;
unsigned *stackstat, *stackbase;
static unsigned statuses[(FACTDEPTH + 2)*(MAXPERIOD + 1)*NUMFACTS];
static unsigned factemplate[(MAXPERIOD + 1)*NUMFACTS];
static unsigned forbearcnt[1000];
unsigned no5wayn[32], no5wayt[32], nowayt[8], *no5way, anychange, mover, *make1;
unsigned make1_0r, make1_0l, make1_1r, make1_1l, make1_2r, make1_2l, make1_3r, make1_3l;
unsigned *rpt, *rpto;
struct roads {
  unsigned value;
  struct roads *parent;
  };
static struct roads allroads[ROADSTORE];
struct roads *onroad, *offroad, *nchild;
struct roads *ancestor, *tancestor, *firsthit;
struct forbears {
  struct roads *loc;
  unsigned rstuff[6*MAXPERIOD];
  unsigned facts[FACTDEPTH*(MAXPERIOD + 1)*NUMFACTS];
  unsigned checker;
  unsigned symmetric;
  unsigned lowper;
  unsigned prostack[3*MAXPROSTACK];
  unsigned protop;
  unsigned knockout;
  unsigned numdives;
  unsigned lastdive;
  unsigned numddives;
  unsigned constack[2*(MAXCONSTACK + 2)];
  unsigned contop;
  unsigned cprstack[3*MAXCPRSTACK];
  unsigned cprtop;
  };
static struct forbears cglist[MAXDEPTH + 2*MAXPERIOD + 1];
struct forbears *gpt, *glist, *cpt, *oldcpt, *tempcpt;
struct todostuff {
  unsigned *where;
  unsigned what;
  unsigned *status;
  };
static struct todostuff todolist[FACTDEPTH*(MAXPERIOD + 1)*NUMFACTS];
struct todostuff *todo;

numprints = 0;
NOSYM = 0;
EVENSYM = 0;
ODDSYM = 0;
BUFFERIGHT = 0;
DEPTH = 5;
XMOVE = 1;
YMOVE = 0;
PERIOD = 5;
SLOWER = 0;
VERYSLOW = 0;
BITSWIDE = 9;
CLEARUP = 0;
CLEARAT = 2;
FLIP = 0;
INTREE = 0;
TREEOUT = 0;
MEMCOMP = 0;
ASYMFORCE = 0;
ASYMROW = 0;
HYPEROW = 0;
if (argc > 1) while(--argc > 0) {
  if ((*++argv)[0] == '-')
    switch ((*argv)[1]) {
    case 'w':
      --argc;
      sscanf(*++argv, "%d", &BITSWIDE);
      break;
    case 'x':
      --argc;
      sscanf(*++argv, "%d", &XMOVE);
      break;
    case 'a':
      --argc;
      ASYMFORCE = 1;
      sscanf(*++argv, "%d", &ASYMROW);
      break;
    case 'h':
      --argc;
      sscanf(*++argv, "%d", &HYPEROW);
      break;
    case 'm':
      --argc;
      sscanf(*++argv, "%d", &MEMCOMP);
      break;
    case 'y':
      --argc;
      sscanf(*++argv, "%d", &YMOVE);
      break;
    case 'c':
      --argc;
      sscanf(*++argv, "%d", &CLEARUP);
      --argc;
      sscanf(*++argv, "%d", &CLEARAT);
      break;
    case 'p':
      --argc;
      sscanf(*++argv, "%d", &PERIOD);
      break;
    case 'd':
      --argc;
      sscanf(*++argv, "%d", &DEPTH);
      break;
    case 'b':
      --argc;
      sscanf(*++argv, "%d", &BUFFERIGHT);
      break;
    case 'n':
      if (!BUFFERIGHT) BUFFERIGHT = 8;
      NOSYM = 1;
      break;
    case 'e':
      EVENSYM = 1;
      break;
    case 'v':
      VERYSLOW = 1;
      break;
    case 'o':
      ODDSYM = 1;
      break;
    case 'f':
      if (!BUFFERIGHT) BUFFERIGHT = 8;
      FLIP = 1;
      NOSYM = 1;
      break;
    case 'i':
      INTREE = 1;
      break;
    case 't':
      TREEOUT = 1;
      break;
    }
  }
else {
  printf("\n");
  printf("Welcome to knight2.\n");
  printf("\n");
  printf("This program searches for spaceships in Conway's\n");
  printf("game of life.  It is named for its initial intention\n");
  printf("to search for a knightship, a ship that moves up 2 and\n");
  printf("over 1.  It turns out that I don't have the patience to\n");
  printf("wait the ~1 million hours of CPU time required to find one,\n");
  printf("but the program can still find a lot of neat things.\n");
  printf("The command line options to control the search are as follows:\n");
  printf("\n");
  printf("-p <PERIOD>   : This sets the number of generations to wait\n");
  printf("              : before checking for isomorphism to the original state.\n");
  printf("              : The maximum period is currently 8.\n");
  printf("\n");
  printf("-x <XMOVE>    : These parameters set the displacement of the initial\n");
  printf("-y <YMOVE>    : pattern for which to check isomorphism.  Since search\n");
  printf("              : time is a high exponential of WIDTH*(PERIOD - XMOVE)\n");
  printf("              : it is a good idea to place most (or all) of the movement\n");
  printf("              : in the XMOVE parameter.\n");
  printf("              : \n");
  printf("-v            : Note that in this version of knight2 XMOVE is inoperative\n");
  printf("              : and YMOVE can only be 0 or 1.  The XMOVE is now implicit\n");
  printf("              : in the period.  The XMOVE will normally be (PERIOD - 2)/2 if\n");
  printf("              : PERIOD is even, and (PERIOD - 3)/2 if PERIOD is odd.  If\n");
  printf("              : -v is asserted XMOVE will be (PERIOD - 4)/2 if PERIOD is\n");
  printf("              : even and behavior is undefined if PERIOD is odd.\n");
  printf("\n");
  printf("-w <BITSWIDE> : This sets the maximum width of the spaceships that will\n");
  printf("              : be searched for.  The program searches by trying to extend\n");
  printf("              : ships whose front parts meet the isomorphism criteria, and\n");
  printf("              : therefore the length of the ships found is essentially unlimited.\n");
  printf("\n");
  printf("-d <DEPTH>    : The search proceeds in a breadth first manner in the large\n");
  printf("              : sense.  For long searches this would require gigabytes of memory.\n");
  printf("              : This parameter sets the number of rows of valid extension of a\n");
  printf("              : prospective spaceship must be found before the first row of the\n");
  printf("              : extension is entered into the search tree.  This saves memory\n");
  printf("              : by reducing the number of entries into the search tree.  A depth\n");
  printf("              : of at least 4 is recommended.\n");
  printf("\n");
  printf("-c <CLEARUP> <CLEARAT> : These parameters control amount of the search tree that\n");
  printf("              : will be pruned when a complete ship is found.  If CLEARAT is 1\n");
  printf("              : pruning will be near the front of ship and CLEARUP should be 0\n");
  printf("              : or negative.  If CLEARAT is 0 pruning will be at the back of the\n");
  printf("              : ship and CLEARUP should be 0 or positive.  Otherwise CLEARAT asserts\n");
  printf("              : the fraction of the length of the ship that should be pruned.\n");
  printf("\n");
  printf("-e            : Search for spaceships with even symmetry.\n");
  printf("-o            : Search for spaceships with odd symmetry.\n");
  printf("-f            : Set the isomorphism check to match to the initial state flipped.\n");
  printf("-n            : Search for spaceships with no symmetry.  This is the only option\n");
  printf("              : that makes sense when YMOVE is nonzero.\n");
  printf("              : Only one of the previous four options should be used at a time.\n");
  printf("              : If none of the options are stated a type of odd symmetric ship\n");
  printf("              : with dead cells along the axis of symmetry are searched for.\n");
  printf("\n");
  printf("-b <BUFFERIGHT> : This sets the number of buffer bits to the right of the ship\n");
  printf("              : in the 32 bit word in which a row of the ship is stored.  This\n");
  printf("              : parameter is automatically set to a reasonable value.\n");
  printf("\n");
  printf("-a <ASYMROW>  : This sets the row by which assymetry is forced to occur.  This\n");
  printf("              : can be useful in guarantying asymmetry in flipper ships.\n");
  printf("\n");
  printf("-h <HYPEROW>  : This sets the row by which full period is forced to occur.  This\n");
  printf("              : is only currently useful when searching for period 6 ships.\n");
  printf("\n");
  printf("-m <MEMCOMP>  : This turns on a couple of memory compression algorithms.  If\n");
  printf("              : the 1 bit is set the search tree is compressed at the completion\n");
  printf("              : of each row.  If the 2 bit is set an algorithm that will result\n");
  printf("              : in the removal of small tags, some reconvergences, and flotillas\n");
  printf("              : is enabled.\n");
  printf("\n");
  printf("-t            : This option results in each row of the search tree database\n");
  printf("              : being printed to standard output as each row of the search is\n");
  printf("              : completed.  This is typically a lot of data.  When this option\n");
  printf("              : is chosen run the search in the background with the output piped\n");
  printf("              : to a file.  The more comprehensible aspects of the output can\n");
  printf("              : be picked off with -- grep -v N <outfile>.\n");
  printf("\n");
  printf("-i            : This option tells the program to expect to read in a partial\n");
  printf("              : search tree database on standard input.  This is useful for\n");
  printf("              : restarting interrupted searches.\n");
  printf("\n");
  printf("When complete spaceships are found they are printed to standard output in\n");
  printf("a format readable by Golly, Xlife, and Alan Hensel's life1.6 for DOS.  Since\n");
  printf("some statistics are printed out with a D line notifier, filtering them out with\n");
  printf("grep -v or findstr /v is required before viewing the resulting armada.  At\n");
  printf("the completion of a search the last incomplete spaceship is printed out.\n");
  printf("If this is undesired notepad, vi, or editing the last few lines of the source\n");
  printf("code is the solution.\n");
  printf("\n");
  printf("-Tim Coe      timcoe81@yahoo.com\n");
  printf("\n");
  printf("Press return to see the results of -- knight -o -p 4 -d 4 -c -44 1 -w 7: ");
  gets(line);
  ODDSYM = 1;
  PERIOD = 4;
  DEPTH = 4;
  CLEARUP = -44;
  CLEARAT = 1;
  BITSWIDE = 7;
  }

if (VERYSLOW) {
  PERIOD += 2;
  SLOWER = 1;
  }
if (PERIOD & 1) {
  PERIOD++;
  SLOWER = 1;
  }
forcntpnt = forbearcnt;
*forcntpnt = 0;
c = 1000;
while (c--) *forcntpnt++ = 0;
xscreen = 0;
yscreen = 0;
glist = cglist + DEPTH;
(glist + 2*PERIOD + 1)->symmetric = 1;
(glist + 2*PERIOD + 1)->lowper = 1;
gpt = glist;
while (gpt < glist + 2*PERIOD + 1) gpt++->loc = NULL;
firsttry = 1;
onroad = allroads;
onroad->value = 0;
onroad->parent = allroads;
/*
onroad++;
onroad->value = 0x008000;
onroad->parent = onroad - 1;
*/
rownum = onroad - allroads;
stackstat = statuses;
while (stackstat < statuses + 2*(PERIOD + 1)*NUMFACTS) *stackstat++ = 0;
while (stackstat < statuses + (FACTDEPTH + 1)*(PERIOD + 1)*NUMFACTS) *stackstat++ = 1;
while (stackstat < statuses + (FACTDEPTH + 2)*(PERIOD + 1)*NUMFACTS) *stackstat++ = 0;
stackbase = statuses + PERIOD*NUMFACTS + 2*(PERIOD + 1)*NUMFACTS;
while (stackbase < statuses + (FACTDEPTH + 1)*(PERIOD + 1)*NUMFACTS) {
  stackstat = stackbase;
  while (stackstat < stackbase + NUMFACTS) *stackstat++ = 0;
  stackbase += (PERIOD + 1)*NUMFACTS;
  }
stackbase = statuses + 2*(PERIOD + 1)*NUMFACTS;
while (stackbase < statuses + (FACTDEPTH + 1)*(PERIOD + 1)*NUMFACTS) {
  stackbase[10] = 2;
  stackbase += (PERIOD + 1)*NUMFACTS;
  }
stackbase = statuses + (PERIOD + 1)*NUMFACTS;
newfacts = factemplate;
t1 = ~(~0 << BUFFERIGHT);
t2 = -(1 << (BITSWIDE + BUFFERIGHT));
c = 8;
while (c--) nowayt[c] = 0;
c = 8;
while (c--) if (c & 2) nowayt[c] |= ~(((1 << BITSWIDE) - 1) << BUFFERIGHT);
c = 8;
while (c--) if (c & 1) nowayt[c] |= 0x1;
//c = 8;
//while (c--) printf("template %d %x\n", c, nowayt[c]);
anychange = 1;
while (anychange) {
  anychange = 0;
  c = 4;
  while (c--) {
    mover = (nowayt[2*c] & nowayt[2*c+1]) << 1;
    anychange |= mover & ~nowayt[c];
    anychange |= mover & ~nowayt[c+4];
    no5wayn[c] = nowayt[c] | mover;
    no5wayn[c+4] = nowayt[c+4] | mover;
    }
  c = 8;
  while (c--) nowayt[c] = no5wayn[c];
  }
anychange = 1;
while (anychange) {
  anychange = 0;
  c = 4;
  while (c--) {
    mover = (nowayt[c] & nowayt[c+4]) >> 1;
    anychange |= mover & ~nowayt[2*c];
    anychange |= mover & ~nowayt[2*c+1];
    no5wayn[2*c] = nowayt[2*c] | mover;
    no5wayn[2*c+1] = nowayt[2*c+1] | mover;
    }
  c = 8;
  while (c--) nowayt[c] = no5wayn[c];
  }
//c = 8;
//while (c--) printf("template %d %x\n", c, nowayt[c]);
c = 32;
while (c--) no5wayt[c] = 0;
c = 32;
while (c--) if (c & 4) no5wayt[c] |= ~(((1 << BITSWIDE) - 1) << BUFFERIGHT);
c = 32;
while (c--) if (c & 1) no5wayt[c] |= 3;
c = 32;
while (c--) if (c & 2) no5wayt[c] |= 1;
//c = 32;
//while (c--) printf("template %d %x\n", c, no5wayt[c]);
anychange = 1;
while (anychange) {
  anychange = 0;
  c = 16;
  while (c--) {
    mover = (no5wayt[2*c] & no5wayt[2*c+1]) << 1;
    anychange |= mover & ~no5wayt[c];
    anychange |= mover & ~no5wayt[c+16];
    no5wayn[c] = no5wayt[c] | mover;
    no5wayn[c+16] = no5wayt[c+16] | mover;
    }
  c = 32;
  while (c--) no5wayt[c] = no5wayn[c];
  }
anychange = 1;
while (anychange) {
  anychange = 0;
  c = 16;
  while (c--) {
    mover = (no5wayt[c] & no5wayt[c+16]) >> 1;
    anychange |= mover & ~no5wayt[2*c];
    anychange |= mover & ~no5wayt[2*c+1];
    no5wayn[2*c] = no5wayt[2*c] | mover;
    no5wayn[2*c+1] = no5wayt[2*c+1] | mover;
    }
  c = 32;
  while (c--) no5wayt[c] = no5wayn[c];
  }
//c = 32;
//while (c--) printf("template %d %x\n", c, no5wayt[c]);
//exit(0);
offroad = onroad + 1;
if (INTREE) while (gets(line) != NULL) {
  if ((line[1] == 'D') && (onroad != offroad)) {
    firsttry = 0;
    onroad = offroad;
    rownum++;
    oldfacts = glist->facts + (PERIOD + 1)*NUMFACTS;
    newfacts = glist->facts;
    while (oldfacts < glist->facts + FACTDEPTH*(PERIOD + 1)*NUMFACTS) *newfacts++ = *oldfacts++;
    oldfacts = factemplate;
    while (newfacts < glist->facts + FACTDEPTH*(PERIOD + 1)*NUMFACTS) *newfacts++ = *oldfacts++;
    }
  if (line[1] == 'N') {
    sscanf(line, "%s %x %d", ljunk, &t1, &t2);
    offroad->value = t1;
    offroad->parent = onroad - t2;
    if (offroad->parent < allroads) offroad->parent = allroads;
    offroad++;
    }
  if (line[1] == 'P') {
    sscanf(line, "%s %d %d\n", ljunk, &xscreen, &yscreen);
    if (NOSYM) xscreen += BITSWIDE + 6;
    else xscreen += 2*BITSWIDE + 6;
    if (xscreen > 300) {
      yscreen += rownum + 6;
      xscreen = 0;
      }
    }
  }
nchild = offroad;
while ((onroad < offroad) && (rownum < 1000)) {
  contramisses = 0;
  contramissesb = 0;
  contries = 0;
  contriesb = 0;
  conmissq = 0;
  conmissqb = 0;
  contrits = 0;
  contritsb = 0;
  numtries = 0;
  numtriesb = 0;
  numhits = 0;
  firsthit = onroad;
  while (onroad < offroad) {
    gpt = glist;
    gpt->loc = onroad;
    forcntpnt = forbearcnt;
    tancestor = allroads;
    while ((gpt->loc->parent != (gpt + 1)->loc) && (gpt < glist + 2*PERIOD)) {
      (*forcntpnt++)++;
      if ((gpt + 1)->loc != NULL) tancestor = (gpt + 1)->loc->parent;
      (gpt + 1)->loc = gpt->loc->parent;
      gpt++;
      if (gpt == glist + 2*PERIOD) {
        ancestor = gpt->loc->parent;
        while (ancestor != tancestor) {
          ancestor = ancestor->parent;
          tancestor = tancestor->parent;
          (*forcntpnt++)++;
          }
        }
      }
    while (gpt >= glist) {
      rpto = (gpt + PERIOD/2)->rstuff;
      rpt = gpt->rstuff;
      r0 = gpt->loc->value;
      t2 = r0;
      if (FLIP && !(((glist - gpt) + rownum) % (PERIOD/2))) {
        t1 = t2;
        t2 = 0;
        c = BITSWIDE;
        while (c--) {
          t2 <<= 1;
          t2 |= t1 & (1 << BUFFERIGHT);
          t1 >>= 1;
          }
        }
      gpt->checker = t2;
      if (YMOVE && !(((glist - gpt) + rownum) % (PERIOD/2))) gpt->checker <<= 1;
      if (!YMOVE && NOSYM && (gpt + 1)->symmetric) {
        t1 = r0;
        t2 = 0;
        c = BITSWIDE;
        while (c--) {
          t2 <<= 1;
          t2 |= (1 << BUFFERIGHT) & t1;
          t1 >>= 1;
          }
        if (t2 == r0) gpt->symmetric = 1;
        else gpt->symmetric = 0;
        }
      else gpt->symmetric = 0;
      make1 = gpt->facts;
      noway = gpt->facts + 8;
      no5way = gpt->facts + 12;
      while (rpt < gpt->rstuff + 6*2) {
//      while (rpt < gpt->rstuff + 6*PERIOD) {
        rpt[0] = r0;
        t1 = r0 >> 1;
        t2 = r0 << 1;
        if (ODDSYM) t2 |= t1 & 1;
        if (EVENSYM) t2 |= r0 & 1;
        t3 = t1 ^ t2;
        rpt[2] = (t1 & t2) ^ (r0 & t3);
        rpt[1] = r0 ^ t3;
        t1 = rpt[1] & rpto[1];
        rpt[3] = rpt[1] ^ rpto[1];
        t2 = rpt[2] & rpto[2];
        t3 = rpt[2] ^ rpto[2];
        rpt[5] = t2 ^ (t3 | t1);
        rpt[4] = ~(t3 ^ t1);
        r0 = (rpto[0] | (rpt[1] ^ rpto[3])) &
             (rpt[2] ^ rpto[4] ^ (rpt[1] | rpto[3])) &
             (rpto[5] ^ (rpt[2] & rpto[4]));
        make1[0] = ((rpt[0] & ~rpt[3] & rpt[4]) |
                    (rpt[3] & ~rpt[4])) & rpt[5];
        make1[1] = (rpt[0] | ~rpt[3]) & ~rpt[4] & rpt[5];
        make1[2] = (rpt[0] & ~rpt[3] & ~rpt[4] & rpt[5]) |
                   (rpt[3] & rpt[4] & ~rpt[5]);
        make1[3] = (rpt[0] | ~rpt[3]) & rpt[4] & ~rpt[5];
        make1 += 4;
        rpt += 6;
        rpto += 6;
        }
      if (HYPEROW && (gpt + 1)->lowper) {
        if (gpt >= (glist + 2*PERIOD - 1)) gpt->lowper = 1;
        else if (gpt->rstuff[6] == (gpt + 2)->rstuff[0]) gpt->lowper = 1;
        else gpt->lowper = 0;
        }
      else gpt->lowper = 0;
      make1 -= 4;
      r0 = (gpt + 1)->checker;
      noway[0] = make1[0] ^ r0;
      noway[1] = make1[1] ^ r0;
      noway[2] = make1[2] ^ r0;
      noway[3] = make1[3] ^ r0;
      if (firsttry && ((PERIOD < 6) || ((gpt > (glist + 0)) && ((PERIOD < 8) || !SLOWER)) || (gpt > (glist + 1)))) {
        noway[1] = ~0;
        noway[2] = ~0;
        noway[3] = ~0;
        }
//c = 4;
//if (firsttry && (gpt == glist)) while (c--) printf("noway %d %d %x\n", gpt - glist, c, noway[c]);
      make1 -= 4;
//c = 4;
//if (firsttry && (gpt == glist)) while (c--) printf("make1 %d %d %x\n", gpt - glist, c, make1[c]);
      if (SLOWER && (!(((glist - gpt) + rownum) % (PERIOD/2)) || (VERYSLOW && !(((glist - gpt) + rownum + 1) % (PERIOD/2))))) {
        noway -= 4;
        noway[0] = make1[0] ^ r0;
        noway[1] = make1[1] ^ r0;
        noway[2] = noway[1];
        noway[3] = make1[2] ^ r0;
        noway[4] = noway[1];
        noway[5] = noway[3];
        noway[6] = noway[3];
        noway[7] = make1[3] ^ r0;
        if (EVENSYM) {
          c = 8;
          while (c) {
            c -= 2;
            if (c & 2) {
              noway[c] = (noway[c] & 0xfffffffe) | (noway[c+1] & 1);
              }
            }
          }
        else if (ODDSYM) {
          c = 8;
          while (c) {
            c -= 2;
            if (c & 4) {
              noway[c] = (noway[c] & 0xfffffffe) | (noway[c+1] & 1);
              }
            }
          }
        c = 8;
        while (c--) noway[c] |= nowayt[c];
        }
      make1_0r = make1[0] << 1;
      make1_0l = make1[0] >> 1;
      make1_1r = make1[1] << 1;
      make1_1l = make1[1] >> 1;
      make1_2r = make1[2] << 1;
      make1_2l = make1[2] >> 1;
      make1_3r = make1[3] << 1;
      make1_3l = make1[3] >> 1;
      if (EVENSYM) {
        make1_0r |= make1[0] & 1;
        make1_1r |= make1[1] & 1;
        make1_2r |= make1[2] & 1;
        make1_3r |= make1[3] & 1;
        }
      else if (ODDSYM) {
        make1_0r |= make1_0l & 1;
        make1_1r |= make1_1l & 1;
        make1_2r |= make1_2l & 1;
        make1_3r |= make1_3l & 1;
        }
      no5way[ 0] = (noway[0] &  (~make1_0l & ~make1[0] & ~make1_0r)) |
                   (noway[1] & ((~make1_0l & ~make1[0] &  make1_0r) |
                                (~make1_0l &  make1[0] & ~make1_0r) |
                                ( make1_0l & ~make1[0] & ~make1_0r))) |
                   (noway[2] & (( make1_0l &  make1[0] & ~make1_0r) |
                                ( make1_0l & ~make1[0] &  make1_0r) |
                                (~make1_0l &  make1[0] &  make1_0r))) |
                   (noway[3] &  ( make1_0l &  make1[0] &  make1_0r));
      no5way[ 1] = (noway[0] &  (~make1_0l & ~make1[0] & ~make1_1r)) |
                   (noway[1] & ((~make1_0l & ~make1[0] &  make1_1r) |
                                (~make1_0l &  make1[0] & ~make1_1r) |
                                ( make1_0l & ~make1[0] & ~make1_1r))) |
                   (noway[2] & (( make1_0l &  make1[0] & ~make1_1r) |
                                ( make1_0l & ~make1[0] &  make1_1r) |
                                (~make1_0l &  make1[0] &  make1_1r))) |
                   (noway[3] &  ( make1_0l &  make1[0] &  make1_1r));
      no5way[ 2] = (noway[0] &  (~make1_0l & ~make1[1] & ~make1_1r)) |
                   (noway[1] & ((~make1_0l & ~make1[1] &  make1_1r) |
                                (~make1_0l &  make1[1] & ~make1_1r) |
                                ( make1_0l & ~make1[1] & ~make1_1r))) |
                   (noway[2] & (( make1_0l &  make1[1] & ~make1_1r) |
                                ( make1_0l & ~make1[1] &  make1_1r) |
                                (~make1_0l &  make1[1] &  make1_1r))) |
                   (noway[3] &  ( make1_0l &  make1[1] &  make1_1r));
      no5way[ 3] = (noway[0] &  (~make1_0l & ~make1[1] & ~make1_2r)) |
                   (noway[1] & ((~make1_0l & ~make1[1] &  make1_2r) |
                                (~make1_0l &  make1[1] & ~make1_2r) |
                                ( make1_0l & ~make1[1] & ~make1_2r))) |
                   (noway[2] & (( make1_0l &  make1[1] & ~make1_2r) |
                                ( make1_0l & ~make1[1] &  make1_2r) |
                                (~make1_0l &  make1[1] &  make1_2r))) |
                   (noway[3] &  ( make1_0l &  make1[1] &  make1_2r));
      no5way[ 4] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_1r)) |
                   (noway[1] & ((~make1_1l & ~make1[1] &  make1_1r) |
                                (~make1_1l &  make1[1] & ~make1_1r) |
                                ( make1_1l & ~make1[1] & ~make1_1r))) |
                   (noway[2] & (( make1_1l &  make1[1] & ~make1_1r) |
                                ( make1_1l & ~make1[1] &  make1_1r) |
                                (~make1_1l &  make1[1] &  make1_1r))) |
                   (noway[3] &  ( make1_1l &  make1[1] &  make1_1r));
      no5way[ 5] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_2r)) |
                   (noway[1] & ((~make1_1l & ~make1[1] &  make1_2r) |
                                (~make1_1l &  make1[1] & ~make1_2r) |
                                ( make1_1l & ~make1[1] & ~make1_2r))) |
                   (noway[2] & (( make1_1l &  make1[1] & ~make1_2r) |
                                ( make1_1l & ~make1[1] &  make1_2r) |
                                (~make1_1l &  make1[1] &  make1_2r))) |
                   (noway[3] &  ( make1_1l &  make1[1] &  make1_2r));
      no5way[ 6] = (noway[0] &  (~make1_1l & ~make1[2] & ~make1_2r)) |
                   (noway[1] & ((~make1_1l & ~make1[2] &  make1_2r) |
                                (~make1_1l &  make1[2] & ~make1_2r) |
                                ( make1_1l & ~make1[2] & ~make1_2r))) |
                   (noway[2] & (( make1_1l &  make1[2] & ~make1_2r) |
                                ( make1_1l & ~make1[2] &  make1_2r) |
                                (~make1_1l &  make1[2] &  make1_2r))) |
                   (noway[3] &  ( make1_1l &  make1[2] &  make1_2r));
      no5way[ 7] = (noway[0] &  (~make1_1l & ~make1[2] & ~make1_3r)) |
                   (noway[1] & ((~make1_1l & ~make1[2] &  make1_3r) |
                                (~make1_1l &  make1[2] & ~make1_3r) |
                                ( make1_1l & ~make1[2] & ~make1_3r))) |
                   (noway[2] & (( make1_1l &  make1[2] & ~make1_3r) |
                                ( make1_1l & ~make1[2] &  make1_3r) |
                                (~make1_1l &  make1[2] &  make1_3r))) |
                   (noway[3] &  ( make1_1l &  make1[2] &  make1_3r));
      no5way[ 8] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_0r)) |
                   (noway[1] & ((~make1_1l & ~make1[1] &  make1_0r) |
                                (~make1_1l &  make1[1] & ~make1_0r) |
                                ( make1_1l & ~make1[1] & ~make1_0r))) |
                   (noway[2] & (( make1_1l &  make1[1] & ~make1_0r) |
                                ( make1_1l & ~make1[1] &  make1_0r) |
                                (~make1_1l &  make1[1] &  make1_0r))) |
                   (noway[3] &  ( make1_1l &  make1[1] &  make1_0r));
      no5way[ 9] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_1r)) |
                   (noway[1] & ((~make1_1l & ~make1[1] &  make1_1r) |
                                (~make1_1l &  make1[1] & ~make1_1r) |
                                ( make1_1l & ~make1[1] & ~make1_1r))) |
                   (noway[2] & (( make1_1l &  make1[1] & ~make1_1r) |
                                ( make1_1l & ~make1[1] &  make1_1r) |
                                (~make1_1l &  make1[1] &  make1_1r))) |
                   (noway[3] &  ( make1_1l &  make1[1] &  make1_1r));
      no5way[10] = (noway[0] &  (~make1_1l & ~make1[2] & ~make1_1r)) |
                   (noway[1] & ((~make1_1l & ~make1[2] &  make1_1r) |
                                (~make1_1l &  make1[2] & ~make1_1r) |
                                ( make1_1l & ~make1[2] & ~make1_1r))) |
                   (noway[2] & (( make1_1l &  make1[2] & ~make1_1r) |
                                ( make1_1l & ~make1[2] &  make1_1r) |
                                (~make1_1l &  make1[2] &  make1_1r))) |
                   (noway[3] &  ( make1_1l &  make1[2] &  make1_1r));
      no5way[11] = (noway[0] &  (~make1_1l & ~make1[2] & ~make1_2r)) |
                   (noway[1] & ((~make1_1l & ~make1[2] &  make1_2r) |
                                (~make1_1l &  make1[2] & ~make1_2r) |
                                ( make1_1l & ~make1[2] & ~make1_2r))) |
                   (noway[2] & (( make1_1l &  make1[2] & ~make1_2r) |
                                ( make1_1l & ~make1[2] &  make1_2r) |
                                (~make1_1l &  make1[2] &  make1_2r))) |
                   (noway[3] &  ( make1_1l &  make1[2] &  make1_2r));
      no5way[12] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_1r)) |
                   (noway[1] & ((~make1_2l & ~make1[2] &  make1_1r) |
                                (~make1_2l &  make1[2] & ~make1_1r) |
                                ( make1_2l & ~make1[2] & ~make1_1r))) |
                   (noway[2] & (( make1_2l &  make1[2] & ~make1_1r) |
                                ( make1_2l & ~make1[2] &  make1_1r) |
                                (~make1_2l &  make1[2] &  make1_1r))) |
                   (noway[3] &  ( make1_2l &  make1[2] &  make1_1r));
      no5way[13] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_2r)) |
                   (noway[1] & ((~make1_2l & ~make1[2] &  make1_2r) |
                                (~make1_2l &  make1[2] & ~make1_2r) |
                                ( make1_2l & ~make1[2] & ~make1_2r))) |
                   (noway[2] & (( make1_2l &  make1[2] & ~make1_2r) |
                                ( make1_2l & ~make1[2] &  make1_2r) |
                                (~make1_2l &  make1[2] &  make1_2r))) |
                   (noway[3] &  ( make1_2l &  make1[2] &  make1_2r));
      no5way[14] = (noway[0] &  (~make1_2l & ~make1[3] & ~make1_2r)) |
                   (noway[1] & ((~make1_2l & ~make1[3] &  make1_2r) |
                                (~make1_2l &  make1[3] & ~make1_2r) |
                                ( make1_2l & ~make1[3] & ~make1_2r))) |
                   (noway[2] & (( make1_2l &  make1[3] & ~make1_2r) |
                                ( make1_2l & ~make1[3] &  make1_2r) |
                                (~make1_2l &  make1[3] &  make1_2r))) |
                   (noway[3] &  ( make1_2l &  make1[3] &  make1_2r));
      no5way[15] = (noway[0] &  (~make1_2l & ~make1[3] & ~make1_3r)) |
                   (noway[1] & ((~make1_2l & ~make1[3] &  make1_3r) |
                                (~make1_2l &  make1[3] & ~make1_3r) |
                                ( make1_2l & ~make1[3] & ~make1_3r))) |
                   (noway[2] & (( make1_2l &  make1[3] & ~make1_3r) |
                                ( make1_2l & ~make1[3] &  make1_3r) |
                                (~make1_2l &  make1[3] &  make1_3r))) |
                   (noway[3] &  ( make1_2l &  make1[3] &  make1_3r));
      no5way[16] = (noway[0] &  (~make1_1l & ~make1[0] & ~make1_0r)) |
                   (noway[1] & ((~make1_1l & ~make1[0] &  make1_0r) |
                                (~make1_1l &  make1[0] & ~make1_0r) |
                                ( make1_1l & ~make1[0] & ~make1_0r))) |
                   (noway[2] & (( make1_1l &  make1[0] & ~make1_0r) |
                                ( make1_1l & ~make1[0] &  make1_0r) |
                                (~make1_1l &  make1[0] &  make1_0r))) |
                   (noway[3] &  ( make1_1l &  make1[0] &  make1_0r));
      no5way[17] = (noway[0] &  (~make1_1l & ~make1[0] & ~make1_1r)) |
                   (noway[1] & ((~make1_1l & ~make1[0] &  make1_1r) |
                                (~make1_1l &  make1[0] & ~make1_1r) |
                                ( make1_1l & ~make1[0] & ~make1_1r))) |
                   (noway[2] & (( make1_1l &  make1[0] & ~make1_1r) |
                                ( make1_1l & ~make1[0] &  make1_1r) |
                                (~make1_1l &  make1[0] &  make1_1r))) |
                   (noway[3] &  ( make1_1l &  make1[0] &  make1_1r));
      no5way[18] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_1r)) |
                   (noway[1] & ((~make1_1l & ~make1[1] &  make1_1r) |
                                (~make1_1l &  make1[1] & ~make1_1r) |
                                ( make1_1l & ~make1[1] & ~make1_1r))) |
                   (noway[2] & (( make1_1l &  make1[1] & ~make1_1r) |
                                ( make1_1l & ~make1[1] &  make1_1r) |
                                (~make1_1l &  make1[1] &  make1_1r))) |
                   (noway[3] &  ( make1_1l &  make1[1] &  make1_1r));
      no5way[19] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_2r)) |
                   (noway[1] & ((~make1_1l & ~make1[1] &  make1_2r) |
                                (~make1_1l &  make1[1] & ~make1_2r) |
                                ( make1_1l & ~make1[1] & ~make1_2r))) |
                   (noway[2] & (( make1_1l &  make1[1] & ~make1_2r) |
                                ( make1_1l & ~make1[1] &  make1_2r) |
                                (~make1_1l &  make1[1] &  make1_2r))) |
                   (noway[3] &  ( make1_1l &  make1[1] &  make1_2r));
      no5way[20] = (noway[0] &  (~make1_2l & ~make1[1] & ~make1_1r)) |
                   (noway[1] & ((~make1_2l & ~make1[1] &  make1_1r) |
                                (~make1_2l &  make1[1] & ~make1_1r) |
                                ( make1_2l & ~make1[1] & ~make1_1r))) |
                   (noway[2] & (( make1_2l &  make1[1] & ~make1_1r) |
                                ( make1_2l & ~make1[1] &  make1_1r) |
                                (~make1_2l &  make1[1] &  make1_1r))) |
                   (noway[3] &  ( make1_2l &  make1[1] &  make1_1r));
      no5way[21] = (noway[0] &  (~make1_2l & ~make1[1] & ~make1_2r)) |
                   (noway[1] & ((~make1_2l & ~make1[1] &  make1_2r) |
                                (~make1_2l &  make1[1] & ~make1_2r) |
                                ( make1_2l & ~make1[1] & ~make1_2r))) |
                   (noway[2] & (( make1_2l &  make1[1] & ~make1_2r) |
                                ( make1_2l & ~make1[1] &  make1_2r) |
                                (~make1_2l &  make1[1] &  make1_2r))) |
                   (noway[3] &  ( make1_2l &  make1[1] &  make1_2r));
      no5way[22] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_2r)) |
                   (noway[1] & ((~make1_2l & ~make1[2] &  make1_2r) |
                                (~make1_2l &  make1[2] & ~make1_2r) |
                                ( make1_2l & ~make1[2] & ~make1_2r))) |
                   (noway[2] & (( make1_2l &  make1[2] & ~make1_2r) |
                                ( make1_2l & ~make1[2] &  make1_2r) |
                                (~make1_2l &  make1[2] &  make1_2r))) |
                   (noway[3] &  ( make1_2l &  make1[2] &  make1_2r));
      no5way[23] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_3r)) |
                   (noway[1] & ((~make1_2l & ~make1[2] &  make1_3r) |
                                (~make1_2l &  make1[2] & ~make1_3r) |
                                ( make1_2l & ~make1[2] & ~make1_3r))) |
                   (noway[2] & (( make1_2l &  make1[2] & ~make1_3r) |
                                ( make1_2l & ~make1[2] &  make1_3r) |
                                (~make1_2l &  make1[2] &  make1_3r))) |
                   (noway[3] &  ( make1_2l &  make1[2] &  make1_3r));
      no5way[24] = (noway[0] &  (~make1_2l & ~make1[1] & ~make1_0r)) |
                   (noway[1] & ((~make1_2l & ~make1[1] &  make1_0r) |
                                (~make1_2l &  make1[1] & ~make1_0r) |
                                ( make1_2l & ~make1[1] & ~make1_0r))) |
                   (noway[2] & (( make1_2l &  make1[1] & ~make1_0r) |
                                ( make1_2l & ~make1[1] &  make1_0r) |
                                (~make1_2l &  make1[1] &  make1_0r))) |
                   (noway[3] &  ( make1_2l &  make1[1] &  make1_0r));
      no5way[25] = (noway[0] &  (~make1_2l & ~make1[1] & ~make1_1r)) |
                   (noway[1] & ((~make1_2l & ~make1[1] &  make1_1r) |
                                (~make1_2l &  make1[1] & ~make1_1r) |
                                ( make1_2l & ~make1[1] & ~make1_1r))) |
                   (noway[2] & (( make1_2l &  make1[1] & ~make1_1r) |
                                ( make1_2l & ~make1[1] &  make1_1r) |
                                (~make1_2l &  make1[1] &  make1_1r))) |
                   (noway[3] &  ( make1_2l &  make1[1] &  make1_1r));
      no5way[26] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_1r)) |
                   (noway[1] & ((~make1_2l & ~make1[2] &  make1_1r) |
                                (~make1_2l &  make1[2] & ~make1_1r) |
                                ( make1_2l & ~make1[2] & ~make1_1r))) |
                   (noway[2] & (( make1_2l &  make1[2] & ~make1_1r) |
                                ( make1_2l & ~make1[2] &  make1_1r) |
                                (~make1_2l &  make1[2] &  make1_1r))) |
                   (noway[3] &  ( make1_2l &  make1[2] &  make1_1r));
      no5way[27] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_2r)) |
                   (noway[1] & ((~make1_2l & ~make1[2] &  make1_2r) |
                                (~make1_2l &  make1[2] & ~make1_2r) |
                                ( make1_2l & ~make1[2] & ~make1_2r))) |
                   (noway[2] & (( make1_2l &  make1[2] & ~make1_2r) |
                                ( make1_2l & ~make1[2] &  make1_2r) |
                                (~make1_2l &  make1[2] &  make1_2r))) |
                   (noway[3] &  ( make1_2l &  make1[2] &  make1_2r));
      no5way[28] = (noway[0] &  (~make1_3l & ~make1[2] & ~make1_1r)) |
                   (noway[1] & ((~make1_3l & ~make1[2] &  make1_1r) |
                                (~make1_3l &  make1[2] & ~make1_1r) |
                                ( make1_3l & ~make1[2] & ~make1_1r))) |
                   (noway[2] & (( make1_3l &  make1[2] & ~make1_1r) |
                                ( make1_3l & ~make1[2] &  make1_1r) |
                                (~make1_3l &  make1[2] &  make1_1r))) |
                   (noway[3] &  ( make1_3l &  make1[2] &  make1_1r));
      no5way[29] = (noway[0] &  (~make1_3l & ~make1[2] & ~make1_2r)) |
                   (noway[1] & ((~make1_3l & ~make1[2] &  make1_2r) |
                                (~make1_3l &  make1[2] & ~make1_2r) |
                                ( make1_3l & ~make1[2] & ~make1_2r))) |
                   (noway[2] & (( make1_3l &  make1[2] & ~make1_2r) |
                                ( make1_3l & ~make1[2] &  make1_2r) |
                                (~make1_3l &  make1[2] &  make1_2r))) |
                   (noway[3] &  ( make1_3l &  make1[2] &  make1_2r));
      no5way[30] = (noway[0] &  (~make1_3l & ~make1[3] & ~make1_2r)) |
                   (noway[1] & ((~make1_3l & ~make1[3] &  make1_2r) |
                                (~make1_3l &  make1[3] & ~make1_2r) |
                                ( make1_3l & ~make1[3] & ~make1_2r))) |
                   (noway[2] & (( make1_3l &  make1[3] & ~make1_2r) |
                                ( make1_3l & ~make1[3] &  make1_2r) |
                                (~make1_3l &  make1[3] &  make1_2r))) |
                   (noway[3] &  ( make1_3l &  make1[3] &  make1_2r));
      no5way[31] = (noway[0] &  (~make1_3l & ~make1[3] & ~make1_3r)) |
                   (noway[1] & ((~make1_3l & ~make1[3] &  make1_3r) |
                                (~make1_3l &  make1[3] & ~make1_3r) |
                                ( make1_3l & ~make1[3] & ~make1_3r))) |
                   (noway[2] & (( make1_3l &  make1[3] & ~make1_3r) |
                                ( make1_3l & ~make1[3] &  make1_3r) |
                                (~make1_3l &  make1[3] &  make1_3r))) |
                   (noway[3] &  ( make1_3l &  make1[3] &  make1_3r));
      if (EVENSYM) {
        c = 32;
        while (c) {
          c -= 2;
          if (c & 2) {
            no5way[c] = (no5way[c] & 0xfffffffd) | (no5way[c+1] & 2);
            }
          else if ((c & 0xc) == 4) {
            no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+2] & 1);
            }
          else if ((c & 0xc) == 8) {
            no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+1] & 1);
            }
          else if ((c & 0xc) == 0xc) {
            no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+3] & 1);
            }
          }
        }
      else if (ODDSYM) {
        c = 32;
        while (c) {
          c -= 2;
          if (c & 4) {
            no5way[c] = (no5way[c] & 0xfffffffd) | (no5way[c+1] & 2);
            }
          if ((c & 0x1b) == 8) {
            no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+2] & 1);
            }
          else if ((c & 0x1b) == 0x10) {
            no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+1] & 1);
            }
          else if ((c & 0x1b) == 0x18) {
            no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+3] & 1);
            }
          }
        }
      c = 32;
      while (c--) no5way[c] |= no5wayt[c];
      contra = ~0;
      c = 32;
      while (c--) contra &= no5way[c];
      anychange = 1;
      if (SLOWER && (!(((glist - gpt) + rownum) % (PERIOD/2)) || (VERYSLOW && !(((glist - gpt) + rownum + 1) % (PERIOD/2)))))
       while (anychange && !contra) {
        anychange = 0;
        contra = ~0;
        c = 4;
        while (c--) {
          mover = (noway[2*c] & noway[2*c+1]) << 1;
          anychange |= mover & ~noway[c];
          anychange |= mover & ~noway[c+4];
          no5wayn[c] = noway[c] | mover;
          no5wayn[c+4] = noway[c+4] | mover;
          contra &= no5wayn[c];
          contra &= no5wayn[c+4];
          }
        c = 8;
        while (c--) noway[c] = no5wayn[c];
        }
      else while (anychange && !contra) {
        anychange = 0;
        contra = ~0;
        c = 16;
        while (c--) {
          mover = (no5way[2*c] & no5way[2*c+1]) << 1;
          anychange |= mover & ~no5way[c];
          anychange |= mover & ~no5way[c+16];
          no5wayn[c] = no5way[c] | mover;
          no5wayn[c+16] = no5way[c+16] | mover;
          contra &= no5wayn[c];
          contra &= no5wayn[c+16];
          }
        c = 32;
        while (c--) no5way[c] = no5wayn[c];
        }
      if (SLOWER && (!(((glist - gpt) + rownum) % (PERIOD/2)) || (VERYSLOW && !(((glist - gpt) + rownum + 1) % (PERIOD/2))))) {
        c = 8;
        while (c--) {
          no5way[ 0 + 2*c + 0] = (noway[((c<<1)&7)  ] << 1) | noway[c] | (noway[  (c>>1)] >> 1);
          no5way[ 0 + 2*c + 1] = (noway[((c<<1)&7)+1] << 1) | noway[c] | (noway[  (c>>1)] >> 1);
          no5way[16 + 2*c + 0] = (noway[((c<<1)&7)  ] << 1) | noway[c] | (noway[4+(c>>1)] >> 1);
          no5way[16 + 2*c + 1] = (noway[((c<<1)&7)+1] << 1) | noway[c] | (noway[4+(c>>1)] >> 1);
          }
        }
//c = 32;
//if (firsttry && (gpt == glist)) while (c--) printf("no5way %d %d %x\n", gpt - glist, c, no5way[c]);
      (gpt + 1)->cprtop = 0;
      no5way = (gpt + 1)->facts + 12;
      c = 32;
      while (c--) no5way[c+96] = no5way[c];
      gpt--;
      }
    oldcpt = glist;
    cpt = glist - 1;
    newval = 0;
    valimit = 1 << (BITSWIDE + BUFFERIGHT);
    valinc = 1 << BUFFERIGHT;
    if (firsttry) {
      newval = valinc;
      firsttry = 0;
      }
    trownum = rownum;
    (cpt + PERIOD/2)->protop = 0;
    no5way = (cpt + PERIOD/2)->facts + 12;
    c = 32;
    while (c--) {
      no5way[c+32] = no5way[96+c] | (no5way[96+(c>>1)] >> 1);
      no5way[c+64] = no5way[96+c] | (no5way[96+16+(c>>1)] >> 1);
      }
    cpt->knockout = valimit;
    cpt->numdives = 0;
    cpt->numddives = 0;
    cpt->contop = 0;
    while (cpt < glist) {
      no5way = (cpt + PERIOD/2)->facts + 12 + 32;
      c = BITSWIDE + BUFFERIGHT - 1;
      r0 = valimit << 1;
      xr0 = 0;
//if ((rownum == 22) && (contramisses >= 85700) && (numprints < 10000)) {
//  numprints++;
//  printf("#C before rownum %d nchild %d newval %x numhits %d contramisses %d\n",
//         rownum, onroad - offroad, newval, numhits, contramisses);
//  fflush(stdout);
//  }
//printf("calc a try %d %d %d %x\n", cpt - glist, c, xr0, newval);
      if (NOSYM) while ((c >= (BUFFERIGHT - 2)) && !xr0) {
        if (r0 & no5way[(newval >> c) & 63]) {
          if (c > BUFFERIGHT) newval = ((newval >> c) + 1) << c;
          else newval = ((newval >> BUFFERIGHT) + 1) << BUFFERIGHT;
          while (~(newval >> c) & 1) {
            r0 <<= 1;
            c++;
            }
          if (c >= (BITSWIDE + BUFFERIGHT)) xr0 = valinc;
//          if (newval >= valimit) xr0 = valinc;
          }
        else {
          c--;
          r0 >>= 1;
          }
        if ((c == (BUFFERIGHT - 2)) && (cpt + PERIOD/2)->cprtop) {
          t1 = (cpt + PERIOD/2)->cprtop;
          while (t1) {
            t1 -= 3;
            if (!((cpt + PERIOD/2)->cprstack[t1 + 1] & (newval ^ (cpt + PERIOD/2)->cprstack[t1 + 2]))) {
              c = (cpt + PERIOD/2)->cprstack[t1];
              if (c > BUFFERIGHT) newval = ((newval >> c) + 1) << c;
              else newval = ((newval >> BUFFERIGHT) + 1) << BUFFERIGHT;
              c = BITSWIDE + BUFFERIGHT - 1;
              r0 = valimit << 1;
              t1 = 0;
              }
            }
          }
        if ((c == (BUFFERIGHT - 2)) && (cpt + PERIOD/2)->protop) {
          t1 = (cpt + PERIOD/2)->protop;
          while (t1) {
            t1 -= 3;
            if (!((cpt + PERIOD/2)->prostack[t1 + 1] & (newval ^ (cpt + PERIOD/2)->prostack[t1 + 2]))) {
              c = (cpt + PERIOD/2)->prostack[t1];
              if (c > BUFFERIGHT) newval = ((newval >> c) + 1) << c;
              else newval = ((newval >> BUFFERIGHT) + 1) << BUFFERIGHT;
              c = BITSWIDE + BUFFERIGHT - 1;
              r0 = valimit << 1;
              t1 = 0;
              }
            }
          }
        }
      else while (r0 && !xr0) {
        if ((r0 > 2) && (r0 & no5way[(newval >> c) & 63])) {
          newval = ((newval >> c) + 1) << c;
          while (~(newval >> c) & 1) {
            r0 <<= 1;
            c++;
            }
          if (c >= (BITSWIDE + BUFFERIGHT)) xr0 = valinc;
          }
        else if ((r0 == 2) && (r0 & no5way[(newval << 1) & 63])) {
          newval++;
          r0 <<= 1;
          c++;
          while (~(newval >> c) & 1) {
            r0 <<= 1;
            c++;
            }
          if (c >= BITSWIDE) xr0 = valinc;
          }
        else if ((r0 == 1) && (r0 & no5way[(newval << 2) & 63])) {
          newval++;
          r0 <<= 1;
          c++;
          r0 <<= 1;
          c++;
          while (~(newval >> c) & 1) {
            r0 <<= 1;
            c++;
            }
          if (c >= BITSWIDE) xr0 = valinc;
          }
        else {
          c--;
          r0 >>= 1;
          }
        if (!r0 && (cpt + PERIOD/2)->cprtop) {
          t1 = (cpt + PERIOD/2)->cprtop;
          while (t1) {
            t1 -= 3;
            if (!((cpt + PERIOD/2)->cprstack[t1 + 1] & (newval ^ (cpt + PERIOD/2)->cprstack[t1 + 2]))) {
              c = (cpt + PERIOD/2)->cprstack[t1];
              if (!(c & 0x80000000)) newval = ((newval >> c) + 1) << c;
              else newval++;
              c = BITSWIDE - 1;
              r0 = valimit << 1;
              t1 = 0;
              }
            }
          }
        if (!r0 && (cpt + PERIOD/2)->protop) {
          t1 = (cpt + PERIOD/2)->protop;
          while (t1) {
            t1 -= 3;
            if (!((cpt + PERIOD/2)->prostack[t1 + 1] & (newval ^ (cpt + PERIOD/2)->prostack[t1 + 2]))) {
              c = (cpt + PERIOD/2)->prostack[t1];
              if (!(c & 0x80000000)) newval = ((newval >> c) + 1) << c;
              else newval++;
              c = BITSWIDE - 1;
              r0 = valimit << 1;
              t1 = 0;
              }
            }
          }
        }
//printf("a try %d %d %d %x\n", cpt - glist, c, xr0, newval);
      xr0loc = 32;
      if (!xr0) {
        numtries++;
        rpto = (cpt + PERIOD/2)->rstuff;
        rpt = cpt->rstuff;
        r0 = newval;
/*
printf("%8x\n", r0);
*/
        make1 = cpt->facts;
        noway = cpt->facts + 8;
        no5way = cpt->facts + 12;
        while (rpt < cpt->rstuff + 6*2) {
          rpt[0] = r0;
          t1 = r0 >> 1;
          t2 = r0 << 1;
          if (ODDSYM) t2 |= t1 & 1;
          if (EVENSYM) t2 |= r0 & 1;
          t3 = t1 ^ t2;
          rpt[2] = (t1 & t2) ^ (r0 & t3);
          rpt[1] = r0 ^ t3;
          r0 = (rpto[0] | (rpt[1] ^ rpto[3])) &
               (rpt[2] ^ rpto[4] ^ (rpt[1] | rpto[3])) &
               (rpto[5] ^ (rpt[2] & rpto[4]));
          t1 = rpt[1] & rpto[1];
          rpt[3] = rpt[1] ^ rpto[1];
          t2 = rpt[2] & rpto[2];
          t3 = rpt[2] ^ rpto[2];
          rpt[5] = t2 ^ (t3 | t1);
          rpt[4] = ~(t3 ^ t1);
          make1[0] = ((rpt[0] & ~rpt[3] & rpt[4]) |
                      (rpt[3] & ~rpt[4])) & rpt[5];
          make1[1] = (rpt[0] | ~rpt[3]) & ~rpt[4] & rpt[5];
          make1[2] = (rpt[0] & ~rpt[3] & ~rpt[4] & rpt[5]) |
                     (rpt[3] & rpt[4] & ~rpt[5]);
          make1[3] = (rpt[0] | ~rpt[3]) & rpt[4] & ~rpt[5];
//c = 4;
//while (c--) printf("make1 and noway late %d %d %x %x %x %x %x %x\n", rpt - cpt->rstuff, c, rpt[0], rpto[0], make1[c], rpt[3], rpt[4], rpt[5]);
          make1 += 4;
          rpt += 6;
          rpto += 6;
          }
        make1 -= 4;
        r0 = (cpt + 1)->checker;
        noway[0] = make1[0] ^ r0;
        noway[1] = make1[1] ^ r0;
        noway[2] = make1[2] ^ r0;
        noway[3] = make1[3] ^ r0;
        props = 0;
        xr0 = ~0;
        c = 4;
        while (c--) xr0 &= noway[c];
//printf("Got here %d %d %d %d\n", rownum, (glist - cpt), PERIOD, SLOWER);
        if (SLOWER && (!(((glist - cpt) + rownum) % (PERIOD/2)) || (VERYSLOW && !(((glist - cpt) + rownum + 1) % (PERIOD/2))))) {
          make1 -= 4;
          noway -= 4;
          noway[0] = make1[0] ^ r0;
          noway[1] = make1[1] ^ r0;
          noway[2] = noway[1];
          noway[3] = make1[2] ^ r0;
          noway[4] = noway[1];
          noway[5] = noway[3];
          noway[6] = noway[3];
          noway[7] = make1[3] ^ r0;
          if (EVENSYM) {
            c = 8;
            while (c) {
              c -= 2;
              if (c & 2) {
                noway[c] = (noway[c] & 0xfffffffe) | (noway[c+1] & 1);
                }
              }
            }
          else if (ODDSYM) {
            c = 8;
            while (c) {
              c -= 2;
              if (c & 4) {
                noway[c] = (noway[c] & 0xfffffffe) | (noway[c+1] & 1);
                }
              }
            }
          c = 8;
          while (c--) noway[c] |= nowayt[c];
          props = 0;
          xr0 = ~0;
          c = 8;
          while (c--) xr0 &= noway[c];
          anychange = 1;
          while (anychange && !xr0) {
            props++;
            contrits++;
            anychange = 0;
            xr0 = ~0;
            c = 4;
            while (c--) {
              mover = (noway[2*c] & noway[2*c+1]) << 1;
              anychange |= mover & ~noway[c];
              anychange |= mover & ~noway[c+4];
              no5wayn[c] = noway[c] | mover;
              no5wayn[c+4] = noway[c+4] | mover;
              xr0 &= no5wayn[c];
              xr0 &= no5wayn[c+4];
              }
            c = 8;
            while (c--) noway[c] = no5wayn[c];
            }
          xr0 >>= props;
          c = 8;
          if (!xr0) while (c--) {
            no5way[ 0 + 2*c + 0] = (noway[((c<<1)&7)  ] << 1) | noway[c] | (noway[  (c>>1)] >> 1);
            no5way[ 0 + 2*c + 1] = (noway[((c<<1)&7)+1] << 1) | noway[c] | (noway[  (c>>1)] >> 1);
            no5way[16 + 2*c + 0] = (noway[((c<<1)&7)  ] << 1) | noway[c] | (noway[4+(c>>1)] >> 1);
            no5way[16 + 2*c + 1] = (noway[((c<<1)&7)+1] << 1) | noway[c] | (noway[4+(c>>1)] >> 1);
            }
          }
        else if (!xr0) {
          contries++;
          make1 -= 4;
          make1_0r = make1[0] << 1;
          make1_0l = make1[0] >> 1;
          make1_1r = make1[1] << 1;
          make1_1l = make1[1] >> 1;
          make1_2r = make1[2] << 1;
          make1_2l = make1[2] >> 1;
          make1_3r = make1[3] << 1;
          make1_3l = make1[3] >> 1;
          if (EVENSYM) {
            make1_0r |= make1[0] & 1;
            make1_1r |= make1[1] & 1;
            make1_2r |= make1[2] & 1;
            make1_3r |= make1[3] & 1;
            }
          else if (ODDSYM) {
            make1_0r |= make1_0l & 1;
            make1_1r |= make1_1l & 1;
            make1_2r |= make1_2l & 1;
            make1_3r |= make1_3l & 1;
            }
          no5way[ 0] = (noway[0] &  (~make1_0l & ~make1[0] & ~make1_0r)) |
                       (noway[1] & ((~make1_0l & ~make1[0] &  make1_0r) |
                                    (~make1_0l &  make1[0] & ~make1_0r) |
                                    ( make1_0l & ~make1[0] & ~make1_0r))) |
                       (noway[2] & (( make1_0l &  make1[0] & ~make1_0r) |
                                    ( make1_0l & ~make1[0] &  make1_0r) |
                                    (~make1_0l &  make1[0] &  make1_0r))) |
                       (noway[3] &  ( make1_0l &  make1[0] &  make1_0r));
          no5way[ 1] = (noway[0] &  (~make1_0l & ~make1[0] & ~make1_1r)) |
                       (noway[1] & ((~make1_0l & ~make1[0] &  make1_1r) |
                                    (~make1_0l &  make1[0] & ~make1_1r) |
                                    ( make1_0l & ~make1[0] & ~make1_1r))) |
                       (noway[2] & (( make1_0l &  make1[0] & ~make1_1r) |
                                    ( make1_0l & ~make1[0] &  make1_1r) |
                                    (~make1_0l &  make1[0] &  make1_1r))) |
                       (noway[3] &  ( make1_0l &  make1[0] &  make1_1r));
          no5way[ 2] = (noway[0] &  (~make1_0l & ~make1[1] & ~make1_1r)) |
                       (noway[1] & ((~make1_0l & ~make1[1] &  make1_1r) |
                                    (~make1_0l &  make1[1] & ~make1_1r) |
                                    ( make1_0l & ~make1[1] & ~make1_1r))) |
                       (noway[2] & (( make1_0l &  make1[1] & ~make1_1r) |
                                    ( make1_0l & ~make1[1] &  make1_1r) |
                                    (~make1_0l &  make1[1] &  make1_1r))) |
                       (noway[3] &  ( make1_0l &  make1[1] &  make1_1r));
          no5way[ 3] = (noway[0] &  (~make1_0l & ~make1[1] & ~make1_2r)) |
                       (noway[1] & ((~make1_0l & ~make1[1] &  make1_2r) |
                                    (~make1_0l &  make1[1] & ~make1_2r) |
                                    ( make1_0l & ~make1[1] & ~make1_2r))) |
                       (noway[2] & (( make1_0l &  make1[1] & ~make1_2r) |
                                    ( make1_0l & ~make1[1] &  make1_2r) |
                                    (~make1_0l &  make1[1] &  make1_2r))) |
                       (noway[3] &  ( make1_0l &  make1[1] &  make1_2r));
          no5way[ 4] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_1r)) |
                       (noway[1] & ((~make1_1l & ~make1[1] &  make1_1r) |
                                    (~make1_1l &  make1[1] & ~make1_1r) |
                                    ( make1_1l & ~make1[1] & ~make1_1r))) |
                       (noway[2] & (( make1_1l &  make1[1] & ~make1_1r) |
                                    ( make1_1l & ~make1[1] &  make1_1r) |
                                    (~make1_1l &  make1[1] &  make1_1r))) |
                       (noway[3] &  ( make1_1l &  make1[1] &  make1_1r));
          no5way[ 5] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_2r)) |
                       (noway[1] & ((~make1_1l & ~make1[1] &  make1_2r) |
                                    (~make1_1l &  make1[1] & ~make1_2r) |
                                    ( make1_1l & ~make1[1] & ~make1_2r))) |
                       (noway[2] & (( make1_1l &  make1[1] & ~make1_2r) |
                                    ( make1_1l & ~make1[1] &  make1_2r) |
                                    (~make1_1l &  make1[1] &  make1_2r))) |
                       (noway[3] &  ( make1_1l &  make1[1] &  make1_2r));
          no5way[ 6] = (noway[0] &  (~make1_1l & ~make1[2] & ~make1_2r)) |
                       (noway[1] & ((~make1_1l & ~make1[2] &  make1_2r) |
                                    (~make1_1l &  make1[2] & ~make1_2r) |
                                    ( make1_1l & ~make1[2] & ~make1_2r))) |
                       (noway[2] & (( make1_1l &  make1[2] & ~make1_2r) |
                                    ( make1_1l & ~make1[2] &  make1_2r) |
                                    (~make1_1l &  make1[2] &  make1_2r))) |
                       (noway[3] &  ( make1_1l &  make1[2] &  make1_2r));
          no5way[ 7] = (noway[0] &  (~make1_1l & ~make1[2] & ~make1_3r)) |
                       (noway[1] & ((~make1_1l & ~make1[2] &  make1_3r) |
                                    (~make1_1l &  make1[2] & ~make1_3r) |
                                    ( make1_1l & ~make1[2] & ~make1_3r))) |
                       (noway[2] & (( make1_1l &  make1[2] & ~make1_3r) |
                                    ( make1_1l & ~make1[2] &  make1_3r) |
                                    (~make1_1l &  make1[2] &  make1_3r))) |
                       (noway[3] &  ( make1_1l &  make1[2] &  make1_3r));
          no5way[ 8] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_0r)) |
                       (noway[1] & ((~make1_1l & ~make1[1] &  make1_0r) |
                                    (~make1_1l &  make1[1] & ~make1_0r) |
                                    ( make1_1l & ~make1[1] & ~make1_0r))) |
                       (noway[2] & (( make1_1l &  make1[1] & ~make1_0r) |
                                    ( make1_1l & ~make1[1] &  make1_0r) |
                                    (~make1_1l &  make1[1] &  make1_0r))) |
                       (noway[3] &  ( make1_1l &  make1[1] &  make1_0r));
          no5way[ 9] = no5way[ 4];
//          no5way[ 9] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_1r)) |
//                       (noway[1] & ((~make1_1l & ~make1[1] &  make1_1r) |
//                                    (~make1_1l &  make1[1] & ~make1_1r) |
//                                    ( make1_1l & ~make1[1] & ~make1_1r))) |
//                       (noway[2] & (( make1_1l &  make1[1] & ~make1_1r) |
//                                    ( make1_1l & ~make1[1] &  make1_1r) |
//                                    (~make1_1l &  make1[1] &  make1_1r))) |
//                       (noway[3] &  ( make1_1l &  make1[1] &  make1_1r));
          no5way[10] = (noway[0] &  (~make1_1l & ~make1[2] & ~make1_1r)) |
                       (noway[1] & ((~make1_1l & ~make1[2] &  make1_1r) |
                                    (~make1_1l &  make1[2] & ~make1_1r) |
                                    ( make1_1l & ~make1[2] & ~make1_1r))) |
                       (noway[2] & (( make1_1l &  make1[2] & ~make1_1r) |
                                    ( make1_1l & ~make1[2] &  make1_1r) |
                                    (~make1_1l &  make1[2] &  make1_1r))) |
                       (noway[3] &  ( make1_1l &  make1[2] &  make1_1r));
          no5way[11] = no5way[ 6];
//          no5way[11] = (noway[0] &  (~make1_1l & ~make1[2] & ~make1_2r)) |
//                       (noway[1] & ((~make1_1l & ~make1[2] &  make1_2r) |
//                                    (~make1_1l &  make1[2] & ~make1_2r) |
//                                    ( make1_1l & ~make1[2] & ~make1_2r))) |
//                       (noway[2] & (( make1_1l &  make1[2] & ~make1_2r) |
//                                    ( make1_1l & ~make1[2] &  make1_2r) |
//                                    (~make1_1l &  make1[2] &  make1_2r))) |
//                       (noway[3] &  ( make1_1l &  make1[2] &  make1_2r));
          no5way[12] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_1r)) |
                       (noway[1] & ((~make1_2l & ~make1[2] &  make1_1r) |
                                    (~make1_2l &  make1[2] & ~make1_1r) |
                                    ( make1_2l & ~make1[2] & ~make1_1r))) |
                       (noway[2] & (( make1_2l &  make1[2] & ~make1_1r) |
                                    ( make1_2l & ~make1[2] &  make1_1r) |
                                    (~make1_2l &  make1[2] &  make1_1r))) |
                       (noway[3] &  ( make1_2l &  make1[2] &  make1_1r));
          no5way[13] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_2r)) |
                       (noway[1] & ((~make1_2l & ~make1[2] &  make1_2r) |
                                    (~make1_2l &  make1[2] & ~make1_2r) |
                                    ( make1_2l & ~make1[2] & ~make1_2r))) |
                       (noway[2] & (( make1_2l &  make1[2] & ~make1_2r) |
                                    ( make1_2l & ~make1[2] &  make1_2r) |
                                    (~make1_2l &  make1[2] &  make1_2r))) |
                       (noway[3] &  ( make1_2l &  make1[2] &  make1_2r));
          no5way[14] = (noway[0] &  (~make1_2l & ~make1[3] & ~make1_2r)) |
                       (noway[1] & ((~make1_2l & ~make1[3] &  make1_2r) |
                                    (~make1_2l &  make1[3] & ~make1_2r) |
                                    ( make1_2l & ~make1[3] & ~make1_2r))) |
                       (noway[2] & (( make1_2l &  make1[3] & ~make1_2r) |
                                    ( make1_2l & ~make1[3] &  make1_2r) |
                                    (~make1_2l &  make1[3] &  make1_2r))) |
                       (noway[3] &  ( make1_2l &  make1[3] &  make1_2r));
          no5way[15] = (noway[0] &  (~make1_2l & ~make1[3] & ~make1_3r)) |
                       (noway[1] & ((~make1_2l & ~make1[3] &  make1_3r) |
                                    (~make1_2l &  make1[3] & ~make1_3r) |
                                    ( make1_2l & ~make1[3] & ~make1_3r))) |
                       (noway[2] & (( make1_2l &  make1[3] & ~make1_3r) |
                                    ( make1_2l & ~make1[3] &  make1_3r) |
                                    (~make1_2l &  make1[3] &  make1_3r))) |
                       (noway[3] &  ( make1_2l &  make1[3] &  make1_3r));
          no5way[16] = (noway[0] &  (~make1_1l & ~make1[0] & ~make1_0r)) |
                       (noway[1] & ((~make1_1l & ~make1[0] &  make1_0r) |
                                    (~make1_1l &  make1[0] & ~make1_0r) |
                                    ( make1_1l & ~make1[0] & ~make1_0r))) |
                       (noway[2] & (( make1_1l &  make1[0] & ~make1_0r) |
                                    ( make1_1l & ~make1[0] &  make1_0r) |
                                    (~make1_1l &  make1[0] &  make1_0r))) |
                       (noway[3] &  ( make1_1l &  make1[0] &  make1_0r));
          no5way[17] = (noway[0] &  (~make1_1l & ~make1[0] & ~make1_1r)) |
                       (noway[1] & ((~make1_1l & ~make1[0] &  make1_1r) |
                                    (~make1_1l &  make1[0] & ~make1_1r) |
                                    ( make1_1l & ~make1[0] & ~make1_1r))) |
                       (noway[2] & (( make1_1l &  make1[0] & ~make1_1r) |
                                    ( make1_1l & ~make1[0] &  make1_1r) |
                                    (~make1_1l &  make1[0] &  make1_1r))) |
                       (noway[3] &  ( make1_1l &  make1[0] &  make1_1r));
          no5way[18] = no5way[ 4];
//          no5way[18] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_1r)) |
//                       (noway[1] & ((~make1_1l & ~make1[1] &  make1_1r) |
//                                    (~make1_1l &  make1[1] & ~make1_1r) |
//                                    ( make1_1l & ~make1[1] & ~make1_1r))) |
//                       (noway[2] & (( make1_1l &  make1[1] & ~make1_1r) |
//                                    ( make1_1l & ~make1[1] &  make1_1r) |
//                                    (~make1_1l &  make1[1] &  make1_1r))) |
//                       (noway[3] &  ( make1_1l &  make1[1] &  make1_1r));
          no5way[19] = no5way[ 5];
//          no5way[19] = (noway[0] &  (~make1_1l & ~make1[1] & ~make1_2r)) |
//                       (noway[1] & ((~make1_1l & ~make1[1] &  make1_2r) |
//                                    (~make1_1l &  make1[1] & ~make1_2r) |
//                                    ( make1_1l & ~make1[1] & ~make1_2r))) |
//                       (noway[2] & (( make1_1l &  make1[1] & ~make1_2r) |
//                                    ( make1_1l & ~make1[1] &  make1_2r) |
//                                    (~make1_1l &  make1[1] &  make1_2r))) |
//                       (noway[3] &  ( make1_1l &  make1[1] &  make1_2r));
          no5way[20] = (noway[0] &  (~make1_2l & ~make1[1] & ~make1_1r)) |
                       (noway[1] & ((~make1_2l & ~make1[1] &  make1_1r) |
                                    (~make1_2l &  make1[1] & ~make1_1r) |
                                    ( make1_2l & ~make1[1] & ~make1_1r))) |
                       (noway[2] & (( make1_2l &  make1[1] & ~make1_1r) |
                                    ( make1_2l & ~make1[1] &  make1_1r) |
                                    (~make1_2l &  make1[1] &  make1_1r))) |
                       (noway[3] &  ( make1_2l &  make1[1] &  make1_1r));
          no5way[21] = (noway[0] &  (~make1_2l & ~make1[1] & ~make1_2r)) |
                       (noway[1] & ((~make1_2l & ~make1[1] &  make1_2r) |
                                    (~make1_2l &  make1[1] & ~make1_2r) |
                                    ( make1_2l & ~make1[1] & ~make1_2r))) |
                       (noway[2] & (( make1_2l &  make1[1] & ~make1_2r) |
                                    ( make1_2l & ~make1[1] &  make1_2r) |
                                    (~make1_2l &  make1[1] &  make1_2r))) |
                       (noway[3] &  ( make1_2l &  make1[1] &  make1_2r));
          no5way[22] = no5way[13];
//          no5way[22] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_2r)) |
//                       (noway[1] & ((~make1_2l & ~make1[2] &  make1_2r) |
//                                    (~make1_2l &  make1[2] & ~make1_2r) |
//                                    ( make1_2l & ~make1[2] & ~make1_2r))) |
//                       (noway[2] & (( make1_2l &  make1[2] & ~make1_2r) |
//                                    ( make1_2l & ~make1[2] &  make1_2r) |
//                                    (~make1_2l &  make1[2] &  make1_2r))) |
//                       (noway[3] &  ( make1_2l &  make1[2] &  make1_2r));
          no5way[23] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_3r)) |
                       (noway[1] & ((~make1_2l & ~make1[2] &  make1_3r) |
                                    (~make1_2l &  make1[2] & ~make1_3r) |
                                    ( make1_2l & ~make1[2] & ~make1_3r))) |
                       (noway[2] & (( make1_2l &  make1[2] & ~make1_3r) |
                                    ( make1_2l & ~make1[2] &  make1_3r) |
                                    (~make1_2l &  make1[2] &  make1_3r))) |
                       (noway[3] &  ( make1_2l &  make1[2] &  make1_3r));
          no5way[24] = (noway[0] &  (~make1_2l & ~make1[1] & ~make1_0r)) |
                       (noway[1] & ((~make1_2l & ~make1[1] &  make1_0r) |
                                    (~make1_2l &  make1[1] & ~make1_0r) |
                                    ( make1_2l & ~make1[1] & ~make1_0r))) |
                       (noway[2] & (( make1_2l &  make1[1] & ~make1_0r) |
                                    ( make1_2l & ~make1[1] &  make1_0r) |
                                    (~make1_2l &  make1[1] &  make1_0r))) |
                       (noway[3] &  ( make1_2l &  make1[1] &  make1_0r));
          no5way[25] = no5way[20];
//          no5way[25] = (noway[0] &  (~make1_2l & ~make1[1] & ~make1_1r)) |
//                       (noway[1] & ((~make1_2l & ~make1[1] &  make1_1r) |
//                                    (~make1_2l &  make1[1] & ~make1_1r) |
//                                    ( make1_2l & ~make1[1] & ~make1_1r))) |
//                       (noway[2] & (( make1_2l &  make1[1] & ~make1_1r) |
//                                    ( make1_2l & ~make1[1] &  make1_1r) |
//                                    (~make1_2l &  make1[1] &  make1_1r))) |
//                       (noway[3] &  ( make1_2l &  make1[1] &  make1_1r));
          no5way[26] = no5way[12];
//          no5way[26] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_1r)) |
//                       (noway[1] & ((~make1_2l & ~make1[2] &  make1_1r) |
//                                    (~make1_2l &  make1[2] & ~make1_1r) |
//                                    ( make1_2l & ~make1[2] & ~make1_1r))) |
//                       (noway[2] & (( make1_2l &  make1[2] & ~make1_1r) |
//                                    ( make1_2l & ~make1[2] &  make1_1r) |
//                                    (~make1_2l &  make1[2] &  make1_1r))) |
//                       (noway[3] &  ( make1_2l &  make1[2] &  make1_1r));
          no5way[27] = no5way[13];
//          no5way[27] = (noway[0] &  (~make1_2l & ~make1[2] & ~make1_2r)) |
//                       (noway[1] & ((~make1_2l & ~make1[2] &  make1_2r) |
//                                    (~make1_2l &  make1[2] & ~make1_2r) |
//                                    ( make1_2l & ~make1[2] & ~make1_2r))) |
//                       (noway[2] & (( make1_2l &  make1[2] & ~make1_2r) |
//                                    ( make1_2l & ~make1[2] &  make1_2r) |
//                                    (~make1_2l &  make1[2] &  make1_2r))) |
//                       (noway[3] &  ( make1_2l &  make1[2] &  make1_2r));
          no5way[28] = (noway[0] &  (~make1_3l & ~make1[2] & ~make1_1r)) |
                       (noway[1] & ((~make1_3l & ~make1[2] &  make1_1r) |
                                    (~make1_3l &  make1[2] & ~make1_1r) |
                                    ( make1_3l & ~make1[2] & ~make1_1r))) |
                       (noway[2] & (( make1_3l &  make1[2] & ~make1_1r) |
                                    ( make1_3l & ~make1[2] &  make1_1r) |
                                    (~make1_3l &  make1[2] &  make1_1r))) |
                       (noway[3] &  ( make1_3l &  make1[2] &  make1_1r));
          no5way[29] = (noway[0] &  (~make1_3l & ~make1[2] & ~make1_2r)) |
                       (noway[1] & ((~make1_3l & ~make1[2] &  make1_2r) |
                                    (~make1_3l &  make1[2] & ~make1_2r) |
                                    ( make1_3l & ~make1[2] & ~make1_2r))) |
                       (noway[2] & (( make1_3l &  make1[2] & ~make1_2r) |
                                    ( make1_3l & ~make1[2] &  make1_2r) |
                                    (~make1_3l &  make1[2] &  make1_2r))) |
                       (noway[3] &  ( make1_3l &  make1[2] &  make1_2r));
          no5way[30] = (noway[0] &  (~make1_3l & ~make1[3] & ~make1_2r)) |
                       (noway[1] & ((~make1_3l & ~make1[3] &  make1_2r) |
                                    (~make1_3l &  make1[3] & ~make1_2r) |
                                    ( make1_3l & ~make1[3] & ~make1_2r))) |
                       (noway[2] & (( make1_3l &  make1[3] & ~make1_2r) |
                                    ( make1_3l & ~make1[3] &  make1_2r) |
                                    (~make1_3l &  make1[3] &  make1_2r))) |
                       (noway[3] &  ( make1_3l &  make1[3] &  make1_2r));
          no5way[31] = (noway[0] &  (~make1_3l & ~make1[3] & ~make1_3r)) |
                       (noway[1] & ((~make1_3l & ~make1[3] &  make1_3r) |
                                    (~make1_3l &  make1[3] & ~make1_3r) |
                                    ( make1_3l & ~make1[3] & ~make1_3r))) |
                       (noway[2] & (( make1_3l &  make1[3] & ~make1_3r) |
                                    ( make1_3l & ~make1[3] &  make1_3r) |
                                    (~make1_3l &  make1[3] &  make1_3r))) |
                       (noway[3] &  ( make1_3l &  make1[3] &  make1_3r));
          if (EVENSYM) {
            c = 32;
            while (c) {
              c -= 2;
              if (c & 2) {
                no5way[c] = (no5way[c] & 0xfffffffd) | (no5way[c+1] & 2);
                }
              else if ((c & 0xc) == 4) {
                no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+2] & 1);
                }
              else if ((c & 0xc) == 8) {
                no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+1] & 1);
                }
              else if ((c & 0xc) == 0xc) {
                no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+3] & 1);
                }
              }
            }
          else if (ODDSYM) {
            c = 32;
            while (c) {
              c -= 2;
              if (c & 4) {
                no5way[c] = (no5way[c] & 0xfffffffd) | (no5way[c+1] & 2);
                }
              if ((c & 0x1b) == 8) {
                no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+2] & 1);
                }
              else if ((c & 0x1b) == 0x10) {
                no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+1] & 1);
                }
              else if ((c & 0x1b) == 0x18) {
                no5way[c] = (no5way[c] & 0xfffffffe) | (no5way[c+3] & 1);
                }
              }
            }
          c = 32;
          while (c--) no5way[c] |= no5wayt[c];
          xr0 = ~0;
          c = 32;
          while (c--) xr0 &= no5way[c];
          if (!xr0) conmissq++;
//printf("after try %d %d %x\n", cpt - glist, c, xr0);
          anychange = 1;
          t1 = 0;
          while (anychange && !xr0) {
            t1++;
            contrits++;
            anychange = 0;
            xr0 = ~0;
            c = 16;
            while (c--) {
              mover = (no5way[2*c] & no5way[2*c+1]) << 1;
              anychange |= mover & ~no5way[c];
              anychange |= mover & ~no5way[c+16];
              no5wayn[c] = no5way[c] | mover;
              no5wayn[c+16] = no5way[c+16] | mover;
              xr0 &= no5wayn[c];
              xr0 &= no5wayn[c+16];
              }
            c = 32;
            while (c--) no5way[c] = no5wayn[c];
            }
          props = t1;
          xr0 >>= props;
          }
        if (xr0) {
          t1 = xr0;
          c = 0;
          if (t1 & 0xffff0000) {
            c += 16;
            t1 &= 0xffff0000;
            }
          else {
            t1 &= 0x0000ffff;
            }
          if (t1 & 0xff00ff00) {
            c += 8;
            t1 &= 0xff00ff00;
            }
          else {
            t1 &= 0x00ff00ff;
            }
          if (t1 & 0xf0f0f0f0) {
            c += 4;
            t1 &= 0xf0f0f0f0;
            }
          else {
            t1 &= 0x0f0f0f0f;
            }
          if (t1 & 0xcccccccc) {
            c += 2;
            t1 &= 0xcccccccc;
            }
          else {
            t1 &= 0x33333333;
            }
          if (t1 & 0xaaaaaaaa) {
            c += 1;
            t1 &= 0xaaaaaaaa;
            }
          else {
            t1 &= 0x55555555;
            }
          if (NOSYM) {
            if (SLOWER && (!(((glist - cpt) + rownum) % (PERIOD/2)) || (VERYSLOW && !(((glist - cpt) + rownum + 1) % (PERIOD/2))))) {
              no5way = (cpt + PERIOD/2)->facts + 12 + 32;
              if (props < 4) {
                t2 = t1 << 1;
                t4 = 1 << (3 + props);
                t5 = (newval >> (c - 1)) & (t4 - 1);
                t3 = 64;
                while (t3) {
                  t3 -= t4;
                  no5way[t3 + t5] |= t2;
                  }
                }
              }
            else {
              if (!props) {
                no5way = (cpt + PERIOD/2)->facts + 12 + 32;
                no5way[(newval >> (c - 2)) & 31] |= t1;
                no5way[32 + ((newval >> (c - 2)) & 31)] |= t1;
//                no5way[((newval >> (c - 3)) & 62) + 0] |= t1 >> 1;
//                no5way[((newval >> (c - 3)) & 62) + 1] |= t1 >> 1;
                }
              else if (props < 2) {
                no5way = (cpt + PERIOD/2)->facts + 12 + 32;
                no5way[(newval >> (c - 2)) & 63] |= t1;
                }
              else if (props < 3) {
                if ((cpt + PERIOD/2)->protop < 3*MAXPROSTACK) {
                  (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop] = c - 2;
                  (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop + 1] = (1 << (c + props + 3)) - (1 << (c - 2));
                  (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop + 2] = newval;
                  (cpt + PERIOD/2)->protop += 3;
                  }
                }
              }
            }
          else {
            if (SLOWER && (!(((glist - cpt) + rownum) % (PERIOD/2)) || (VERYSLOW && !(((glist - cpt) + rownum + 1) % (PERIOD/2))))) {
              no5way = (cpt + PERIOD/2)->facts + 12 + 32;
              if (props < 4) {
                t2 = t1 << 1;
                t4 = 1 << (3 + props);
                if (c) t5 = (newval >> (c - 1)) & (t4 - 1);
                else t5 = (newval << 1) & (t4 - 1);
                t3 = 64;
                while (t3) {
                  t3 -= t4;
                  no5way[t3 + t5] |= t2;
                  }
                }
              }
            else {
              if (!props) {
                no5way = (cpt + PERIOD/2)->facts + 12 + 32;
                if (c >= 2) {
                  no5way[(newval >> (c - 2)) & 31] |= t1;
                  no5way[32 + ((newval >> (c - 2)) & 31)] |= t1;
                  }
                else {
                  no5way[(newval << (2 - c)) & 31] |= t1;
                  no5way[32 + ((newval << (2 - c)) & 31)] |= t1;
                  }
                }
              else if (props < 2) {
                no5way = (cpt + PERIOD/2)->facts + 12 + 32;
                if (c >= 2) {
                  no5way[(newval >> (c - 2)) & 63] |= t1;
                  }
                else {
                  no5way[(newval << (2 - c)) & 63] |= t1;
                  }
                }
              else if (props < 3) {
                if ((cpt + PERIOD/2)->protop < 3*MAXPROSTACK) {
                  if (c >= 2) {
                    (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop] = c - 2;
                    (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop + 1] = (1 << (c + props + 3)) - (1 << (c - 2));
                    (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop + 2] = newval;
                    (cpt + PERIOD/2)->protop += 3;
                    }
                  else {
                    (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop] = 0;
                    (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop + 1] = (1 << (c + props + 3)) - 1;
                    (cpt + PERIOD/2)->prostack[(cpt + PERIOD/2)->protop + 2] = newval;
                    (cpt + PERIOD/2)->protop += 3;
                    }
                  }
                }
              }
            }
//if (c == 32) printf("really big early %d %d %x %x\n", props, cpt->contop, xr0, newval);
          if (1) {
            xr0 = t1;
            }
          xr0loc = c;
          if (FLIP && !(((glist - cpt) + rownum - 1) % (PERIOD/2))) cpt->constack[cpt->contop] = 2*BUFFERIGHT + BITSWIDE - c - props - 1;
          else cpt->constack[cpt->contop] = c;
          cpt->constack[cpt->contop+1] = props;
          if (cpt->contop < 2*MAXCONSTACK) cpt->contop += 2;
          }
        if (!xr0) contramisses++;
/*
printf("\n");
*/
        }
//if ((rownum == 22) && (contramisses >= 85700) && (numprints < 10000)) {
//  numprints++;
//  printf("#C after rownum %d nchild %d newval %x xr0 %x numhits %d contramisses %d\n",
//         rownum, onroad - offroad, newval, xr0, numhits, contramisses);
//  fflush(stdout);
//  }
      if (HYPEROW && !xr0) {
        if ((cpt + 1)->lowper) {
          t1 = cpt->rstuff[6];
          t2 = 0;
          c = BITSWIDE;
          while (c--) {
            t2 <<= 1;
            t2 |= (1 << BUFFERIGHT) & t1;
            t1 >>= 1;
            }
          if (((cpt->rstuff[6] == (cpt + 2)->rstuff[0]) && (HYPEROW >= 2) && (trownum == HYPEROW)) ||
              ((cpt->rstuff[6] > (cpt + 2)->rstuff[0]) ||
               (NOSYM && (cpt + 3)->symmetric && (cpt->rstuff[6] != (cpt + 2)->rstuff[0]) && (t2 > (cpt + 2)->rstuff[0])))) {
            xr0 = valinc;
            cpt->knockout = valinc;
            cpt->numdives++;
            (cpt + 1)->numddives++;
            cpt->constack[cpt->contop] = BUFFERIGHT;
            cpt->constack[cpt->contop+1] = props;
            if (cpt->contop < 2*MAXCONSTACK) cpt->contop += 2;
            }
          else if (cpt->rstuff[6] == (cpt + 2)->rstuff[0]) cpt->lowper = 1;
          else cpt->lowper = 0;
          }
        else cpt->lowper = 0;
        }
      else cpt->lowper = 0;
      if (!xr0 && !YMOVE && NOSYM) {
        if ((cpt + 1)->symmetric) {
          t1 = newval;
          t2 = 0;
          c = BITSWIDE;
          while (c--) {
            t2 <<= 1;
            t2 |= (1 << BUFFERIGHT) & t1;
            t1 >>= 1;
            }
          if (((!HYPEROW && (t2 < newval)) || (HYPEROW && (t2 > newval))) || (ASYMFORCE && (t2 == newval) && (trownum == ASYMROW))) {
            xr0 = valinc;
            cpt->knockout = valinc;
            cpt->numdives++;
            (cpt + 1)->numddives++;
            cpt->constack[cpt->contop] = BUFFERIGHT;
            cpt->constack[cpt->contop+1] = props;
            if (cpt->contop < 2*MAXCONSTACK) cpt->contop += 2;
            }
          else if (t2 == newval) cpt->symmetric = 1;
          else cpt->symmetric = 0;
          }
        else cpt->symmetric = 0;
        }
      if ((!xr0) && (cpt == glist - DEPTH)) {
//if (!((nchild - allroads) % 256)) {
//  printf("#C rownum %d nchild %d newval %x numhits %d contramisses %d\n",
//         rownum, onroad - offroad, newval, numhits, contramisses);
//  fflush(stdout);
//  }
        numhits++;
        newval = (glist - 1)->rstuff[0];
        nchild->value = newval;
        nchild->parent = onroad;
        (glist - 1)->loc = nchild;
        nchild++;
        if (nchild == allroads + ROADSTORE) exit(0);
        if (!cpt->rstuff[0]) {
          checkend = 0;
          c = PERIOD;
          while (c--) checkend |= (cpt + c)->rstuff[0];
          c = PERIOD;
          while (c--) checkend |= (cpt + c)->facts[12];
          checkend |= (rownum + CLEARUP) & (1 << 31);
          if (!checkend) {
            if (PERIOD < DEPTH - 1) {
              c = 1;
              while (c < DEPTH - PERIOD) {
                (nchild + c - 1)->value = (glist - c - 1)->rstuff[0];
                (nchild + c - 1)->parent = nchild + c - 2;
                (glist - c - 1)->loc = nchild + c - 1;
                c++;
                }
              }
            printf("#P %d %d\n", xscreen, yscreen);
            if (NOSYM) xscreen += BITSWIDE + 6;
            else xscreen += 2*BITSWIDE + 6;
            if (xscreen > 300) {
              yscreen += rownum/(PERIOD/2) + 8;
              xscreen = 0;
              }
            ancestor = (cpt + PERIOD)->loc;
            c = (DEPTH + rownum - 1) % (PERIOD/2);
//printf("fault here %d %d\n", c, DEPTH + rownum);
//fflush(stdout);
            while (c--) ancestor = ancestor->parent;
//printf("more fault here %d %d\n", c, DEPTH + rownum);
//fflush(stdout);
            while (ancestor != allroads) {
              t1 = ancestor->value;
              if (!t1) putchar('.');
              if (NOSYM && t1) {
                t1 >>= (BUFFERIGHT - EXRIGHT);
                }
              else if (t1) {
                t2 = 1 << (BUFFERIGHT + BITSWIDE + EXLEFT - 1);
                while (t2 > 1) {
                  if (t2 & t1) putchar('*');
                  else putchar('.');
                  t2 >>= 1;
                  }
                if (EVENSYM) {
                  if (t2 & t1) putchar('*');
                  else putchar('.');
                  }
                else if (ODDSYM);
                else {
                  if (t2 & t1) putchar('*');
                  else putchar('.');
                  putchar('.');
                  }
                }
              while (t1) {
                if (t1 & 1) putchar('*');
                else putchar('.');
                t1 >>= 1;
                }
              putchar('\n');
              c = PERIOD/2;
              while (c--) ancestor = ancestor->parent;
              }
            fflush(stdout);
            if (CLEARAT) clearsum = (rownum + CLEARUP)/CLEARAT;
            else clearsum = CLEARUP;
            c = clearsum;
            tancestor = nchild - 1;
            while (c--) tancestor = tancestor->parent;
            ancestor = tancestor;
            while (tancestor == ancestor) {
              nchild--;
              c = clearsum;
              ancestor = nchild - 1;
              while (c--) ancestor = ancestor->parent;
              }
            if (clearsum) ancestor = tancestor;
            while (tancestor == ancestor) {
              onroad++;
              c = clearsum - 1;
              ancestor = onroad;
              while (c--) ancestor = ancestor->parent;
              }
            if (clearsum) {
              onroad--;
              (glist - 1)->rstuff[0] = valimit;
              }
            }
          }
        trownum = rownum;
        cpt = glist - 1;
        tempcpt = cpt;
        if (PERIOD > 4) while (tempcpt < glist + 3) {
          tempcpt->cprtop = 0;
          no5way = tempcpt->facts + 12;
          c = 32;
          while (c--) no5way[c+96] = no5way[c];
          tempcpt->knockout = valinc;
          tempcpt++;
          }
        oldcpt = cpt;
        oldval = cpt->rstuff[0];
        newval = oldval + valinc;
        if (newval >= valimit) cpt = glist;
        }
      else if (!xr0) {
        if (contries >= 1000000000) {
          contries -= 1000000000;
          contriesb++;
          }
        if (conmissq >= 1000000000) {
          conmissq -= 1000000000;
          conmissqb++;
          }
        if (contramisses >= 1000000000) {
          contramisses -= 1000000000;
          contramissesb++;
          }
        if (contrits >= 1000000000) {
          contrits -= 1000000000;
          contritsb++;
          }
        if (numtries >= 1000000000) {
          numtries -= 1000000000;
          numtriesb++;
          }
        trownum++;
        rpto = (cpt + 1)->rstuff;
        rpt = cpt->rstuff;
        t2 = *rpt;
        if (FLIP && !(((glist - cpt) + rownum) % (PERIOD/2))) {
          t1 = t2;
          t2 = 0;
          c = BITSWIDE;
          while (c--) {
            t2 <<= 1;
            t2 |= t1 & (1 << BUFFERIGHT);
            t1 >>= 1;
            }
          }
        cpt->checker = t2;
        if (YMOVE && !(((glist - cpt) + rownum) % (PERIOD/2))) cpt->checker <<= 1;
        while (rpt < cpt->rstuff + 6*2) {
          rpt += 6;
          rpto += 6;
          }
        if (0 && (cpt->numdives)) {
          no5way = (cpt + 1)->facts + 12;
          c = 32;
          while (c--) no5way[c+96] = no5way[c];
          cpt->knockout = valinc;
          cpt->numdives++;
          (cpt + 1)->numddives++;
          t1 = cpt->lastdive ^ newval;
          cpt->lastdive = newval;
          cpt--;
          while (cpt->knockout & t1) cpt->knockout <<= 1;
          cpt->numdives = 0;
          cpt->numddives = 0;
          newval = 0;
          (cpt + PERIOD/2)->protop = 0;
          no5way = (cpt + PERIOD/2)->facts + 12;
          c = 64;
          while (c--) no5way[c+32] &= ~(t1 | (t1 >> 1));
          c = 32;
          while (c--) {
            no5way[c+32] |= no5way[96+c] | (no5way[96+(c>>1)] >> 1);
            no5way[c+64] |= no5way[96+c] | (no5way[96+16+(c>>1)] >> 1);
            }
          }
        else {
          (cpt + 1)->cprtop = 0;
          no5way = (cpt + 1)->facts + 12;
          c = 32;
          while (c--) no5way[c+96] = no5way[c];
          cpt->knockout = valinc;
          cpt->numdives++;
          (cpt + 1)->numddives++;
          cpt->lastdive = newval;
          cpt--;
          cpt->knockout = valimit;
          cpt->numdives = 0;
          cpt->numddives = 0;
          cpt->contop = 0;
          newval = 0;
          (cpt + PERIOD/2)->protop = 0;
          no5way = (cpt + PERIOD/2)->facts + 12;
          c = 32;
          while (c--) {
            no5way[c+32] = no5way[96+c] | (no5way[96+(c>>1)] >> 1);
            no5way[c+64] = no5way[96+c] | (no5way[96+16+(c>>1)] >> 1);
            }
          }
        }
      else {
        if (SLOWER && (!(((glist - cpt) + rownum) % (PERIOD/2)) || (VERYSLOW && !(((glist - cpt) + rownum + 1) % (PERIOD/2)))))
          t1 = ((xr0 >> 1) | valinc) >> 1;
        else t1 = ((xr0 >> 2) | valinc) >> 1;
        t1 |= t1 >> 1;
        t1 |= t1 >> 2;
        t1 |= t1 >> 4;
        t1 |= t1 >> 8;
        t1 |= t1 >> 16;
        if (newval < valimit) {
          if (FLIP && !(((glist - cpt) + rownum - 1) % (PERIOD/2))) {
            xr0 = 1 << (2*BUFFERIGHT + BITSWIDE - xr0loc - props - 1);
//printf("xr0loc %d %d %x %x %x %x %x\n", ((glist - cpt) + rownum - 1), xr0loc, xr0, t1, cpt->knockout, (cpt + 1)->rstuff[0], newval);
            if (xr0loc == 32) xr0 = valinc;
//            xr0 = valinc;
            }
          if (YMOVE && !(((glist - cpt) + rownum - 1) % (PERIOD/2))) xr0 >>= 1;
          if (xr0 < valinc) cpt->knockout = valinc;
          c = valinc;
          while (c < cpt->knockout) {
            if (c & xr0) cpt->knockout = c;
//            if (!(~c & xr0)) cpt->knockout = c;
            else {
              xr0 &= ~c;
              c <<= 1;
              }
            }
          }
        oldval = newval;
        newval = (oldval & ~t1) + t1 + 1;
        while ((newval >= valimit) && (cpt < glist)) {
          if (cpt->numddives && (PERIOD >= 6)) {
            tempcpt = cpt + 3;
            while (tempcpt < cpt + 4) {
              tempcpt->cprtop = 0;
              no5way = tempcpt->facts + 12;
              c = 32;
              while (c--) no5way[c+96] = no5way[c];
              tempcpt->knockout = valinc;
              tempcpt++;
              }
            }
          if (cpt->numddives && (PERIOD >= 8)) {
            tempcpt = cpt + 4;
            while (tempcpt < cpt + 5) {
              tempcpt->cprtop = 0;
              no5way = tempcpt->facts + 12;
              c = 32;
              while (c--) no5way[c+96] = no5way[c];
              tempcpt->knockout = valinc;
              tempcpt++;
              }
            }
          if (1 && (!cpt->numdives || (!cpt->numddives && (PERIOD >= 6))) && cpt->contop) {
            no5way = (cpt + PERIOD/2 + 1)->facts + 12;
            oldval = (cpt + 1)->rstuff[0];
            if (cpt->contop < 2*MAXCONSTACK) {
              c = cpt->contop;
              t1 = 32;
              t2 = 0;
//printf("contop %d %d %x %x %x\n", cpt->contop, cpt->constack[cpt->contop - 1], cpt->constack[cpt->contop - 2], oldval, (cpt + 2)->rstuff[0]);
//printf("contop more %x %x %x %x\n", t1, t2, t3, oldval);
              t3 = 0;
              while (c) {
                c -= 2;
                if (cpt->constack[c] < t1) t1 = cpt->constack[c];
                if ((cpt->constack[c] + cpt->constack[c+1]) > t2) t2 = cpt->constack[c] + cpt->constack[c+1];
                t3 |= (1 << (cpt->constack[c] + cpt->constack[c+1] + 1)) - (1 << cpt->constack[c]);
                }
              if ((t2 - t1) < 5) {
                t3 >>= t1;
                if (YMOVE && !(((glist - cpt) + rownum - 1) % (PERIOD/2))) {
                  oldval >>= t1 - 1;
                  t2 = 1 << (t1 + 1);
                  }
                else {
                  oldval >>= t1;
                  t2 = 1 << (t1 + 2);
                  }
                c = 32;
                while (c--) if (!(t3 & (c ^ oldval))) no5way[96 + c] |= t2;
                }
              else if ((cpt + PERIOD/2 + 1)->cprtop < 3*MAXCPRSTACK) {
                if (YMOVE && !(((glist - cpt) + rownum - 1) % (PERIOD/2))) {
                  t1--;
                  t3 >>= 1;
                  }
                (cpt + PERIOD/2 + 1)->cprstack[(cpt + PERIOD/2 + 1)->cprtop] = t1 - 2;
                (cpt + PERIOD/2 + 1)->cprstack[(cpt + PERIOD/2 + 1)->cprtop + 1] = t3;
                (cpt + PERIOD/2 + 1)->cprstack[(cpt + PERIOD/2 + 1)->cprtop + 2] = oldval;
                (cpt + PERIOD/2 + 1)->cprtop += 3;
                }
              }
            c = 32;
            while (c--) {
              no5way[c+32] |= no5way[96+c] | (no5way[96+(c>>1)] >> 1);
              no5way[c+64] |= no5way[96+c] | (no5way[96+16+(c>>1)] >> 1);
              }
            }
          xr0 = 0;
          cpt++;
          oldcpt = cpt;
          trownum--;
          oldval = cpt->rstuff[0];
          newval = (oldval & ~((cpt - 1)->knockout - 1)) + (cpt - 1)->knockout;
//          newval = oldval + valinc;
          }
        }
      }
    onroad++;
    }
  tempcpt = glist + 2*PERIOD;
  while (tempcpt > glist) {
    tempcpt->loc = allroads;
    tempcpt--;
    tempcpt->loc = allroads;
    newfacts = (tempcpt + 1)->facts;
    oldfacts = tempcpt->facts;
    while (oldfacts < tempcpt->facts + FACTDEPTH*(PERIOD + 1)*NUMFACTS) *newfacts++ = *oldfacts++;
    }
/*
  oldfacts = glist->facts + (PERIOD + 1)*NUMFACTS;
  newfacts = glist->facts;
  while (oldfacts < glist->facts + FACTDEPTH*(PERIOD + 1)*NUMFACTS) *newfacts++ = *oldfacts++;
  oldfacts = factemplate;
  while (newfacts < glist->facts + FACTDEPTH*(PERIOD + 1)*NUMFACTS) *newfacts++ = *oldfacts++;
*/
  offroad = nchild;
  forcntpnt = forbearcnt;
  while (*forcntpnt != 0) forcntpnt++;
  printf("#D");
  while (forcntpnt-- > forbearcnt) {
    printf(" %d", *forcntpnt);
    *forcntpnt = 0;
    }
  printf("\n");
  rownum++;
  if (contrits >= 1000000000) {
    contrits -= 1000000000;
    contritsb++;
    }
  if (numtries >= 1000000000) {
    numtries -= 1000000000;
    numtriesb++;
    }
  printf("#D %d %d %d %d %d %d %d %d %d %d %d %d %d\n", rownum, numtriesb, numtries, contriesb, contries,
         conmissqb, conmissq, contritsb, contrits, contramissesb, contramisses, offroad - allroads, numhits);
  ancestor = onroad;
  if (TREEOUT) while (ancestor < offroad) {
    printf("#N %x %d\n", ancestor->value, onroad - ancestor->parent);
    ancestor++;
    }
  fflush(stdout);
  if ((onroad < offroad) && (MEMCOMP & 1)) {
    tancestor = onroad;
    nchild = offroad - 1;
    ancestor = tancestor;
    while (nchild->parent > allroads) {
      if (nchild->parent == ancestor) {
        nchild->parent = tancestor;
        nchild--;
        }
      else {
        ancestor = nchild->parent;
        tancestor--;
        tancestor->value = nchild->parent->value;
        tancestor->parent = nchild->parent->parent;
        nchild->parent = tancestor;
        nchild--;
        }
      }
    ancestor = allroads + 1;
    nchild = tancestor;
    while (nchild->parent == allroads) {
      ancestor->value = nchild->value;
      ancestor->parent = nchild->parent;
      ancestor++;
      nchild++;
      }
    while (nchild < offroad) {
      ancestor->value = nchild->value;
      ancestor->parent = nchild->parent - (nchild - ancestor);
      ancestor++;
      nchild++;
      }
    onroad = onroad - (nchild - ancestor);
    offroad = ancestor;
    nchild = offroad;
    }
  if ((onroad < offroad) && (MEMCOMP & 2)) {
    t0 = 1;
    while (t0 < (offroad - onroad)) {
      t1 = 0;
      while (t1 < (offroad - onroad)) {
        t5 = t1;
        t3 = t1;
        t1 += t0;
        if (t1 > (offroad - onroad)) t1 = offroad - onroad;
        t2 = t1;
        t4 = t1;
        t1 += t0;
        if (t1 > (offroad - onroad)) t1 = offroad - onroad;
        while (t5 < t1) {
          if (t4 == t1) {
            ancestor = onroad + t3;
            tancestor = offroad + t5;
            tancestor->value = ancestor->value;
            tancestor->parent = ancestor->parent;
            t3++;
            }
          else if (t3 == t2) {
            ancestor = onroad + t4;
            tancestor = offroad + t5;
            tancestor->value = ancestor->value;
            tancestor->parent = ancestor->parent;
            t4++;
            }
          else {
            ancestor = onroad + t3;
            tancestor = onroad + t4;
            c = 2*PERIOD - 1;
            while (c && (ancestor->value == tancestor->value)) {
              c--;
              ancestor = ancestor->parent;
              tancestor = tancestor->parent;
              }
            if ((ancestor->value < tancestor->value) || ((ancestor->value == tancestor->value) && (ancestor->parent < tancestor->parent))) {
              ancestor = onroad + t3;
              tancestor = offroad + t5;
              tancestor->value = ancestor->value;
              tancestor->parent = ancestor->parent;
              t3++;
              }
            else {
              ancestor = onroad + t4;
              tancestor = offroad + t5;
              tancestor->value = ancestor->value;
              tancestor->parent = ancestor->parent;
              t4++;
              }
            }
          t5++;
          }
        }
      t1 = 0;
      while (t1 < (offroad - onroad)) {
        tancestor = onroad + t1;
        ancestor = offroad + t1;
        tancestor->value = ancestor->value;
        tancestor->parent = ancestor->parent;
        t1++;
        }
      t0 <<= 1;
      }
    t2 = 0;
    t1 = 0;
    ancestor = onroad + t1;
    tancestor = offroad + t2;
    tancestor->value = ancestor->value;
    tancestor->parent = ancestor->parent;
    t2++;
    t1++;
    while (t1 < (offroad - onroad)) {
      ancestor = onroad + t1;
      tancestor = offroad + t2;
      tancestor->value = ancestor->value;
      tancestor->parent = ancestor->parent;
      ancestor = onroad + t1 - 1;
      tancestor = onroad + t1;
      c = 2*PERIOD - 1;
      while (c && (ancestor->value == tancestor->value)) {
        c--;
        ancestor = ancestor->parent;
        tancestor = tancestor->parent;
        }
      if (ancestor->value != tancestor->value) t2++;
/*
      else {
        ancestor = onroad + t1 - 1;
        printf("#P %d 0\n", rownum);
        while (ancestor != allroads) {
          t3 = ancestor->value >> BUFFERIGHT;
          if (!t3) putchar('.');
          while (t3) {
            if (t3 & 1) putchar('*');
            else putchar('.');
            t3 >>= 1;
            }
          putchar('\n');
          c = PERIOD/2;
          while (c--) ancestor = ancestor->parent;
          }
        ancestor = onroad + t1;
        printf("#P %d 0\n", rownum);
        while (ancestor != allroads) {
          t3 = ancestor->value >> BUFFERIGHT;
          if (!t3) putchar('.');
          while (t3) {
            if (t3 & 1) putchar('*');
            else putchar('.');
            t3 >>= 1;
            }
          putchar('\n');
          c = PERIOD/2;
          while (c--) ancestor = ancestor->parent;
          }
        }
*/
      t1++;
      }
    t1 = t2;
    while (t1--) {
      tancestor = onroad + t1;
      ancestor = offroad + t1;
      tancestor->value = ancestor->value;
      tancestor->parent = ancestor->parent;
      }
    offroad = onroad + t2;
    t0 = 1;
    while (t0 < (offroad - onroad)) {
      t1 = 0;
      while (t1 < (offroad - onroad)) {
        t5 = t1;
        t3 = t1;
        t1 += t0;
        if (t1 > (offroad - onroad)) t1 = offroad - onroad;
        t2 = t1;
        t4 = t1;
        t1 += t0;
        if (t1 > (offroad - onroad)) t1 = offroad - onroad;
        while (t5 < t1) {
          if (t4 == t1) {
            ancestor = onroad + t3;
            tancestor = offroad + t5;
            tancestor->value = ancestor->value;
            tancestor->parent = ancestor->parent;
            t3++;
            }
          else if (t3 == t2) {
            ancestor = onroad + t4;
            tancestor = offroad + t5;
            tancestor->value = ancestor->value;
            tancestor->parent = ancestor->parent;
            t4++;
            }
          else {
            ancestor = onroad + t3;
            tancestor = onroad + t4;
            if ((ancestor->parent < tancestor->parent) || ((ancestor->parent == tancestor->parent) && (ancestor->value < tancestor->value))) {
              ancestor = onroad + t3;
              tancestor = offroad + t5;
              tancestor->value = ancestor->value;
              tancestor->parent = ancestor->parent;
              t3++;
              }
            else {
              ancestor = onroad + t4;
              tancestor = offroad + t5;
              tancestor->value = ancestor->value;
              tancestor->parent = ancestor->parent;
              t4++;
              }
            }
          t5++;
          }
        }
      t1 = 0;
      while (t1 < (offroad - onroad)) {
        tancestor = onroad + t1;
        ancestor = offroad + t1;
        tancestor->value = ancestor->value;
        tancestor->parent = ancestor->parent;
        t1++;
        }
      t0 <<= 1;
      }
    nchild = offroad;
    }
  }
if (1 || TREEOUT) printf("#P %d 0\n", -(BITSWIDE + 10));
ancestor = firsthit;
while ((rownum - 2) % (PERIOD/2)) {
  ancestor = ancestor->parent;
  rownum--;
  }
if (1 || TREEOUT) while (ancestor != allroads) {
              t1 = ancestor->value;
              if (!t1) putchar('.');
              if (NOSYM && t1) {
                t1 >>= (BUFFERIGHT - EXRIGHT);
                }
              else if (t1) {
                t2 = 1 << (BUFFERIGHT + BITSWIDE + EXLEFT - 1);
                while (t2 > 1) {
                  if (t2 & t1) putchar('*');
                  else putchar('.');
                  t2 >>= 1;
                  }
                if (EVENSYM) {
                  if (t2 & t1) putchar('*');
                  else putchar('.');
                  }
                else if (ODDSYM);
                else {
                  if (t2 & t1) putchar('*');
                  else putchar('.');
                  putchar('.');
                  }
                }
              while (t1) {
                if (t1 & 1) putchar('*');
                else putchar('.');
                t1 >>= 1;
                }
              putchar('\n');
              c = PERIOD/2;
              while (c--) ancestor = ancestor->parent;
  }
}
