Problem:
C: 見つからないように移動する
問題
\(H\) 行 \(W\) 列のグリッドがあります。上から \(i\) 行目、左から \(j\) 列目のマスを \((i,j)\) で表します。
グリッド内には \(N\) 人の見張りがいます。見張りには 見張り \(1\), 見張り \(2\), …, 見張り \(N\) と番号がついています。見張り \(i\) はマス \((x_i,y_i)\) にいます。
見張り \(i\) は、自分の位置からマンハッタン距離が \(k_i\) 以下のマスをすべて見張っています。ただし、距離が \(k_i\) 以下であるようなマスはすべてグリッド内部に存在します。
ととりは最初マス \((s_x,s_y)\) にいて上下左右に隣り合うマスへの移動を繰り返すことでマス \((g_x,g_y)\) を目指します。
見張りに見つからずに マス \((s_x,s_y)\) からマス \((g_x,g_y)\) に行くことはできるでしょうか。
マンハッタン距離とは
マス \((x_i,y_i)\) とマス \((x_j,y_j)\) のマンハッタン距離は \(|x_i - x_j|+|y_i-y_j|\) のことをいいます。
制約
\(1\le N\le 10^5\)
\(3\le H \times W\le 10^5\)
\(0\le k_i\)
\(1+k_i\le x_i \le H-k_i\)
\(1+k_i\le y_i \le W-k_i\)
\(1\le s_x,g_x \le H\)
\(1\le s_y,g_y \le W\)
マス \((s_x,s_y)\),\((g_x,g_y)\) は見張られていない。
入力はすべて整数
入力
H
W
N
s_x
s_y
g_x
g_y
x_1
y_1
k_1
x_2
y_2
k_2
︙
x_N
y_N
k_N
出力
移動できるなら
Yes
を、そうでないなら
No
を出力してください。
入力例1
4 4 2
1 1 4 4
2 3 1
4 1 0
出力例1
Yes
以下のように移動することができます。
\((1,1)\rightarrow(2,1)\rightarrow(3,1)\rightarrow(3,2)\rightarrow(4,2)\rightarrow(4,3)\rightarrow(4,4)\)
入力例2
3 3 1
1 1 3 3
2 2 1
出力例2
No

Submitted solutions:

code_snippet: // AOJ #3287 escape
// 2025.4.1

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

#define gc() getchar_unlocked()

int Cin() {
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

const int dr[4] = {1,-1,0,0};
const int dc[4] = {0,0,1,-1};

int main(){
    int H = Cin(), W = Cin(), N = Cin();
    int sx = Cin(), sy = Cin(), gx = Cin(), gy = Cin();

    vector<vector<int>> d(H+1, vector<int>(W+2, 0));

    for(int i=0;i<N;i++){
        int x = Cin(), y = Cin(), k = Cin();
        int r1 = max(1, x - k), r2 = min(H, x + k);
        for(int r = r1; r <= r2; r++){
            int t = abs(r - x);
            int rmd = k - t;
            int c1 = max(1, y - rmd), c2 = min(W, y + rmd);
            d[r][c1]++;
            d[r][c2+1]--;
        }
    }

    vector<vector<bool>> g(H+1, vector<bool>(W+1, false));
    for(int r = 1; r <= H; r++){
        int sum = 0;
        for(int c = 1; c <= W; c++){
            sum += d[r][c];
            if(sum > 0) g[r][c] = true;
        }
    }

    vector<vector<bool>> v(H+1, vector<bool>(W+1, false));
    queue<pair<int,int>> qu;
    qu.push({sx, sy});
    v[sx][sy] = true;
    bool ok = false;
    while(!qu.empty()){
        auto [r, c] = qu.front(); qu.pop();
        if(r == gx && c == gy){ ok = true; break; }
        for(int i=0;i<4;i++){
            int nr = r + dr[i], nc = c + dc[i];
            if(nr < 1 || nr > H || nc < 1 || nc > W) continue;
            if(!v[nr][nc] && !g[nr][nc]){
                v[nr][nc] = true;
                qu.push({nr, nc});
            }
        }
    }
    puts(ok? "Yes": "No");
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5812
final_rank: 9

code_snippet: #line 2 "library/KowerKoint/base.hpp"

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using ull = unsigned long long;
using VUL = vector<ull>;
using VVUL = vector<VUL>;
using VVVUL = vector<VVUL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != (int) v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

#ifdef DEBUG
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}
#else
template<typename... Args>
void dbg(const Args &... args) {}
#endif

template<typename T>
vector<vector<T>> split(typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T val) {
    vector<vector<T>> res;
    vector<T> cur;
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(*it);
    }
    res.push_back(cur);
    return res;
}

vector<string> split(typename string::const_iterator begin, typename string::const_iterator end, char val) {
    vector<string> res;
    string cur = "";
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(*it);
    }
    res.push_back(cur);
    return res;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

template <typename It>
auto rle(It begin, It end) {
    vector<pair<typename It::value_type, int>> res;
    if(begin == end) return res;
    auto pre = *begin;
    int num = 1;
    for(auto it = begin + 1; it != end; it++) {
        if(pre != *it) {
            res.emplace_back(pre, num);
            pre = *it;
            num = 1;
        } else num++;
    }
    res.emplace_back(pre, num);
    return res;
}

template <typename It>
vector<pair<typename It::value_type, int>> rle_sort(It begin, It end) {
    vector<typename It::value_type> cloned(begin, end);
    sort(ALL(cloned));
    auto e = rle(ALL(cloned));
    sort(ALL(e), [](const auto& l, const auto& r) { return l.second < r.second; });
    return e;
}

template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
    vector<T> res(n+1), rev(n+1);
    res[0] = 1;
    REP(i, n) res[i+1] = res[i] * (i+1);
    rev[n] = 1 / res[n];
    for(int i = n; i > 0; i--) {
        rev[i-1] = rev[i] * i;
    }
    return make_pair(res, rev);
}
#line 3 "library/KowerKoint/operator.hpp"

template <typename T>
T add_op(T a, T b) { return a + b; }
template <typename T>
T sub_op(T a, T b) { return a - b; }
template <typename T>
T zero_e() { return T(0); }
template <typename T>
T div_op(T a, T b) { return a / b; }
template <typename T>
T mult_op(T a, T b) { return a * b; }
template <typename T>
T one_e() { return T(1); }
template <typename T>
T xor_op(T a, T b) { return a ^ b; }
template <typename T>
T and_op(T a, T b) { return a & b; }
template <typename T>
T or_op(T a, T b) { return a | b; }
ll mod3() { return 998244353LL; }
ll mod7() { return 1000000007LL; }
ll mod9() { return 1000000009LL; }
template <typename T>
T max_op(T a, T b) { return max(a, b); }
template <typename T>
T min_op(T a, T b) { return min(a, b); }

template <typename T>
T max_e() { return numeric_limits<T>::max(); }
template <typename T>
T min_e() { return numeric_limits<T>::min(); }
#line 2 "library/KowerKoint/integer/extgcd.hpp"

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1, y = 0;
    ll nx = 0, ny = 1;
    while(b) {
        ll q = a / b;
        tie(a, b) = LP(b, a % b);
        tie(x, nx) = LP(nx, x - nx*q);
        tie(y, ny) = LP(ny, y - ny*q);
    }
    return a;
}
#line 3 "library/KowerKoint/integer/pow-mod.hpp"

ll inv_mod(ll n, ll m) {
    ll x, y;
    assert(extgcd(n, m, x, y) == 1);
    x %= m;
    if(x < 0) x += m;
    return x;
}

ll pow_mod(ll a, ll n, ll m) {
    if(n == 0) return 1LL;
    if(n < 0) return inv_mod(pow_mod(a, -n, m), m);
    ll res = 1;
    while(n) {
        if(n & 1) {
            res *= a;
            res %= m;
        }
        n >>= 1;
        a *= a;
        a %= m;
    }
    return res;
}
#line 4 "library/KowerKoint/integer/modint.hpp"

template <ll (*mod)()>
struct Modint {
    ll val;
    
    Modint(): val(0) {}

    Modint(ll x): val(x) {
        val %= mod();
        if(val < 0) val += mod();
    }

    Modint& operator+=(const Modint& r) {
        val += r.val;
        if(val >= mod()) val -= mod();
        return *this;
    }
    friend Modint operator+(const Modint& l, const Modint& r) {
        return Modint(l) += r;
    }

    Modint& operator-=(const Modint& r) {
        val -= r.val;
        if(val < 0) val += mod();
        return *this;
    }
    friend Modint operator-(const Modint& l, const Modint& r) {
        return Modint(l) -= r;
    }

    Modint& operator*=(const Modint& r) {
        val *= r.val;
        val %= mod();
        return *this;
    }
    Modint operator*(const Modint& r) {
        return (Modint(*this) *= r);
    }
    friend Modint operator*(const Modint& l, const Modint& r) {
        return Modint(l) *= r;
    }

    Modint pow(ll n) const {
        return Modint(pow_mod(val, n, mod()));
    }

    Modint inv() const {
        return Modint(inv_mod(val, mod()));
    }

    Modint& operator/=(const Modint& r) {
        return (*this *= r.inv());
    }
    friend Modint operator/(const Modint& l, const Modint& r) {
        return Modint(l) /= r;
    }

    Modint& operator^=(const ll n) {
        val = pow_mod(val, n, mod());
        return *this;
    }
    Modint operator^(const ll n) {
        return this->pow(n);
    }

    Modint operator+() const { return *this; }
    Modint operator-() const { return Modint() - *this; }

    Modint& operator++() {
        val++;
        if(val == mod()) val = 0LL;
        return *this;
    }
    Modint& operator++(int) {
        Modint res(*this);
        ++*this;
        return res;
    }

    Modint& operator--() {
        if(val == 0LL) val = mod();
        val--;
        return *this;
    }
    Modint& operator--(int) {
        Modint res(*this);
        --*this;
        return res;
    }

    friend bool operator==(const Modint& l, const Modint& r) {
        return l.val == r.val;
    }
    friend bool operator!=(const Modint& l, const Modint& r) {
        return l.val != r.val;
    }

    static pair<vector<Modint>, vector<Modint>> factorial(int n) {
        vector<Modint> fact(n+1), rfact(n+1);
        fact[0] = 1;
        REP(i, n) fact[i+1] = fact[i] * (i+1);
        rfact[n] = 1 / fact[n];
        for(int i = n-1; i >= 0; i--) rfact[i] = rfact[i+1] * (i+1);
        return {fact, rfact};
    }

    friend istream& operator>>(istream& is, Modint& mi) {
        is >> mi.val;
        return is;
    }

    friend ostream& operator<<(ostream& os, const Modint& mi) {
        os << mi.val;
        return os;
    }
};

using MI3 = Modint<mod3>;
using V3 = vector<MI3>;
using VV3 = vector<V3>;
using VVV3 = vector<VV3>;
using MI7 = Modint<mod7>;
using V7 = vector<MI7>;
using VV7 = vector<V7>;
using VVV7 = vector<VV7>;
using MI9 = Modint<mod9>;
using V9 = vector<MI9>;
using VV9 = vector<V9>;
using VVV9 = vector<VV9>;
#line 3 "library/KowerKoint/counting/counting.hpp"

template <typename T>
struct Counting {
    vector<T> fact, ifact;

    Counting() {}
    Counting(ll n) {
        expand(n);
    }

    void expand(ll n) {
        ll sz = (ll)fact.size();
        if(sz > n) return;
        fact.resize(n+1);
        ifact.resize(n+1);
        fact[0] = 1;
        FOR(i, max(1LL, sz), n+1) fact[i] = fact[i-1] * i;
        ifact[n] = 1 / fact[n];
        for(ll i = n-1; i >= sz; i--) ifact[i] = ifact[i+1] * (i+1);
    }

    T p(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[n-r];
    }

    T c(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[r] * ifact[n-r];
    }

    T h(ll n, ll r) {
        assert(n >= 0);
        assert(r >= 0);
        return c(n+r-1, r);
    }

    T stirling(ll n, ll k) {
        assert(n >= k);
        assert(k >= 0);
        if(n == 0) return 1;
        T res = 0;
        int sign = k%2? -1 : 1;
        expand(k);
        REP(i, k+1) {
            res += sign * ifact[i] * ifact[k-i] * T(i).pow(n);
            sign *= -1;
        }
        return res;
    }

    vector<vector<T>> stirling_table(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        vector<vector<T>> res(n+1, vector<T>(k+1));
        res[0][0] = 1;
        FOR(i, 1, n+1) FOR(j, 1, k+1) {
            res[i][j] = res[i-1][j-1] + j * res[i-1][j];
        }
        return res;
    }

