Language: C++

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

ll R,C;
ll N;
vector<ll> r,c,a;

int main(){
    CININIT;
    cin>>R>>C>>N;
    r.resize(N);
    c.resize(N);
    a.resize(N);
    vector<int> needx,needy;

    rep(i,N){
        cin>>r[i]>>c[i]>>a[i];
        r[i]--;
        c[i]--;
        a[i]++;
        needx.emplace_back(r[i]);
        if(r[i]+1<R) needx.emplace_back(r[i]+1);
        if(r[i]-1>=0) needx.emplace_back(r[i]-1);

        needy.emplace_back(c[i]);
        if(c[i]+1<C) needy.emplace_back(c[i]+1);
        if(c[i]-1>=0) needy.emplace_back(c[i]-1);
    }


    sort(ALL(needx));
    sort(ALL(needy));
    needx.erase(unique(needx.begin(),needx.end()),needx.end());
    needy.erase(unique(needy.begin(),needy.end()),needy.end());


    vi rr(N),cc(N);
    vi aa(N);

    for(int i=0;i<N;i++){
        rr[i] = find(all(needx),r[i]) - needx.begin();
        cc[i] = find(all(needy),c[i]) - needy.begin();
        aa[i] = a[i];
    }


    ll RR = needx.size();
    ll CC = needy.size();

    if(RR==1 or CC==1){
        cout << "Yes" << endl;
        return 0;
    }

    vector<vector<ll>> vec(RR,vector<ll>(CC,0));
    for(int i=0;i<N;i++){
        vec[rr[i]][cc[i]] = aa[i];
    }


    __int128 hoge = RR*CC;
    hoge=100000000LL/hoge;
    if(hoge<1){
        cout << "No" << endl;
        return 0;
    }

    if(RR*CC>10000000){
        cout << "No" << endl;
        return 0;
    }

    auto beg(vec);
/*{{{*/
    ll counter = -1;
    while(true){
        beg = vec;
        if(++counter==min<ll>(hoge,5)){
            cout <<"No" << endl;
            return 0;
        }
        for(int i=0;i<RR-1;i++){
            for(int j=0;j<CC-1;j++){
                if(vec[i][j]>0){
                    ll sum1 = vec[i][j]+vec[i+1][j+1];
                    ll sum2 = vec[i+1][j]+vec[i][j+1];
                    if(vec[i+1][j]==0 and vec[i][j+1]==0) continue;
                    if(sum1 == sum2) continue;

                    if(vec[i+1][j+1]!=0){
                        if(sum2 > sum1){
                            cout <<"No" << endl;
                            return 0;
                        }
                    }

                    if(vec[i+1][j+1]==0 and vec[i+1][j]!=0 and vec[i][j+1]!=0){
                        vec[i+1][j+1] = sum2 - sum1;
                        if(vec[i+1][j+1]<0){
                            cout << "No" << endl;
                            return 0;
                        }
                    }

                    if(vec[i+1][j]==0 and vec[i+1][j+1]>0 and vec[i][j+1]>0){
                        vec[i+1][j] == sum1 - sum2;
                        if(vec[i+1][j]<0){
                            cout << "No" << endl;
                            return 0;
                        }
                    }

                    if(vec[i][j+1]==0 and vec[i+1][j+1]>0 and vec[i+1][j]>0){
                        vec[i][j+1] = sum1 -sum2;
                        if(vec[i][j+1]<0){
                            cout  << "No" << endl;
                            return 0;
                        }
                    }

                    if(vec[i+1][j]!=0 and vec[i][j+1]!=0){
                        if(sum1 > sum2){
                            cout << "No" << endl;
                            return 0;
                        }else{
                            if(vec[i+1][j]>0 and vec[i][j+1]==0){
                                vec[i][j+1] = sum1 - sum2;
                            }else if(vec[i+1][j]==0 and vec[i][j+1]>0){
                                vec[i+1][j] = sum1 - sum2;
                            }
                        }
                    }
                }
                if(vec[i][j]==0 and vec[i+1][j+1]>0 and vec[i][j+1]>0 and vec[i+1][j]>0){
                    vec[i][j] = vec[i+1][j] + vec[i][j+1] - vec[i+1][j+1];
                    if(vec[i][j] < 0){
                        cout <<"No" << endl;
                        return 0;
                    }
                }

            }
        }
        if(vec == beg){
            break;
        }
    }
/*}}}*/
//    for(int i=0;i<RR;i++){
//        cout << vec[i] << endl;
//    }

    cout << "Yes" << endl;
}


