Problem:
Score : 800 points

Problem Statement

There is a grid with R rows and C columns.
We call the cell in the r-th row and c-th column (r，c).

Mr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a non-negative integer a_i into (r_i，c_i) for each i (1≤i≤N).
After that he fell asleep.

Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing integers into all remaining cells.
The grid must meet the following conditions to really surprise Mr. Takahashi.

Condition 1: Each cell contains a non-negative integer.

Condition 2: For any 2×2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers.

Determine whether it is possible to meet those conditions by properly writing integers into all remaining cells.

Constraints

2≤R，C≤10^5

1≤N≤10^5

1≤r_i≤R

1≤c_i≤C

(r_i，c_i) ≠ (r_j，c_j) (i≠j)

a_i is an integer.

0≤a_i≤10^9

Input

The input is given from Standard Input in the following format:

R C
N
r_1 c_1 a_1
r_2 c_2 a_2
:
r_N c_N a_N

Output

Print Yes if it is possible to meet the conditions by properly writing integers into all remaining cells.
Otherwise, print No.

Sample Input 1

2 2
3
1 1 0
1 2 10
2 1 20

Sample Output 1

Yes

You can write integers as follows.

Sample Input 2

2 3
5
1 1 0
1 2 10
1 3 20
2 1 30
2 3 40

Sample Output 2

No

There are two 2×2 squares on the grid, formed by the following cells:

Cells (1，1), (1，2), (2，1) and (2，2)

Cells (1，2), (1，3), (2，2) and (2，3)

You have to write 40 into the empty cell to meet the condition on the left square, but then it does not satisfy the condition on the right square.

Sample Input 3

2 2
3
1 1 20
1 2 10
2 1 0

Sample Output 3

No

You have to write -10 into the empty cell to meet condition 2, but then it does not satisfy condition 1.

Sample Input 4

3 3
4
1 1 0
1 3 10
3 1 10
3 3 20

Sample Output 4

Yes

You can write integers as follows.

Sample Input 5

2 2
4
1 1 0
1 2 10
2 1 30
2 2 20

Sample Output 5

No

All cells already contain a integer and condition 2 is not satisfied.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using ti3 = tuple<int, int, int>;
using vti3 = vector<ti3>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
template<class T> void cmin(T &a, const T&b) { if (a > b)a = b; }
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
const ll mod = 1000000007;
#ifndef INT_MAX
const int INT_MAX = numeric_limits<signed>().max();
#endif
template <class T>
inline void hash_combine(size_t & seed, const T & v) {
	hash<T> hasher;
	seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
namespace std {

	template<typename S, typename T> struct hash<pair<S, T>> {
		inline size_t operator()(const pair<S, T> & v) const {
			size_t seed = 0;
			hash_combine(seed, v.first);
			hash_combine(seed, v.second);
			return seed;
		}
	};
	// Recursive template code derived from Matthieu M.
	template <class Tuple, size_t Index = std::tuple_size<Tuple>::value - 1>
	struct HashValueImpl
	{
		static void apply(size_t& seed, Tuple const& tuple)
		{
			HashValueImpl<Tuple, Index - 1>::apply(seed, tuple);
			hash_combine(seed, std::get<Index>(tuple));
		}
	};

	template <class Tuple>
	struct HashValueImpl<Tuple, 0>
	{
		static void apply(size_t& seed, Tuple const& tuple)
		{
			hash_combine(seed, std::get<0>(tuple));
		}
	};

template <typename ... TT>
struct hash<std::tuple<TT...>>
{
	size_t
		operator()(std::tuple<TT...> const& tt) const
	{
		size_t seed = 0;
		HashValueImpl<std::tuple<TT...> >::apply(seed, tt);
		return seed;
	}

}; }
umap<ti3, ll> memo;
ll pow(ll base, ll i,ll mod) {
	ll a=1;
	while (i) {
		if (i & 1) {
			a *= base;
			a %= mod;
		}
		base *= base;
		base %= mod;
		i/=2;
	}
	return a;
}
class unionfind {
	vector<int> par, rank, size_;//速度ではなくメモリ効率を考えるならrankのかわりにsizeを使う
public:
	unionfind(int n) :par(n), rank(n), size_(n, 1) {
		iota(ALL(par), 0);
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y])swap(x, y);
		par[y] = x;
		size_[x] += size_[y];
		if (rank[x] == rank[y])rank[x]++;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return size_[find(x)];
	}
};
ll gcd(ll a, ll b) {
	while (b) {
		ll c = a%b;
		a = b;
		b = c;
	}
	return a;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}
