// Escribe en DIMACS una fórmula 3-SAT al azar: random_3sat VARIABLES CLAUSULAS SEMILLA. Cada cláusula tiene
// tres variables distintas y signos al azar. Usa std::mt19937 directamente, y sale igual en toda máquina.
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <random>

int main(int argc, char* argv[]) {
    if (argc != 4) {
        std::cerr << "uso: random_3sat VARIABLES CLAUSULAS SEMILLA\n";
        return 1;
    }
    const std::uint32_t n = static_cast<std::uint32_t>(std::atoi(argv[1]));
    const std::uint32_t m = static_cast<std::uint32_t>(std::atoi(argv[2]));
    std::mt19937 random(static_cast<std::uint32_t>(std::atoi(argv[3])));
    std::cout << "p cnf " << n << ' ' << m << '\n';
    for (std::uint32_t c = 0; c < m; c++) {
        std::uint32_t a = 1 + random() % n;
        std::uint32_t b = a;
        std::uint32_t d = a;
        while (b == a) b = 1 + random() % n;
        while (d == a || d == b) d = 1 + random() % n;
        for (std::uint32_t v : {a, b, d}) std::cout << (random() % 2 ? "-" : "") << v << ' ';
        std::cout << "0\n";
    }
}