    T bell(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        expand(k);
        vector<T> tmp(k+1);
        int sign = 1;
        tmp[0] = 1;
        FOR(i, 1, k+1) {
            sign *= -1;
            tmp[i] = tmp[i-1] + sign * ifact[i];
        }
        T res = 0;
        REP(i, k+1) {
            res += T(i).pow(n) * ifact[i] * tmp[k-i];
        }
        return res;
    }

    vector<vector<T>> partition_table(ll n, ll k) {
        assert(n >= 0);
        vector<vector<T>> res(n+1, vector<T>(k+1));
        REP(i, k+1) res[0][i] = 1;
        FOR(i, 1, n+1) FOR(j, 1, k+1) {
            res[i][j] = res[i][j-1] + (i<j? 0 : res[i-j][j]);
        }
        return res;
    }
};
#line 2 "Contests/main.cpp"

/* #include <atcoder/all> */
/* using namespace atcoder; */
/* #include "KowerKoint/expansion/ac-library/all.hpp" */

void solve(){
    int h, w, n; cin >> h >> w >> n;
    int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; sx += 5; sy += 5; gx += 5; gy += 5;
    VVI imos(h+10, VI(w+10));
    REP(i, n) {
        int x, y, k; cin >> x >> y >> k; x += 5; y += 5;
        VP plus, minus;
        plus.emplace_back(x-k, y);
        plus.emplace_back(x-k+1, y);
        minus.emplace_back(x+1, y-k-1);
        minus.emplace_back(x+1, y-k);
        minus.emplace_back(x+1, y+k);
        minus.emplace_back(x+1, y+k+1);
        plus.emplace_back(x+k+1, y);
        plus.emplace_back(x+k+2, y);
        for(auto [ix, iy] : plus) {
            if(ix < 0 || ix >= h+10 || iy < 0 || iy >= w+10) continue;
            imos[ix][iy]++;
        }
        for(auto [ix, iy] : minus) {
            if(ix < 0 || ix >= h+10 || iy < 0 || iy >= w+10) continue;
            imos[ix][iy]--;
        }
    }
    FOR(xy, -h-w-30, h+w+30) {
        REP(x, h+9) {
            int y = xy - x;
            if(0 <= x && x <= h+8 && 1 <= y && y <= w+9) {
                imos[x+1][y-1] += imos[x][y];
            }
        }
    }
    FOR(xy, -h-w-30, h+w+30) {
        REP(x, h+9) {
            int y = xy + x;
            if(0 <= x && x <= h+8 && 0 <= y && y <= w+8) {
                imos[x+1][y+1] += imos[x][y];
            }
        }
    }
    VVI dist(h+10, VI(w+10, INF));
    dist[sx][sy] = 0;
    queue<pair<int, int>> que;
    que.emplace(sx, sy);
    while(!que.empty()) {
        auto [x, y] = que.front(); que.pop();
        REP(i, 4) {
            int nx = x + DX[i], ny = y + DY[i];
            if(nx < 6 || h+5 < nx || ny < 6 || w+5 < ny) continue;
            if(imos[nx][ny]) continue;
            if(chmin(dist[nx][ny], dist[x][y] + 1)) {
                que.emplace(nx, ny);
            }
        }
    }
    print(dist[gx][gy] == INF? "No" : "Yes");
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 480
memory_kb: 5808
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001




int H,W,P;
ll** table;

#define SIZE 100005

int N;
int d_row[4] = {-1,0,0,1},d_col[4] = {0,-1,1,0};
int boss[SIZE],height[SIZE],num_member[SIZE];


int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

int isSame(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[boss_x] > height[boss_y]){

		num_member[boss_x] += num_member[boss_y];
		boss[boss_y] = boss_x;

	}else if(height[boss_x] < height[boss_y]){

		num_member[boss_y] += num_member[boss_x];
		boss[boss_x] = boss_y;

	}else{ //height[boss_x] == height[boss_y]

		num_member[boss_x] += num_member[boss_y];
		boss[boss_y] = boss_x;
		height[x]++;
	}
}

bool rangeCheck(int row,int col){

	return row >= 1 && row <= H && col >= 1 && col <= W;
}

int getIndex(int row,int col){

	return (row-1)*W + (col-1);
}


int main(){

	scanf("%d %d %d",&H,&W,&P);

	table = new ll*[H+2];


	for(int row = 0; row <= H+1; row++){

		table[row] = new ll[W+2];
		for(int col = 0; col <= W+1; col++){

			table[row][col] = 0;
		}
	}

	int sx,sy,gx,gy;
	scanf("%d %d %d %d",&sx,&sy,&gx,&gy);


	N = H*W;

	int x,y,k;

	for(int i = 0; i < P; i++){

		scanf("%d %d %d",&x,&y,&k);

		//一番外側だけ印する
		for(int d_row = -k; d_row <= k; d_row++){
			int rest = k-abs(d_row);
			int adj_row = x+d_row;
			int adj_col=y-rest;

			table[adj_row][adj_col] = 1;

			adj_col = y+rest;
			table[adj_row][adj_col] = 1;
		}
	}

	/*for(int row = 1; row <= H; row++){
		for(int col = 1; col <= W; col++){

			printf(" %lld",table[row][col]);
		}
		printf("\n");
	}*/

	for(int i = 0; i < N; i++){

		boss[i] = i;
	}

	for(int row = 1; row <= H; row++){
		for(int col = 1; col <= W; col++){
			if(table[row][col] > 0)continue;

			int from = getIndex(row,col);

			for(int i = 0; i < 4; i++){
				int adj_row = row+d_row[i];
				int adj_col = col+d_col[i];
				if(!rangeCheck(adj_row,adj_col) || table[adj_row][adj_col] > 0)continue;

				int to = getIndex(adj_row,adj_col);

				unite(from,to);
			}
		}
	}

	if(isSame(getIndex(sx,sy),getIndex(gx,gy))){

		printf("Yes\n");

	}else{

		printf("No\n");
	}

	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 5504
final_rank: 14

code_snippet: #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<long double,long double> pdd;
typedef vector<vector<ll>> mat;
const ll mod=1000000007;
const ll mod2=998244353;
const ll mod3=1000000009;
ll inf=numeric_limits<ll>::max()/2;
int iinf=numeric_limits<int>::max()/2;
double pi=3.14159265358979323846;
double eps=1e-10;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x+=0x9e3779b97f4a7c15;x=(x^(x>>30))*0xbf58476d1ce4e5b9;x=(x^(x>>27))*0x94d049bb133111eb;
        return x^(x>>31);}
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);}
};
#define umh unordered_map<int,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<0)a=-a;if(b<0)b=-b;if(a<b)swap(a,b);if(b==0)return a;if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);a/=c;a*=b;return a;}
ll Pow(ll n,ll k){
    if(k<0)return 0;ll ret=1;ll now=n;while(k>0){if(k&1)ret*=now;now*=now;k/=2;}return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;ll now=n;now%=md;
  while(k>0){
    if(k%2==1){ret*=now;ret%=md;}
    now*=now;now%=md;k=k>>1;}return ret;
}
ll gyaku(ll n,ll md){return beki(n,md-2,md);}
ll popcount(ll n){ll ret=0;ll u=n;while(u>0){ret+=u%2;u/=2;}return ret;}
#ifndef ATCODER_INTERNAL_BITOP_HPP
#define ATCODER_INTERNAL_BITOP_HPP 1
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
int ceil_pow2(int n) {
    int x = 0;while ((1U << x) < (unsigned int)(n)) x++;return x;}
int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}}}
#endif
#ifndef ATCODER_INTERNAL_MATH_HPP
#define ATCODER_INTERNAL_MATH_HPP 1
#include <utility>
namespace atcoder {
namespace internal {
constexpr long long safe_mod(long long x, long long m) {
    x%=m;if(x<0)x+=m;return x;}
struct barrett {
    unsigned int _m;
    unsigned long long im;
    barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
    unsigned int umod() const { return _m; }
    unsigned int mul(unsigned int a, unsigned int b) const {
        unsigned long long z = a;z *= b;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(z, im, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
        unsigned int v = (unsigned int)(z - x * _m);
        if (_m <= v) v += _m;
        return v;
    }
};
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
    if (m == 1) return 0;
    unsigned int _m = (unsigned int)(m);
    unsigned long long r = 1;
    unsigned long long y = safe_mod(x, m);
    while (n) {
        if (n & 1) r = (r * y) % _m;y = (y * y) % _m;n >>= 1;
    }
    return r;
}

constexpr bool is_prime_constexpr(int n) {
    if (n<=1) return false;
    if (n==2||n==7||n==61) return true;
    if (n%2==0) return false;
    long long d = n - 1;
    while (d%2==0)d/=2;
    for (long long a : {2, 7, 61}) {
        long long t = d;
        long long y = pow_mod_constexpr(a, t, n);
        while (t != n - 1 && y != 1 && y != n - 1) {
            y = y * y % n;t <<= 1;}
        if (y != n - 1 && t % 2 == 0) {return false;}
    }
    return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};
    long long s = b, t = a;
    long long m0 = 0, m1 = 1;
    while (t) {
        long long u = s / t;
        s -= t * u;
        m0 -= m1 * u;
        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}
constexpr int primitive_root_constexpr(int m) {
    if (m == 2) return 1;
    if (m == 167772161) return 3;
    if (m == 469762049) return 3;
    if (m == 754974721) return 11;
    if (m == 998244353) return 3;
    int divs[20] = {};
    divs[0] = 2;
    int cnt = 1;
    int x = (m - 1) / 2;
    while (x % 2 == 0) x /= 2;
    for (int i = 3; (long long)(i)*i <= x; i += 2) {
        if (x % i == 0) {
            divs[cnt++] = i;
            while (x % i == 0) {
                x /= i;}
        }
    }
    if (x > 1) {divs[cnt++] = x;}
    for (int g = 2;; g++) {
        bool ok = true;
        for (int i = 0; i < cnt; i++) {
            if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                ok = false;break;
            }
        }
        if (ok) return g;
    }
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
}
}
#endif
#ifndef ATCODER_INTERNAL_QUEUE_HPP
#define ATCODER_INTERNAL_QUEUE_HPP 1
#include <vector>
namespace atcoder {
namespace internal {
template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();pos = 0;}
    void pop() { pos++; }
};
}
}
#endif
#ifndef ATCODER_INTERNAL_SCC_HPP
#define ATCODER_INTERNAL_SCC_HPP 1
#include <algorithm>
#include <utility>
#include <vector>
namespace atcoder {
namespace internal {
template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {start[e.first + 1]++;}
        for (int i = 1; i <= n; i++) {start[i] += start[i - 1];}
        auto counter = start;
        for (auto e : edges) {elist[counter[e.first]++] = e.second;}
    }
};
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}
    int num_vertices() { return _n; }
    void add_edge(int from, int to) { edges.push_back({from, {to}}); }
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);low[v] = std::min(low[v], low[to]);
                } else {low[v] = std::min(low[v], ord[to]);}
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();ord[u] = _n;ids[u] = group_num;if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {if (ord[i] == -1) dfs(dfs, i);}
        for (auto& x : ids) {x = group_num - 1 - x;}
        return {group_num, ids};
    }
    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }
  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};
}
}
#endif
#ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP
#define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1
#include <cassert>
#include <numeric>
#include <type_traits>
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;
template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;
template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;
template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
}
}
#endif
#ifndef ATCODER_MODINT_HPP
#define ATCODER_MODINT_HPP 1
#include <cassert>
#include <numeric>
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
struct modint_base {};
struct static_modint_base : modint_base {};
template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;
}
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
    using mint = static_modint;
  public:
    static constexpr int mod() { return m; }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }
    static_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    static_modint(T v) {
        long long x = (long long)(v % (long long)(umod()));
        if (x < 0) x += umod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    static_modint(T v) {
        _v = (unsigned int)(v % umod());
    }
    static_modint(bool v) { _v = ((unsigned int)(v) % umod()); }
    unsigned int val() const { return _v; }
    mint& operator++() {_v++;if (_v == umod()) _v = 0;return *this;}
    mint& operator--() {if (_v == 0) _v = umod();_v--;return *this;}
    mint operator++(int) {mint result = *this;++*this;return result;}
    mint operator--(int) {mint result = *this;--*this;return result;}
    mint& operator+=(const mint& rhs) {_v += rhs._v;if (_v >= umod()) _v -= umod();return *this;}
    mint& operator-=(const mint& rhs) {_v -= rhs._v;if (_v >= umod()) _v += umod();return *this;}
    mint& operator*=(const mint& rhs) {
        unsigned long long z = _v;
        z *= rhs._v;
        _v = (unsigned int)(z % umod());
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        if (prime) {
            assert(_v);
            return pow(umod() - 2);
        } else {
            auto eg = internal::inv_gcd(_v, m);
            assert(eg.first == 1);
            return eg.second;
        }
    }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }
  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
    static constexpr bool prime = internal::is_prime<m>;
};
template <int id> struct dynamic_modint : internal::modint_base {
    using mint = dynamic_modint;
  public:
    static int mod() { return (int)(bt.umod()); }
    static void set_mod(int m) {
        assert(1 <= m);
        bt = internal::barrett(m);
    }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }
    dynamic_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        long long x = (long long)(v % (long long)(mod()));
        if (x < 0) x += mod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        _v = (unsigned int)(v % mod());
    }
    dynamic_modint(bool v) { _v = ((unsigned int)(v) % mod()); }
    unsigned int val() const { return _v; }
    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }
    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v += mod() - rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        _v = bt.mul(_v, rhs._v);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        auto eg = internal::inv_gcd(_v, mod());
        assert(eg.first == 1);
        return eg.second;
    }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }
  private:
    unsigned int _v;
    static internal::barrett bt;
    static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt = 998244353;
