Language: C++

#include <vector>
#include <iostream>
#include <cstdio>
#include <cassert>

using namespace std;
typedef long long ll;

int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

template <class T>
T remin(T &x, T val) {
    if (x > val) {x = val;}
    return x;
}

template <class T>
T remax(T &x, T val) {
    if (x < val) {x = val;}
    return x;
}
using pii = pair<int, int>;

struct F{
    int a, b, c;
};

void solve() {
    int n = nxt();
    int m = nxt();
    vector<vector<int> > d(n, vector<int>(m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            d[i][j] = nxt();
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j + 1 < m; ++j) {
            if (d[i][j + 1] < d[i][j]) {
                cout << "Impossible\n";
                return;
            }
        }
    }

    for (int i = 0; i + 1 < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (d[i + 1][j] < d[i][j]) {
                cout << "Impossible\n";
                return;
            }
        }
    }

    vector<F> v;
    const int T = 101;
    for (int i = 0; i < T; ++i) {
        for (int j = 0; j < T; ++j) {
            int k = -10000;
            for (int x = 0; x < n; ++x) {
                for (int y = 0; y < m; ++y) {
                    int cd = (x + 1) * i + (y + 1) * j;
                    int delta = d[x][y] - cd;
                    k = max(k, delta);
                }
            }
            v.push_back(F{i, j, k});
        }
    }

    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < m; ++y) {
            int val = 10000;
            for (const F&f : v) {
                int cv = f.a * (x + 1) + f.b * (y + 1) + f.c;
                assert(cv >= d[x][y]);
                val = min(val, cv);
            }
            if (val != d[x][y]) {
                cout << "Impossible\n";
                return;
            }
        }
    }
    int s = 0;
    int t = 299;
    vector<pii> e;
    vector<int> c;
    for (int i = 0; i < T; ++i) {
        e.push_back(make_pair(i, i + 1));
        c.push_back(INT_MIN);
    }
    int YY = T + 1;
    for (int i = 0; i < T; ++i) {
        e.push_back(make_pair(i + YY, i + 1 + YY));
        c.push_back(INT_MIN + 1);
    }

    for (const auto &f : v) {
        e.push_back(make_pair(f.a, YY));
        c.push_back(0);
        e.push_back(make_pair(YY + f.b, t));
        c.push_back(f.c);
    }
    cout << t + 1 << " " << e.size() << "\n";
    for (int i = 0; i < e.size(); ++i) {
        cout << e[i].first + 1 << " " << e[i].second + 1 << " ";
        if (c[i] == INT_MIN) {
            cout << "X";
        } else if (c[i] == INT_MIN + 1) {
            cout << "Y";
        } else {
            cout << c[i];
        }
        cout << "\n";
    }
    cout << s + 1 << " " << t + 1 << "\n";
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "r", stdout);
#endif

//    int t = nxt();
//    for (int i = 0; i < t; ++i) {
//        solve();
//    }
    solve();
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:96:21: error: 'INT_MIN' was not declared in this scope
   96 |         c.push_back(INT_MIN);
      |                     ^~~~~~~
a.cc:5:1: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include <cassert>
  +++ |+#include <climits>
    5 | 
a.cc:101:21: error: 'INT_MIN' was not declared in this scope
  101 |         c.push_back(INT_MIN + 1);
      |                     ^~~~~~~
a.cc:101:21: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:113:21: error: 'INT_MIN' was not declared in this scope
  113 |         if (c[i] == INT_MIN) {
      |                     ^~~~~~~
a.cc:113:21: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'