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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.NoSuchElementException;

public class Main {
	private static void solve() {
		final long LARGE = 1000000;
		HashMap<Long, Long> m1 = new HashMap<Long, Long>();
		int w = nei();
		int h = nei();
		int n = nei();
		for (int i = 0; i < n; i++) {
			m1.put((nei() - 1) * LARGE + (nei() - 1), (long) nei());
		}
		HashMap<Long, Long> m2 = new HashMap<Long, Long>();
		HashMap<Long, Long> m3 = new HashMap<Long, Long>();
		HashMap<Long, Long> ma = new HashMap<Long, Long>();
		ma.putAll(m1);
		int mode = 0;
		int d = 0;
		while (true) {
			for (Entry<Long, Long> e : m1.entrySet()) {
				long pos = e.getKey();
				int x = (int) (pos / LARGE);
				int y = (int) (pos % LARGE);
				for (int i = x - 1; i <= x; i++) {
					for (int j = y - 1; j <= y; j++) {
						if (i < 0 || j < 0 || i == w - 1 || j == h - 1)
							continue;
						long i1 = i * LARGE + j;
						long i2 = i1 + 1;
						long i3 = i1 + LARGE;
						long i4 = i1 + 1 + LARGE;
						int c = 0;
						boolean b1 = ma.containsKey(i1);
						boolean b2 = ma.containsKey(i2);
						boolean b3 = ma.containsKey(i3);
						boolean b4 = ma.containsKey(i4);
						long v1 = b1 ? ma.get(i1) : -1;
						long v2 = b2 ? ma.get(i2) : -1;
						long v3 = b3 ? ma.get(i3) : -1;
						long v4 = b4 ? ma.get(i4) : -1;
						if (b1)
							c++;
						if (b2)
							c++;
						if (b3)
							c++;
						if (b4)
							c++;
						boolean no = false;
						if (c == 2) {
							if (mode == 1) {
								if (!b1 && !b2) {
									m2.put(i1, 114514l);
								}
								if (!b2 && !b4) {
									m2.put(i2, 114514l);
								}
								if (!b1 && !b3) {
									m2.put(i1, 114514l);
								}
								if (!b3 && !b4) {
									m2.put(i4, 114514l);
								}
							}
						} else if (c == 3) {
							if (!b1) {
								v1 = v2 + v3 - v4;
								m2.put(i1, v1);
							}
							if (!b2) {
								v2 = v1 + v4 - v3;
								m2.put(i2, v2);
							}
							if (!b3) {
								v3 = v1 + v4 - v2;
								m2.put(i3, v3);
							}
							if (!b4) {
								v4 = v2 + v3 - v1;
								m2.put(i4, v4);
							}
							no = v1 < 0 || v2 < 0 || v3 < 0 || v4 < 0;
						} else if (c == 4) {
							no = v1 + v4 != v2 + v3;
						}
//						out(i + ", " + j);
//						out(v1 + " " + v2);
//						out(v3 + " " + v4);
//						out("");
//						if (no) {
//							out("No");
//							return;
//						}
					}
				}
			}
			if (!m2.isEmpty()) {
				m3.clear();
				m3.putAll(m2);
			}
			if (mode == 1 && (m2.isEmpty() && d > 5))
				break;
			if (mode == 1)
				d++;
			if (m2.isEmpty() && mode == 0)
				mode = 1;
			ma.putAll(m2);
			
//			out("-------------------" + mode);
//
//			long[][] mm = new long[w][h];
//			for (int i = 0; i < w; i++) {
//				for (int j = 0; j < h; j++) {
//					mm[i][j] = -1;
//				}
//			}
//			for (Entry<Long, Long> e : ma.entrySet()) {
//				long pos = e.getKey();
//				int x = (int) (pos / LARGE);
//				int y = (int) (pos % LARGE);
//				mm[x][y] = e.getValue();
//			}
//			for (int i = 0; i < w; i++) {
//				String s = "";
//				for (int j = 0; j < h; j++) {
//					s += mm[i][j] + " ";
//				}
//				out(s);
//			}
//
//			out("-------------------");
			
			HashMap<Long, Long> tmp = m1;
			m1 = m2;
			m2 = tmp;
			m2.clear();
			m1.putAll(m3);
		}
		out("Yes");
	}