Compiler output:
a.cc:1:2: error: invalid preprocessing directive #<
    1 | #<ll>include <bits/stdc++.h>
      |  ^
a.cc:16:22: error: 'ostream' does not name a type
   16 | template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
      |                      ^~~~~~~
a.cc:20:9: error: 'pair' does not name a type
   20 | typedef pair<int,int> pii;
      |         ^~~~
a.cc:21:9: error: 'vector' does not name a type
   21 | typedef vector<int> vi;
      |         ^~~~~~
a.cc:22:9: error: 'vector' does not name a type
   22 | typedef vector<vi> vvi;
      |         ^~~~~~
a.cc:26:1: error: 'vector' does not name a type
   26 | vector<ll> r,c,a;
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:15:17: error: 'cin' was not declared in this scope
   15 | #define CININIT cin.tie(0),ios::sync_with_stdio(false)
      |                 ^~~
a.cc:29:5: note: in expansion of macro 'CININIT'
   29 |     CININIT;
      |     ^~~~~~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #<ll>include <bits/stdc++.h>
a.cc:15:28: error: 'ios' has not been declared
   15 | #define CININIT cin.tie(0),ios::sync_with_stdio(false)
      |                            ^~~
a.cc:29:5: note: in expansion of macro 'CININIT'
   29 |     CININIT;
      |     ^~~~~~~
a.cc:31:5: error: 'r' was not declared in this scope
   31 |     r.resize(N);
      |     ^
a.cc:32:5: error: 'c' was not declared in this scope
   32 |     c.resize(N);
      |     ^
a.cc:33:5: error: 'a' was not declared in this scope
   33 |     a.resize(N);
      |     ^
a.cc:34:5: error: 'vector' was not declared in this scope
   34 |     vector<int> needx,needy;
      |     ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #<ll>include <bits/stdc++.h>
a.cc:34:12: error: expected primary-expression before 'int'
   34 |     vector<int> needx,needy;
      |            ^~~
a.cc:41:9: error: 'needx' was not declared in this scope
   41 |         needx.emplace_back(r[i]);
      |         ^~~~~
a.cc:45:9: error: 'needy' was not declared in this scope
   45 |         needy.emplace_back(c[i]);
      |         ^~~~~
a.cc:51:14: error: 'needx' was not declared in this scope
   51 |     sort(ALL(needx));
      |              ^~~~~
a.cc:11:17: note: in definition of macro 'ALL'
   11 | #define ALL(v) (v).begin(),(v).end()
      |                 ^
a.cc:51:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   51 |     sort(ALL(needx));
      |     ^~~~
      |     short
a.cc:52:14: error: 'needy' was not declared in this scope
   52 |     sort(ALL(needy));
      |              ^~~~~
a.cc:11:17: note: in definition of macro 'ALL'
   11 | #define ALL(v) (v).begin(),(v).end()
      |                 ^
a.cc:53:17: error: 'unique' was not declared in this scope
   53 |     needx.erase(unique(needx.begin(),needx.end()),needx.end());
      |                 ^~~~~~
a.cc:57:5: error: 'vi' was not declared in this scope; did you mean 'void'?
   57 |     vi rr(N),cc(N);
      |     ^~
      |     void
a.cc:58:7: error: expected ';' before 'aa'
   58 |     vi aa(N);
      |       ^~~
      |       ;
a.cc:61:9: error: 'rr' was not declared in this scope
   61 |         rr[i] = find(all(needx),r[i]) - needx.begin();
      |         ^~
a.cc:61:17: error: 'find' was not declared in this scope
   61 |         rr[i] = find(all(needx),r[i]) - needx.begin();
      |                 ^~~~
a.cc:62:9: error: 'cc' was not declared in this scope
   62 |         cc[i] = find(all(needy),c[i]) - needy.begin();
      |         ^~
