A(n, k) = fromdigits(binary(n), 3) + fromdigits(binary(k), 3)
nb(n) = my (t = digits(n, 3)); 2^sum(k=1, #t, t[k]==1)

{
	T = vector((3^7-1)/2, n, vector(nb(n)));
	occ = vector(#T);
	u = 1;

	a = vector(8255);

	m = 0;
	i = 0;
	for (d = 1, oo,
		for (k = 0, d,
			m++;
			v = A(d-k, k);
			if (v <= #T,
				T[v][occ[v]++] = m;
				while (occ[u]==nb(u),
					apply (w -> a[w] = i++, T[u]);
					if (u++ > #T,
						break (3);
					);
				);
			);
		);
	);

	print ("0 0");
	for (n = 1, #a,
		print (n " " a[n]);
	);
}

quit