// hloya template v25 // ░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░░░░░ // ░░░░░░█░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░█░░░░░ // ░░░░░░█░█░▀░░░░░▀░░▀░░░░█░█░░░░░ // ░░░░░░█░█░░░░░░░░▄▀▀▄░▀░█░█▄▀▀▄░ // █▀▀█▄░█░█░░▀░░░░░█░░░▀▄▄█▄▀░░░█░ // ▀▄▄░▀██░█▄░▀░░░▄▄▀░░░░░░░░░░░░▀▄ // ░░▀█▄▄█░█░░░░▄░░█░░░▄█░░░▄░▄█░░█ // ░░░░░▀█░▀▄▀░░░░░█░██░▄░░▄░░▄░███ // ░░░░░▄█▄░░▀▀▀▀▀▀▀▀▄░░▀▀▀▀▀▀▀░▄▀░ // ░░░░█░░▄█▀█▀▀█▀▀▀▀▀▀█▀▀█▀█▀▀█░░░ // ░░░░▀▀▀▀░░▀▀▀░░░░░░░░▀▀▀░░▀▀░░░░ #include #include using namespace std; bool dbg = 0; clock_t start_time = clock(); #define current_time fixed< #define umap unordered_map #define files1 freopen("input.txt","r",stdin) #define files2 freopen("out2.txt","w",stdout) #define files files1;files2 #define fast_io ios_base::sync_with_stdio(0);cin.tie(0) #define endl '\n' #define ln(i,n) " \n"[(i) == (n) - 1] void bad(string mes = "Impossible"){cout << mes;exit(0);} void bad(int mes){cout << mes;exit(0);} template string bin(T x, int st = 2){ string ans = ""; while (x > 0){ ans += char('0' + x % st); x /= st; } reverse(ans.begin(), ans.end()); return ans.empty() ? "0" : ans; } template void amax(T& x, T y) { x = max(x, y); } template void amin(T& x, T y) { x = min(x, y); } inline int popcount(int x){ int count = 0; __asm__ volatile("POPCNT %1, %0;":"=r"(count):"r"(x):); return count; } template T input(){ T ans = 0, m = 1; char c = ' '; while (!((c >= '0' && c <= '9') || c == '-')) { c = getchar(); } if (c == '-') m = -1, c = getchar(); while (c >= '0' && c <= '9'){ ans = ans * 10 + (c - '0'), c = getchar(); } return ans * m; } template void read(T& a) { a = input(); } template void read(T& a, T& b) { read(a), read(b); } template void read(T& a, T& b, T& c) { read(a, b), read(c); } template void read(T& a, T& b, T& c, T& d) { read(a, b), read(c, d); } const int inf = 1e9 + 20; const short short_inf = 3e4 + 20; const long double eps = 1e-12; const int maxn = 1e5 + 12, base = 1e9 + 7; const ll llinf = 2e18 + 5; template T binpow(T n, T s) { if (s <= 0) return 1LL; if (s % 2 == 0){ T b = binpow(n, s / 2); return ( 1LL * b * b ) % base; } else { return (1LL* binpow(n, s - 1) * n) % base; } } int b[1011][1011]; int c[1011], d[1011], a[1001], n; void print() { int x = a[0]; for (int i = 0; i < n; i++) { a[i] -= x; c[i] = -a[i]; } bool le = 1; for (int i = 0; i < n; i++) { if (a[i] < c[i]) { le = 1; break; } if (a[i] > c[i]) { le = 0; break; } } if (le) { for (int i = 0; i < n; i++) { printf("%d", a[i]); if (i != n - 1) printf(" "); } puts(""); } else { for (int i = 0; i < n; i++) { printf("%d", c[i]); if (i != n - 1) printf(" "); } puts(""); } } int main() { int q; // files1; read(n, q); pii res = mp(-inf, 0); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { read(b[i][j]); amax(res, mp(b[i][j], i)); } int r = res.s; for (int i = 0; i < n; i++) { a[i] = b[r][i]; } print(); for (int i = 0; i < q; i++) { int row; read(row); row--; for (int j = 0; j < n; j++) { read(d[j]); b[row][j] = d[j]; b[j][row] = d[j]; } if (row == 0) { a[0] = a[1] - b[1][0]; bool ok = 1; for (int j = 0; j < n; j++) { if (b[0][j] != abs(a[0] - a[j])) { ok = 0; break; } } if (!ok) { a[0] = a[1] + b[1][0]; ok = 1; for (int j = 0; j < n; j++) { if (b[0][j] != abs(a[0] - a[j])) assert(0); } } } else { a[row] = a[0] - b[0][row]; bool ok = 1; for (int j = 0; j < n; j++) { if (b[row][j] != abs(a[row] - a[j])) { ok = 0; break; } } if (!ok) { a[row] = a[0] + b[0][row]; ok = 1; for (int j = 0; j < n; j++) { if (b[row][j] != abs(a[row] - a[j])) assert(0); } } } print(); } return 0; }