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)

a = vector(10 000)
a[1] = 1
a[2] = 2

{
	p=0;
	n=0;
	for (r=1, oo,
		for (v=1, oo,
			if (p!=v && !seen(z=a[r]+v*I),
				see(z);
				for (i=1, a[r],
					a[n++]=v;
					print (n " " v);
					if (n==#a, break (3));
				);
				p=v;
				break;
			);
		);
	);
}

quit