// Print all b-subsets of AG(3,3) with >= minL lines, one per translation class, as 4D indices (3D index * 3, hyperplane x4=0).
#include <cstdio>
#include <cstdlib>
#include <cstdint>
static int ADD[27][27], THIRD[27][27];
static inline int enc(int a, int b, int c) { return a * 9 + b * 3 + c; }
uint32_t translate(uint32_t m, int v) { uint32_t r = 0; for (int x = 0; x < 27; x++) if (m >> x & 1) r |= 1u << ADD[x][v]; return r; }
bool transl_min(uint32_t m) { for (int v = 1; v < 27; v++) if (translate(m, v) < m) return false; return true; }
int main(int argc, char** argv) {
    int b = atoi(argv[1]), minL = atoi(argv[2]);
    for (int x = 0; x < 27; x++) for (int y = 0; y < 27; y++) { int xc[3] = {x / 9, (x / 3) % 3, x % 3}, yc[3] = {y / 9, (y / 3) % 3, y % 3};
        ADD[x][y] = enc((xc[0] + yc[0]) % 3, (xc[1] + yc[1]) % 3, (xc[2] + yc[2]) % 3);
        THIRD[x][y] = enc((6 - xc[0] - yc[0]) % 3, (6 - xc[1] - yc[1]) % 3, (6 - xc[2] - yc[2]) % 3); }
    uint32_t mask = 0; int L = 0, n = 0;
    for (uint64_t i = 1; i < (1ull << 27); i++) {
        int p = __builtin_ctzll(i); int cnt = 0; uint32_t m = mask & ~(1u << p);
        while (m) { int y = __builtin_ctz(m); m &= m - 1; if (mask >> THIRD[p][y] & 1) cnt++; } cnt /= 2;
        if (mask >> p & 1) { mask &= ~(1u << p); L -= cnt; n--; } else { mask |= 1u << p; L += cnt; n++; }
        if (n == b && L >= minL && transl_min(mask)) { for (int x = 0; x < 27; x++) if (mask >> x & 1) printf("%d ", 3 * x); printf("\n"); }
    }
}