	static BigInteger combination(int a, int b, BigInteger mod) {
		BigInteger q = BigInteger.ONE;
		BigInteger p = BigInteger.ONE;
		for (int i = a - b + 1; i <= a; i++) {
			q = q.multiply(BigInteger.valueOf(i)).mod(mod);
		}
		for (int j = 1; j <= b; j++) {
			p = p.multiply(BigInteger.valueOf(j)).mod(mod);
		}
		return q.multiply(p.modInverse(mod)).mod(mod);
	}

	static int abs(int x) {
		return x < 0 ? -x : x;
	}

	static int gcd(int x, int y) {
		if (x < y) {
			x ^= y;
			y ^= x;
			x ^= y;
		}
		int z = x % y;
		if (z == 0)
			return y;
		return gcd(y, z);
	}

	static int clamp(int a, int min, int max) {
		return a < min ? min : a > max ? max : a;
	}

	static int max(int a, int b) {
		return a > b ? a : b;
	}

	static int min(int a, int b) {
		return a < b ? a : b;
	}

	static long max(long a, long b) {
		return a > b ? a : b;
	}

	static long min(long a, long b) {
		return a < b ? a : b;
	}

	static void out(String val) {
		IO.out(val);
	}

	static void out(int val) {
		IO.out(String.valueOf(val));
	}

	static void out(long val) {
		IO.out(String.valueOf(val));
	}

	static void out(char val) {
		IO.out(String.valueOf(val));
	}

	static void out(float val) {
		IO.out(String.valueOf(val));
	}

	static void out(double val) {
		IO.out(String.valueOf(val));
	}

	static void out(boolean val) {
		IO.out(String.valueOf(val));
	}

	static String next() {
		return IO.next();
	}

	static int nei() {
		return IO.nextInt();
	}

	static long nel() {
		return IO.nextLong();
	}

	static int parseInt(String val) {
		return Integer.parseInt(val);
	}

	static int parseInt(char val) {
		return Integer.parseInt(String.valueOf(val));
	}

	static long parseLong(String val) {
		return Long.parseLong(val);
	}

	public static void main(String[] args) {
		solve();
		IO.flush();
	}
}

final class UnionFind {
	int[] data;

	UnionFind(int n) {
		data = new int[n];
		for (int i = 0; i < n; i++) {
			data[i] = -1;
		}
	}

	boolean union(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)
			return false;
		if (data[y] < data[x]) {
			x ^= y;
			y ^= x;
			x ^= y;
		}
		data[x] += data[y];
		data[y] = x;
		return true;
	}

	boolean find(int x, int y) {
		return root(x) == root(y);
	}

	int root(int x) {
		return data[x] < 0 ? x : (data[x] = root(data[x]));
	}

	int size(int x) {
		return -data[root(x)];
	}
}

final class IO {
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out, false);
	private static final byte[] buffer = new byte[1024];
	private static int ptr = 0;
	private static int len = 0;

	private static boolean hasNextByte() {
		if (ptr < len)
			return true;
		ptr = 0;
		try {
			len = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return len > 0;
	}

	private static int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	static boolean hasNext() {
		byte c;
		while (hasNextByte() && ((c = buffer[ptr]) < '!' || c > '~'))
			ptr++;
		return hasNextByte();
	}

	static String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (b >= '!' && b <= '~') {
			sb.append((char) b);
			b = readByte();
		}
		return sb.toString();
	}

	static long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}

	static int nextInt() {
		if (!hasNext())
			throw new NoSuchElementException();
		int n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}

	static void out(String val) {
		out.println(val);
	}

	static void flush() {
		out.flush();
	}
}