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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ilyakor
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        static final long SENTINEL = (long) (-1E17);
        public static final long inf = (long) (1E16);
        long[] d1;
        long[] d2;
        ArrayList<Pair<Integer, Long>>[] g1;
        ArrayList<Pair<Integer, Long>>[] g2;
        int i0;
        int j0;
        long c0;
        long lower;
        long upper;
        long len;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            d1 = new long[n];
            d2 = new long[m];
            Arrays.fill(d1, SENTINEL);
            Arrays.fill(d2, SENTINEL);

            g1 = new ArrayList[n];
            for (int i = 0; i < n; ++i)
                g1[i] = new ArrayList<>();
            g2 = new ArrayList[m];
            for (int i = 0; i < m; ++i)
                g2[i] = new ArrayList<>();

            int k = in.nextInt();
            i0 = -1;
            j0 = -1;
            c0 = -1;
            for (int i = 0; i < k; ++i) {
                int x = in.nextInt() - 1;
                int y = in.nextInt() - 1;
                long c = in.nextLong();
                if (i0 == -1) {
                    i0 = x;
                    j0 = y;
                    c0 = c;
                    d1[x] = c;
                    d2[y] = c;
                } else if (x == i0) {
                    d2[y] = c;
                } else if (y == j0) {
                    d1[x] = c;
                } else {
                    g1[x].add(new Pair<>(y, c + c0));
                    g2[y].add(new Pair<>(x, c + c0));
                }
            }

            for (int i = 0; i < n; ++i)
                if (d1[i] != SENTINEL)
                    if (!dfs1(0, i)) {
                        out.printLine("No");
                        return;
                    }
            for (int i = 0; i < m; ++i)
                if (d2[i] != SENTINEL)
                    if (!dfs1(1, i)) {
                        out.printLine("No");
                        return;
                    }

            len = c0;
            long U = inf + 1, D = inf + 1;
            for (int i = 0; i < n; ++i)
                if (d1[i] != SENTINEL)
                    U = Math.min(U, d1[i]);
            for (int i = 0; i < m; ++i)
                if (d2[i] != SENTINEL)
                    D = Math.min(D, d2[i]);
            len = Math.max(len, 2 * c0 - U - D);

            if (U + D < c0) {
                out.printLine("No");
                return;
            }

            for (int i = 0; i < n; ++i) {
                if (d1[i] != SENTINEL) continue;
                lower = 0;
                upper = inf + 1;
                dfs2(0, i, 0);
                if (lower > upper + len) {
                    out.printLine("No");
                    return;
                }
                long val = Math.max(0L, c0 - D);
                val = upper - lower - val;
                U = Math.min(U, val);
            }

            for (int i = 0; i < m; ++i) {
                if (d2[i] != SENTINEL) continue;
                lower = -inf - 1;
                upper = 0;
                dfs2(1, i, 0);
                if (lower > upper + len) {
                    out.printLine("No");
                    return;
                }
                long val = Math.max(0L, c0 - D);
                val = upper - lower - val;
                U = Math.min(U, val);
            }
            if (U + D < c0) {
                out.printLine("No");
                return;
            }
            out.printLine("Yes");
        }

        private void dfs2(int ind, int x, long c) {
            if (ind == 0) {
                d1[x] = c;
                // 0 <= c + x
                // x >= -c
                if (lower < -c)
                    lower = -c;
            } else {
                d2[x] = c;
                // c - x >= 0
                // x <= c
                if (upper > c)
                    upper = c;
            }
            if (lower > upper + len) return;
            int oind = 1 - ind;
            ArrayList<Pair<Integer, Long>> adj = ind == 0 ? g1[x] : g2[x];
            for (Pair<Integer, Long> edge : adj) {
                int y = edge.first;
                long oc = edge.second - c;
                long oval = oind == 0 ? d1[y] : d2[y];
                if (oval == SENTINEL) {
                    dfs2(oind, y, oc);
                } else {
                    if (oval != oc) {
                        lower = 1;
                        upper = -1;
                        return;
                    }
                }
                if (lower > upper + len) return;
            }
        }

        private boolean dfs1(int ind, int x) {
            int oind = 1 - ind;
            ArrayList<Pair<Integer, Long>> adj = ind == 0 ? g1[x] : g2[x];
            long val = ind == 0 ? d1[x] : d2[x];
            for (Pair<Integer, Long> edge : adj) {
                int y = edge.first;
                long c = edge.second - val;
                if (c < 0)
                    return false;
                long oval = oind == 0 ? d1[y] : d2[y];
                if (oval == SENTINEL) {
                    if (oind == 0)
                        d1[y] = c;
                    else
                        d2[y] = c;
                    if (!dfs1(oind, y))
                        return false;
                } else {
                    if (oval != c)
                        return false;
                }
            }
            return true;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buffer = new byte[10000];
        private int cur;
        private int count;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isSpace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int read() {
            if (count == -1) {
                throw new InputMismatchException();
            }
            try {
                if (cur >= count) {
                    cur = 0;
                    count = stream.read(buffer);
                    if (count <= 0)
                        return -1;
                }
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            return buffer[cur++];
        }

        public int readSkipSpace() {
            int c;
            do {
                c = read();
            } while (isSpace(c));
            return c;
        }

        public int nextInt() {
            int sgn = 1;
            int c = readSkipSpace();
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10 + c - '0';
                c = read();
            } while (!isSpace(c));
            res *= sgn;
            return res;
        }

        public long nextLong() {
            long sgn = 1;
            int c = readSkipSpace();
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res = res * 10L + (long) (c - '0');
                c = read();
            } while (!isSpace(c));
            res *= sgn;
            return res;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class Pair<P, Q> {
        public P first;
        public Q second;

        public Pair() {
        }

        public Pair(P first, Q second) {
            this.first = first;
            this.second = second;
        }


        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Pair pair = (Pair) o;

            if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
            if (second != null ? !second.equals(pair.second) : pair.second != null) return false;

            return true;
        }


        public int hashCode() {
            int result = first != null ? first.hashCode() : 0;
            result = 31 * result + (second != null ? second.hashCode() : 0);
            return result;
        }

    }
}