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)

/*
Sometimes I feel like I don't have a partner
Sometimes I feel like my only friend
It's the city I live in, the City of Angels
Lonely as I am, together we cry

I drive on her streets 'cause she's my companion
I walk through her hills cause she knows who I am
She sees my good deeds and she kisses me windy
I never worry, now that is a lie

I dont ever wanna feel like I did that day
Take me to the place I love, take me all the way
I dont ever wanna feel like I did that day
Take me to the place I love, take me all the way
Yeah, yeah, yeah

It's hard to believe that there's nobody out there
It's hard believe that I'm all alone
At least I have her love the city, she loves me
Lonely as I am, together we cry

And I dont ever wanna feel like I did that day
Take me to the place I love, take me all the way
And I dont ever wanna feel like I did that day
Take me to the place I love, take me all the way
Yeah, yeah, yeah, oh, no, no, no
Yeah, yeah, love me I say yeah, yeah

Under the bridge downtown is where I drew some blood
Under the bridge downtown I could not get enough
Under the bridge downtown forgot about my love
Under the bridge downtown I gave my life away
Yeah, yeah, yeah

Yeah, yeah, yeah, oh, no, no, no
Yeah, yeah, oh, no, no
I said yea yeah, Ill stay
*/

//#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd

#define eps 1e-9
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 350

using namespace std;

const int INF = 1e9;
const int N = 500031;

int  C, n;
int r[N], c[N], val[N];
set<int> by_row[N], by_col[N];
int used[N];
long long c_val[N], r_val[N];
pair<long long, long long> s_r[N], s_c[N];
long long L,R;
int rr;

void normalize(pair<long long, long long> p)
{
	if (p.first == -1)
	{
		R = min(R, 0ll+p.second);
	}
	else
	{
		L = max(L, 0ll-p.second);
	}
}

pair<long long, long long> sub(int val, pair<long long, long long> a)
{
	pair<long long, long long> p = make_pair(0, val);
	a.first = p.first - a.first;
	a.second = p.second - a.second;
	return a;
}

void dfs(int v)
{
	//cout << s_r[r[v]].first << " " << s_r[r[v]].second << " " << v << " " << r[v] <<" "<<L<<" "<<R<< endl;
	//cout << s_c[c[v]].first << " " << s_c[c[v]].second << endl;

	if (L > R)
		return;
	
	used[v] = 1;
	normalize(s_r[r[v]]);
	normalize(s_c[c[v]]);

	set<int>::iterator it;
	while (true)
	{
		if (by_row[r[v]].size())
		{
			it = by_row[r[v]].begin();
			int id = (*it);
			by_row[r[v]].erase(it);

			if (used[id] == 0)
			{
				c_val[c[id]] = val[id] - r_val[r[id]];
				s_c[c[id]] = sub(val[id], s_r[r[id]]);
				dfs(id);
			}
			continue;
		}
		if (by_col[c[v]].size())
		{
			it = by_col[c[v]].begin();
			int id = (*it);
			by_col[c[v]].erase(it);
			if (used[id] == 0)
			{
				r_val[r[id]] = val[id] - c_val[c[id]];
				s_r[r[id]] = sub(val[id], s_c[c[id]]);
				dfs(id);
			}
			continue;
		}
		break;
	}
}

int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/in.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);
	
	//cout << "No" << endl;
	//return 0;

	cin >> rr >> C >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> r[i] >> c[i] >> val[i];
		by_row[r[i]].insert(i);
		by_col[c[i]].insert(i);
	}

	int shit = 0;

	for (int i = 1; i <= n; i++)
	{
		if (used[i])
			continue;
		L = -1e18;
		R = 1e18;
		r_val[i] = 0;
		c_val[i] = val[i];
		s_r[i] = make_pair(1, 0);
		s_c[i] = make_pair(-1, val[i]);
		dfs(i);
	//	cout << "%" << L << " " << R << endl;
		if (L > R)
			shit = 1;
	}

	/*if (shit)
	{
		cout << "No" << endl;
		//while (true);
		return 0;
	}
	*/
	for (int i = 1; i <= n; i++)
	{
		if (c_val[c[i]] + r_val[r[i]] != val[i])
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	cin.get(); cin.get();
	return 0;
}