#include #include #include #include using namespace std; typedef pair number; int main() { bool first = true; int p, s; while (cin >> p && p > 0) { cin >> s; if (first) { first = false; } else { cout << endl; } number n[128][128]; map< pair, int> results; for (int i = 0; i < p + 1; i++) { for (int j = 0; j < s + 1; j++) { string str; cin >> str; if (str == "?") { n[i][j].second = true; } else { istringstream iss(str); iss >> n[i][j].first; n[i][j].second = false; } } } while (true) { bool found = false; for (int i = 0; i < p; i++) { int sum = 0, missing = -1; for (int j = 0; j < s; j++) { if (n[i][j].second) { if (missing >= 0) { missing = -1; break; } else { missing = j; } } else { sum += n[i][j].first; } } if (missing >= 0) { found = true; n[i][missing].first = (n[i][s].first - sum); n[i][missing].second = false; results[make_pair(i, missing)] = n[i][missing].first; } } for (int j = 0; j < s; j++) { int sum = 0, missing = -1; for (int i = 0; i < p; i++) { if (n[i][j].second) { if (missing >= 0) { missing = -1; break; } else { missing = i; } } else { sum += n[i][j].first; } } if (missing >= 0) { found = true; n[missing][j].first = (n[p][j].first - sum); n[missing][j].second = false; results[make_pair(missing, j)] = n[missing][j].first; } } if (!found) { break; } } bool found = false; for (int i = 0; i < p; i++) { for (int j = 0; j < s; j++) { if (n[i][j].second) { found = true; } } } if (found) { cout << "NO" << endl; } else { for (map< pair, int>::iterator it = results.begin(); it != results.end(); it++) { cout << it->second << endl; } } } return 0; }