using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;
namespace internal {
template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;
template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;
template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};
template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;
}
}
#endif

using namespace atcoder;
#define endl "\n"
using mint=static_modint<mod2>;

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,h,w;cin>>h>>w>>n;
    int sh,sw,gh,gw;cin>>sh>>sw>>gh>>gw;
    sh--;
    sw--;
    gh--;
    gw--;
    priority_queue<pipi> q;
    int d[h][w];
    rep(i,0,h)rep(j,0,w)d[i][j]=-1;
    rep(i,0,n){
        int x,y,k;cin>>x>>y>>k;
        x--;
        y--;
        q.push({k,{x,y}});
        d[x][y]=k;
    }
    while(q.size()>0){
        pipi p=q.top();q.pop();
        int nd=p.first,nh=p.second.first,nw=p.second.second;
        if(d[nh][nw]>nd)continue;
        rep(i,0,4){
            int nnh=nh+dh[i],nnw=nw+dw[i];
            if(nnh<0||nnh>=h||nnw<0||nnw>=w)continue;
            if(d[nnh][nnw]<nd-1){
                d[nnh][nnw]=nd-1;
                q.push({nd-1,{nnh,nnw}});
            }
        }
    }
    bool used[h][w];
    memset(used,false,sizeof used);
    used[sh][sw]=true;
    queue<pii> qq;
    qq.push({sh,sw});
    while(qq.size()>0){
        pii p=qq.front();qq.pop();
        int nh=p.first,nw=p.second;
        rep(i,0,4){
            int nnh=nh+dh[i],nnw=nw+dw[i];
            if(nnh<0||nnh>=h||nnw<0||nnw>=w)continue;
            if(d[nnh][nnw]==-1&&used[nnh][nnw]==false){
                used[nnh][nnw]=true;
                qq.push({nnh,nnw});
            }
        }
    }
    if(used[gh][gw])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 5216
final_rank: 4

code_snippet: #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; }
template <typename T> bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; }
int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> vector<T> sort_unique(vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; }
template <typename T> int arglb(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); }
template <typename T> int argub(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
#if __cplusplus >= 201703L
template <typename... T> istream &operator>>(istream &is, tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
#endif
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef HITONANODE_LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
#define dbgif(cond, x) ((cond) ? cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl : cerr)
#else
#define dbg(x) (x)
#define dbgif(cond, x) 0
#endif

struct GridUnionFind {
    int H, W;
    std::vector<int> par, cou;
    using P = std::pair<int, int>;
    GridUnionFind(int H_, int W_) : H(H_), W(W_), par(H * W), cou(H * W, 1) {
        std::iota(par.begin(), par.end(), 0);
    }
    inline int id_(int h, int w) { return h * W + w; }
    inline bool coordinate_valid(int h, int w) { return h >= 0 and h < H and w >= 0 and w < W; }
    int _find(int x) { return (par[x] == x) ? x : (par[x] = _find(par[x])); }
    bool _unite(int x, int y) {
        x = _find(x), y = _find(y);
        if (x == y) return false;
        if (cou[x] < cou[y]) std::swap(x, y);
        par[y] = x, cou[x] += cou[y];
        return true;
    }
    int find(int h, int w) {
        assert(coordinate_valid(h, w));
        return _find(id_(h, w));
    }
    bool unite(int h, int w, int h2, int w2) {
        assert(coordinate_valid(h, w) and coordinate_valid(h2, w2));
        return _unite(id_(h, w), id_(h2, w2));
    }
    int count(int h, int w) { return cou[find(h, w)]; }
    bool same(int h, int w, int h2, int w2) { return find(h, w) == find(h2, w2); }

    int find(P p) { return find(p.first, p.second); }
    bool unite(P p, P p2) { return unite(p.first, p.second, p2.first, p2.second); }
    int count(P p) { return count(p.first, p.second); }
    bool same(P p, P p2) { return same(p.first, p.second, p2.first, p2.second); }

    void merge_outer() {
        for (int h = 0; h < H - 1; h++) unite(h, 0, h + 1, 0), unite(h, W - 1, h + 1, W - 1);
        for (int w = 0; w < W - 1; w++) unite(0, w, 0, w + 1), unite(H - 1, w, H - 1, w + 1);
    }
    template <typename OStream> friend OStream &operator<<(OStream &os, GridUnionFind &g) {
        constexpr int WW = 3;
        os << "[(" << g.H << " * " << g.W << " grid)\n";
        for (int i = 0; i < g.H; i++) {
            for (int j = 0; j < g.W - 1; j++) {
                os << std::setw(WW) << g.find(i, j) << (g.same(i, j, i, j + 1) ? '-' : ' ');
            }
            os << std::setw(WW) << g.find(i, g.W - 1) << '\n';
            if (i < g.H - 1) {
                for (int j = 0; j < g.W; j++)
                    os << std::setw(WW + 1) << (g.same(i, j, i + 1, j) ? "| " : "  ");
                os << "\n";
            }
        }
        os << "]\n";
        return os;
    }
};


int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vector A(H + 3, vector<int>(W + 2));
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    while (N--) {
        int x, y, k;
        cin >> x >> y >> k;

        A[x - k][y] += 1;
        A[x + 1][y - k - 1] -= 1;
        A[x + 1][y + k + 1] -= 1;
        A[x + k + 2][y] += 1;
    }

    REP(i, A.size() - 1) REP(j, W + 1) A[i + 1][j + 1] += A[i][j];
    REP(i, A.size() - 1) REP(j, W + 1) A[i + 1][j] += A[i][j + 1];

    GridUnionFind uf(H + 2, W + 2);

    array<int, 2> dx{1, 0}, dy{0, 1};
    FOR(i, 1, H + 1) FOR(j, 1, W + 1) {
        if (A[i][j]) continue;
        REP(d, dx.size()) {
            int ni = i + dx[d], nj = j + dy[d];
            if (ni <= H and nj <= W and !A[ni][nj]) uf.unite(i, j, ni, nj);
        }
    }
    cout << (uf.same(sx, sy, gx, gy) ? "Yes" : "No") << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 5012
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;

using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in: v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e: t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

/**
 * @brief Union-Find
 * @docs docs/union-find.md
 */
struct UnionFind {
  vector< int > data;

  UnionFind() = default;

  explicit UnionFind(size_t sz) : data(sz, -1) {}

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  int find(int k) {
    if(data[k] < 0) return (k);
    return data[k] = find(data[k]);
  }

  int size(int k) {
    return -data[find(k)];
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  vector< vector< int > > groups() {
    int n = (int) data.size();
    vector< vector< int > > ret(n);
    for(int i = 0; i < n; i++) {
      ret[find(i)].emplace_back(i);
    }
    ret.erase(remove_if(begin(ret), end(ret), [&](const vector< int > &v) {
      return v.empty();
    }));
    return ret;
  }
};

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  --A, --B, --C, --D;
  auto dp = make_v< int >(H, W);
  fill_v(dp, -1);
  using pii = tuple< int, int, int >;
  priority_queue< pii > que;
  for(int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    if(chmax(dp[a][b], c)) {
      que.emplace(c, a, b);
    }
  }
  const int vy[] = {-1, 0, 0, 1};
  const int vx[] = {0, 1, -1, 0};
  while(not que.empty()) {
    auto[c, y, x]=que.top();
    que.pop();
    if(dp[y][x] != c) {
      continue;
    }
    if(c > 0) {
      for(int k = 0; k < 4; k++) {
        int ny = y + vy[k];
        int nx = x + vx[k];
        if(ny < 0 or nx < 0 or ny >= H or nx >= W) {
          continue;
        }
        if(chmax(dp[ny][nx], c - 1)) {
          que.emplace(dp[ny][nx], ny, nx);
        }
      }
    }
  }
  UnionFind uf(H * W);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(dp[i][j] == -1) {
        if(i and dp[i - 1][j] == -1) {
          uf.unite(i * W + j, i * W + j - W);
        }
        if(j and dp[i][j - 1] == -1) {
          uf.unite(i * W + j, i * W + j - 1);
        }
      }
    }
  }
  if(uf.same(A * W + B, C * W + D)) cout << "Yes\n";
  else cout << "No\n";
}
accuracy: 1
time_ms: 30
memory_kb: 5644
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> s(2), g(2);
    for(int i = 0; i < 2; i++) {
        cin >> s[i];
        s[i]--;
    }
    for(int i = 0; i < 2; i++) {
        cin >> g[i];
        g[i]--;
    }
    vector<vector<int>> field(H, vector<int>(W, -1));
    int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
    {priority_queue<tuple<int, int, int>> q;
    for(int i = 0; i < N; i++){
        int x, y, k;
        cin >> x >> y >> k;
        x--;
        y--;
        field[x][y] = k;
        q.push({k, x, y});
    }
    while(!q.empty()){
        auto [rest, x, y] = q.top();
        q.pop();
        if(rest == 0) continue;
        if(field[x][y] > rest) continue;
        rest--;
        for(int i = 0; i < 4; i++){
            int nx = x + dx[i], ny = y + dy[i];
            if(0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] < rest){
                field[nx][ny] = rest;
                q.push({rest, nx, ny});
            }
        }
    }}
    vector<vector<bool>> d(H, vector<bool>(W, false));
    queue<pair<int, int>> q;
    q.push({s[0], s[1]});
    d[s[0]][s[1]] = true;
    while(!q.empty()){
        auto[x, y] = q.front();
        q.pop();
        for(int i = 0; i < 4; i++){
            int nx = x + dx[i], ny = y + dy[i];
            if(0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] == -1 && !d[nx][ny]){
                d[nx][ny] = true;
                q.push({nx, ny});
            }
        }
    }
    if(d[g[0]][g[1]]) cout << "Yes" << endl;
    else cout << "No" << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 5792
final_rank: 8

code_snippet: #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <unistd.h>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdexcept>

using namespace std;
#define rep(i,n) for(long long i=0;i<n;++i)
#define rep1(i,n) for(long long i=1;i<=n;++i)
#define rrep(i,n) for(long long i=n-1;i>=0;--i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1.1e18;const lint inf=1.01e9;
constexpr int MOD=1000000007;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }

using E=int;
struct DualSegmentTree {
  int sz, height;
  vector<int> lazy;
  const int ei=0;

  void build(int n){
    sz = 1;
    height = 0;
    while(sz < n) sz <<= 1, height++;
    lazy.assign(2 * sz, ei);
  }

  inline void propagate(int k) {
    if(lazy[k] != ei) {
      lazy[2 * k + 0] = lazy[2 * k + 0]+lazy[k];
      lazy[2 * k + 1] =lazy[2 * k + 1]+lazy[k];
      lazy[k] = ei;
    }
  }

  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }

  void update(int a, int b, const E &x) {
    thrust(a += sz);
    thrust(b += sz - 1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) lazy[l] = lazy[l]+ x, ++l;
      if(r & 1) --r, lazy[r] = lazy[r]+ x;
    }
  }

  E operator[](int k) {
    thrust(k += sz);
    return lazy[k];
  }
};

class Scanner {
    vector<char> buffer;
    ssize_t n_written;
    ssize_t n_read;

public:
    Scanner(): buffer(1024*1024) { do_read(); }

    int64_t read_int() {
        int64_t ret = 0, sgn = 1;
        int ch = current_char();
        while (isspace(ch)) { ch = next_char(); }
        if (ch == '-') { sgn = -1; ch = next_char(); }
        for (; isdigit(ch); ch = next_char())
            ret = (ret * 10) + (ch - '0');
        return sgn * ret;
    }

private:
    void do_read() {
        ssize_t r = read(0, &buffer[0], buffer.size());
        if (r < 0) {
            throw runtime_error(strerror(errno));
        }
        n_written = r;
        n_read = 0;
    }

