#include using namespace std; static const int N = 50; static const int MOD = 100000000; typedef long long ll; //=== Annealing parameters ===// struct SAParams { double T0 = 1e4; // initial temperature double Tend = 1e-4; // final temperature double alpha = 0.995; // cooling rate int maxIter = 1000000; // maximum iterations double timeLimit = 1.9; // seconds int deltaRange = 1000000; // max random change per move } sa; int a[N][N]; int c[N]; int best_c[N]; int b[N][N]; mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); uniform_int_distribution uni_pos(0, N - 1); uniform_int_distribution uni_delta(-sa.deltaRange, sa.deltaRange); double elapsed() { static auto start = chrono::high_resolution_clock::now(); auto now = chrono::high_resolution_clock::now(); return chrono::duration(now - start).count(); } // Build pyramid from bottom c into b void build() { for (int j = 0; j < N; j++) b[N - 1][j] = (c[j] % MOD + MOD) % MOD; for (int i = N - 2; i >= 0; i--) { for (int j = 0; j <= i; j++) { b[i][j] = (b[i + 1][j] + b[i + 1][j + 1]) % MOD; } } } // Compute maximum modular error int evaluate() { int mx = 0; for (int i = 0; i < N; i++) for (int j = 0; j <= i; j++) { int diff = abs(a[i][j] - b[i][j]); mx = max(mx, min(diff, MOD - diff)); } return mx; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); for (int i = 0; i < N; i++) for (int j = 0; j <= i; j++) cin >> a[i][j]; // initialize bottom randomly for (int i = 0; i < N; i++) c[i] = uniform_int_distribution(0, MOD - 1)(rng); build(); int curScore = evaluate(); memcpy(best_c, c, sizeof(c)); int bestScore = curScore; double T = sa.T0; int iter = 0; while (elapsed() < sa.timeLimit && T > sa.Tend) { int pos = uni_pos(rng); int old = c[pos]; int delta = uni_delta(rng); c[pos] = (old + delta + MOD) % MOD; build(); int newScore = evaluate(); int diff = newScore - curScore; if (diff < 0 || exp(-diff / T) > uniform_real_distribution(0, 1)(rng)) { curScore = newScore; if (newScore < bestScore) { bestScore = newScore; memcpy(best_c, c, sizeof(c)); } } else { c[pos] = old; } T *= sa.alpha; iter++; } // output best solution for (int i = 0; i < N; i++) cout << best_c[i] << (i + 1 < N ? ' ' : '\n'); return 0; }