allocate mem(2^30) tr(v)=if (v>=0, 1+2*v, -2*v) big = 1 000 000 s = 0 S = [] xS = [] unseen = 0 seen(v) = { v = tr(v); if (v < big, bittest(s, v), setsearch(S, v) || setsearch(xS, v) ) } see(v) = { v = tr(v); if (v < big, s = bitor(s, 2^v), S = setunion(S, [v]); if (#S == 10 000, xS = setunion(xS, S); S = []; ); ); while (seen(unseen) && seen(-unseen), unseen++ ) } { m = -1; for (n = 1, 141, r = vector(n); v0 = unseen; while (1, if (!seen(v0), r[1] = v0; ok = 1; for (k=2, n, r[k] = -r[k-1]-p[k-1]; if (seen(r[k]), ok = 0; break; ); ); if (ok && #Set(r)==n, apply (see, r); break; ); ); v0 = (v0<=0) - v0; ); apply (v -> print (m++ " " v), r); p = r; ); } quit