    inline int next_char() {
        ++n_read;
        if (n_read == n_written) { do_read(); }
        return current_char();
    }

    inline int current_char() {
        return (n_read == n_written) ? EOF : buffer[n_read];
    }
};

signed main(){
  Scanner scanner;
  int h,w,n;//cin>>h>>w>>n;
  h=scanner.read_int();
  w=scanner.read_int();
  n=scanner.read_int();
  bool hw=h>w;
  P s,g;//cin>>s.first>>s.second>>g.first>>g.second;
  s.first=scanner.read_int();
  s.second=scanner.read_int();
  g.first=scanner.read_int();
  g.second=scanner.read_int();
  if(hw){
    swap(h,w);
    swap(s.first,s.second);
    swap(g.first,g.second);
  }
  vector<int> x(n),y(n),k(n);
  rep(i,n){
    x[i]=scanner.read_int();
    y[i]=scanner.read_int();
    k[i]=scanner.read_int();
    if(hw)swap(x[i],y[i]);
  }
  /*
  vector<DualSegmentTree> tree(h+1);
  rep1(i,h){
    tree[i].build(w+1);
  }
  */

  vector<vector<int>> kabe(h+1,vector<int>(w+2,0));

  rep(i,n){
    for(int j=x[i]-k[i];j<=x[i]+k[i];++j){
      int l=y[i]-(k[i]-abs(j-x[i]));
      int r=y[i]+(k[i]-abs(j-x[i]));
      kabe[j][l]+=1;
      kabe[j][r+1]-=1;
    }
  }
  rep1(i,h)rep1(j,w){
    kabe[i][j]+=kabe[i][j-1];
  }
  vector<vector<bool>> dp(h+1,vector<bool>(w+1,0));
  vector<vector<bool>> ng(h+1,vector<bool>(w+1,0));
  queue<P> que;
  que.push(s);
  int dx[]={1,0,-1,0};
  int dy[]={0,1,0,-1};
  while(!que.empty()){
    auto [yy,xx]=que.front();que.pop();
    if(dp[yy][xx])continue;
    dp[yy][xx]=1;
    if(yy==g.first&&xx==g.second)break;
    rep(i,4){
      int xxx=xx+dx[i];
      int yyy=yy+dy[i];
      if(xxx<1||xxx>w)continue;
      if(yyy<1||yyy>h)continue;
      if(dp[yyy][xxx])continue;
      if(ng[yyy][xxx])continue;
      if(kabe[yyy][xxx]>0){
        ng[yyy][xxx]=1;
        continue;
      }
      que.push({yyy,xxx});
    }
  }
  if(dp[g.first][g.second]==1){
    cout<<"Yes"<<"\n";
  }
  else cout<<"No"<<"\n";
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5632
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#include <complex>
#include <random>
#include <functional>
using namespace std;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
vvll G;
int main() {
    ll H, W, N;
    cin >> H >> W >> N;
    ll SX, SY, GX, GY;
    cin >> SX >> SY >> GX >> GY;
    SX--; SY--; GX--; GY--;
    vector<vll> G(H + W + 10);
    map<pair<ll, ll>, ll> M;
    map<pair<ll, ll>, ll> SM;
    rep(i, N) {
        ll X, Y, K;
        cin >> X >> Y >> K;
        X--; Y--;
        M[{X + Y - K, X - Y - K}]++;
        M[{X + Y + K + 1, X - Y - K}]--;
        M[{X + Y - K, X - Y + K + 1}]--;
        M[{X + Y + K + 1, X - Y + K + 1}]++;
    }
    set<pair<ll, ll>> S;
    for (ll i = -2; i <= H + W + 3; i++) {
        for (ll j = max(-i, -2 * (W)+i) - 2; j <= min(2 * (H)-i, i) + 2; j++) {
            ll PM = -SM[{i - 1, j - 1}] + SM[{i, j - 1}] + SM[{i - 1, j}] + M[{i, j}];
            
            SM[{i, j}] = PM;
            /*if (PM != 0) {
                cout << i<<" "<<j<<" "<<SM[{i - 1, j - 1}] << " " << SM[{i, j - 1}] << " " << SM[{i - 1, j}] << " " << M[{i, j}] << endl;
                cout << "";
            }*/
        }
    }
    map<pair<ll, ll>, bool> seen;
    queue<pair<ll, ll>> Q;
    Q.push({ SX + SY,SX - SY });
    vll dx = { 1,1,-1,-1 };
    vll dy = { 1,-1,1,-1 };
    while (!Q.empty()) {
        auto p = Q.front();
        Q.pop();
        if (seen.count(p))continue;
        seen[p] = true;
        rep(d, 4) {
            ll nxpy = p.first + dx[d];
            ll nxmy = p.second + dy[d];
            ll nx = (nxpy + nxmy) / 2;
            ll ny = (nxpy - nxmy) / 2;
            if (nx < 0 || nx >= H || ny < 0 || ny >= W)continue;
            if (seen.count({ nxpy,nxmy }))continue;
            if (!SM.count({ nxpy,nxmy }))continue;
            if (SM[{nxpy, nxmy}] != 0)continue;
            Q.push({ nxpy,nxmy });
        }

    }
    if (seen.count({ GX + GY,GX - GY })) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

}
accuracy: 1
time_ms: 180
memory_kb: 38976
final_rank: 18

code_snippet: #include "bits/stdc++.h"
#include <unistd.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using i_b = pair<int, bool>;
using l_l = pair<i64, i64>;
using d_d = pair<double, double>;
using s_s = pair<string, string>;
using i_i_i = tuple<int, int, int>;
using i_i_i_i = tuple<int, int, int, int>;
using l_l_l = tuple<i64, i64, i64>;
using l_l_l_l = tuple<i64, i64, i64, i64>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define ifbit(n,k) ((n>>k)&1) //if kth bit of n is on then true (sitakara, 0-indexed)
#define zpad(i) cout << setfill('0') << setw(i)
#define dout cout << fixed << setprecision(10)
#define pcnt __builtin_popcount
constexpr int INF = 2147483647;
constexpr i64 I64F = 9223372036854775807;
constexpr int m1007 = 1000000007;
constexpr int m9982 = 998244353;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};
int main() {
	int h, w; cin >> h >> w;
	int n; cin >> n;
	int sx, sy; cin >> sx >> sy;
	int gx, gy; cin >> gx >> gy;
	sx--;sy--;gx--;gy--;
	vector g(h, vector<int>(w));
	auto f = [&](int si, int sj, int k) {
		int i = si, j = sj;
		j += k;
		while (j != sj) {
			g[i][j] = true;
			i--;j--;
		}
		while (i != si) {
			g[i][j] = true;
			i++;j--;
		}
		while (j != sj) {
			g[i][j] = true;
			i++;j++;
		}
		while (i != si) {
			g[i][j] = true;
			i--;j++;
		}
	};
	for (int i = 0; i < n; i++) {
		int x, y, k; cin >> x >> y >> k;
		x--;y--;
		if (k == 0) {
			g[x][y] = true;
		}
		else {
			f(x, y, k);
		}
	}
	vector dp(h, vector<int>(w));
	queue<i_i> q;
	q.push({sx, sy});
	while (q.size()) {
		auto [i, j] = q.front(); q.pop();
		if (dp[i][j]) continue;
		dp[i][j] = true;
		for (int t = 0; t < 4; t++) {
			int ni = di[t] + i;
			int nj = dj[t] + j;
			if (ni < 0 or ni >= h or nj < 0 or nj >= w) continue;
			if (g[ni][nj]) continue;
			if (dp[ni][nj]) continue;
			q.push({ni, nj});
		}
	}
	bool yes = false;
	if (dp[gx][gy]) yes = true;
	cout << (yes ? "Yes" : "No") << endl;
	
	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 5020
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll h,w,n;cin >> h >> w >> n;
    ll sx,sy,gx,gy;cin >> sx >> sy >> gx >> gy;sx--;sy--;gx--;gy--;
    vvl g(h,vl(w));
    rep(i,n){
        ll x,y,k;cin >> x >> y >> k;

        x--;y--;
        x-=k;
        g[x][y]=1;
        rep(_,k){
            g[x][y]=1;
            x+=1;y-=1;
        }
        rep(_,k){
            g[x][y]=1;
            x+=1;y+=1;
        }
        rep(_,k){
            g[x][y]=1;
            x-=1;y+=1;
        }
        rep(_,k){
            g[x][y]=1;
            x-=1;y-=1;
        }
    }
    /*rep(i,h){
        rep(j,w)cout << g[i][j];
        cout << endl;
    }*/
    queue<pl> que;
    que.push({sx,sy});
    vvl dist(h,vl(w,-1));
    dist[sx][sy]=0;
    while(!que.empty()){
        auto [a,b]=que.front();que.pop();
        rep(k,4){
            ll nx=a+dx[k],ny=b+dy[k];
            if(nx<0||nx>=h||ny<0||ny>=w)continue;
            if(g[nx][ny]==1)continue;
            if(dist[nx][ny]!=-1)continue;
            dist[nx][ny]=dist[a][b]+1;
            que.push({nx,ny});
        }
    }
    if(dist[gx][gy]!=-1)cout << "Yes" << endl;
    else cout << "No" << endl;
}
accuracy: 1
time_ms: 130
memory_kb: 5396
final_rank: 15

code_snippet: #define MOD_TYPE 2

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

#if 0
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#if 0
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <typename T>
using extset =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#if 0
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif

#pragma region Macros

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename T>
using smaller_queue = priority_queue<T, vector<T>, greater<T>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-7;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";
#define UNIQUE(v) v.erase(unique(all(v)), v.end())

struct io_init {
  io_init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; }
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val) {
  fill((T *)array, (T *)(array + N), val);
}
template <typename T>
vector<T> compress(vector<T> &v) {
  vector<T> val = v;
  sort(all(val)), val.erase(unique(all(val)), val.end());
  for (auto &&vi : v) vi = lower_bound(all(val), vi) - val.begin();
  return val;
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept {
  os << p.first << " " << p.second;
  return os;
}
template <typename T>
constexpr istream &operator>>(istream &is, vector<T> &v) noexcept {
  for (int i = 0; i < v.size(); i++) is >> v[i];
  return is;
}
template <typename T>
constexpr ostream &operator<<(ostream &os, vector<T> &v) noexcept {
  for (int i = 0; i < v.size(); i++)
    os << v[i] << (i + 1 == v.size() ? "" : " ");
  return os;
}
template <typename T>
constexpr void operator--(vector<T> &v, int) noexcept {
  for (int i = 0; i < v.size(); i++) v[i]--;
}
random_device seed_gen;
mt19937_64 engine(seed_gen());

#pragma endregion

// --------------------------------------

struct UnionFind {
 public:
  UnionFind() : _n(0) {}
  UnionFind(int n) : _n(n), parent_or_size(n, -1) {}

  int unite(int a, int b) {
    assert(0 <= a && a < _n);
    assert(0 <= b && b < _n);
    int x = root(a), y = root(b);
    if (x == y) return x;
    if (-parent_or_size[x] < -parent_or_size[y]) swap(x, y);
    parent_or_size[x] += parent_or_size[y];
    parent_or_size[y] = x;
    return x;
  }

  bool same(int a, int b) {
    assert(0 <= a && a < _n);
    assert(0 <= b && b < _n);
    return root(a) == root(b);
  }

  int root(int a) {
    assert(0 <= a && a < _n);
    if (parent_or_size[a] < 0) return a;
    return parent_or_size[a] = root(parent_or_size[a]);
  }

  int size(int a) {
    assert(0 <= a && a < _n);
    return -parent_or_size[root(a)];
  }

  vector<vector<int>> groups() {
    vector<int> leader_buf(_n), group_size(_n);
    for (int i = 0; i < _n; i++) {
      leader_buf[i] = root(i);
      group_size[leader_buf[i]]++;
    }
    vector<vector<int>> result(_n);
    for (int i = 0; i < _n; i++) {
      result[i].reserve(group_size[i]);
    }
    for (int i = 0; i < _n; i++) {
      result[leader_buf[i]].push_back(i);
    }
    result.erase(remove_if(result.begin(), result.end(),
                           [&](const vector<int> &v) { return v.empty(); }),
                 result.end());
    return result;
  }

 private:
  int _n;
  vector<int> parent_or_size;
};

void solve() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<vector<int>> imos(h + 10, vector<int>(w + 10));
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  sx--, sy--, gx--, gy--;
  rep(i, n) {
    int x, y, k;
    cin >> x >> y >> k;
    x += 4, y += 4;
    imos[x][y - k]++;
    imos[x - k - 1][y + 1]--;
    imos[x + k + 1][y + 1]--;
    imos[x][y + k + 2]++;
    imos[x][y - k + 1]++;
    imos[x - k][y + 1]--;
    imos[x + k][y + 1]--;
    imos[x][y + k + 1]++;
  }
  for (int i = h - 1 + 9; i >= 1; i--) {
    REP(j, 1, w + 9) { imos[i - 1][j + 1] += imos[i][j]; }
  }
  REP(i, 1, h + 9) {
    REP(j, 1, w + 9) { imos[i + 1][j + 1] += imos[i][j]; }
  }
  /*
  rep(i, h + 10) {
    rep(j, w + 10) cout << imos[i][j];
    cout << "\n";
  }*/
  UnionFind uf(h * w);
  auto f = [&](int i, int j) { return i * w + j; };
  rep(i, h) rep(j, w - 1) {
    if (imos[i + 5][j + 5] == 0 and imos[i + 5][j + 6] == 0)
      uf.unite(f(i, j), f(i, j + 1));
  }
  rep(i, h - 1) rep(j, w) {
    if (imos[i + 5][j + 5] == 0 and imos[i + 6][j + 5] == 0)
      uf.unite(f(i, j), f(i + 1, j));
  }
  Yes(uf.same(f(sx, sy), f(gx, gy)));
}