a.cc:63:9: error: 'aa' was not declared in this scope
   63 |         aa[i] = a[i];
      |         ^~
a.cc:71:9: error: 'cout' was not declared in this scope
   71 |         cout << "Yes" << endl;
      |         ^~~~
a.cc:71:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:71:26: error: 'endl' was not declared in this scope
   71 |         cout << "Yes" << endl;
      |                          ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | #<ll>include <bits/stdc++.h>
a.cc:75:21: error: expected primary-expression before '>>' token
   75 |     vector<vector<ll>> vec(RR,vector<ll>(CC,0));
      |                     ^~
a.cc:75:40: error: expected primary-expression before '>' token
   75 |     vector<vector<ll>> vec(RR,vector<ll>(CC,0));
      |                                        ^
a.cc:75:24: error: 'vec' was not declared in this scope
   75 |     vector<vector<ll>> vec(RR,vector<ll>(CC,0));
      |                        ^~~
a.cc:77:13: error: 'rr' was not declared in this scope; did you mean 'RR'?
   77 |         vec[rr[i]][cc[i]] = aa[i];
      |             ^~
      |             RR
a.cc:77:20: error: 'cc' was not declared in this scope; did you mean 'CC'?
   77 |         vec[rr[i]][cc[i]] = aa[i];
      |                    ^~
      |                    CC
a.cc:77:29: error: 'aa' was not declared in this scope
   77 |         vec[rr[i]][cc[i]] = aa[i];
      |                             ^~
a.cc:84:9: error: 'cout' was not declared in this scope
   84 |         cout << "No" << endl;
      |         ^~~~
a.cc:84:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:84:25: error: 'endl' was not declared in this scope
   84 |         cout << "No" << endl;
      |                         ^~~~
a.cc:84:25: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:89:9: error: 'cout' was not declared in this scope
   89 |         cout << "No" << endl;
      |         ^~~~
a.cc:89:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:89:25: error: 'endl' was not declared in this scope
   89 |         cout << "No" << endl;
      |                         ^~~~
a.cc:89:25: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:98:23: error: 'min' was not declared in this scope; did you mean 'main'?
   98 |         if(++counter==min<ll>(hoge,5)){
      |                       ^~~
      |                       main
a.cc:98:29: error: expected primary-expression before '>' token
   98 |         if(++counter==min<ll>(hoge,5)){
      |                             ^
a.cc:99:13: error: 'cout' was not declared in this scope
   99 |             cout <<"No" << endl;
      |             ^~~~
a.cc:99:13: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:99:28: error: 'endl' was not declared in this scope
   99 |             cout <<"No" << endl;
      |                            ^~~~
a.cc:99:28: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:112:29: error: 'cout' was not declared in this scope
  112 |                             cout <<"No" << endl;
      |                             ^~~~
a.cc:112:29: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:112:44: error: 'endl' was not declared in this scope
  112 |                             cout <<"No" << endl;
      |                                            ^~~~
a.cc:112:44: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:120:29: error: 'cout' was not declared in this scope
  120 |                             cout << "No" << endl;
      |                             ^~~~
a.cc:120:29: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:120:45: error: 'endl' was not declared in this scope
  120 |                             cout << "No" << endl;
      |                                             ^~~~
a.cc:120:45: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:128:29: error: 'cout' was not declared in this scope
  128 |                             cout << "No" << endl;
      |                             ^~~~
a.cc:128:29: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:128:45: error: 'endl' was not declared in this scope
  128 |                             cout << "No" << endl;
      |                                             ^~~~
a.cc:128:45: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:136:29: error: 'cout' was not declared in this scope
  136 |                             cout  << "No" << endl;
      |                             ^~~~
a.cc:136:29: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:136:46: error: 'endl' was not declared in this scope
  136 |                             cout  << "No" << endl;
      |                                              ^~~~
a.cc:136:46: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:143:29: error: 'cout' was not declared in this scope
  143 |                             cout << "No" << endl;
      |                             ^~~~
a.cc:143:29: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:143:45: error: 'endl' was not declared in this scope
  143 |                             cout << "No" << endl;
      |                                             ^~~~
a.cc:143:45: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:157:25: error: 'cout' was not declared in this scope
  157 |                         cout <<"No" << endl;
      |