#include <stdio.h>
#include <stdlib.h>
#include "alexg.misc/avgmalloc.h"
#include "alexg.misc/avgtime.h"

#define ELMNTS 8
#define MODULO 100000
#define MODULO_UINT ((unsigned int) 0x7FFFFFFF)

#define WRITELINE2  if (DEBUG) { \
        printf("C: %6d(%2d %2d)Out:",n, 1     ,1      );\
        for(i=0;i<ELMNTS+4;i++) printf("%d ",(int)ptr1[i]); printf("...");\
        for(i=n-ELMNTS-4;i<n;i++) printf("%7d ",(int)ptr1[i]); printf("\n");\
        printf("      +         "); \
        for(i=0;i<ELMNTS;i++) printf("%7d ",(int)ptr2[i]); printf("...");\
        for(i=n-ELMNTS;i<n;i++) printf("%7d ",(int)ptr2[i]); printf("\n");\
        }\
        printf("(%3d,%3d,%9d,%d,%d):",1,1,n,type,runs);
#define CHECKLINE   for(i=0;i<n-1;i++) if (ptr1[i]>ptr1[i+1]) {printf("Not Sorted* %d :  %d %d\n",i,ptr1[i],ptr1[i+1]); }\
    if (ptr1[n-1]>ptr2[0]) {printf("NotSorted** %d : %d %d\n",0,ptr1[n-1],ptr2[0]);}\
    for(i=0;i<n-1;i++) if (ptr2[i]>ptr2[i+1]) {printf("Not Sorted*** %d : %d %d\n",i,ptr2[i],ptr2[i+1]); }
#define WRITELINE1   fflush(stdout);\
        if (DEBUG) { \
        printf("A: %6d(%2d %2d)In :",n,1      ,1      );\
        for(i=0;i<ELMNTS;i++) printf("%d ",(int)ptr1[i]); printf("..."); \
        for(i=n-ELMNTS;i<n;i++) printf("%d ",(int)ptr1[i]); printf("\n");\
        printf("B: %6d(%2d %2d)In :",n,1      ,1      );\
        for(i=0;i<ELMNTS;i++) printf("%d ",ptr2[i]); printf("...");\
        for(i=n-ELMNTS;i<n;i++) printf("%d ",ptr2[i]); printf("\n");\
        }
#define WRITE1  elapsed=0.0; for(j=0;j<runs;j++){\
	 memcpy(ptr1,bptr1,n*sizeof(int)); memcpy(ptr2,bptr2,n*sizeof(int)); \
	for(i=0;i<n;i++) ptr2[i] = bptr2[i]; avg_tstart();
#define WRITE2  avg_tend(); elapsed += (avg_treturn()); }