int main() { solve(); }
accuracy: 1
time_ms: 10
memory_kb: 4788
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

class union_find {
  private:
    vector<int> parent;

  public:
    union_find(int n) : parent(n, -1) {}
    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            if(size(x) < size(y)) swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            return true;
        }
        return false;
    }
    int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
    int size(int x) { return -parent[root(x)]; }
    bool same(int x, int y) { return root(x) == root(y); }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int H,W,N; cin >> H >> W >> N;
    int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
    sx--; sy--; gx--; gy--;
    vector<tuple<int,int,int>> a(N);
    rep(i,N) {
        int x,y,k; cin >> x >> y >> k; x--; y--;
        a[i] = {x, y, k};
    }

    if(H > W) {
        swap(H, W);
        swap(sx, sy);
        swap(gx, gy);
        rep(i,N) {
            auto [x, y, k] = a[i];
            swap(x, y);
            a[i] = {x, y, k};
        }
    }

    // H <= W
    vector<vector<int>> sum(H, vector<int>(W + 1));
    rep(i,N) {
        auto [x, y, k] = a[i];
        for(int i = x - k; i <= x + k; i++) {
            int d = k - abs(i - x);
            int L = y - d, R = y + d;
            sum[i][L]++; sum[i][R + 1]--;
        }
    }
    rep(i,H)rep(j,W) sum[i][j + 1] += sum[i][j];

    union_find uf(H * W);
    auto f = [&](int i, int j){ return i * W + j; };
    rep(i,H)rep(j,W) {
        if(sum[i][j] == 0) {
            if(i + 1 < H && sum[i + 1][j] == 0) {
                uf.unite(f(i, j), f(i + 1, j));
            }
            if(j + 1 < W && sum[i][j + 1] == 0) {
                uf.unite(f(i, j), f(i, j + 1));
            }
        }
    }

    cout << (uf.same(f(sx, sy), f(gx, gy)) ? "Yes" : "No") << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 5192
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli dx[4] = {-1,0,1,0};
lli dy[4] = {0,1,0,-1};

// Generated by 2.11.0 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){

    lli h,w,n;
    cin>>h>>w>>n;
    vector<vector<lli> > board(h+10,vector<lli>(w+10,0));

    lli sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    sx--;
    sy--;
    gx--;
    gy--;

    REP(i,0,n){
        lli x,y,k;
        cin>>x>>y>>k;
        x--;
        y--;
        queue<lli> qx,qy,qlefK;
        qx.push(x);
        qy.push(y);
        qlefK.push(k);

        board[x][y] = 1;

        while(!qx.empty()){
            lli nowX = qx.front();
            lli nowY = qy.front();
            lli lefK = qlefK.front();
            LOG3(nowX,nowY,lefK);
            qx.pop();
            qy.pop();
            qlefK.pop();

            if(lefK==0)continue;

            REP(j,0,4){
                lli nextX = nowX + dx[j];
                lli nextY = nowY + dy[j];

                if(nextX < 0 || h <= nextX || nextY < 0 || w <= nextY)continue;
                if(board[nextX][nextY]==1)continue;
                board[nextX][nextY] = 1;
                qx.push(nextX);
                qy.push(nextY);
                qlefK.push(lefK-1);
            }
        }
    }

    queue<lli> qx,qy;
    qx.push(sx);
    qy.push(sy);
    board[sx][sy]=1;
    while(!qx.empty()){
        lli nowX = qx.front();
        lli nowY = qy.front();
        LOG2(nowX,nowY);
        if(nowX == gx && nowY == gy){
            cout<<"Yes"<<endl;
            return 0;
        }

        qx.pop();
        qy.pop();
        REP(j,0,4){
            lli nextX = nowX + dx[j];
            lli nextY = nowY + dy[j];
            if(nextX < 0 || h <= nextX || nextY < 0 || w <= nextY)continue;
            if(board[nextX][nextY]==1)continue;
            board[nextX][nextY] = 1;
            qx.push(nextX);
            qy.push(nextY);
        }
    }
    cout<<"No"<<endl;
    return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 5212
final_rank: 12

code_snippet: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#include <array>
#include <unordered_set>
#include <unordered_map>
#define rep(x, s, t) for(ll x = (s); (x) <= (t); (x)++)
#define per(x, s, t) for(ll x = (s); (x) >= (t); (x)--)
#define reps(x, s) for(ll x = 0; (x) < (ll)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define outl(...) dump_func(__VA_ARGS__)
#define outf(x) cout << fixed << setprecision(16) << (x) << endl
#define pb push_back
#define fi first
#define se second
#define inf 2e18
#define eps 1e-9
const double PI = 3.1415926535897932384626433;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct edge{
	ll to, cost;
	edge(){}
	edge(ll a, ll b){ to = a, cost = b;}
};
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

const int mod = 1000000007;
//const int mod = 998244353;

struct mint{
	int x;
	mint(ll y = 0){if(y < 0 || y >= mod) y = (y%mod+mod)%mod; x = y;}
	mint(const mint &ope) {x = ope.x;}
	mint operator-(){return mint(-x);}
	mint operator+(const mint &ope){return mint(x) += ope;}
	mint operator-(const mint &ope){return mint(x) -= ope;}
	mint operator*(const mint &ope){return mint(x) *= ope;}
	mint operator/(const mint &ope){return mint(x) /= ope;}
	mint& operator+=(const mint &ope){x += ope.x; if(x >= mod) x -= mod; return *this;}
	mint& operator-=(const mint &ope){x += mod - ope.x; if(x >= mod) x -= mod; return *this;}
	mint& operator*=(const mint &ope){ll tmp = x; tmp *= ope.x, tmp %= mod; x = tmp; return *this;}
	mint& operator/=(const mint &ope){
		ll n = mod-2; mint mul = ope;
		while(n){if(n & 1) *this *= mul; mul *= mul; n >>= 1;}
		return *this;
	}
	mint inverse(){return mint(1) / *this;}
	bool operator ==(const mint &ope){return x == ope.x;}
	bool operator !=(const mint &ope){return x != ope.x;}
	bool operator <(const mint &ope)const{return x < ope.x;}
};
mint modpow(mint a, ll n){
	if(n == 0) return mint(1);
	if(n % 2) return a * modpow(a, n-1);
	else return modpow(a*a, n/2);
}
istream& operator >>(istream &is, mint &ope){ll t; is >> t, ope.x = t; return is;}
ostream& operator <<(ostream &os, mint &ope){return os << ope.x;}
ostream& operator <<(ostream &os, const mint &ope){return os << ope.x;}

ll modpow(ll a, ll n, ll mod){
	if(n == 0) return 1;
	if(n % 2) return ((a%mod) * (modpow(a, n-1, mod)%mod)) % mod;
	else return modpow((a*a)%mod, n/2, mod) % mod;
}

vector<mint> fact, fact_inv;
void make_fact(int n){
	fact.resize(n+1), fact_inv.resize(n+1);
	fact[0] = mint(1); rep(i, 1, n) fact[i] = fact[i-1] * mint(i);
	fact_inv[n] = fact[n].inverse(); per(i, n-1, 0) fact_inv[i] = fact_inv[i+1] * mint(i+1);
}
mint comb(int n, int k){ if(n < 0 || k < 0 || n < k) return mint(0); return fact[n] * fact_inv[k] * fact_inv[n-k];}
mint perm(int n, int k){ return comb(n, k) * fact[k]; }
template<typename T> T comb2(ll n, ll k){ T ret = 1; rep(i, 1, k) ret *= n-k+i, ret /= i; return ret;}

vector<int> prime, pvec, qrime;
void make_prime(int n){
	prime.resize(n+1);
	rep(i, 2, n){
		if(prime[i] == 0) pvec.push_back(i), prime[i] = i;
		for(auto p : pvec){ if(i*p > n || p > prime[i]) break; prime[i*p] = p;}
	}
}
void make_qrime(int n){
	qrime.resize(n+1);
	rep(i, 2, n){int ni = i / prime[i]; if(prime[i] == prime[ni]) qrime[i] = qrime[ni] * prime[i]; else qrime[i] = prime[i];}
}

bool exceed(ll x, ll y, ll m){return y > 0 && x >= m / y + 1;}
void mark(){ cout << "*" << endl; }
void yes(){ cout << "YES" << endl; }
void no(){ cout << "NO" << endl; }
ll floor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a >= 0) return a/b; else return -((-a+b-1)/b); }
ll ceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a >= 0) return (a+b-1)/b; else return -((-a)/b); }
ll modulo(ll a, ll b){ b = abs(b); return a - floor(a, b) * b;}
ll sgn(ll x){ if(x > 0) return 1; if(x < 0) return -1; return 0;}
ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a%b);}
ll lcm(ll a, ll b){return a/gcd(a, b)*b;}
ll arith(ll x){return x*(x+1)/2;}
ll arith(ll l, ll r){return arith(r) - arith(l-1);}
ll digitnum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret++; return ret;}
ll digitsum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret += x % b; return ret;}
string lltos(ll x, ll b = 10){string ret; for(;x;x/=b) ret += x % b + '0'; reverse(all(ret)); return ret;}
ll stoll(string &s, ll b = 10){ll ret = 0; for(auto c : s) ret *= b, ret += c - '0'; return ret;}
template<typename T> void uniq(T &vec){sort(all(vec)); vec.erase(unique(all(vec)), vec.end());}
int popcount(ull x){
	x -= ((x>>1)&0x5555555555555555ULL), x = (x & 0x3333333333333333ULL) + ((x>>2) & 0x3333333333333333ULL);
	return (((x + (x>>4)) & 0x0F0F0F0F0F0F0F0FULL) * 0x0101010101010101ULL) >> 56;
}

template<class S, class T> pair<S, T>& operator+=(pair<S, T> &s, const pair<S, T> &t){s.first += t.first, s.second += t.second; return s;}
template<class S, class T> pair<S, T>& operator-=(pair<S, T> &s, const pair<S, T> &t){s.first -= t.first, s.second -= t.second; return s;}
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t){return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t){return pair<S,T>(s.first-t.first, s.second-t.second);}
template<class T> T dot(const pair<T, T> &s, const pair<T, T> &t){return s.first*t.first + s.second*t.second;}
template<class T> T cross(const pair<T, T> &s, const pair<T, T> &t){return s.first*t.second - s.second*t.first;}

template<typename T> ostream& operator << (ostream& os, vector<T>& vec){reps(i, vec) os << vec[i] << " "; return os;}
template<typename T> ostream& operator << (ostream& os, const vector<T>& vec){reps(i, vec) os << vec[i] << " "; return os;}
template<typename T> ostream& operator << (ostream& os, list<T>& ls){for(auto x : ls) os << x << " "; return os;}
template<typename T> ostream& operator << (ostream& os, const list<T>& ls){for(auto x : ls) os << x << " "; return os;}
template<typename T> ostream& operator << (ostream& os, deque<T>& deq){reps(i,  deq) os << deq[i] << " "; return os;}
template<typename T, typename U> ostream& operator << (ostream& os, pair<T, U>& ope){ os << "(" << ope.first << ", " << ope.second << ")"; return os;}
template<typename T, typename U> ostream& operator << (ostream& os, const pair<T, U>& ope){ os << "(" << ope.first << ", " << ope.second << ")"; return os;}
template<typename T, typename U> ostream& operator << (ostream& os, map<T, U>& ope){ for(auto p : ope) os << "(" << p.first << ", " << p.second << "),";return os;}
template<typename T> ostream& operator << (ostream& os, set<T>& ope){for(auto x : ope) os << x << " "; return os;}
template<typename T> ostream& operator << (ostream& os, multiset<T>& ope){for(auto x : ope) os << x << " "; return os;}
template<typename T> void outa(T a[], ll s, ll t){rep(i, s, t){ cout << a[i]; if(i < t) cout << " ";} cout << endl;}
template<typename T, size_t N> ostream& operator << (ostream& os, array<T, N>& arr){reps(i, arr) os << arr[i] << " "; return os;}
template<typename T, size_t N> ostream& operator << (ostream& os, const array<T, N>& arr){reps(i, arr) os << arr[i] << " "; return os;}
void dump_func(){cout << endl;}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail){cout << head; if(sizeof...(Tail) > 0) cout << " "; dump_func(std::move(tail)...);}

