Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll A, B, N, M, S, T, d[15][15];
ll adj[102][102];
ll dist[204];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> A >> B;
	for (int i = 1; i <= A; ++i){
		for (int j = 1; j <= B; ++j){
			cin >> d[i][j];
		}
	}
	S = 1;
	T = 202;
	for (int i = 0; i <= 100; ++i){
		for (int j = 0; j <= 100; ++j){
			int maxi = 0;
			for (int k = 1; k <= A; ++k){
				for (int l = 1; l <= B; ++l){
					maxi = max(maxi,d[k][l]-k*i-j*l);
				}
			}
			adj[i][j] = maxi;
			if (maxi > 100){
				cout << "Impossible\n";
				return 0;
			}
		}
	}
	for (int k = 1; k <= A; ++k){
		for (int l = 1; l <= B; ++l){
			dist[1] = 0;
			for (int i = 1; i <= 100; ++i){
				dist[i+1] = dist[i] + k;
			}
			for (int i = 0; i <= 100; ++i){
				int mini = 1e9;
				for (int j = 0; j <= 100; ++j){
					mini = min(mini,adj[j][100-i]+dist[j+1]);
				}
				if (i > 0){
					mini = min(mini,dist[102+i-1]+l);
				}
				dist[102+i] = mini;
			}
			if (dist[202] != d[k][l]){
				cout << "Impossible\n";
				return 0;
			}
		}
	}
	N = 202;
	M = 100+100+(101*101);
	for (int i = 1; i <= 100; ++i){
		cout << i << ' ' << i+1 << ' ' << 'X' << '\n';
	}
	for (int i = 102; i <= 201; ++i){
		cout << i << ' ' << i+1 << ' ' << 'Y' << '\n';
	}
	for (int i = 0; i <= 100; ++i){
		for (int j = 0; j <= 100; ++j){
			cout << i+1 << ' ' << j+102 << ' ' << adj[i][100-j] << '\n';
		}
	}
	cout << S << ' ' << T << '\n';
	cout << flush;
	//for (int i = 1; i < 1e9; ++i){for (int j = 0; j < 1e9; ++j){}}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:51: error: no matching function for call to 'max(int&, ll)'
   27 |                                         maxi = max(maxi,d[k][l]-k*i-j*l);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:27:51: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   27 |                                         maxi = max(maxi,d[k][l]-k*i-j*l);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:27:51: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   27 |                                         maxi = max(maxi,d[k][l]-k*i-j*l);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:46:51: error: no matching function for call to 'min(int&, ll)'
   46 |                                         mini = min(mini,adj[j][100-i]+dist[j+1]);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:46:51: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   46 |                                         mini = min(mini,adj[j][100-i]+dist[j+1]);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:46:51: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   46 |                                         mini = min(mini,adj[j][100-i]+dist[j+1]);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:49:51: error: no matching function for call to 'min(int&, ll)'
   49 |                                         mini = min(mini,dist[102+i-1]+l);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:49:51: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   49 |                                         mini = min(mini,dist[102+i-1]+l);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:49:51: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   49 |                                         mini = min(mini,dist[102+i-1]+l);
      |                                                ~~~^~~~~~~~~~~~~~~~~~~~~~