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: Accepted)

//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of jonathanirvings' template v3.0.3 (BETA)

int r,c,n;
pii pos[100005];
int isi[100005];
vi adax[100005];
int miny[100005];
vii maju[100005];
int root[100005];
LL sum[100005];
LL minn[100005];
LL minnn;

bool f(int a,int b)
{
  return pos[a].se < pos[b].se;
}

void dfs(int pt,int now,LL cur)
{
  root[now] = pt;
  sum[now] = cur;
  MIN(minnn,cur);
  REP(i,SIZE(maju[now])) if (root[maju[now][i].fi] == -1)
  {
    dfs(pt,maju[now][i].fi,cur + maju[now][i].se);
  }
}

int main()
{
  scanf("%d %d",&r,&c);
  scanf("%d",&n);
  FORN(j,1,c) miny[j] = INF;
  REP(i,n)
  {
    scanf("%d %d %d",&pos[i].fi,&pos[i].se,&isi[i]);
    adax[pos[i].fi].pb(i);
    MIN(miny[pos[i].se],isi[i]);
  }
  FORN(i,1,r) sort(ALL(adax[i]),f);
  FORN(tries,1,1)
  {
    FORN(i,1,r)
    {
      /*int minn = INF;
      REP(j,SIZE(adax[i]))
      {
        MIN(minn,isi[adax[i][j]]);
      }
      REP(j,SIZE(adax[i]))
      {
        int y = pos[adax[i][j]].se;
        if (minn - isi[adax[i][j]] + miny[y] < 0)
        {
          puts("No");
          return 0;
        }
      }*/
      FOR(j,1,SIZE(adax[i]))
      {
        int ixa = adax[i][j-1];
        int ixb = adax[i][j];
        maju[pos[ixa].se].pb(mp(pos[ixb].se,isi[ixb] - isi[ixa]));
        maju[pos[ixb].se].pb(mp(pos[ixa].se,isi[ixa] - isi[ixb]));
      }
    }
    RESET(root,-1);
    FORN(j,1,c) if (root[j] == -1)
    {
      minnn = INFF;
      dfs(j,j,0);
      minn[j] = minnn;
    }
    FORN(i,1,r)
    {
      FOR(j,1,SIZE(adax[i]))
      {
        int ixa = adax[i][j-1];
        int ixb = adax[i][j];
        int ya = pos[ixa].se;
        int yb = pos[ixb].se;
        if (isi[ixb] - isi[ixa] != sum[yb] - sum[ya])
        {
          puts("No");
          return 0;
        }
      }
      REP(j,SIZE(adax[i]))
      {
        int ix = adax[i][j];
        int y = pos[ix].se;
        if (isi[ix] - sum[y] + minn[root[y]] < 0)
        {
          puts("No");
          return 0;
        }
      }
    }
    /*REPN(i,r) adax[i].clear();
    REPN(j,c) aday[j].clear();
    swap(r,c);
    REP(i,n)
    {
      swap(pos[i].fi,pos[i].se);
      adax[pos[i].fi].pb(i);
      aday[pos[i].se].insert(i);
    }*/
  }
  puts("Yes");
  return 0;
}