ll n, h, w;
ll sx, sy, gx, gy;
map<P, ll> mp;
set<P> S;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> n;
	cin >> sy >> sx >> gy >> gx;
	
	ll x, y, k;
	rep(i, 1, n){
		cin >> y >> x >> k;
		ll u = x+y, v = x-y;
		mp[P(u-k, v-k)]++;
		mp[P(u+k+1, v-k)]--;
		mp[P(u-k, v+k+1)]--;
		mp[P(u+k+1, v+k+1)]++;
	}
	
	vector<P> vec;
	rep(x, 1, w) rep(y, 1, h){
		vec.pb(P(x+y, x-y));
		rep(i, 0, 3) vec.pb(P(x+y+dx[i], x-y+dy[i]));
	}
	uniq(vec);
	for(auto p : vec){
		ll u = p.fi, v = p.se;
		mp[P(u, v)] += mp[P(u, v-1)];
	}
	
	vec.clear();
	rep(x, 1, w) rep(y, 1, h){
		vec.pb(P(x-y, x+y));
		rep(i, 0, 3) vec.pb(P(x-y+dx[i], x+y+dy[i]));
	}
	uniq(vec);
	for(auto p : vec){
		ll v = p.fi, u = p.se;
		mp[P(u, v)] += mp[P(u-1, v)];
	}
	
	queue<P> Q;
	Q.push(P(sx, sy)), S.insert(P(sx, sy));
	
	while(sz(Q)){
		ll x = Q.front().fi, y = Q.front().se; Q.pop();
		rep(i, 0, 3){
			ll nx = x + dx[i], ny = y + dy[i];
			if(nx <= 0 || nx > w || ny <= 0 || ny > h) continue;
			if(S.count(P(nx, ny)) || mp[P(nx+ny, nx-ny)] > 0) continue;
			Q.push(P(nx, ny)), S.insert(P(nx, ny));
		}
	}
	if(S.count(P(gx, gy))) outl("Yes");
	else outl("No");
	
	return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 25784
final_rank: 16

code_snippet: #ifdef SUMMARY

#library <graph_template>
#library <bfs>

int solve(){
	lin(h, w, n);
	lint H = h*3/2, W = w*2;
	lin(sx, sy, gx, gy);
	ve(lint)x(n), y(n), k(n);
	rep(n)in(x[i], y[i], k[i]);
	--sx, --sy, --gx, --gy;
	i0(x, y);
	P d4n[4] = { P(1,1),P(1,-1),P(-1,-1),P(-1,1) };

	vector a(vec(2, lint, 2*h+2, 2*w+2, 0));
	{
		rep(n){
			++a[2*(x[i]-k[i])][1+2*y[i]];
			--a[2*x[i]+1][1+2*(y[i]-k[i])-1];
			--a[2*x[i]+1][1+2*(y[i]+k[i])+1];
			++a[2*(x[i]+k[i])+2][1+2*y[i]];
		}
		rep(2*h+1)rep(j, 2*w+1)a[i+1][j+1] += a[i][j];
		rep(2*h+1)rep(j, 1, 2*w+2)a[i+1][j-1] += a[i][j];
		each(a)deb(e);
	}

	auto z = [&](P p)->int{ return p.f*w+p.s; };
	auto uz = [&](int c)->P{ return P(c/w, c%w); };
	ve(ll)d(h*w, linf);
	d[z(P(sx, sy))] = 0;
	bfs(h*w, z(P(sx, sy)),[&](int c)->ve(edge){
		ve(edge)res;
		P C = uz(c);
		rep(di, 4){
			P N = C+d4[di];
			if(N.f<0||h<=N.f||N.s<0||w<=N.s)continue;
			if(a[2*N.f][1+2*N.s])continue;
			res.push_back(edge(c, z(N)));
		}
		return res;
	},[&](edge e)->void{
		d[e.to] = d[e.src]+1;
	});
	Yes(d[z(P(gx, gy))]<linf);
	return 0;
}

#endif // SUMMARY

//sub-BOF

// author: Tqk
// pc: desktop
// template version: D20220314

#define _AOJ_
#define _C_INPUT_

//#pragma region template

//#pragma region basic
#define IN_FILE "./in.txt"
//#pragma GCC optimize ("O3")
#pragma warning(disable: 4455 4244 4067 4068 4996)
#pragma GCC target ("avx")
#pragma GCC diagnostic ignored "-Wliteral-suffix"
#define NOMINMAX
#ifdef _ENV_TQK_
#include <Windows.h>
#endif
#include "bits/stdc++.h"
using namespace std;
#ifndef _AOJ_
#include <atcoder/all>
#endif
#define ac atcoder
using lint = int64_t;
using ll = int64_t;
using ld = long double;
using cs = string;
using vl = vector<ll>;
#define _getname1(_0, name, ...) name
#define _getname2(_0, _1, name, ...) name
#define _getname3(_0, _1, _2, name, ...) name
#define _getname4(_0, _1, _2, _3, name, ...) name
#define _tgetname1(ex) _getname1 ex
#define _tgetname2(ex) _getname2 ex
#define _tgetname3(ex) _getname3 ex
#define _tgetname4(ex) _getname4 ex
#define _vec2(ty, h, ...) h, vector<ty>(__VA_ARGS__)
#define _vec3(ty, x, y, ...) x, vector(y, vector<ty>(__VA_ARGS__))
#define _vec4(ty, x, y, z, ...) x, vector(y, vector(z, vector<ty>(__VA_ARGS__)))
#define _vec5(ty, x, y, z, t, ...) x, vector(y, vector(z, vector(t, vector<ty>(__VA_ARGS__))))
#define _tvec2(ex) _vec2 ex
#define _tvec3(ex) _vec3 ex
#define _tvec4(ex) _vec4 ex
#define _tvec5(ex) _vec5 ex
#define vec(d, ...) _tvec##d((__VA_ARGS__))
#define ve(ty) vector<ty>
#define linf 1152921504606846976
#ifndef _AOJ_
inline ll operator""z(const unsigned long long n){ return ll(n); }
#endif
//#pragma endregion

//#pragma region rep
#define _rep1(n) for(ll i=0;i<n;++i)
#define _rep2(i,n) for(ll i=0;i<n;++i)
#define _rep3(i,a,b) for(ll i=a;i<b;++i)
#define _rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define _trep2(ex) _rep2 ex
#define _trep3(ex) _rep3 ex
#define _trep4(ex) _rep4 ex
#define rep(...) _tgetname4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__))
#define _per1(n) for(ll i=n-1;i>=0;--i)
#define _per2(i,n) for(ll i=n-1;i>=0;--i)
#define _per3(i,a,b) for(ll i=b-1;i>=a;--i)
#define _per4(i,a,b,c) for(ll i=a+(b-a-1)/c*c;i>=a;i-=c)
#define _tper2(ex) _per2 ex
#define _tper3(ex) _per3 ex
#define _tper4(ex) _per4 ex
#define per(...) _tgetname4((__VA_ARGS__,_tper4,_tper3,_tper2,_per1))((__VA_ARGS__))
#define _all1(v) v.begin(),v.end()
#define _all2(v,a) v.begin(),v.begin()+a
#define _all3(v,a,b) v.begin()+a,v.begin+b
#define _tall2(ex) _all2 ex
#define _tall3(ex) _all3 ex
#define all(...) _tgetname3((__VA_ARGS__,_tall3,_tall2,_all1))((__VA_ARGS__))
#define _each1(c) for(auto &e:c)
#define _each2(e, c) for(auto &e:c)
#define _teach2(ex) _each2 ex
#define each(...) _tgetname2((__VA_ARGS__,_teach2,_each1))((__VA_ARGS__))
//#pragma endregion

//#pragma region io
template<class T> istream& operator>>(istream& is, vector<T>& vec){ for(T& x: vec) is>>x; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p){ is>>p.first; is>>p.second; return is; }
template<class T> ostream& operator<<(ostream& os, vector<T>& vec){ if(vec.size())os<<vec[0]; rep(i, 1, vec.size())os<<' '<<vec[i]; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p){ os<<p.first<<" "<<p.second; return os; }
template<class T> ostream& operator<<(ostream& os, set<T>& s){ each(s)os<<e<<" "; return os; }

#ifdef _ENV_TQK_
/*
ifstream infile(IN_FILE);
template<class T>
ifstream& operator>>(ifstream& is,vector<T>& vec);
template<class T,size_t size>
ifstream& operator>>(ifstream& is,array<T,size>& vec);
template<class T,class L>
ifstream& operator>>(ifstream& is,pair<T,L>& p);
template<class T>
ifstream& operator>>(ifstream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
ifstream& operator>>(ifstream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
inline void fin(){}
template <class Head,class... Tail>
inline void fin(Head&& head,Tail&&... tail){ infile>>head;fin(move(tail)...); }
*/
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
inline void in(){ SetConsoleTextAttribute(hConsole,10); }
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){
	SetConsoleTextAttribute(hConsole,15);
	cin>>head;in(move(tail)...);
}
#else
inline void in(){}
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); }
#endif

inline bool out(){ return(cout<<'\n',0); }
template <class T>
inline bool out(T t){ return(cout<<t<<'\n',0); }
template <class Head,class... Tail>
inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; }
#define o(p) cout<<(p)<<endl, 0
#define sp(p) cout<<(p)<<" ", 0
#define no(p) cout<<(p), 0
#ifdef _ENV_TQK_
inline bool deb(){ SetConsoleTextAttribute(hConsole,10); return(cout<<'\n',0); }
template <class T>
inline bool deb(T t){ return(SetConsoleTextAttribute(hConsole,12),cout<<t<<'\n',SetConsoleTextAttribute(hConsole,10),0); }
template <class Head,class... Tail>
inline bool deb(Head head,Tail... tail){
	SetConsoleTextAttribute(hConsole,12);
	cout<<head<<' ';deb(move(tail)...);return 0;
}
#define dsp(ex) SetConsoleTextAttribute(hConsole,12), sp(ex)
#define dno(ex) SetConsoleTextAttribute(hConsole,12), no(ex)
#define look(v) SetConsoleTextAttribute(hConsole,12),cout<<#v<<": ",deb(v);
#else
#define deb(...) 0
#define dsp(ex) 0
#define dno(ex) 0
#define look(v) 0
#endif

//#pragma endregion

//#pragma region TA
#define lin(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define stin(...) string __VA_ARGS__;in(__VA_ARGS__)
#define vin(type,name,size) vector<type> name(size);in(name)
#define pb push_back
#define fi e.first
#define se e.second
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define POSSIBLE(c) cout<<((c)?"POSSIBLE\n":"IMPOSSIBLE\n"),0
#define Possible(c) cout<<((c)?"Possible\n":"Impossible\n"),0
#define st(v) sort(all(v))
#define psort(l,r) if(l>r)swap(l,r);
#define fn(ty1,ty2,ex) [&](ty1 l,ty2 r){ return(ex); }
#define lfn(ex) [&](ll l,ll r){ return(ex); }

//#pragma endregion

//#pragma region func
#ifndef _AOJ_
vector<ll>& iota(ll n){
	vector<ll>ret(n);
	iota(all(ret), 0);
	return ret;
}
#endif
inline constexpr ll gcd(ll a,ll b){ while(b){ ll c=b;b=a%b;a=c; }return a; }
inline constexpr ll lcm(ll a,ll b){ return a/gcd(a,b)*b; }
template<typename T>
inline constexpr bool chmin(T &mn,const T &cnt){ if(mn>cnt){ mn=cnt;return 1; } else return 0; }
template<typename T>
inline constexpr bool chmax(T &mx,const T &cnt){ if(mx<cnt){ mx=cnt;return 1; } else return 0; }
template <class F>
inline void srt(F f){  }
template <class F, class Head, class... Tail>
inline void srt(F f, Head&& head, Tail&&... tail){
	vector<int>a(head.size());
	iota(all(a), 0);
	sort(all(a), f);
	auto res = head;
	rep(head.size())res[i] = head[a[i]];
	head = res;
	srt(f, move(tail)...);
}
template <class T>
auto smaller(vector<T>&a){
	return [&](int i,int j){return a[i]<a[j];};
}
template <class T>
auto larger(vector<T>&a){
	return [&](int i,int j){return a[i]>a[j];};
}
inline void i0(){  }
template<class Head, class... Tail>
inline void i0(Head&& head,Tail&&... tail){
	each(head)--e;
	i0(move(tail)...);
}
//#pragma endregion

