s = 0 unseen = 1 seen(v) = bit test(s, v) see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++) a = vector(10 000) used = 0 unused = 1 { for (n=1, #a, if (!seen(n), for (w=unused, oo, if (!bittest(used, w) && !seen(n+w) && !seen(n+2*w), see(n); see(n+w); see(n+2*w); a[n] = w; if (n+w<=#a, a[n+w] = w; if (n+2*w<=#a, a[n+2*w] = w; ); ); used += 2^w; while (bittest(used, unused), unused++; ); break; ); ); ); print (n " " a[n]); ); } quit