int popcnt(unsigned long long a) {
	a = (a & 0x5555555555555555) + (a >> 1 & 0x5555555555555555);
	a = (a & 0x3333333333333333) + (a >> 2 & 0x3333333333333333);
	a = (a & 0x0f0f0f0f0f0f0f0f) + (a >> 4 & 0x0f0f0f0f0f0f0f0f);
	a = (a & 0x00ff00ff00ff00ff) + (a >> 8 & 0x00ff00ff00ff00ff);
	a = (a & 0x0000ffff0000ffff) + (a >> 16 & 0x0000ffff0000ffff);
	return (a & 0xffffffff) + (a >> 32);
}
signed main() {
	int r, c, n;
	cin >> r >> c >> n;
	vti3 a(n);
	vi vr(n), vc(n);
	rep(i, n) {
		int ri, ci, ai;
		cin >> ri >> ci >> ai;
		a[i] = make_tuple(ri, ci, ai);
		vr[i] = ri, vc[i] = ci;
	}
	sort(ALL(vr)); sort(ALL(vc));
	vr.erase(unique(ALL(vr)), vr.end());
	vc.erase(unique(ALL(vc)), vc.end());
	rep(i, n) {
		int ri, ci, ai;
		tie(ri, ci, ai) = a[i];
		ri = lower_bound(ALL(vr), ri) - vr.begin();
		ci = lower_bound(ALL(vc), ci) - vc.begin();
		a[i] = make_tuple(ri, ci, ai);
	}
	auto ac = a;
	sort(ALL(a));
	sort(ALL(ac), [](const ti3 &a, const ti3 &b) {return (get<1>(a) == get<1>(b)) ? (get<0>(a) < get<0>(b)) : (get<1>(a) < get<1>(b)); });
	vpii dr(vr.size(),pii(-1,0)), dc(vc.size(),pii(-1,0));
	uset<int> used;
	for (auto &x : ac) {
		if (!used.insert(get<0>(x)).second)continue;
		auto lit = lower_bound(ALL(a), make_tuple(get<0>(x) + 1, 0, 0));
		auto it = lower_bound(ALL(a), x);
		int p1 = get<1>(*it);
		if (dc[p1].first == -1)dc[p1].first = p1;
		int as = get<2>(*it);
		for (it++; it != lit; it++) {
			int p2 = get<1>(*it);
			if (dc[p2].first==-1)dc[p2] = pii(dc[p1].first,get<2>(*it) - as);
			else if (dc[p2].second != get<2>(*it) - as) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	used.erase(ALL(used));
	for (auto &x : a) {
		if (!used.insert(get<1>(x)).second)continue;
		auto lit = lower_bound(ALL(ac), make_tuple(0,get<1>(x) + 1, 0), [](const ti3 &a, const ti3 &b) {return (get<1>(a) == get<1>(b)) ? (get<0>(a) < get<0>(b)) : (get<1>(a) < get<1>(b)); });
		auto it = lower_bound(ALL(ac), x, [](const ti3 &a, const ti3 &b) {return (get<1>(a) == get<1>(b)) ? (get<0>(a) < get<0>(b)) : (get<1>(a) < get<1>(b)); });
		int p1 = get<1>(*it);
		if (dr[p1].first == -1)dr[p1].first = p1;
		int as = get<2>(*it);
		for (it++; it != lit; it++) {
			int p2 = get<0>(*it);
			if (dr[p2].first == -1)dr[p2] = pii(dr[p1].first, get<2>(*it) - as);
			else if (dr[p2].second != get<2>(*it) - as) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	auto dr2 = dr, dc2 = dc;
	sort(ALL(dr2)), sort(ALL(dc2));
	for (auto&x : a) {
		if (upper_bound(ALL(dr2),pii(dr[get<0>(x)].first-1,INT_MAX))->second - dr[get<0>(x)].second + get<2>(x) < 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	for (auto&x : a) {
		if (upper_bound(ALL(dc2), pii(dc[get<1>(x)].first-1,INT_MAX))->second - dc[get<1>(x)].second + get<2>(x) < 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}