//#pragma region P

class P{
public:
	ll f, s;
	P():f(0), s(0){};
	P(ll a, ll b):f(a), s(b){};
};
istream& operator>>(istream& os, P& p){ os>>p.f>>p.s; return os; }
inline constexpr bool operator<(const P& l, const P& r){ return(l.f-r.f?l.f<r.f:l.s<r.s); }
inline constexpr bool operator>(const P& l, const P& r){ return(l.f-r.f?l.f>r.f:l.s>r.s); }
inline constexpr bool operator==(const P& l, const P& r){ return(l.f==r.f&&l.s==r.s); }
inline constexpr bool operator!=(const P& l, const P& r){ return(l.f!=r.f||l.s!=r.s); }
inline P operator+(const P& l, const P& r){ return P(l.f+r.f, l.s+r.s); }
inline P operator-(const P& l, const P& r){ return P(l.f-r.f, l.s-r.s); }
inline P operator-(const P& r){ return P(-r.f, -r.s); }
inline P operator*(const ll& l, const P& r){ return P(l*r.f, l*r.s); }
inline P operator/(const P& l, const ll& r){ return P(l.f/r, l.s/r); }
inline ld abs(P p){ return sqrtl(p.f*p.f+p.s*p.s); }
inline ll mabs(P p){ return abs(p.f)+abs(p.s); }
inline ll mht(P x, P y){ return mabs(x-y); }

//#pragma endregion

//#pragma region start
struct Start{
	Start(){
#ifndef _C_INPUT_
		cin.tie(0),cout.tie(0);
		ios::sync_with_stdio(0);
#endif
		cout<<fixed<<setprecision(16);
	}
} __start;
//#pragma endregion

//#pragma endregion

//#pragma region const
#define mod 998244353
const ld pi=acosl(-1);
const ld tau=(1.+sqrtl(5))/2.;
P d4[4]={P(1,0),P(0,1),P(-1,0),P(0,-1)};
P d8[8]={P(1,0),P(1,1),P(0,1),P(-1,1),P(-1,0),P(-1,-1),P(0,-1),P(1,-1)};
const cs AUTO_YES = "Yes";
const cs AUTO_NO = "No";
int cho(bool c,cs yes=AUTO_YES,cs no=AUTO_NO){
	return out((c?yes:no));
}
//#pragma endregion

//#pragma region solve

//#pragma region lib_graph_template
//, url:"https://tqkoh.github.io/library/lib/graph/graph-template.hpp", version:"2021-11-09"

using length = lint;
struct edge{
	int src, to, id;
	edge() = default;
	edge(int src, int to, int id = 0): src(src), to(to), id(id){}
};

using Edges = vector<edge>;
class Graph: public vector<Edges>{
public:
	Graph(int n){
		this->resize(n);
	}
	void add_edge(edge e, bool directed = 0){
		(*this)[e.src].push_back(e);
		if(!directed)(*this)[e.to].push_back(edge(e.to, e.src, e.id));
	}
	void add_edge(int src, int to, int id = 0, bool directed = 0){
		(*this)[src].push_back(edge(src, to, id));
		if(!directed)(*this)[to].push_back(edge(to, src, id));
	}
};
class Matrix: public vector<vector<length>>{
public:
	Matrix(int n, length inf = 2*linf){
		this->resize(n, vector<length>(n, inf));
		for(int i = 0; i<n; ++i)(*this)[i][i] = 0;
	}
	void add_edge(edge e, length cost, bool directed = 0){
		if((*this)[e.src][e.to]>cost)(*this)[e.src][e.to] = cost;
		if(!directed)if((*this)[e.to][e.src]>cost)(*this)[e.to][e.src] = cost;
	}
	void add_edge(int src, int to, length cost, bool directed = 0){
		if((*this)[src][to]>cost)(*this)[src][to] = cost;
		if(!directed)if((*this)[to][src]>cost)(*this)[to][src] = cost;
	}
};


/*
* @title Graph Template
*/


//#pragma endregion
//#pragma region lib_bfs
//, url:"https://tqkoh.github.io/library/lib/graph/bfs.hpp", version:"2022-03-11"

template<class veFi, class vFe >
void bfs(int n, int s, veFi g, vFe dtmn){
	vector<int>vis(n); vis[s] = 1;
	queue<int>q({ s });
	while(q.size()){
		int c = q.front(); q.pop();
		for(auto e: g(c))if(!vis[e.to])vis[e.to] = 1, dtmn(e), q.push(e.to);
	}
}

/*
* @title BFS
*/


//#pragma endregion

int solve(){
	lin(h, w, n);
	lint H = h*3/2, W = w*2;
	lin(sx, sy, gx, gy);
	ve(lint)x(n), y(n), k(n);
	rep(n)in(x[i], y[i], k[i]);
	--sx, --sy, --gx, --gy;
	i0(x, y);
	P d4n[4] = { P(1,1),P(1,-1),P(-1,-1),P(-1,1) };

	vector a(vec(2, lint, 2*h+2, 2*w+2, 0));
	{
		rep(n){
			++a[2*(x[i]-k[i])][1+2*y[i]];
			--a[2*x[i]+1][1+2*(y[i]-k[i])-1];
			--a[2*x[i]+1][1+2*(y[i]+k[i])+1];
			++a[2*(x[i]+k[i])+2][1+2*y[i]];
		}
		rep(2*h+1)rep(j, 2*w+1)a[i+1][j+1] += a[i][j];
		rep(2*h+1)rep(j, 1, 2*w+2)a[i+1][j-1] += a[i][j];
		each(a)deb(e);
	}

	auto z = [&](P p)->int{ return p.f*w+p.s; };
	auto uz = [&](int c)->P{ return P(c/w, c%w); };
	ve(ll)d(h*w, linf);
	d[z(P(sx, sy))] = 0;
	bfs(h*w, z(P(sx, sy)),[&](int c)->ve(edge){
		ve(edge)res;
		P C = uz(c);
		rep(di, 4){
			P N = C+d4[di];
			if(N.f<0||h<=N.f||N.s<0||w<=N.s)continue;
			if(a[2*N.f][1+2*N.s])continue;
			res.push_back(edge(c, z(N)));
		}
		return res;
	},[&](edge e)->void{
		d[e.to] = d[e.src]+1;
	});
	Yes(d[z(P(gx, gy))]<linf);
	return 0;
}

//#pragma endregion

//#pragma region main

int main(){
	solve();
}

//#pragma endregion

//sub-EOF
accuracy: 1
time_ms: 30
memory_kb: 11168
final_rank: 13

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

using ll = long long int ;
using ld = long double ;
using P = pair<ll,ll>;
using PD = pair<ld,ld>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back 
#define eb emplace_back 
#define ppb pop_back 
#define mpa make_pair 
#define fi first  
#define se second  
#define set20 cout<<fixed<<setprecision(20)  ;
const ll INF=1e18 ;   
inline void chmax(ll& a,ll b){a=max(a,b);}  
inline void chmin(ll& a,ll b){a=min(a,b);} 
long double pi=acos(-1) ;  
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}  
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} 
ll dx[4] {1,0,-1,0} ;
ll dy[4] {0,1,0,-1} ;
#define debug cout<<888<<endl ;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


// sum(x) x以下の和
// sum(a,b) a以上b以下の和
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {  //x=1ならsumは個数のカウント
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int i,int j) {
    if(i>0) return sum(j)-sum(i-1);
    else return sum(j) ; } 
};

//using mint = modint998244353;
//using mint = modint1000000007;
/*
void dfs(ll s,ll t,Graph &g,vector<ll> &d){
  for(auto u:g[t]){
    if(u==s) continue;
    d[u]=d[t]+1;
  }
}
*/


int main(){
  ios::sync_with_stdio(false) ;
  cin.tie(nullptr) ; 

  ll h,w; cin>>h>>w;
  ll n; cin>>n;

  ll A[h][w];
  rep(i,h)rep(j,w) A[i][j]=0ll;

  ll a,b,c,d; cin>>a>>b>>c>>d;
  a-- ; b--; c--; d--;

  rep(i,n){
    ll x,y; cin>>x>>y; 
    x--; y--;
    ll k ;cin>>k;
    queue<pair<P,ll>> q;
    q.push({{x,y},k}); 

    while(!q.empty()){
      auto u=q.front();
      q.pop();
      A[u.fi.fi][u.fi.se]=1; 
      rep(i,4){
        ll xx=u.fi.fi+dx[i];
        ll yy=u.fi.se+dy[i]; 
        if(xx<0||h<=xx||yy<0||w<=yy) continue;
        if(A[xx][yy]==0&&u.se>0){ 
          A[xx][yy]=1ll;
          q.push({{xx,yy},u.se-1});
        }
      }
    }

  }

  

  ll dist[h][w];
  rep(i,h)rep(j,w) dist[i][j]=-1;
  dist[a][b]=0ll;

  queue<P> p;

  p.push({a,b});

  while(!p.empty()){
    auto u=p.front();
    p.pop();
    rep(i,4){
      ll xx=u.fi+dx[i];
      ll yy=u.se+dy[i];
      if(xx<0||h<=xx||yy<0||w<=yy) continue;
      if(dist[xx][yy]==-1&&A[xx][yy]==0){ 
        dist[xx][yy]=dist[u.fi][u.se]+1;
        p.push({xx,yy});
      }
    }
  }
  
  if(dist[c][d]!=-1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  /*
  rep(i,h){
    rep(j,w) cout<<A[i][j];
    cout<<endl;
  }
  */

  return 0 ;
  }
accuracy: 1
time_ms: 10
memory_kb: 5028
final_rank: 3

code_snippet: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#include <array>
#include <unordered_set>
#include <unordered_map>
#define rep(x, s, t) for(ll x = (s); (x) <= (t); (x)++)
#define per(x, s, t) for(ll x = (s); (x) >= (t); (x)--)
#define reps(x, s) for(ll x = 0; (x) < (ll)(s).size(); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define sz(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define outl(...) dump_func(__VA_ARGS__)
#define outf(x) cout << fixed << setprecision(16) << (x) << endl
#define pb push_back
#define fi first
#define se second
#define inf 2e18
#define eps 1e-9
const double PI = 3.1415926535897932384626433;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct edge{
	ll to, cost;
	edge(){}
	edge(ll a, ll b){ to = a, cost = b;}
};
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

const int mod = 1000000007;
//const int mod = 998244353;

struct mint{
	int x;
	mint(ll y = 0){if(y < 0 || y >= mod) y = (y%mod+mod)%mod; x = y;}
	mint(const mint &ope) {x = ope.x;}
	mint operator-(){return mint(-x);}
	mint operator+(const mint &ope){return mint(x) += ope;}
	mint operator-(const mint &ope){return mint(x) -= ope;}
	mint operator*(const mint &ope){return mint(x) *= ope;}
	mint operator/(const mint &ope){return mint(x) /= ope;}
	mint& operator+=(const mint &ope){x += ope.x; if(x >= mod) x -= mod; return *this;}
	mint& operator-=(const mint &ope){x += mod - ope.x; if(x >= mod) x -= mod; return *this;}
	mint& operator*=(const mint &ope){ll tmp = x; tmp *= ope.x, tmp %= mod; x = tmp; return *this;}
	mint& operator/=(const mint &ope){
		ll n = mod-2; mint mul = ope;
		while(n){if(n & 1) *this *= mul; mul *= mul; n >>= 1;}
		return *this;
	}
	mint inverse(){return mint(1) / *this;}
	bool operator ==(const mint &ope){return x == ope.x;}
	bool operator !=(const mint &ope){return x != ope.x;}
	bool operator <(const mint &ope)const{return x < ope.x;}
};
mint modpow(mint a, ll n){
	if(n == 0) return mint(1);
	if(n % 2) return a * modpow(a, n-1);
	else return modpow(a*a, n/2);
}
istream& operator >>(istream &is, mint &ope){ll t; is >> t, ope.x = t; return is;}
ostream& operator <<(ostream &os, mint &ope){return os << ope.x;}
ostream& operator <<(ostream &os, const mint &ope){return os << ope.x;}

ll modpow(ll a, ll n, ll mod){
	if(n == 0) return 1;
	if(n % 2) return ((a%mod) * (modpow(a, n-1, mod)%mod)) % mod;
	else return modpow((a*a)%mod, n/2, mod) % mod;
}

vector<mint> fact, fact_inv;
void make_fact(int n){
	fact.resize(n+1), fact_inv.resize(n+1);
	fact[0] = mint(1); rep(i, 1, n) fact[i] = fact[i-1] * mint(i);
	fact_inv[n] = fact[n].inverse(); per(i, n-1, 0) fact_inv[i] = fact_inv[i+1] * mint(i+1);
}
mint comb(int n, int k){ if(n < 0 || k < 0 || n < k) return mint(0); return fact[n] * fact_inv[k] * fact_inv[n-k];}
mint perm(int n, int k){ return comb(n, k) * fact[k]; }
template<typename T> T comb2(ll n, ll k){ T ret = 1; rep(i, 1, k) ret *= n-k+i, ret /= i; return ret;}

vector<int> prime, pvec, qrime;
void make_prime(int n){
	prime.resize(n+1);
	rep(i, 2, n){
		if(prime[i] == 0) pvec.push_back(i), prime[i] = i;
		for(auto p : pvec){ if(i*p > n || p > prime[i]) break; prime[i*p] = p;}
	}
}
void make_qrime(int n){
	qrime.resize(n+1);
	rep(i, 2, n){int ni = i / prime[i]; if(prime[i] == prime[ni]) qrime[i] = qrime[ni] * prime[i]; else qrime[i] = prime[i];}
}

bool exceed(ll x, ll y, ll m){return y > 0 && x >= m / y + 1;}
void mark(){ cout << "*" << endl; }
void yes(){ cout << "YES" << endl; }
void no(){ cout << "NO" << endl; }
ll floor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a >= 0) return a/b; else return -((-a+b-1)/b); }
ll ceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a >= 0) return (a+b-1)/b; else return -((-a)/b); }
ll modulo(ll a, ll b){ b = abs(b); return a - floor(a, b) * b;}
ll sgn(ll x){ if(x > 0) return 1; if(x < 0) return -1; return 0;}
ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a%b);}
ll lcm(ll a, ll b){return a/gcd(a, b)*b;}
ll arith(ll x){return x*(x+1)/2;}
ll arith(ll l, ll r){return arith(r) - arith(l-1);}
ll digitnum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret++; return ret;}
ll digitsum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret += x % b; return ret;}
string lltos(ll x, ll b = 10){string ret; for(;x;x/=b) ret += x % b + '0'; reverse(all(ret)); return ret;}
ll stoll(string &s, ll b = 10){ll ret = 0; for(auto c : s) ret *= b, ret += c - '0'; return ret;}
template<typename T> void uniq(T &vec){sort(all(vec)); vec.erase(unique(all(vec)), vec.end());}
int popcount(ull x){
	x -= ((x>>1)&0x5555555555555555ULL), x = (x & 0x3333333333333333ULL) + ((x>>2) & 0x3333333333333333ULL);
	return (((x + (x>>4)) & 0x0F0F0F0F0F0F0F0FULL) * 0x0101010101010101ULL) >> 56;
}

