allocate mem(2^31);

tr(v)=if (v>=0, 1+2*v, -2*v)
big = 100000
s = []
S = []
seen(z)=my (x=tr(real(z)),y=tr(imag(z)));if (max(x,y)>big, setsearch(S,z), x>#s, 0, bittest(s[x],y))
see(z)=my (x=tr(real(z)),y=tr(imag(z)));if (max(x,y)>big, S=setunion(S,Set(z)); return, x>#s, s=concat(s,vector(x-#s))); s[x]=bitor(s[x],2^y)

dz = [1+I, 2*I, I-1, -1-I, -2*I, 1-I]

{
	dir = 1;

	mid points = [0];
	new mid points = [0];

	print ("0 0");
	
	for (n=1, M=2^13,
		print (n " " #mid points);

		if (n<M,
			apply (see, mid points);

			mm = 0;

			for (m=1, #mid points,
				z = mid points[m];

				for (c=0, 3,
					zz = z + (1+I)*I^c;

					if (!seen(zz),
						nb = 0;

						for (d=1, #dz,
							if (seen(zz + dz[d]*dir),
								nb++;
							);
						);

						if (nb==1,
							if (mm++ > #new mid points,
								new mid points = concat(new mid points, vector(#new mid points));
							);
							new mid points[mm] = zz;
						);
					);
				);
			);

			mid points = Set(new mid points[1..mm]);

			dir *= I;
		);
	);
}

quit