D = 200 H = vector(D, n, [+oo]) V = vector(D, k, [+oo]) { a = vector(10 000); u = 1; m = 0; for (d = 1, D, for (n = 1, d, k = d + 1 - n; if (n==1 && k==1, v = 1, H[n][1] < V[k][1], v = H[n][1]; H[n] = H[n][2..#H[n]], v = V[k][1]; V[k] = V[k][2..#V[k]] ); m++; if (v <= #a, a[v] = m; while (a[u], print (u " " a[u]); if (u++ > #a, break (3); ); ); ); H[n] = setunion(H[n], [2*v]); V[k] = setunion(V[k], [2*v+1]); ); ); } quit