template<class S, class T> pair<S, T>& operator+=(pair<S, T> &s, const pair<S, T> &t){s.first += t.first, s.second += t.second; return s;}
template<class S, class T> pair<S, T>& operator-=(pair<S, T> &s, const pair<S, T> &t){s.first -= t.first, s.second -= t.second; return s;}
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t){return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t){return pair<S,T>(s.first-t.first, s.second-t.second);}
template<class T> T dot(const pair<T, T> &s, const pair<T, T> &t){return s.first*t.first + s.second*t.second;}
template<class T> T cross(const pair<T, T> &s, const pair<T, T> &t){return s.first*t.second - s.second*t.first;}

template<typename T> ostream& operator << (ostream& os, vector<T>& vec){reps(i, vec) os << vec[i] << " "; return os;}
template<typename T> ostream& operator << (ostream& os, const vector<T>& vec){reps(i, vec) os << vec[i] << " "; return os;}
template<typename T> ostream& operator << (ostream& os, list<T>& ls){for(auto x : ls) os << x << " "; return os;}
template<typename T> ostream& operator << (ostream& os, const list<T>& ls){for(auto x : ls) os << x << " "; return os;}
template<typename T> ostream& operator << (ostream& os, deque<T>& deq){reps(i,  deq) os << deq[i] << " "; return os;}
template<typename T, typename U> ostream& operator << (ostream& os, pair<T, U>& ope){ os << "(" << ope.first << ", " << ope.second << ")"; return os;}
template<typename T, typename U> ostream& operator << (ostream& os, const pair<T, U>& ope){ os << "(" << ope.first << ", " << ope.second << ")"; return os;}
template<typename T, typename U> ostream& operator << (ostream& os, map<T, U>& ope){ for(auto p : ope) os << "(" << p.first << ", " << p.second << "),";return os;}
template<typename T> ostream& operator << (ostream& os, set<T>& ope){for(auto x : ope) os << x << " "; return os;}
template<typename T> ostream& operator << (ostream& os, multiset<T>& ope){for(auto x : ope) os << x << " "; return os;}
template<typename T> void outa(T a[], ll s, ll t){rep(i, s, t){ cout << a[i]; if(i < t) cout << " ";} cout << endl;}
template<typename T, size_t N> ostream& operator << (ostream& os, array<T, N>& arr){reps(i, arr) os << arr[i] << " "; return os;}
template<typename T, size_t N> ostream& operator << (ostream& os, const array<T, N>& arr){reps(i, arr) os << arr[i] << " "; return os;}
void dump_func(){cout << endl;}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail){cout << head; if(sizeof...(Tail) > 0) cout << " "; dump_func(std::move(tail)...);}

ll n, h, w;
ll sx, sy, gx, gy;
map<P, ll> mp;
set<P> S;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> n;
	cin >> sy >> sx >> gy >> gx;
	
	ll x, y, k;
	rep(i, 1, n){
		cin >> x >> y >> k;
		ll u = x+y, v = x-y;
		mp[P(u-k, v-k)]++;
		mp[P(u+k+1, v-k)]--;
		mp[P(u-k, v+k+1)]--;
		mp[P(u+k+1, v+k+1)]++;
	}
	
	vector<P> vec;
	rep(x, 1, w) rep(y, 1, h){
		vec.pb(P(x+y, x-y));
		rep(i, 0, 3) vec.pb(P(x+y+dx[i], x-y+dy[i]));
	}
	uniq(vec);
	for(auto p : vec){
		ll u = p.fi, v = p.se;
		mp[P(u, v)] += mp[P(u, v-1)];
	}
	
	vec.clear();
	rep(x, 1, w) rep(y, 1, h){
		vec.pb(P(x-y, x+y));
		rep(i, 0, 3) vec.pb(P(x-y+dx[i], x+y+dy[i]));
	}
	uniq(vec);
	for(auto p : vec){
		ll v = p.fi, u = p.se;
		mp[P(u, v)] += mp[P(u-1, v)];
	}
	
	queue<P> Q;
	Q.push(P(sx, sy)), S.insert(P(sx, sy));
	
	while(sz(Q)){
		ll x = Q.front().fi, y = Q.front().se; Q.pop();
		rep(i, 0, 3){
			ll nx = x + dx[i], ny = y + dy[i];
			if(nx <= 0 || nx > w || ny <= 0 || ny > h) continue;
			if(S.count(P(nx, ny)) || mp[P(nx+ny, nx-ny)] > 0) continue;
			Q.push(P(nx, ny)), S.insert(P(nx, ny));
		}
	}
	if(S.count(P(gx, gy))) outl("Yes");
	else outl("No");
	
	return 0;
}
accuracy: 0.20588235294117646
time_ms: 200
memory_kb: 23924
final_rank: 20

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

using ll = long long int ;
using ld = long double ;
using P = pair<ll,ll>;
using PD = pair<ld,ld>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back 
#define eb emplace_back 
#define ppb pop_back 
#define mpa make_pair 
#define fi first  
#define se second  
#define set20 cout<<fixed<<setprecision(20)  ;
const ll INF=1e18 ;   
inline void chmax(ll& a,ll b){a=max(a,b);}  
inline void chmin(ll& a,ll b){a=min(a,b);} 
long double pi=acos(-1) ;  
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}  
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} 
ll dx[4] {1,0,-1,0} ;
ll dy[4] {0,1,0,-1} ;
#define debug cout<<888<<endl ;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


// sum(x) x以下の和
// sum(a,b) a以上b以下の和
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {  //x=1ならsumは個数のカウント
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int i,int j) {
    if(i>0) return sum(j)-sum(i-1);
    else return sum(j) ; } 
};

//using mint = modint998244353;
//using mint = modint1000000007;
/*
void dfs(ll s,ll t,Graph &g,vector<ll> &d){
  for(auto u:g[t]){
    if(u==s) continue;
    d[u]=d[t]+1;
  }
}
*/


int main(){
  ios::sync_with_stdio(false) ;
  cin.tie(nullptr) ; 

  ll h,w; cin>>h>>w;
  ll n; cin>>n;

  ll A[h][w];
  rep(i,h)rep(j,w) A[i][j]=0ll;

  ll a,b,c,d; cin>>a>>b>>c>>d;
  a-- ; b--; c--; d--;

  rep(i,n){
    ll x,y; cin>>x>>y; 
    x--; y--;
    ll k ;cin>>k;
    queue<pair<P,ll>> q;
    q.push({{x,y},k}); 

    while(!q.empty()){
      auto u=q.front();
      q.pop();
      A[u.fi.fi][u.fi.se]=1; 
      rep(i,4){
        ll xx=u.fi.fi+dx[i];
        ll yy=u.fi.se+dy[i]; 
        if(A[xx][yy]==0&&u.se>0){ 
          A[xx][yy]=1ll;
          q.push({{xx,yy},u.se-1});
        }
      }
    }

  }

  

  ll dist[h][w];
  rep(i,h)rep(j,w) dist[i][j]=-1;
  dist[a][b]=0ll;

  queue<P> p;

  p.push({a,b});

  while(!p.empty()){
    auto u=p.front();
    p.pop();
    rep(i,4){
      ll xx=u.fi+dx[i];
      ll yy=u.se+dy[i];
      if(xx<0||h<=xx||yy<0||w<=yy) continue;
      if(dist[xx][yy]==-1&&A[xx][yy]==0){ 
        dist[xx][yy]=dist[u.fi][u.se]+1;
        p.push({xx,yy});
      }
    }
  }
  
  if(dist[c][d]!=-1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  /*
  rep(i,h){
    rep(j,w) cout<<A[i][j];
    cout<<endl;
  }
  */

  return 0 ;
  }
accuracy: 0.4117647058823529
time_ms: 10
memory_kb: 5020
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <stdio.h>
#include <math.h>
#include <assert.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll=long long;

int main(){
  ll H,W,N;
  cin>>H>>W>>N;
  vector<vector<int>> d(H,vector<int>(W,0));
  ll sx,sy,gx,gy;
  cin>>sx>>sy>>gx>>gy;
  sx--;sy--;gx--;gy--;
  for(int i=0;i<N;i++){
    ll x,y,k;
    cin>>x>>y>>k;
    x--;y--;
    for(int j=0;j<=k;j++){
      d[x-(k-j)][y+j]=1;
      d[x+(k-j)][y-j]=1;
      d[x+(k-j)][y+j]=1;
      d[x-(k-j)][y-j]=1;
    }
  }
  // for(auto i:d){
  //   for(auto j:i){
  //     cerr<<j<<" ";
  //   }cerr<<endl;
  // }
  deque<pair<ll,ll>> dq;
  dq.push_back(make_pair(sx,sy));
  vector<pair<int,int>> ar={{0,1},{0,-1},{1,0},{-1,0}};
  while(!dq.empty()){
    pair<ll,ll> q=dq.front();dq.pop_front();
    d[q.first][q.second]=-1;
    for(pair<int,int> x:ar){
      int i=x.first;
      int j=x.second;
      if(0<=q.first+i && q.first+i<H && 0<=q.second+j && q.second+j<W && d[q.first+i][q.second+j]==0){
        d[q.first+i][q.second+j]=-1;
        dq.push_back(make_pair(q.first+i,q.second+j));
      }
    }
  }
  if(d[gx][gy]==-1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  // for(auto i:d){
  //   for(auto j:i){
  //     cerr<<j<<" ";
  //   }cerr<<endl;
  // }
}
accuracy: 1
time_ms: 90
memory_kb: 4156
final_rank: 10