#include #include #include #define M(S,I) (putchar ("\n "#S[((I)+1)%5])) #define I(D) (D<<2)%15 #define N(X,Y) (X<0 || Y<0 || X>=a || Y>=b) #define O(X,Y,Z) (s?X=(g=s)->x, Y=s->y, Z=s->z, s=s->n, free (g),1:0) #define T(X,Y,Z) (A(g,1)->n=s, (s=g)->x=(X), s->y=(Y), s->z=(Z)) #define A(V,S) (V = malloc(sizeof*V*(S))) #define U(X,Y,Z) X+=!!(Z&10)*(-!!(Z&9)+!!(Z&6)), Y+=!!(Z&5)*(-!!(Z&9)+!!(Z&6)) #define R(L) ((int)(((double)rand()/RAND_MAX)*(L))) #define call(FUNC,X,Y) do { T(z+1,c,t), T(FUNC,X,Y), return(0); #define from(FUNC,L) sub FUNC+L:; } while (0) #define return(R) longjmp (j, R) #define begin int main(int argc,char**argv) {srand((unsigned)time(NULL)),r=setjmp(j)-1,O(z,c,t);switch(z){ #define end }return 0;} #define sub case #define endsub return(0);break; enum {n,E,H,W,V,F,M=7,C=9,G=11,Z=14}; int a,b,c,d,e,k,l,m,o,p,r,t,v,w,x,y,z,putchar(int); unsigned char**u; jmp_buf j; struct{int x,y,z;void*n;}*f,*g,*s; begin sub Z: x=(c%(a+H))-E, y=(c/(a+H))-E; M (#io,x==v&&y==w?H:x==o&&y==p?W:x==a?V:ym/H)*l, c=l?R(v?m-l:l):l++, x=f[c+v].x, y=f[c+v].y, v?U(x,y,d),d=I(d):(u[y][x]|=E<E?atoi(argv[E]):G-E)<(b=argc>H?atoi(argv[H]):F), m = b*a, A(f, m--), A(u, b); call (M, b-E, n) from (n,E); call (F, m, n) from (n,H); call (G, n, E) from (n,W); v=e?R(a)*H:-E, w=e?-E:R(b)*H; o=e?R(a)*H:a*H-E, p=e?b*H-E:R(b)*H, a*=H, b*=H; call (Z, n, n) from (n, V); end