Problem:
Problem E:
Safe Area
Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams
from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan
moves a circular-shaped machine within the screen, in such a way it does not overlap a laser
beam. As in many shooters, the machine is destroyed when the overlap happens.
Nathan is facing an uphill stage. Many enemies attack simultaneously in this stage, so eventually
laser beams fill out almost all of the screen. Surprisingly, it is even possible he has no "safe area" on the screen. In other words, the machine cannot survive wherever it is located in some
cases.
The world is as kind as it is cruel! There is a special item that helps the machine to survive
any dangerous situation, even if it is exposed in a shower of laser beams, for some seconds. In
addition, another straight line (called "a warning line") is drawn on the screen for a few seconds
before a laser beam is emit along that line.
The only problem is that Nathan has a little slow reflexes. He often messes up the timing to
use the special item. But he knows a good person who can write a program to make up his slow
reflexes - it's you! So he asked you for help.
Your task is to write a program to make judgement whether he should use the item or not, for
given warning lines and the radius of the machine.
Input
The input is a sequence of datasets. Each dataset corresponds to one situation with warning
lines in the following format:
W H N R
x
1,1
y
1,1
x
1,2
y
1,2
t
1
x
2,1
y
2,1
x
2,2
y
2,2
t
2
...
x
N
,1
y
N
,1
x
N
,2
y
N
,2
t
N
The first line of a dataset contains four integers
W
,
H
,
N
and
R
(2 <
W
≤ 640, 2 <
H
≤ 480,
0 ≤
N
≤ 100 and 0 <
R
< min{
W
,
H
}/2). The first two integers
W
and
H
indicate the width
and height of the screen, respectively. The next integer
N
represents the number of laser beams.
The last integer
R
indicates the radius of the machine. It is guaranteed that the output would
remain unchanged if the radius of the machine would become larger by 10
-5
than
R
.
The following
N
lines describe the
N
warning lines. The (
i
+1)-th line of the dataset corresponds
to the
i
-th warning line, which is represented as a straight line which passes through two given
different coordinates (
x
i
,1
,
y
i
,1
) and (
x
i
,2
,
y
i
,2
). The last integer
t
i
indicates the thickness of the
laser beam corresponding to the
i
-th warning line.
All given coordinates (
x
,
y
) on the screen are a pair of integers (0 ≤
x
≤
W
, 0 ≤
y
≤
H
). Note
that, however, the machine is allowed to be located at non-integer coordinates during the play.
The input is terminated by a line with four zeros. This line should not be processed.
Output
For each case, print "
Yes
" in a line if there is a safe area, or print "
No
" otherwise.
Sample Input
100 100 1 1
50 0 50 100 50
640 480 1 1
0 0 640 480 100
0 0 0 0
Output for the Sample Input
No
Yes

Submitted solutions:

code_snippet: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define FOR(a,b,c) for (int a=b,_c=c;a<=_c;a++)
#define FORD(a,b,c) for (int a=b;a>=c;a--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; ++i)
#define REPD(i,a) for(int i=(a)-1; i>=0; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define reset(a,b) memset(a,b,sizeof(a))
#define oo 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn=107;
int n, W, H, cnt, RR;
struct edge{
    double a,b,c,t;   
    edge(){}
    edge(double x1, double y1, double x2, double y2, double _t){
        t=_t;
        double vx=y2-y1, vy=x1-x2;
        a = vx;
        b = vy;
        c = -vx*x1 - vy*y1;
    }
} e[maxn];

edge move(edge e, double R, int flag){
    double dis = e.t/2 + R;
    double sign = (flag?1:-1);
    e.c += dis*sign*sqrt(e.a*e.a + e.b*e.b);
    return e;
}

bool hpt(double a1, double b1, double c1, double a2, double b2, double c2, double &X, double &Y){
    double d=a1*b2-a2*b1;
    if(fabs(d)<1e-9) return 0;
    double dx=b1*c2-b2*c1;
    double dy=c1*a2-c2*a1;
    X=dx/d; Y=dy/d;
    return 1;   
}

bool intersec(edge e1, edge e2, double &X, double &Y){
    return hpt(e1.a, e1.b, e1.c, e2.a, e2.b, e2.c, X, Y);
}

double dis(double x, double y, edge e){    
    return (fabs(e.a*x + e.b*y + e.c) / sqrt(e.a*e.a + e.b*e.b)) - e.t/2;
}

bool check(double R){
    double X, Y;
    for(int i=1; i<cnt; ++i) for(int j=i+1; j<=cnt; ++j) 
        for(int f1=0; f1<2; ++f1) for(int f2=0; f2<2; ++f2){
            edge e1 = move(e[i],R,f1);
            edge e2 = move(e[j],R,f2);
            if(intersec(e1,e2,X,Y)){
                if(X<=0 || Y<=0 || X>=W || Y>=H) continue;
                bool ok=1;
                for(int k=1; k<=cnt; ++k){
                    if(dis(X,Y,e[k]) + 1e-9 < R){
                        ok=0;
                        break;   
                    }
                }
                if(ok) return 1;
            }
        }
    return 0;
}


int main(){
    while(scanf("%d%d%d%d",&W,&H,&n,&RR),W>0){
        cnt=0;
        e[++cnt] = edge(0,0,W,0,0);
        e[++cnt] = edge(0,0,0,H,0);
        e[++cnt] = edge(0,H,W,H,0);
        e[++cnt] = edge(W,0,W,H,0);
        int x1,y1,x2,y2,t;
        for(int i=0; i<n; ++i){
            scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&t);
            e[++cnt] = edge(x1,y1,x2,y2,t*2);
        }
        double l=0, r=max(W,H), mid;
        bool found = 0;
        while(r-l>1e-12){
            mid=(l+r)/2;
            if(check(mid)) l=mid, found = 1;
            else r=mid;                        
        }
        double R = (l+r)/2;
        if(!found) R=0;
        if(RR-1e-5<=R) printf("Yes"); else printf("No");
        puts("");
    }
    return 0;  
}
accuracy: 1
time_ms: 190
memory_kb: 3484
final_rank: 12

code_snippet: // AOJ #2179
// Safe Area 2025.2.10

#include <bits/stdc++.h>
using namespace std;
 
struct Beam {
    double A, B, C;
    double L;
    double d;
};
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    while(true){
        int W, H, N, R;
        cin >> W >> H >> N >> R;
        if(W==0) break;
 
        vector<Beam> beams;
        beams.reserve(N);
 
        for(int i = 0; i < N; i++){
            int x1, y1, x2, y2, t;
            cin >> x1 >> y1 >> x2 >> y2 >> t;
            Beam b;
            b.A = double(y1 - y2);
            b.B = double(x2 - x1);
            b.C = double(x1)*y2 - double(x2)*y1;
            b.L = sqrt(b.A * b.A + b.B * b.B);
            b.d = (t + R) * b.L;
            beams.push_back(b);
        }
 
        double lo_x = R, hi_x = W - R;
        double lo_y = R, hi_y = H - R;
 
        if(N == 0){
            cout << "Yes" << endl;
            continue;
        }
 
        auto f = [&](double x, double y) -> double {
            double m = 1e12;
            for (int i = 0; i < N; i++){
                double val = fabs(beams[i].A * x + beams[i].B * y + beams[i].C) - beams[i].d;
                if(val < m) m = val;
            }
            return m;
        };
 
        double bestOverall = -1e12;
 
        mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());
        uniform_real_distribution<double> distX(lo_x, hi_x);
        uniform_real_distribution<double> distY(lo_y, hi_y);
 
        int numRestarts = 200;
        for (int start = 0; start < numRestarts; start++){
            double cur_x = distX(rng);
            double cur_y = distY(rng);
            double cur_val = f(cur_x, cur_y);
 
            double step = max(hi_x - lo_x, hi_y - lo_y);
 
            while(step > 1e-3){
                bool improved = false;
                for (int dx = -1; dx <= 1; dx++){
                    for (int dy = -1; dy <= 1; dy++){
                        double nx = cur_x + dx * step;
                        double ny = cur_y + dy * step;
                        nx = max(lo_x, min(nx, hi_x));
                        ny = max(lo_y, min(ny, hi_y));
                        double nval = f(nx, ny);
                        if(nval > cur_val){
                            cur_val = nval;
                            cur_x = nx;
                            cur_y = ny;
                            improved = true;
                        }
                    }
                }
                if(!improved) step *= 0.5;
            }
            bestOverall = max(bestOverall, cur_val);
        }
        if(bestOverall > 1e-9) cout << "Yes" << endl;
        else                   cout <<  "No" << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3468
final_rank: 9

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)

#define all(c) std::begin(c), std::end(c)

#ifdef LOCAL
#define debug(...) debug_impl(#__VA_ARGS__, __VA_ARGS__)
template <class T, class ...Args> void debug_impl(string s, T&& f, Args &&...args) {
    cerr << "(" << s << "): " << "(" << forward<T>(f);
    ((cerr << ", " << forward<Args>(args)), ..., (cerr << ")\n"));
}
#else
#define debug(...) void(0)
#endif

template <class T> bool chmax(T& a, const T& b) { return b > a ? (a = b, true) : false; }
template <class T> bool chmin(T& a, const T& b) { return b < a ? (a = b, true) : false; }


template <class T> istream& operator>>(istream& in, vector<T>& v) {
    for (auto& e : v) in >> e;
    return in;
}
template <class ...Args> void read(Args&... args) {
    (cin >> ... >> args);
}

template <class T> ostream& operator<<(ostream& out, const vector<T>& v) {
    int n = v.size();
    rep(i, n) {
        out << v[i];
        if (i + 1 != n) out << ' ';
    }
    return out;
}

template <class T, class ...Tails> void print(T&& h, Tails &&... tails) {
    cout << h, ((cout << ' ' << forward<Tails>(tails)), ..., (cout << '\n'));
}

using ld = long double;
using point = complex<ld>;

constexpr ld eps = 1e-10;

ld dot(point const& a, point const& b) {
    return real(conj(a) * b);
}

ld cross(point const& a, point const& b) {
    return imag(conj(a) * b);
}

int ccw(point a, point b, point c) {
    b -= a; c -= a;
    if (cross(b, c) > eps) return 1;
    if (cross(b, c) < -eps) return -1;
    if (dot(b, c) < 0) return 2;
    if (norm(b) < norm(c)) return -2;
    return 0;
}

struct line {
    ld a, b, c;
    line() = default;
    line(ld a, ld b, ld c) : a(a), b(b), c(c) {}

    point unit_housen() {
        point p{ a, b };
        return p / abs(p);
    }

    line translate(point t) {
        return line{ a, b, c - a * t.real() - b * t.imag() };
    }

    ld distance(point t) {
        return abs(a * t.real() + b * t.imag() + c) / sqrt(a * a + b * b);
    }
};

point is_ll(line s, line t) {
    ld a0 = s.a, b0 = s.b, c0 = s.c;
    ld a1 = t.a, b1 = t.b, c1 = t.c;

    a0 *= t.a, b0 *= t.a, c0 *= t.a;
    a1 *= s.a, b1 *= s.a, c1 *= s.a;

    assert(abs(b0 - b1) > eps);

    ld x;
    ld y = -(c0 - c1) / (b0 - b1);
    if (abs(s.a) > eps) {
        x = -(s.b * y + s.c) / s.a;
    } else {
        x = -(t.b * y + t.c) / t.a;
    }
    return { x, y };
}

int main() {
    while (true) {
        int w, h, n, r;
        read(w, h, n, r);

        if (w == 0 and h == 0 and n == 0 and r == 0) break;

        vector<pair<line, ld>> lines(n);
        rep(i, n) {
            int x0, y0, x1, y1, t;
            read(x0, y0, x1, y1, t);

            ld a = +(y1 - y0);
            ld b = -(x1 - x0);
            ld c = x1 * y0 - x0 * y1;
            lines[i] = { line{ a, b, c }, t };

            // debug(a, b, c);
        }
        lines.emplace_back(line{ 1, 0, 0 }, 0);
        lines.emplace_back(line{ 1, 0, ld(-w) }, 0);
        lines.emplace_back(line{ 0, 1, 0 }, 0);
        lines.emplace_back(line{ 0, 1, ld(-h) }, 0);

        vector<point> candidates;

        rep(i, n + 4) rep(j, i) {
            point pi = lines[i].first.unit_housen();
            point pj = lines[j].first.unit_housen();
            ld ti = lines[i].second;
            ld tj = lines[j].second;

            for (ld si : { -1, +1 }) for (ld sj : { -1, +1 }) {

                line li = lines[i].first.translate(si * pi * (ti + r));
                line lj = lines[j].first.translate(sj * pj * (tj + r));

                assert(abs(abs(si * pi * (ti + r)) - (ti + r)) < eps);
                assert(abs(abs(sj * pj * (tj + r)) - (tj + r)) < eps);

                if (abs(cross(li.unit_housen(), lj.unit_housen())) < eps) {
                    continue;
                }

                point ctr = is_ll(li, lj);

                assert(abs(li.a * ctr.real() + li.b * ctr.imag() + li.c) < eps);
                assert(abs(lj.a * ctr.real() + lj.b * ctr.imag() + lj.c) < eps);

                candidates.push_back(ctr);
            }
        }

        bool yes = false;

        for (point ctr : candidates) {
            if (ctr.real() < r or ctr.real() > w - r) continue;
            if (ctr.imag() < r or ctr.imag() > h - r) continue;

            bool ok = true;
            rep(i, n) {
                ld t = lines[i].second;
                point p = lines[i].first.unit_housen();
                line l1 = lines[i].first.translate(-p * t);
                line l2 = lines[i].first.translate(+p * t);

                ld d1 = l1.distance(ctr);
                ld d2 = l2.distance(ctr);

                if (abs((d1 + d2) - 2 * t) < eps or eps < r - min(d1, d2)) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                yes = true;
                break;
            }
        }
        print(yes ? "Yes" : "No");
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4768
final_rank: 17

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
const int mod = 1e9 + 7;
//const int mod = 998244353;

namespace geometry {
    // Point : 複素数型を位置ベクトルとして扱う
    // 実軸(real)をx軸、挙軸(imag)をy軸として見る
    using D = long double;
    using Point = complex<D>;
    const D EPS = 1e-7;
    const D PI = acosl(-1);

    inline bool equal(const D &a, const D &b) { return fabs(a - b) < EPS; }

    // 単位ベクトル(unit vector)を求める
    Point unitVector(const Point &a) { return a / abs(a); }

    // 法線ベクトル(normal vector)を求める
    // 90度回転した単位ベクトルをかける
    // -90度がよければPoint(0, -1)をかける
    Point normalVector(const Point &a) { return a * Point(0, 1); }

    // 内積(dot product) : a・b = |a||b|cosΘ
    D dot(const Point &a, const Point &b) {
        return (a.real() * b.real() + a.imag() * b.imag());
    }

    // 外積(cross product) : a×b = |a||b|sinΘ
    D cross(const Point &a, const Point &b) {
        return (a.real() * b.imag() - a.imag() * b.real());
    }

    // 点pを反時計回りにtheta度回転
    // thetaはラジアン！！！
    Point rotate(const Point &p, const D &theta) {
        return Point(cos(theta) * p.real() - sin(theta) * p.imag(),
                     sin(theta) * p.real() + cos(theta) * p.imag());
    }

    // ラジアン->度
    D radianToDegree(const D &radian) { return radian * 180.0 / PI; }

    // 度->ラジアン
    D degreeToRadian(const D &degree) { return degree * PI / 180.0; }

    // 点の回転方向
    // 点a, b, cの位置関係について(aが基準点)
    int ccw(const Point &a, Point b, Point c) {
        b -= a, c -= a;
        // 点a, b, c が
        // 反時計回りの時、
        if(cross(b, c) > EPS) return 1;
        // 時計回りの時、
        if(cross(b, c) < -EPS) return -1;
        // c, a, bがこの順番で同一直線上にある時、
        if(dot(b, c) < 0) return 2;
        // a, b, cがこの順番で同一直線上にある場合、
        if(norm(b) < norm(c)) return -2;
        // cが線分ab上にある場合、
        return 0;
    }

    // Line : 直線を表す構造体
    // b - a で直線・線分を表せる
    struct Line {
        Point a, b;
        Line() = default;
        Line(Point a, Point b) : a(a), b(b) {}
        // Ax+By=C
        Line(D A, D B, D C) {
            if(equal(A, 0)) {
                a = Point(0, C / B), b = Point(1, C / B);
            } else if(equal(B, 0)) {
                b = Point(C / A, 0), b = Point(C / A, 1);
            } else {
                a = Point(0, C / B), b = Point(C / A, 0);
            }
        }
    };

    // Segment : 線分を表す構造体
    // Lineと同じ
    struct Segment : Line {
        Segment() = default;

        Segment(Point a, Point b) : Line(a, b) {}
    };

    // Circle : 円を表す構造体
    // pが中心の位置ベクトル、rは半径
    struct Circle {
        Point p;
        D r;

        Circle() = default;

        Circle(Point p, D r) : p(p), r(r) {}
    };

    // 2直線の直交判定 : a⊥b <=> dot(a, b) = 0
    bool isOrthogonal(const Line &a, const Line &b) {
        return equal(dot(a.b - a.a, b.b - b.a), 0);
    }
    // 2直線の平行判定 : a//b <=> cross(a, b) = 0
    bool isParallel(const Line &a, const Line &b) {
        return equal(cross(a.b - a.a, b.b - b.a), 0);
    }

    // 点cが直線ab上にあるか
    bool isPointOnLine(const Point &a, const Point &b, const Point &c) {
        return isParallel(Line(a, b), Line(a, c));
    }

    // 点cが"線分"ab上にあるか
    bool isPointOnSegment(const Point &a, const Point &b, const Point &c) {
        // |a-c| + |c-b| <= |a-b| なら線分上
        return (abs(a - c) + abs(c - b) < abs(a - b) + EPS);
    }

    // 直線lと点pの距離を求める
    D distanceBetweenLineAndPoint(const Line &l, const Point &p) {
        return abs(cross(l.b - l.a, p - l.a)) / abs(l.b - l.a);
    }

    // 線分lと点pの距離を求める
    // 定義：点pから「線分lのどこか」への最短距離
    D distanceBetweenSegmentAndPoint(const Segment &l, const Point &p) {
        if(dot(l.b - l.a, p - l.a) < EPS) return abs(p - l.a);
        if(dot(l.a - l.b, p - l.b) < EPS) return abs(p - l.b);
        return abs(cross(l.b - l.a, p - l.a)) / abs(l.b - l.a);
    }

    // 直線s, tの交点の計算
    Point crossPoint(const Line &s, const Line &t) {
        D d1 = cross(s.b - s.a, t.b - t.a);
        D d2 = cross(s.b - s.a, s.b - t.a);
        if(equal(abs(d1), 0) && equal(abs(d2), 0)) return t.a;
        return t.a + (t.b - t.a) * (d2 / d1);
    }

    // 線分s, tの交点の計算
    Point crossPoint(const Segment &s, const Segment &t) {
        return crossPoint(Line(s), Line(t));
    }

    // 線分sと線分tが交差しているかどうか
    // bound:線分の端点を含むか
    bool isIntersect(const Segment &s, const Segment &t, bool bound) {
        return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) < bound &&
               ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) < bound;
    }

    // 線分sとtの距離
    D distanceBetweenSegments(const Segment &s, const Segment &t) {
        if(isIntersect(s, t, 1)) return (D)(0);
        D ans = distanceBetweenSegmentAndPoint(s, t.a);
        chmin(ans, distanceBetweenSegmentAndPoint(s, t.b));
        chmin(ans, distanceBetweenSegmentAndPoint(t, s.a));
        chmin(ans, distanceBetweenSegmentAndPoint(t, s.b));
        return ans;
    }

    // 射影(projection)
    // 直線(線分)lに点pから引いた垂線の足を求める
    Point projection(const Line &l, const Point &p) {
        D t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
        return l.a + (l.a - l.b) * t;
    }

    Point projection(const Segment &l, const Point &p) {
        D t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
        return l.a + (l.a - l.b) * t;
    }

    // 反射(reflection)
    // 直線lを対称軸として点pと線対称の位置にある点を求める
    Point reflection(const Line &l, const Point &p) {
        return p + (projection(l, p) - p) * (D)2.0;
    }

    // 2つの円の交差判定
    // 返り値は共通接線の数
    int isIntersect(const Circle &c1, const Circle &c2) {
        D d = abs(c1.p - c2.p);
        // 2つの円が離れている場合
        if(d > c1.r + c2.r + EPS) return 4;
        // 外接している場合
        if(equal(d, c1.r + c2.r)) return 3;
        // 内接している場合
        if(equal(d, abs(c1.r - c2.r))) return 1;
        // 内包している場合
        if(d < abs(c1.r - c2.r) - EPS) return 0;
        return 2;
    }

    // 2つの円の交点
    vector<Point> crossPoint(const Circle &c1, const Circle &c2) {
        vector<Point> res;
        int mode = isIntersect(c1, c2);
        // 2つの中心の距離
        D d = abs(c1.p - c2.p);
        // 2円が離れている場合
        if(mode == 4) return res;
        // 1つの円がもう1つの円に内包されている場合
        if(mode == 0) return res;
        // 2円が外接する場合
        if(mode == 3) {
            D t = c1.r / (c1.r + c2.r);
            res.emplace_back(c1.p + (c2.p - c1.p) * t);
            return res;
        }
        // 内接している場合
        if(mode == 1) {
            if(c2.r < c1.r - EPS) {
                res.emplace_back(c1.p + (c2.p - c1.p) * (c1.r / d));
            } else {
                res.emplace_back(c2.p + (c1.p - c2.p) * (c2.r / d));
            }
            return res;
        }
        // 2円が重なる場合
        D rc1 = (c1.r * c1.r + d * d - c2.r * c2.r) / (2 * d);
        D rs1 = sqrt(c1.r * c1.r - rc1 * rc1);
        if(c1.r - abs(rc1) < EPS) rs1 = 0;
        Point e12 = (c2.p - c1.p) / abs(c2.p - c1.p);
        res.emplace_back(c1.p + rc1 * e12 + rs1 * e12 * Point(0, 1));
        res.emplace_back(c1.p + rc1 * e12 + rs1 * e12 * Point(0, -1));
        return res;
    }

    // 点pが円cの内部(円周上も含む)に入っているかどうか
    bool isInCircle(const Circle &c, const Point &p) {
        D d = abs(c.p - p);
        return (equal(d, c.r) || d < c.r - EPS);
    }

    // 円cと直線lの交点
    vector<Point> crossPoint(const Circle &c, const Line &l) {
        vector<Point> res;
        D d = distanceBetweenLineAndPoint(l, c.p);
        // 交点を持たない
        if(d > c.r + EPS) return res;
        // 接する
        Point h = projection(l, c.p);
        if(equal(d, c.r)) {
            res.emplace_back(h);
            return res;
        }
        Point e = unitVector(l.b - l.a);
        D ph = sqrt(c.r * c.r - d * d);
        res.emplace_back(h - e * ph);
        res.emplace_back(h + e * ph);
        return res;
    }

    // 点pを通る円cの接線
    // 2本あるので、接点のみを返す
    vector<Point> tangentToCircle(const Point &p, const Circle &c) {
        return crossPoint(c, Circle(p, sqrt(norm(c.p - p) - c.r * c.r)));
    }

    // 円の共通接線
    vector<Line> tangent(const Circle &a, const Circle &b) {
        vector<Line> ret;
        // 2円の中心間の距離
        D g = abs(a.p - b.p);
        // 円が内包されている場合
        if(equal(g, 0)) return ret;
        Point u = unitVector(b.p - a.p);
        Point v = rotate(u, PI / 2);
        for(int s : {-1, 1}) {
            D h = (a.r + b.r * s) / g;
            if(equal(h * h, 1)) {
                ret.emplace_back(a.p + (h > 0 ? u : -u) * a.r,
                                 a.p + (h > 0 ? u : -u) * a.r + v);

            } else if(1 - h * h > 0) {
                Point U = u * h, V = v * sqrt(1 - h * h);
                ret.emplace_back(a.p + (U + V) * a.r,
                                 b.p - (U + V) * (b.r * s));
                ret.emplace_back(a.p + (U - V) * a.r,
                                 b.p - (U - V) * (b.r * s));
            }
        }
        return ret;
    }

    // 多角形の面積を求める
    D PolygonArea(const vector<Point> &p) {
        D res = 0;
        int n = p.size();
        for(int i = 0; i < n - 1; i++) res += cross(p[i], p[i + 1]);
        res += cross(p[n - 1], p[0]);
        return res * 0.5;
    }

    // 凸多角形かどうか
    bool isConvex(const vector<Point> &p) {
        int n = p.size();
        int now, pre, nxt;
        for(int i = 0; i < n; i++) {
            pre = (i - 1 + n) % n;
            nxt = (i + 1) % n;
            now = i;
            if(ccw(p[pre], p[now], p[nxt]) == -1) return false;
        }
        return true;
    }

    // 凸包 O(NlogN)
    vector<Point> ConvexHull(vector<Point> &p) {
        int n = (int)p.size(), k = 0;
        sort(all(p), [](const Point &a, const Point &b) {
            return (real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b));
        });
        vector<Point> ch(2 * n);
        // 一直線上の3点を含める -> (< -EPS)
        // 含め無い -> (< EPS)
        for(int i = 0; i < n; ch[k++] = p[i++]) { // lower
            while(k >= 2 &&
                  cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < EPS)
                --k;
        }
        for(int i = n - 2, t = k + 1; i >= 0; ch[k++] = p[i--]) { // upper
            while(k >= t &&
                  cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < EPS)
                --k;
        }
        ch.resize(k - 1);
        return ch;
    }

    // 多角形gに点pが含まれているか?
    // 含まれる:2, 辺上にある:1, 含まれない:0
    int isContained(const vector<Point> &g, const Point &p) {
        bool in = false;
        int n = (int)g.size();
        for(int i = 0; i < n; i++) {
            Point a = g[i] - p, b = g[(i + 1) % n] - p;
            if(imag(a) > imag(b)) swap(a, b);
            if(imag(a) <= EPS && EPS < imag(b) && cross(a, b) < -EPS) in = !in;
            if(cross(a, b) == 0 && dot(a, b) <= 0) return 1;
        }
        return (in ? 2 : 0);
    }

    vector<Point> convex_cut(const vector<Point> &g, Line l){
        vector<Point> ret;
        for(int i=0; i<g.size(); i++){
            Point now = g[i], nxt = g[(i+1)%g.size()];
            if(ccw(l.a,l.b,now) != -1) ret.push_back(now);
            if(ccw(l.a,l.b,now) * ccw(l.a,l.b,nxt) < 0){
                ret.push_back(crossPoint(Line(now,nxt),l));
            }
        }
        return ret;
    }

    bool equal (const Point &a, const Point &b) {
        return equal(a.real(),b.real()) && equal(a.imag(),b.imag());
    }

    D circlesIntersectArea(Circle &a, Circle &b){
        double d = abs(a.p - b.p);
        if(d >= a.r + b.r - EPS) return 0; //2円が離れている
        auto R = minmax(a.r,b.r);
        if(d <= R.second - R.first + EPS) return R.first*R.first*pi; //円が円を内包する
        D theta1 = acos((d*d + a.r*a.r - b.r*b.r)/(2*a.r*d));
        D theta2 = acos((d*d + b.r*b.r - a.r*a.r)/(2*b.r*d));
        D ret = a.r*a.r*(theta1-cos(theta1)*sin(theta1)) + b.r*b.r*(theta2-cos(theta2)*sin(theta2));
        return ret;
    }
} // namespace geometry

using namespace geometry;


int main(){
    while(1){
        int w,h,n,r; cin >> w >> h >> n >> r;
        if(!w) break;
        vector<Line> L(n*2);
        rep(i,n){
            int a,b,c,d,t; cin >> a >> b >> c >> d >> t;
            Point p1 = Point(a,b), p2 = Point(c,d);
            Point h = unitVector(Point(b-d,c-a)); 
            h *= (r+t);
            L[i] = Line(p1+h,p2+h);
            L[i+n] = Line(p1-h,p2-h);
            assert(isParallel(L[i],L[i+n]));
        }
        L.emplace_back(Point(r,h-r),Point(w-r,h-r));
        L.emplace_back(Point(r,r),Point(w-r,r));
        vector<Point> points;
        rep(i,n*2) rep(j,n*2+2){
            if(!isParallel(L[i],L[j])){
                points.emplace_back(crossPoint(L[i],L[j]));
            }
        }
        sort(all(points),[](Point a, Point b){
            if(equal(real(a),real(b))) return imag(a) < imag(b);
            return real(a) < real(b);
        });
        bool yes = false;
        for(auto p : points){
            if(real(p) + eps < r || real(p) - eps > w-r) continue;
            if(imag(p) + eps < r || imag(p) - eps > h-r) continue;
            Line l(Point(real(p),0), Point(real(p),h));
            bool f = true;
            rep(i,n){
                Point p1 = crossPoint(l,L[i]);
                Point p2 = crossPoint(l,L[i+n]);
                D y1 = imag(p1), y2 = imag(p2);
                if(y1 > y2) swap(y1,y2);
                if(y1 + eps < imag(p) && imag(p) < y2 - eps){
                    f = false;
                    break;
                }
            }
            if(f) yes = true;
        }
        if(yes) cout << "Yes\n";
        else cout << "No\n";
    }
}
accuracy: 1
time_ms: 20
memory_kb: 6496
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=155;
const ll INF=1LL<<60;
//幾何ライブラリ

const double eps=1e-8;
const double pi=acos((double)-1.0L);
#define equals(a,b) (fabs((a)-(b))<eps)

double torad(double deg) {return (double)(deg)*pi/180.0;}
double todeg(double ang) {return ang*180.0/pi;}

class Point{
public:
    double x,y;
    
    Point(double x=0,double y=0):x(x),y(y){}
    
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double a){return Point(a*x,a*y);}
    Point operator / (double a){return Point(x/a,y/a);}
    
    double abs(){return sqrt(norm());}
    double norm(){return x*x+y*y;}
    
    bool operator < (const Point &p)const{
        return x+eps<p.x||(equals(x,p.x)&&y+eps<p.y);
    }
    
    bool operator == (const Point &p)const{
        return fabs(x-p.x)<eps/100000&&fabs(y-p.y)<eps/100000;
    }
};

typedef Point Vector;

double norm(Vector a){
    return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

double dot(Vector a,Vector b){
    return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

struct Segment{
    Point p1,p2;
};

bool isOrthogonal(Vector a,Vector b){
    return equals(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
    return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Segment s1,Segment s2){
    return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

bool isParallel(Vector a,Vector b){
    return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
    return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
    return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

Point project(Segment s,Point p){
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/norm(base);
    return s.p1+base*r;
}

Point reflect(Segment s,Point p){
    return p+(project(s,p)-p)*2.0;
}

Point turn(Point p,Point c,double pi){
    double q=atan2(p.y-c.y,p.x-c.x);
    q+=pi;
    p=c+Point{cos(q)*abs(p-c),sin(q)*abs(p-c)};
    
    return p;
}
//pをcを中心としてpi回転させる(1周で2π)
//p=cのときnan

//p0,p1,p2の順に見たときどうなるか？

static const int counter_clockwise=1;
static const int clockwise=-1;
static const int online_back=2;
static const int online_front=-2;
static const int on_segment=0;

int ccw(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    
    if(cross(a,b)>eps) return counter_clockwise;
    if(cross(a,b)<-eps) return clockwise;
    if(dot(a,b)<-eps) return online_back;
    if(a.norm()<b.norm()) return online_front;
    
    return on_segment;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
    return(ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

bool overlap(Segment s1,Segment s2){
    int a=ccw(s1.p1,s1.p2,s2.p1),b=ccw(s1.p1,s1.p2,s2.p2);
    if(a&1||b&1) return 0;
    if(a==2){
        if(b==-2||(b==0&&!(s2.p2==s1.p1))) return 1;
        else return 0;
    }
    if(a==-2){
        if(b==2||(b==0&&!(s2.p2==s1.p2))) return 1;
        else return 0;
    }
    if(a==0){
        if(s1.p1==s2.p1){
            if(b!=2) return 1;
            else return 0;
        }
        else if(s1.p2==s2.p1){
            if(b!=-2) return 1;
            else return 0;
        }
        else return 1;
    }
    return 0;
}
//s1とs2の共通の線分(長さ0より大きい)があるかどうか

typedef Segment Line;

double getDistance(Point a,Point b){
    return abs(a-b);
}

double getDistanceLP(Line l,Point p){
    return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

double getDistanceSP(Segment s,Point p){
    if(dot(s.p2-s.p1,p-s.p1)<0.0) return abs(p-s.p1);
    if(dot(s.p1-s.p2,p-s.p2)<0.0) return abs(p-s.p2);
    return getDistanceLP(s,p);
}

double getDistance(Segment s1,Segment s2){
    if(intersect(s1,s2)) return 0.0;
    return min({getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2),getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)});
}

Point getCrossPointS(Segment s1,Segment s2){
    //if(ccw(s1.p1,s1.p2,s2.p1)==0&&ccw(s1.p1,s1.p2,s2.p2)==0) return s1.p1;
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}//同じ時壊れます

Point getCrossPointL(Line l1,Line l2){
    //if(ccw(s1.p1,s1.p2,s2.p1)==0&&ccw(s1.p1,s1.p2,s2.p2)==0) return s1.p1;
    
    Vector v1=l1.p2-l1.p1,v2=l2.p2-l2.p1;
    
    return l1.p1+v1*cross(v2,l2.p1-l1.p1)/cross(v2,v1);
}

Segment ParallelSegment(Segment s,double d){
    Vector v={-(s.p2-s.p1).y,(s.p2-s.p1).x};
    v=v/abs(v);
    
    s.p1=s.p1+v*d;
    s.p2=s.p2+v*d;
    
    return s;
}

Point naisin(Point p1,Point p2,Point p3){
    if(p1==p2&&p2==p3&&p3==p1) return p1;
    
    return (p1*abs(p2-p3)+p2*abs(p1-p3)+p3*abs(p1-p2))/(abs(p2-p3)+abs(p1-p3)+abs(p1-p2));
}

Point naisin(Line l1,Line l2,Line l3){
    //平行でない前提
    
    Point p1=getCrossPointL(l1,l2),p2=getCrossPointL(l1,l3),p3=getCrossPointL(l2,l3);
    return naisin(p1,p2,p3);
}

//ネットの適当を書いたのであってるか全く知りません→あってそう

class Circle{
public:
    Point c;
    double r;
    Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

Point CircleCenter(Point a,Point b,Point c){
    Point u=a-b,v=a-c;
    double m1=(norm(a)-norm(b))/2.0,m2=(norm(a)-norm(c))/2.0;
    
    Point res;
    if(cross(u,v)==0.0){
        res.x=1e9;
        res.y=1e9;
        
        return res;
    }
    res.x=(m1*v.y-m2*u.y)/cross(u,v);
    res.y=(m1*v.x-m2*u.x)/cross(v,u);
    
    return res;
}
//3点を通る円の中心を返す

//交わる 0
// c1がc2のinside 1
// c1がc2のoutside 2
// 交わらない 3

int not_intersect(Circle c1,Circle c2){
    double d=getDistance(c1.c,c2.c);
    double r1=c1.r,r2=c2.r;
    if(r1<r2){
        if(d<(r2-r1)) return 1;
    }
    if(r1>r2){
        if(d<(r1-r2)) return 2;
    }
    if(d<=r1+r2) return 0;
    else return 3;
}

pair<Point,Point> segCrossPpoints(Circle c,Line l){
    //assert(intersect(c,l));
    Vector pr=project(l,c.c);
    Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);
    double base=sqrt(c.r*c.r-norm(pr-c.c));
    return make_pair(pr+e*base,pr-e*base);
}

double arg(Vector p){return atan2(p.y,p.x);}
Vector polar(double a,double r){return Point(cos(r)*a,sin(r)*a);}

//inside(outside)

pair<Point,Point> getCrossPoints(Circle c1,Circle c2){
    //assert(intersect(c1,c2));
    double d=abs(c1.c-c2.c);
    double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
    double t=arg(c2.c-c1.c);
    return make_pair(c1.c+polar(c1.r,t+a),c1.c+polar(c1.r,t-a));
}

vector<Line> Commontangent(Circle c1,Circle c2){
    vector<Line> res;
    Point p=c2.c-c1.c;
    
    if(abs(p)>=(c1.r+c2.r)){
        Point a,b;
        a.x=c1.r*(p.x*(c1.r+c2.r)+p.y*sqrt(norm(p)-(c1.r+c2.r)*(c1.r+c2.r)))/norm(p);
        a.y=c1.r*(p.y*(c1.r+c2.r)-p.x*sqrt(norm(p)-(c1.r+c2.r)*(c1.r+c2.r)))/norm(p);
        
        b.x=c1.r*(p.x*(c1.r+c2.r)-p.y*sqrt(norm(p)-(c1.r+c2.r)*(c1.r+c2.r)))/norm(p);
        b.y=c1.r*(p.y*(c1.r+c2.r)+p.x*sqrt(norm(p)-(c1.r+c2.r)*(c1.r+c2.r)))/norm(p);
        
        res.push_back(Line{a+c1.c,a+c1.c+Point{-a.y,a.x}});
        if(!(a==b)){
            res.push_back(Line{b+c1.c,b+c1.c+Point{-b.y,b.x}});
        }
    }
    
    if(abs(p)>=abs(c1.r-c2.r)){
        Point a,b;
        a.x=c1.r*(p.x*(c1.r-c2.r)+p.y*sqrt(norm(p)-(c1.r-c2.r)*(c1.r-c2.r)))/norm(p);
        a.y=c1.r*(p.y*(c1.r-c2.r)-p.x*sqrt(norm(p)-(c1.r-c2.r)*(c1.r-c2.r)))/norm(p);
        
        b.x=c1.r*(p.x*(c1.r-c2.r)-p.y*sqrt(norm(p)-(c1.r-c2.r)*(c1.r-c2.r)))/norm(p);
        b.y=c1.r*(p.y*(c1.r-c2.r)+p.x*sqrt(norm(p)-(c1.r-c2.r)*(c1.r-c2.r)))/norm(p);
        
        res.push_back(Line{a+c1.c,a+c1.c+Point{-a.y,a.x}});
        if(!(a==b)){
            res.push_back(Line{b+c1.c,b+c1.c+Point{-b.y,b.x}});
        }
    }
    
    return res;
}

typedef vector<Point> Polygon;

/*
 IN 2
 ON 1
 OUT 0
 */

int contains(Polygon g,Point p){
    int n=int(g.size());
    bool x=false;
    for(int i=0;i<n;i++){
        Point a=g[i]-p,b=g[(i+1)%n]-p;
        if(a.y>b.y) swap(a,b);
        if(a.y<eps&&0<b.y&&cross(a,b)<0) x=!x;
        if(abs(cross(a,b))<eps&&dot(a,b)<eps) return 1;
    }
    return (x?2:0);
}

Polygon andrewScan(Polygon s,bool ok){
    Polygon u,l;
    sort(all(s));
    
    if(int(s.size())<3) return s;
    int n=int(s.size());
    
    u.push_back(s[0]);
    u.push_back(s[1]);
    
    l.push_back(s[n-1]);
    l.push_back(s[n-2]);
    
    if(ok){
        for(int i=2;i<n;i++){
            for(int j=int(u.size());j>=2&&ccw(u[j-2],u[j-1],s[i])==counter_clockwise;j--){
                u.pop_back();
            }
            u.push_back(s[i]);
        }
        
        for(int i=int(s.size())-3;i>=0;i--){
            for(int j=int(l.size());j>=2&&ccw(l[j-2],l[j-1],s[i])==counter_clockwise;j--){
                l.pop_back();
            }
            l.push_back(s[i]);
        }
    }
    
    if(!ok){
        for(int i=2;i<n;i++){
            for(int j=int(u.size());j>=2&&ccw(u[j-2],u[j-1],s[i])!=clockwise;j--){
                u.pop_back();
            }
            u.push_back(s[i]);
        }
        
        for(int i=int(s.size())-3;i>=0;i--){
            for(int j=int(l.size());j>=2&&ccw(l[j-2],l[j-1],s[i])!=clockwise;j--){
                l.pop_back();
            }
            l.push_back(s[i]);
        }
    }
    
    reverse(all(l));
    
    for(int i=int(u.size())-2;i>=1;i--) l.push_back(u[i]);
    
    return l;
}//ok==1なら辺の上も含める

Polygon convex_cut(const Polygon& P, const Line& l) {
    Polygon Q;
    for(int i=0;i<si(P);i++){
        Point A=P[i],B=P[(i+1)%si(P)];
        if(ccw(l.p1,l.p2,A)!=-1)Q.push_back(A);
        if(ccw(l.p1,l.p2,A)*ccw(l.p1,l.p2,B)<0) Q.push_back(getCrossPointL(Line{A,B},l));
    }
    return Q;
}

double area(Point a,Point b,Point c){
    b=b-a;
    c=c-a;
    return abs(b.x*c.y-b.y*c.x)/2.0;
}

double area(Polygon &P){
    if(si(P)==0) return 0.0;
    double res=0;
    Point c={0.0,0.0};
    for(int i=0;i<si(P);i++){
        c=c+P[i];
    }
    c=c/si(P);
    
    for(int i=0;i<si(P);i++){
        res+=area(c,P[i],P[(i+1)%si(P)]);
    }
    
    return res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        double W,H,R;int N;cin>>W>>H>>N>>R;
        if(W==0) break;
        vector<Line> L;
        L.push_back({{R,0.0},{R,H}});
        L.push_back({{W-R,0.0},{W-R,H}});
        L.push_back({{0.0,R},{W,R}});
        L.push_back({{0.0,H-R},{W,H-R}});
        vector<Line> A(N);
        vector<double> t(N);
        for(int i=0;i<N;i++){
            cin>>A[i].p1.x>>A[i].p1.y>>A[i].p2.x>>A[i].p2.y>>t[i];
            L.push_back(ParallelSegment(A[i],t[i]+R));
            L.push_back(ParallelSegment(A[i],-t[i]-R));
        }
        bool ok=false;
        for(int i=0;i<si(L);i++){
            for(int j=i+1;j<si(L);j++){
                if(isParallel(L[i],L[j])) continue;
                Point p=getCrossPointL(L[i],L[j]);
                if(p.x<R||p.x>W-R||p.y<R||p.y>H-R) continue;
                bool f=true;
                for(int k=0;k<N;k++){
                    double d=getDistanceLP(A[k],p);
                    if(d<R+t[k]-eps) f=false;
                }
                if(f) ok=true;
            }
        }
        if(ok) cout<<"Yes\n";
        else cout<<"No\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3500
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
const double EPS = 0.00000001;
struct point{
  double x, y;
  point(){
  }
  point(double x, double y): x(x), y(y){
  }
  point operator +(point P){
    return point(x + P.x, y + P.y);
  }
  point operator -(point P){
    return point(x - P.x, y - P.y);
  }
  point operator *(double k){
    return point(x * k, y * k);
  }
  point operator /(double k){
    return point(x / k, y / k);
  }
};
double abs(point P){
  return sqrt(P.x * P.x + P.y * P.y);
}
point rotate90(point P){
  return point(P.y, -P.x);
}
double cross(point P, point Q){
  return P.x * Q.y - P.y * Q.x;
}
struct line{
  point A, B;
  line(){
  }
  line(point A, point B): A(A), B(B){
  }
};
point vec(line L){
  return L.B - L.A;
}
double point_line_distance(point P, line L){
  return abs(cross(L.A - P, vec(L))) / abs(vec(L));
}
bool is_parallel(line L1, line L2){
  return abs(cross(vec(L1), vec(L2))) <= EPS;
}
point line_intersection(line L1, line L2){
  return L1.A + vec(L1) * cross(L2.A - L1.A, vec(L2)) / cross(vec(L1), vec(L2));
}
int main(){
  while (true){
    int W, H, N, R;
    cin >> W >> H >> N >> R;
    if (W == 0 && H == 0 && N == 0 && R == 0){
      break;
    }
    vector<line> L(N);
    vector<double> t(N);
    for (int i = 0; i < N; i++){
      cin >> L[i].A.x >> L[i].A.y >> L[i].B.x >> L[i].B.y >> t[i];
    }
    vector<line> L2;
    L2.push_back(line(point(R, R), point(W - R, R)));
    L2.push_back(line(point(R, R), point(R, H - R)));
    L2.push_back(line(point(W - R, R), point(W - R, H - R)));
    L2.push_back(line(point(R, H - R), point(W -R, H - R)));
    for (int i = 0; i < N; i++){
      point P = vec(L[i]) / abs(vec(L[i])) * (R + t[i]);
      P = rotate90(P);
      L2.push_back(line(L[i].A + P, L[i].B + P));
      L2.push_back(line(L[i].A - P, L[i].B - P));
    }
    int cnt1 = L2.size();
    vector<point> C;
    for (int i = 0; i < cnt1; i++){
      for (int j = i + 1; j < cnt1; j++){
        if (!is_parallel(L2[i], L2[j])){
          C.push_back(line_intersection(L2[i], L2[j]));
        }
      }
    }
    int cnt2 = C.size();
    bool ok = false;
    for (int i = 0; i < cnt2; i++){
      if (R - EPS <= C[i].x && C[i].x <= W - R + EPS && R - EPS <= C[i].y && C[i].y <= H - R + EPS){
        bool ok2 = true;
        for (int j = 0; j < N; j++){
          double d = point_line_distance(C[i], L[j]);
          if (d < R + t[j] - EPS){
            ok2 = false;
          }
        }
        if (ok2){
          ok = true;
        }
      }
    }
    if (ok){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
accuracy: 1
time_ms: 30
memory_kb: 3596
final_rank: 11

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> 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<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

using R = long double; // Rにmint渡せるようにする
using P = complex<R>;
using L = pair<P,P>;
using G = vector<P>;
struct C {
    P c; R r;
    C() {}
    C(const P &a, const R &b) : c(a), r(b) {}
};
struct S : public L {
    S() {}
    S(const P &a, const P &b) : L(a,b) {}
};

const R EPS = 1e-8;
const R PI = atan(1)*4;

inline int sgn(const R& r) { return (r>EPS) - (r<-EPS); }
inline R dot(const P& a, const P& b) {
    return real(a)*real(b) + imag(a)*imag(b);
}
inline R det(const P& a, const P& b) {
    return real(a)*imag(b) - imag(a)*real(b);
}
inline P rotate(const P& p, const R& arg) {
    return P(cos(arg)*p.real()-sin(arg)*p.imag(),
             sin(arg)*p.real()+cos(arg)*p.imag());
}
inline P vec(const L& l) {return l.second - l.first;}
namespace std {
	bool operator < (const P& a, const P& b) {
		return sgn(real(a-b)) ? real(a-b) < 0 : sgn(imag(a-b)) < 0;
	}
	bool operator == (const P& a, const P& b) {
		return sgn(real(a-b)) == 0 && sgn(imag(a-b)) == 0;
	}
    bool cmp_y (const P& a, const P& b) {
        return sgn(imag(a-b)) ? imag(a-b) < 0 : sgn(real(a-b)) < 0;
    }
}

// P,L,Sについて入力
inline istream& operator>>(istream& is, P& p) {
    R x, y;
    is >> x >> y;
    p = P(x, y);
    return is;
}
inline istream& operator>>(istream& is, L& l) {
    P a, b;
    is >> a >> b;
    l = L(a, b);
    return is;
}
inline istream& operator>>(istream& is, S& s) {
    P a, b;
    is >> a >> b;
    s = S(a, b);
    return is;
}

// 線分abから見たcの位置
enum CCW{LEFT=1, RIGHT=2, BACK=4, FRONT=8, ON_SEG=16};
int ccw(P a, P b, P c) {
	P p = (c-a)/(b-a);
	if(sgn(imag(p)) > 0) return LEFT;
	if(sgn(imag(p)) < 0) return RIGHT;
	if(sgn(real(p)) < 0) return BACK;
	if(sgn(real(p)-1) > 0) return FRONT;
	return ON_SEG;
}

// 射影
P inline projection(const L &l, const P &p) {
    R t = dot(p-l.first, l.first-l.second) / norm(l.first-l.second);
    return l.first + t*(l.first-l.second);
}
template<bool strict=false> inline bool intersect(const L&l1, const L&l2) {
    if(strict) return sgn(det(vec(l1),vec(l2))) != 0;
    return sgn(det(vec(l1),vec(l2))) != 0 || l1 == l2;
}
inline P crosspoint(const L& l1, const L& l2) {
    R ratio = det(vec(l2), l2.first-l1.first)/det(vec(l2),vec(l1));
    return l1.first + vec(l1)*ratio;
}
R dist(const L& l, const P& p) {
    P q = projection(l, p);
    return abs(p-q);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(1) {
        ll w, h, n, r;
        cin >> w >> h >> n >> r;
        if(!w) break;
        vector<L> v(n);
        vector<P> nv(n);
        vector<ll> t(n);
        REP(i, n) {
            cin >> v[i] >> t[i];
            nv[i] = (v[i].second - v[i].first) * P(0, 1);
            nv[i] = nv[i] / abs(nv[i]);
            nv[i] *= (t[i]+r);
        }

        // レーザーの端と長方形の辺になる直線を全列挙
        vector<L> lines;
        REP(i, n) {
            lines.push_back({v[i].first+nv[i], v[i].second+nv[i]});
            lines.push_back({v[i].first-nv[i], v[i].second-nv[i]});
        }
        lines.push_back(L(P(r,r), P(w-r,r)));
        lines.push_back(L(P(w-r,r), P(w-r,h-r)));
        lines.push_back(L(P(w-r,h-r), P(r,h-r)));
        lines.push_back(L(P(r,h-r), P(r,r)));

        // cout << lines << endl;

        // 直線の間の円の位置を列挙
        vector<C> circle;
        REP(i, lines.size()) FOR(j, i+1, lines.size()) {
            if(!intersect<true>(lines[i], lines[j])) continue;
            P p = crosspoint(lines[i], lines[j]);
            if(0<=sgn(p.real()-r) && sgn(p.real()+r-w)<=0 && 0<=sgn(p.imag()-r) && sgn(p.imag()+r-h)<=0) {
                circle.push_back(C(p, r));
            }
        }

        // for(auto c: circle) cout << c.c << "," << c.r << " ";
        // cout << endl;

        // 円がレーザーに交差しないところがあるかの確認
        bool ok = false;
        for(auto c: circle) {
            // cout << "c=" << c.c << "," << c.r << endl;
            bool flag = true;
            REP(i, n) {
                // cout << v[i] << " " << dist(v[i], c.c) << endl;
                if(sgn(dist(v[i], c.c) - r - t[i]) < 0) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                ok = true;
                break;
            }
        }

        if(ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4348
final_rank: 16

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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)

const double EPS = 1e-8;
// 点
typedef complex<double> P;
namespace std {
  bool isnan(const P&p){
    return isnan(p.real()) or isnan(p.imag());
  }
}

// 外積
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
// 内積
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

// 直線
// 線分は端点を入れる
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

// 円
struct C {
  P p; double r;
  C(const P &p_, double r_) : p(p_), r(r_) { }
};

// 交差判定
// 直線同士
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
    abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}

// 直線の交点
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) return P(nan(""),nan("")); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

// 点の線への射影
P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}

// 直線と点の距離
double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}

// 直線lを垂線方向にdis移動
L slideL(L l, double dis){
  double deg = arg(l[1]-l[0]);
  P p = P(dis*sin(deg),-dis*cos(deg));
  l[0] += p;
  l[1] += p;
  return l;
}

signed main(){
  int n;
  double w,h,r;
  while(cin >> w >> h >> n >> r, n){
    // input
    vector<L> ls;
    vector<double> ts(n);
    rep(i,n){
      double a,b,c,d;
      cin >> a >> b >> c >> d;
      P x{a,b},y{c,d};
      ls.emplace_back(x,y);
      cin >> ts[i];
    }

    // 候補を列挙
    vector<P> can;
    // 四隅を追加
    can.push_back({r,r});
    can.push_back({r,h-r});
    can.push_back({w-r,r});
    can.push_back({w-r,h-r});
    // 2線に接する点を追加
    rep(i,n) FOR(j,i+1,n){
      // 交差しない
      if(not intersectLL(ls[i],ls[j])) continue;

      // 元の直線からr+t平行移動した直線l,rを用意
      // 交点が候補の候補となる
      L li = slideL(ls[i],-r-ts[i]), ri = slideL(ls[i],r+ts[i]);
      L lj = slideL(ls[j],-r-ts[j]), rj = slideL(ls[j],r+ts[j]);
      vector<P> tmpcan;
      tmpcan.push_back(crosspoint(li,lj));
      tmpcan.push_back(crosspoint(li,rj));
      tmpcan.push_back(crosspoint(ri,lj));
      tmpcan.push_back(crosspoint(ri,rj));

      // 枠の中にあるなら候補
      auto isin = [&](const P &p){
	return r < p.real()+EPS and p.real()-EPS < w-r and r < p.imag()+EPS and p.imag()-EPS < h-r;
      };
      rep(k,4){
	if((not isnan(tmpcan[k])) and isin(tmpcan[k]))
	  can.push_back(tmpcan[k]);
      }
    }

    // 各候補が全ての線からr+t以上離れているか
    bool f = false;
    rep(i,can.size()){
      bool g = true;
      rep(j,n){
	double d = distanceLP(ls[j],can[i]);
	if(r + ts[j] > d + EPS){
	  g = false;
	  break;
	}
      }
      if(g){
	f = true;
	break;
      }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3972
final_rank: 15

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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)

const double EPS = 1e-8;
// 点
typedef complex<double> P;
namespace std {
  bool isnan(const P&p){
    return isnan(p.real()) or isnan(p.imag());
  }
}

// 外積
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
// 内積
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

// 直線
// 線分は端点を入れる
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

// 円
struct C {
  P p; double r;
  C(const P &p_, double r_) : p(p_), r(r_) { }
};

// 交差判定
// 直線同士
bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
    abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}

// 直線の交点
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) return P(nan(""),nan("")); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

// 点の線への射影
P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}

// 直線と点の距離
double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}

signed main(){
  int n;
  double w,h,r;
  while(cin >> w >> h >> n >> r, n){
    // input
    vector<L> ls;
    vector<double> ts(n);
    rep(i,n){
      double a,b,c,d;
      cin >> a >> b >> c >> d;
      P x{a,b},y{c,d};
      ls.emplace_back(x,y);
      cin >> ts[i];
    }

    // 候補を列挙
    vector<P> can;
    // 四隅を追加
    can.push_back({r,r});
    can.push_back({r,h-r});
    can.push_back({w-r,r});
    can.push_back({w-r,h-r});
    // 2線に接する点を追加
    rep(i,n) FOR(j,i+1,n){
      // 交差しない
      if(not intersectLL(ls[i],ls[j])) continue;

      // 元の直線からr+t平行移動した直線l,rを用意
      // 交点が候補の候補となる
      double thetai = arg(ls[i][1]-ls[i][0]), thetaj = arg(ls[j][1]-ls[j][0]);
      L li{ls[i]}, ri{ls[i]}, lj{ls[j]}, rj{ls[j]};
      P tmpi{(r+ts[i])*sin(thetai),-(r+ts[i])*cos(thetai)};
      P tmpj{(r+ts[j])*sin(thetaj),-(r+ts[j])*cos(thetaj)};
      rep(k,2){
	li[k] -= tmpi;
	ri[k] += tmpi;
	lj[k] -= tmpj;
	rj[k] += tmpj;
      }
      vector<P> tmpcan;
      tmpcan.push_back(crosspoint(li,lj));
      tmpcan.push_back(crosspoint(li,rj));
      tmpcan.push_back(crosspoint(ri,lj));
      tmpcan.push_back(crosspoint(ri,rj));

      // 枠の中にあるなら候補
      auto isin = [&](const P &p){
	return r < p.real()+EPS and p.real()-EPS < w-r and r < p.imag()+EPS and p.imag()-EPS < h-r;
      };
      rep(k,4){
	if((not isnan(tmpcan[k])) and isin(tmpcan[k]))
	  can.push_back(tmpcan[k]);
      }
    }

    // 各候補が全ての線からr+t以上離れているか
    bool f = false;
    rep(i,can.size()){
      bool g = true;
      rep(j,n){
	double d = distanceLP(ls[j],can[i]);
	if(r + ts[j] > d + EPS){
	  g = false;
	  break;
	}
      }
      if(g){
	f = true;
	break;
      }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3904
final_rank: 14

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

using ld = double;
using point = std::complex<ld>;
using polygon = std::vector<point>;

constexpr ld eps = 1e-7;
const ld pi = std::acos(-1.0);

ld dot(point const& a, point const& b) {
    return std::real(std::conj(a) * b);
}
ld cross(point const& a, point const& b) {
    return std::imag(std::conj(a) * b);
}

struct line {
    line() : a(0, 0), b(0, 0) {}
    line(point a_, point b_) : a(a_), b(b_) {}
    point a, b;
};

bool isis_ll(line l, line m) {
    return cross(l.b - l.a, m.b - m.a) != 0;
}

point is_ll(line s, line t) {
    point sv = s.b - s.a, tv = t.b - t.a;
    assert(cross(sv, tv) != 0);
    return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

point proj(line l, point p) {
    ld t = dot(p - l.a, l.a - l.b) / std::norm(l.a - l.b);
    return l.a + t * (l.a - l.b);
}

long double dist_lp(line l, point p) {
    return std::abs(p - proj(l, p));
}

int main() {
    int w, h, n, r;
    while(cin >> w >> h >> n >> r, w) {
        vector<vector<line>> ls(n);
        vector<line> ls2;
        ls2.emplace_back(point{0, -(ld)h}, point{0, (ld)h * 2});
        ls2.emplace_back(point{-(ld)w, 0}, point{(ld)w * 2, 0});
        ls2.emplace_back(point{(ld)w, -(ld)h}, point{(ld)w, (ld)h * 2});
        ls2.emplace_back(point{-(ld)w, (ld)h}, point{(ld)w * 2, (ld)h});
        for(int i = 0; i < n; ++i) {
            ld x1, y1, x2, y2, t; cin >> x1 >> y1 >> x2 >> y2 >> t;
            point a{x1, y1}, b{x2, y2};
            const auto vec = (a - b) / abs(a - b) * t * point(0, 1);
            ls[i].emplace_back(a - vec, b - vec);
            ls[i].emplace_back(a + vec, b + vec);
            ls2.emplace_back(a - vec, b - vec);
            ls2.emplace_back(a + vec, b + vec);
        }

        auto create_circles = [&] (int i, int j) {
            const auto ip = is_ll(ls2[i], ls2[j]);
            //cout << " ip: " << ip << endl;
            auto ps1 = {ls2[i].a, ls2[i].b}, ps2 = {ls2[j].a, ls2[j].b};
            vector<point> res;
            for(auto const& p1 : ps1) {
                for(auto const& p2 : ps2) {
                    const auto v1 = (p1 - ip) / abs(p1 - ip);
                    const auto v2 = (p2 - ip) / abs(p2 - ip);
                    auto p = (v1 + v2) * 0.5;
                    const ld rr = abs(p) * sin(abs(arg(p / v1)));
                    res.push_back(ip + p * (ld)r / rr);
                }
            }
            return res;
        };
        const int m = ls2.size();
        bool ans = false;
        for(int i = 0; i < m && !ans; ++i) {
            for(int j = i + 1; j < m && !ans; ++j) {
                if(!isis_ll(ls2[i], ls2[j])) continue;
                for(auto&& p : create_circles(i, j)) {
                    bool check = -eps <= real(p) - r && real(p) + r <= w + eps && -eps <= imag(p) - r && imag(p) + r <= h + eps;
                    for(int k = 0; k < 4 && check; ++k) {
                        check &= dist_lp(ls2[k], p) >= r - eps;
                    }
                    for(int k = 0; k < n && check; ++k) {
                        check &= dist_lp(ls[k][0], p) >= r - eps && dist_lp(ls[k][1], p) >= r - eps;
                        const ld c1 = cross(p - ls[k][0].a, p - ls[k][0].b);
                        const ld c2 = cross(p - ls[k][1].a, p - ls[k][1].b);
                        check &= c1 * c2 >= 0;
                    }
                    ans |= check;
                }
            }
        }

        cout << (ans ? "Yes" : "No") << endl;
    }
}
accuracy: 1
time_ms: 120
memory_kb: 3604
final_rank: 13

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

using ld = long double;
using point = std::complex<ld>;
using polygon = std::vector<point>;

constexpr ld eps = 1e-7;
const ld pi = std::acos(-1.0);

ld dot(point const& a, point const& b) {
    return std::real(std::conj(a) * b);
}
ld cross(point const& a, point const& b) {
    return std::imag(std::conj(a) * b);
}

struct line {
    line() : a(0, 0), b(0, 0) {}
    line(point a_, point b_) : a(a_), b(b_) {}
    point a, b;
};

bool isis_ll(line l, line m) {
    return cross(l.b - l.a, m.b - m.a) != 0;
}

point is_ll(line s, line t) {
    point sv = s.b - s.a, tv = t.b - t.a;
    assert(cross(sv, tv) != 0);
    return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

point proj(line l, point p) {
    long double t = dot(p - l.a, l.a - l.b) / std::norm(l.a - l.b);
    return l.a + t * (l.a - l.b);
}

long double dist_lp(line l, point p) {
    return std::abs(p - proj(l, p));
}

int main() {
    int w, h, n, r;
    while(cin >> w >> h >> n >> r, w) {
        vector<vector<line>> ls(n);
        vector<line> ls2;
        ls2.emplace_back(point{0, -(ld)h}, point{0, (ld)h * 2});
        ls2.emplace_back(point{-(ld)w, 0}, point{(ld)w * 2, 0});
        ls2.emplace_back(point{(ld)w, -(ld)h}, point{(ld)w, (ld)h * 2});
        ls2.emplace_back(point{-(ld)w, (ld)h}, point{(ld)w * 2, (ld)h});
        for(int i = 0; i < n; ++i) {
            ld x1, y1, x2, y2, t; cin >> x1 >> y1 >> x2 >> y2 >> t;
            point a{x1, y1}, b{x2, y2};
            const auto vec = (a - b) / abs(a - b) * t * point(0, 1);
            //{
            //    const auto v2 = (a - b);
            //    a += v2 * 1000.0L;
            //    b -= v2 * 1000.0L;
            //}
            ls[i].emplace_back(a - vec, b - vec);
            ls[i].emplace_back(a + vec, b + vec);
            ls2.emplace_back(a - vec, b - vec);
            ls2.emplace_back(a + vec, b + vec);
        }

        auto create_circles = [&] (int i, int j) {
            const auto ip = is_ll(ls2[i], ls2[j]);
            //cout << " ip: " << ip << endl;
            auto ps1 = {ls2[i].a, ls2[i].b}, ps2 = {ls2[j].a, ls2[j].b};
            vector<point> res;
            for(auto const& p1 : ps1) {
                for(auto const& p2 : ps2) {
                    const auto v1 = (p1 - ip) / abs(p1 - ip);
                    const auto v2 = (p2 - ip) / abs(p2 - ip);
                    auto p = (v1 + v2) * 0.5L;
                    //cout << "  == v1: " << v1 << ",  v2: " << v2 << "  , p : " << p << endl;
                    //cout << "  == ang: " << abs(arg(v1 / v2)) << "  ang2: " << abs(arg(p / v1)) << endl;
                    const ld rr = abs(p) * sin(abs(arg(p / v1)));
                    res.push_back(ip + p * (ld)r / rr);
                }
            }
            return res;
        };
        const int m = ls2.size();
        bool ans = false;
        for(int i = 0; i < m; ++i) {
            for(int j = i + 1; j < m; ++j) {
                //cout << i << " " << j << endl;
                if(!isis_ll(ls2[i], ls2[j])) continue;
                for(auto&& p : create_circles(i, j)) {
                    //cout << " -> cp: " << p << endl;
                    bool check = -eps <= real(p) - r && real(p) + r <= w + eps && -eps <= imag(p) - r && imag(p) + r <= h + eps;
                    //cout << " in ? " << check << endl;
                    for(int k = 0; k < 4; ++k) {
                        //cout << " dist: " << fixed << setprecision(6) << dist_lp(ls2[k], p) << " " << r + eps << endl;
                        check &= dist_lp(ls2[k], p) >= r - eps;
                    }
                    //cout << " ok2: " << check << endl;
                    for(int k = 0; k < n; ++k) {
                        check &= dist_lp(ls[k][0], p) >= r - eps && dist_lp(ls[k][1], p) >= r - eps;
                        const ld c1 = cross(p - ls[k][0].a, p - ls[k][0].b);
                        const ld c2 = cross(p - ls[k][1].a, p - ls[k][1].b);
                        check &= c1 * c2 >= 0;
                    }
                    ans |= check;
                }
            }
        }

        cout << (ans ? "Yes" : "No") << endl;
    }
}
accuracy: 1
time_ms: 7580
memory_kb: 3552
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}



#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define PI 3.141592653589793238
 
// COUNTER CLOCKWISE
static const int CCW_COUNTER_CLOCKWISE = 1;
static const int CCW_CLOCKWISE = -1;
static const int CCW_ONLINE_BACK = 2;
static const int CCW_ONLINE_FRONT = -2;
static const int CCW_ON_SEGMENT = 0;

//Intercsect Circle & Circle
static const int ICC_SEPERATE = 4;
static const int ICC_CIRCUMSCRIBE = 3;
static const int ICC_INTERSECT = 2;
static const int ICC_INSCRIBE = 1;
static const int ICC_CONTAIN = 0;

struct Point{
  double x,y;
  Point(){}
  Point(double x,double y) :x(x),y(y){}
  Point operator+(Point p) {return Point(x+p.x,y+p.y);}
  Point operator-(Point p) {return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
  double norm(){return x*x+y*y;}
  double abs(){return sqrt(norm());}

  bool operator < (const Point &p) const{
    return x!=p.x?x<p.x:y<p.y;
    //grid-point only
    //return !equals(x,p.x)?x<p.x:!equals(y,p.y)?y<p.y:0;
  }

  bool operator == (const Point &p) const{
    return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
  }
};

struct EndPoint{
  Point p;
  int seg,st;
  EndPoint(){}
  EndPoint(Point p,int seg,int st):p(p),seg(seg),st(st){}
  bool operator<(const EndPoint &ep)const{
    if(p.y==ep.p.y) return st<ep.st;
    return p.y<ep.p.y;
  }
};

istream &operator >> (istream &is,Point &p){
  is>>p.x>>p.y;
  return is;
}

ostream &operator << (ostream &os,Point p){
  os<<fixed<<setprecision(12)<<p.x<<" "<<p.y;
  return os;
}

bool sort_x(Point a,Point b){
  return a.x!=b.x?a.x<b.x:a.y<b.y;
}

bool sort_y(Point a,Point b){
  return a.y!=b.y?a.y<b.y:a.x<b.x;
}

typedef Point Vector;
typedef vector<Point> Polygon;

istream &operator >> (istream &is,Polygon &p){
  for(int i=0;i<(int)p.size();i++) is>>p[i];
  return is;
}

struct Segment{
  Point p1,p2;
  Segment(){}
  Segment(Point p1, Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

istream &operator >> (istream &is,Segment &s){
  is>>s.p1>>s.p2;
  return is;
}

struct Circle{
  Point c;
  double r;
  Circle(){}
  Circle(Point c,double r):c(c),r(r){}
};

istream &operator >> (istream &is,Circle &c){
  is>>c.c>>c.r;
  return is;
}

double norm(Vector a){
  return a.x*a.x+a.y*a.y;
}
double abs(Vector a){
  return sqrt(norm(a));
}
double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

Point orth(Point p){return Point(-p.y,p.x);}

bool isOrthogonal(Vector a,Vector b){
  return equals(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Segment s1,Segment s2){
  return equals(dot(s1.p2-s1.p1,s2.p2-s2.p1),0.0);
}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
  return equals(cross(s1.p2-s1.p1,s2.p2-s2.p1),0.0); 
}

Point project(Segment s,Point p){
  Vector base=s.p2-s.p1;
  double r=dot(p-s.p1,base)/norm(base);
  return s.p1+base*r;
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2.0;
}

double arg(Vector p){
  return atan2(p.y,p.x);
}

Vector polar(double a,double r){
  return Point(cos(r)*a,sin(r)*a);
}

int ccw(Point p0,Point p1,Point p2);
bool intersectSS(Point p1,Point p2,Point p3,Point p4);
bool intersectSS(Segment s1,Segment s2);
bool intersectPS(Polygon p,Segment l);
int intersectCC(Circle c1,Circle c2);
bool intersectSC(Segment s,Circle c);
double getDistanceLP(Line l,Point p);
double getDistanceSP(Segment s,Point p);
double getDistanceSS(Segment s1,Segment s2);
Point getCrossPointSS(Segment s1,Segment s2);
Point getCrossPointLL(Line l1,Line l2);
Polygon getCrossPointCL(Circle c,Line l);
Polygon getCrossPointCC(Circle c1,Circle c2);
int contains(Polygon g,Point p);
Polygon andrewScan(Polygon s);
Polygon convex_hull(Polygon ps);
double diameter(Polygon s);
bool isConvex(Polygon p);
double area(Polygon s);
Polygon convexCut(Polygon p,Line l);
Line bisector(Point p1,Point p2);
Vector translate(Vector v,double theta);
vector<Line> corner(Line l1,Line l2);
vector<vector<pair<int, double> > >
segmentArrangement(vector<Segment> &ss, Polygon &ps);
  
int ccw(Point p0,Point p1,Point p2){
  Vector a = p1-p0;
  Vector b = p2-p0;
  if(cross(a,b) > EPS) return CCW_COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS) return CCW_CLOCKWISE;
  if(dot(a,b) < -EPS) return CCW_ONLINE_BACK;
  if(a.norm()<b.norm()) return CCW_ONLINE_FRONT;
  return CCW_ON_SEGMENT;
}

bool intersectSS(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4) <= 0 &&
          ccw(p3,p4,p1)*ccw(p3,p4,p2) <= 0 );
}

bool intersectSS(Segment s1,Segment s2){
  return intersectSS(s1.p1,s1.p2,s2.p1,s2.p2);
}

bool intersectPS(Polygon p,Segment l){
  int n=p.size();
  for(int i=0;i<n;i++)
    if(intersectSS(Segment(p[i],p[(i+1)%n]),l)) return 1;
  return 0;
}

int intersectCC(Circle c1,Circle c2){
  if(c1.r<c2.r) swap(c1,c2);
  double d=abs(c1.c-c2.c);
  double r=c1.r+c2.r;
  if(equals(d,r)) return ICC_CIRCUMSCRIBE;
  if(d>r) return ICC_SEPERATE;
  if(equals(d+c2.r,c1.r)) return ICC_INSCRIBE;
  if(d+c2.r<c1.r) return ICC_CONTAIN;
  return ICC_INTERSECT;
}

bool intersectSC(Segment s,Circle c){
  return getDistanceSP(s,c.c)<=c.r;
}

int intersectCS(Circle c,Segment s){
  if(norm(project(s,c.c)-c.c)-c.r*c.r>EPS) return 0;
  double d1=abs(c.c-s.p1),d2=abs(c.c-s.p2);
  if(d1<c.r+EPS&&d2<c.r+EPS) return 0;
  if((d1<c.r-EPS&&d2>c.r+EPS)||(d1>c.r+EPS&&d2<c.r-EPS)) return 1;
  Point h=project(s,c.c);
  if(dot(s.p1-h,s.p2-h)<0) return 2;
  return 0;
}

double getDistanceLP(Line l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

double getDistanceSP(Segment s,Point p){
  if(dot(s.p2-s.p1,p-s.p1) < 0.0 ) return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2) < 0.0 ) return abs(p-s.p2);
  return getDistanceLP(s,p);
}

double getDistanceSS(Segment s1,Segment s2){
  if(intersectSS(s1,s2)) return 0.0;
  return min(min(getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2)),
             min(getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)));
}

Point getCrossPointSS(Segment s1,Segment s2){
  for(int k=0;k<2;k++){
    if(getDistanceSP(s1,s2.p1)<EPS) return s2.p1; 
    if(getDistanceSP(s1,s2.p2)<EPS) return s2.p2;
    swap(s1,s2);
  }
  Vector base=s2.p2-s2.p1;
  double d1=abs(cross(base,s1.p1-s2.p1));
  double d2=abs(cross(base,s1.p2-s2.p1));
  double t=d1/(d1+d2);
  return s1.p1+(s1.p2-s1.p1)*t;
}

Point getCrossPointLL(Line l1,Line l2){
  double a=cross(l1.p2-l1.p1,l2.p2-l2.p1);
  double b=cross(l1.p2-l1.p1,l1.p2-l2.p1);
  if(abs(a)<EPS&&abs(b)<EPS) return l2.p1;
  return l2.p1+(l2.p2-l2.p1)*(b/a);
}

Polygon getCrossPointCL(Circle c,Line l){
  Polygon ps;
  Point pr=project(l,c.c);
  Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);
  if(equals(getDistanceLP(l,c.c),c.r)){
    ps.emplace_back(pr);
    return ps;
  }
  double base=sqrt(c.r*c.r-norm(pr-c.c));
  ps.emplace_back(pr+e*base);
  ps.emplace_back(pr-e*base);
  return ps;
}

Polygon getCrossPointCS(Circle c,Segment s){
  Line l(s);
  Polygon res=getCrossPointCL(c,l);
  if(intersectCS(c,s)==2) return res;
  if(res.size()>1u){
    if(dot(l.p1-res[0],l.p2-res[0])>0) swap(res[0],res[1]);
    res.pop_back();
  }
  return res;
}


Polygon getCrossPointCC(Circle c1,Circle c2){
  Polygon p(2);
  double d=abs(c1.c-c2.c);
  double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
  double t=arg(c2.c-c1.c);
  p[0]=c1.c+polar(c1.r,t+a);
  p[1]=c1.c+polar(c1.r,t-a);
  return p;
}

// IN:2 ON:1 OUT:0
int contains(Polygon g,Point p){
  int n=g.size();
  bool x=false;
  for(int i=0;i<n;i++){
    Point a=g[i]-p,b=g[(i+1)%n]-p;
    if(fabs(cross(a,b)) < EPS && dot(a,b) < EPS) return 1;
    if(a.y>b.y) swap(a,b);
    if(a.y < EPS && EPS < b.y && cross(a,b) > EPS ) x = !x;
  }
  return (x?2:0);
}

Polygon andrewScan(Polygon s){
  Polygon u,l;
  if(s.size()<3) return s;
  sort(s.begin(),s.end());
  u.push_back(s[0]);
  u.push_back(s[1]);
  l.push_back(s[s.size()-1]);
  l.push_back(s[s.size()-2]);
  for(int i=2;i<(int)s.size();i++){
    for(int n=u.size();n>=2&&ccw(u[n-2],u[n-1],s[i])!=CCW_CLOCKWISE;n--){
      u.pop_back();
    }
    u.push_back(s[i]);
  } 
  for(int i=s.size()-3;i>=0;i--){
    for(int n=l.size();n>=2&&ccw(l[n-2],l[n-1],s[i])!=CCW_CLOCKWISE;n--){
      l.pop_back();
    }
    l.push_back(s[i]);
  }
  reverse(l.begin(),l.end());
  for(int i=u.size()-2;i>=1;i--) l.push_back(u[i]);
  return l;
} 

Polygon convex_hull(Polygon ps){
  int n=ps.size();
  sort(ps.begin(),ps.end(),sort_y);
  int k=0;
  Polygon qs(n*2);
  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--;
    qs[k++]=ps[i];
  }
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0) k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}

double diameter(Polygon s){
  Polygon p=s;
  int n=p.size();
  if(n==2) return abs(p[0]-p[1]);
  int i=0,j=0;
  for(int k=0;k<n;k++){
    if(p[i]<p[k]) i=k;
    if(!(p[j]<p[k])) j=k;
  }
  double res=0;
  int si=i,sj=j;
  while(i!=sj||j!=si){
    res=max(res,abs(p[i]-p[j]));
    if(cross(p[(i+1)%n]-p[i],p[(j+1)%n]-p[j])<0.0){
      i=(i+1)%n;
    }else{
      j=(j+1)%n;
    }
  }
  return res;
}

bool isConvex(Polygon p){
  bool f=1;
  int n=p.size();
  for(int i=0;i<n;i++){
    int t=ccw(p[(i+n-1)%n],p[i],p[(i+1)%n]);
    f&=t!=CCW_CLOCKWISE;
  }
  return f;
}

double area(Polygon s){
  double res=0;
  for(int i=0;i<(int)s.size();i++){
    res+=cross(s[i],s[(i+1)%s.size()])/2.0;
  }
  return abs(res);
}

double area(Circle c1,Circle c2){
  double d=abs(c1.c-c2.c);
  if(c1.r+c2.r<=d+EPS) return 0;
  if(d<=abs(c1.r-c2.r)){
    double r=min(c1.r,c2.r);
    return PI*r*r;
  }
  double rc=(d*d+c1.r*c1.r-c2.r*c2.r)/(2*d);
  double th=acos(rc/c1.r);
  double ph=acos((d-rc)/c2.r);
  return c1.r*c1.r*th+c2.r*c2.r*ph-d*c1.r*sin(th);
}

Polygon convexCut(Polygon p,Line l){
  Polygon q;
  for(int i=0;i<(int)p.size();i++){
    Point a=p[i],b=p[(i+1)%p.size()];
    if(ccw(l.p1,l.p2,a)!=-1) q.push_back(a);
    if(ccw(l.p1,l.p2,a)*ccw(l.p1,l.p2,b)<0)
      q.push_back(getCrossPointLL(Line(a,b),l));
  }
  return q;
}

Line bisector(Point p1,Point p2){
  Circle c1=Circle(p1,abs(p1-p2)),c2=Circle(p2,abs(p1-p2));
  Polygon p=getCrossPointCC(c1,c2);
  if(cross(p2-p1,p[0]-p1)>0) swap(p[0],p[1]);
  return Line(p[0],p[1]);
}

Vector translate(Vector v,double theta){
  Vector res;
  res.x=cos(theta)*v.x-sin(theta)*v.y;
  res.y=sin(theta)*v.x+cos(theta)*v.y;
  return res;
}

vector<Line> corner(Line l1,Line l2){
  vector<Line> res;
  if(isParallel(l1,l2)){
    double d=getDistanceLP(l1,l2.p1)/2.0;
    Vector v1=l1.p2-l1.p1;
    v1=v1/v1.abs()*d;
    Point p=l2.p1+translate(v1,90.0*(PI/180.0));
    double d1=getDistanceLP(l1,p);
    double d2=getDistanceLP(l2,p);
    if(abs(d1-d2)>d){
      p=l2.p1+translate(v1,-90.0*(PI/180.0));
    }
    res.push_back(Line(p,p+v1));
  }else{
    Point p=getCrossPointLL(l1,l2);
    Vector v1=l1.p2-l1.p1,v2=l2.p2-l2.p1;
    v1=v1/v1.abs();
    v2=v2/v2.abs();
    res.push_back(Line(p,p+(v1+v2)));
    res.push_back(Line(p,p+translate(v1+v2,90.0*(PI/180.0))));
  }
  return res;
}

Polygon tangent(Circle c1,Point p2){
  Circle c2=Circle(p2,sqrt(norm(c1.c-p2)-c1.r*c1.r));
  Polygon p=getCrossPointCC(c1,c2);
  sort(p.begin(),p.end());
  return p;
}

vector<Line> tangent(Circle c1,Circle c2){
  vector<Line> ls;
  if(c1.r<c2.r) swap(c1,c2);
  double g=norm(c1.c-c2.c);
  if(equals(g,0)) return ls;
  Point u=(c2.c-c1.c)/sqrt(g);
  Point v=orth(u);
  for(int s=1;s>=-1;s-=2){
    double h=(c1.r+s*c2.r)/sqrt(g);
    if(equals(1-h*h,0)){
      ls.emplace_back(c1.c+u*c1.r,c1.c+(u+v)*c1.r);
    }else if(1-h*h>0){
      Point uu=u*h,vv=v*sqrt(1-h*h);
      ls.emplace_back(c1.c+(uu+vv)*c1.r,c2.c-(uu+vv)*c2.r*s);
      ls.emplace_back(c1.c+(uu-vv)*c1.r,c2.c-(uu-vv)*c2.r*s);
    }
  }
  
  return ls;
}

double closest_pair(Polygon &a,int l=0,int r=-1){
  if(r<0){
    r=a.size();
    sort(a.begin(),a.end(),sort_x);
  }
  if(r-l<=1) return abs(a[0]-a[1]);
  int m=(l+r)>>1;
  double x=a[m].x;
  double d=min(closest_pair(a,l,m),closest_pair(a,m,r));
  inplace_merge(a.begin()+l,a.begin()+m,a.begin()+r,sort_y);

  Polygon b;
  for(int i=l;i<r;i++){
    if(fabs(a[i].x-x)>=d) continue;
    for(int j=0;j<(int)b.size();j++){
      double dy=a[i].y-next(b.rbegin(),j)->y;
      if(dy>=d) break;
      d=min(d,abs(a[i]-*next(b.rbegin(),j)));
    }
    b.emplace_back(a[i]);
  }
  return d;
}

vector<vector<pair<int, double> > >
segmentArrangement(vector<Segment> &ss, Polygon &ps){
  int n=ss.size();
  for(int i=0;i<n;i++){
    ps.emplace_back(ss[i].p1);
    ps.emplace_back(ss[i].p2);
    for(int j=i+1;j<n;j++)
      if(intersectSS(ss[i],ss[j]))
        ps.emplace_back(getCrossPointSS(ss[i],ss[j]));
  }
  sort(ps.begin(),ps.end());
  ps.erase(unique(ps.begin(),ps.end()),ps.end());

  vector<vector<pair<int, double> > > G(ps.size());
  for(int i=0;i<n;i++){
    vector<pair<double,int> > ls;
    for(int j=0;j<(int)ps.size();j++)
      if(getDistanceSP(ss[i],ps[j])<EPS)
        ls.emplace_back(make_pair(norm(ss[i].p1-ps[j]),j));
      
    sort(ls.begin(),ls.end());
    for(int j=0;j+1<(int)ls.size();j++){
      int a=ls[j].second,b=ls[j+1].second;
      G[a].emplace_back(b,abs(ps[a]-ps[b]));
      G[b].emplace_back(a,abs(ps[a]-ps[b]));
    }
  }
  return G;
}

int manhattanIntersection(vector<Segment> ss,const int INF){
  const int BTM = 0;
  const int LFT = 1;
  const int RGH = 2;
  const int TOP = 3;
  
  int n=ss.size();
  vector<EndPoint> ep;
  for(int i=0;i<n;i++){
    if(ss[i].p1.y==ss[i].p2.y){
      if(ss[i].p1.x>ss[i].p2.x) swap(ss[i].p1,ss[i].p2);
      ep.emplace_back(ss[i].p1,i,LFT);
      ep.emplace_back(ss[i].p2,i,RGH);
    }else{
      if(ss[i].p1.y>ss[i].p2.y) swap(ss[i].p1,ss[i].p2);      
      ep.emplace_back(ss[i].p1,i,BTM);
      ep.emplace_back(ss[i].p2,i,TOP);
    }    
  }   
  sort(ep.begin(),ep.end());

  set<int> bt;
  bt.insert(INF);
  
  int cnt=0;
  for(int i=0;i<n*2;i++){
    if(ep[i].st==TOP){
      bt.erase(ep[i].p.x);
    }else if(ep[i].st==BTM){
      bt.emplace(ep[i].p.x);
    }else if(ep[i].st==LFT){
      auto b=bt.lower_bound(ss[ep[i].seg].p1.x);
      auto e=bt.upper_bound(ss[ep[i].seg].p2.x);
      cnt+=distance(b,e);
    }    
  }
  
  return cnt;
}

double area(Polygon ps,Circle c){
  if(ps.size()<3u) return 0;
  function<double(Circle, Point, Point)> dfs=
    [&](Circle c,Point a,Point b){
      Vector va=c.c-a,vb=c.c-b;
      double f=cross(va,vb),res=0;
      if(equals(f,0.0)) return res;
      if(max(abs(va),abs(vb))<c.r+EPS) return f;
      Vector d(dot(va,vb),cross(va,vb));
      if(getDistanceSP(Segment(a,b),c.c)>c.r-EPS)
        return c.r*c.r*atan2(d.y,d.x);
      auto u=getCrossPointCS(c,Segment(a,b));
      if(u.empty()) return res;
      if(u.size()>1u&&dot(u[1]-u[0],a-u[0])>0) swap(u[0],u[1]);
      u.emplace(u.begin(),a);
      u.emplace_back(b);
      for(int i=1;i<(int)u.size();i++)
        res+=dfs(c,u[i-1],u[i]);
      return res;
    };
  double res=0;
  for(int i=0;i<(int)ps.size();i++)
    res+=dfs(c,ps[i],ps[(i+1)%ps.size()]);
  return res/2;
}


//INSERT ABOVE HERE
signed main(){
  int w,h,n,r;
  while(cin>>w>>h>>n>>r,w){
    vector<Line> ls(n);
    vector<double> zs(n);
    for(int i=0;i<n;i++) cin>>ls[i].p1>>ls[i].p2>>zs[i];

    ls.push_back(Line(Point(0,0),Point(w,0)));
    ls.push_back(Line(Point(w,0),Point(w,h)));
    ls.push_back(Line(Point(w,h),Point(0,h)));
    ls.push_back(Line(Point(0,h),Point(0,0)));
    zs.push_back(0);
    zs.push_back(0);
    zs.push_back(0);
    zs.push_back(0);

    vector<Line> la;
    vector<double> za;
    for(int i=0;i<(int)ls.size();i++){
      Line l=ls[i];
      Vector v=orth(l.p1-l.p2);
      v=v/abs(v);
      v=v*zs[i];
      la.push_back(Line(l.p1+v,l.p2+v));
      la.push_back(Line(l.p1-v,l.p2-v));
    }

    auto check=
      [&](Point p)->int{
        //cout<<p<<":"<<r<<endl;
        if(p.x-r<0||p.x+r>w) return 0;
        if(p.y-r<0||p.y+r>h) return 0;
        for(int i=0;i<n;i++){
          double d=getDistanceLP(ls[i],p);
          if(d<zs[i]+r) return 0;
        }
        return 1;
      };
    
    int ok=0;
    for(int i=0;i<(int)la.size();i++){
      Vector u=la[i].p1-la[i].p2;
      u=u/abs(u);
      for(int j=0;j<i;j++){
        if(isParallel(la[i],la[j])) continue;
        auto vl=corner(la[i],la[j]);
        vl.push_back(Line(vl[0].p1,vl[0].p1*2-vl[0].p2));
        vl.push_back(Line(vl[1].p1,vl[1].p1*2-vl[1].p2));
        for(auto l:vl){
          Vector v=l.p1-l.p2;
          v=v/abs(v);
          double a=r/sin(acos(dot(u,v)));
          v=v*a;
          // cout<<l.p1<<" + "<<v<<endl;
          ok|=check(l.p1+v);
          ok|=check(l.p1-v);
        }
      }
    }
    
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3440
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef complex<double> V;
typedef vector<P> vecP;
typedef pair<P,P> L;
typedef pair<P,P> S;
typedef pair<P,double> C;
const double eps=1e-6;
const double PI=acos(-1);
const double PI2=PI*2.0;
 
namespace std{
  bool operator < (const P &a,const P &b){
    return (a.real()!=b.real()?
            a.real() <b.real():
            a.imag() <b.imag());
  }
};
 
V normal(V a){
  assert( abs(a)>0 );
  return a/abs(a);
}
 
double Sqrt( double x ){
  if(x<0)return 0;
  else return sqrt(x);
}
 
P Vector(L a){
  return a.second-a.first;
}
 
bool eq(double a,double b){
  return (-eps<a-b&&a-b<eps);
}
 
bool eq(P a,P b){
  return ( eq(a.real(),b.real()) && eq(a.imag(),b.imag()) );
}
 
double dot(P a,P b){
  return real(b*conj(a));
}
 
double cross(P a,P b){
  return imag(b*conj(a));
}
 
double getArg(P a,P b){
  return arg(b*conj(a));
}
 
double getTime(V a,V b){
  assert( eq(cross(a,b),0) );
  return ( dot(a,b) < 0 ? -1.0 : 1.0 ) * abs(b) / abs(a);
}
 
 
P project(P a,P b,P c){
  b-=a,c-=a;
  return a+b*real(c/b);
}
 
P reflect(P a,P b,P c){
  b-=a,c-=a;
  return a+b*conj(c/b);
}
 
int ccw(P a,P b,P c){
  P ab=b-a,ac=c-a;
  P k=ac*conj(ab);
  if(k.imag()>eps)return 1;
  if(k.imag()<-eps)return -1;
  if(k.real()<-eps)return 2;
  if(abs(ab)+eps<abs(ac))return -2;
  return 0;
}
 
bool isParallel(P a,P b){
  return eq(0, cross(a,b));
}
 
bool isParallel(S a,S b){
  return eq(0, cross( Vector(a) , Vector(b) ) );
}
 
bool onLP(L l,P p){
  P a=l.first, b=l.second;
  return eq(0, cross(b-a,p-a));
}
 
bool onSP(S s,P p){
  P a=s.first, b=s.second;
  return eq( abs(b-a) , abs(a-p)+abs(b-p) );
}
 
bool isCrossSS(S s0,S s1){
  P a=s0.first, b=s0.second;
  P c=s1.first, d=s1.second;
  int f0 = ccw(a,b,c) * ccw(a,b,d);
  int f1 = ccw(c,d,a) * ccw(c,d,b);
  return (f0<=0 && f1<=0);
}
 
bool isCrossLS(L l,S s){
  P a=l.first, b=l.second;
  P c=s.first, d=s.second;
  return ( ccw(a,b,c) * ccw(a,b,d) <= 0 );
}
 
double distLP(L l,P p){
  P a=l.first, b=l.second;
  double res = cross(b-a,p-a) / abs(b-a);
  return abs(res);
}
 
double distSP(S s,P p){
  P a=s.first, b=s.second;
  if( dot(b-a,p-a) < eps )return abs(p-a);
  if( dot(a-b,p-b) < eps )return abs(p-b);
  return distLP(s,p);
}
 
double distSS(S s0,S s1){
  if( isCrossSS(s0,s1) )return 0;
  double res0 = min( distSP( s0, s1.first ) , distSP(s0, s1.second) );
  double res1 = min( distSP( s1, s0.first ) , distSP(s1, s0.second) );
  return min(res0,res1);
}
 
P getCrossLL(L l0,L l1){
  P a=l0.first, b=l0.second;
  P c=l1.first, d=l1.second;
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
 
  
int inPolygon(vecP &t,P p){
  int n=t.size();
  double sum=0;
  for(int i=0;i<n;i++){
    P a=t[i],b=t[(i+1==n?0:i+1)];
    if( ccw(a,b,p)==0 )return 1;
    sum+= getArg(a-p,b-p);
  }
  if( abs(sum) < eps )return 0;
  else return 2;
}
 
vecP andrewScan(vecP &t){
  int N=t.size(),C=0;
  vecP R(N);
  for(int i=0;i<N;i++){
    while(2<=C&&ccw(R[C-2],R[C-1],t[i])==-1)C--;
    R[C++]=t[i];
  }
  vecP res(C);
  for(int i=0;i<C;i++)res[i]=R[i];
  return res;
}
  
vecP convexHull(vecP &t){
  sort(t.begin(),t.end());
  vecP u=andrewScan(t);
  reverse(t.begin(),t.end());
  vecP l=andrewScan(t);
  for(int i=1;i+1<(int)l.size();i++)u.push_back(l[i]);
  return u;
}
 
vecP cutConvex(vecP &t,L l){
  P a=l.first, b=l.second;
  int N=t.size();
  vecP res;
  for(int i=0;i<N;i++){
    P c=t[i],d=t[(i+1)%N];
    int C=ccw(a,b,c),D=ccw(a,b,d);
    if(C!=-1)res.push_back(c);
    if(C==-D&&abs(C)==1)res.push_back(getCrossLL( l ,L(c,d) ));
  }
  return res;
}
 
P getVector(const vecP &t, int id){
  int n=t.size();
  return t[ (id+1)%n ] - t[id%n];
}
 
double convex_diameter(vecP &t) {
  int n = t.size();
  int is = 0, js = 0;
  for (int i = 1; i < n; ++i) {
    if (imag(t[i]) > imag(t[is])) is = i;
    if (imag(t[i]) < imag(t[js])) js = i;
  }
  double maxd = norm(t[is]-t[js]);
  
  int i, maxi, j, maxj;
  i = maxi = is;
  j = maxj = js;
  do {
     
    if (cross( getVector(t,i), getVector(t,j)) >= 0) j = (j+1) % n;
     
    else i = (i+1) % n;
    if (norm(t[i]-t[j]) > maxd) {
      maxd = norm(t[i]-t[j]);
      maxi = i; maxj = j;
    }
  } while (i != is || j != js);
  return sqrt(maxd); /* farthest pair is (maxi, maxj). */
}
 
bool compare_y(const P &a,const P &b){
  return a.imag() < b.imag();
}
 
double closest_pair(P *a, int n){
  if(n <= 1) return 1e30;
  int m = n / 2;
  double x = a[m].real();
  double d = min(closest_pair(a, m), closest_pair(a + m, n - m));
  inplace_merge(a, a + m, a + n, compare_y);
  vector<P> b;
  for(int i=0;i<n;i++){
    if( abs(a[i].real() - x) >= d) continue;
    for(int j=0;j<(int)b.size();j++){
      double dx = real(a[i] - b[b.size() - j - 1]);
      double dy = imag(a[i] - b[b.size() - j - 1]);
      if(dy >= d) break;
      d = min(d, sqrt(dx * dx + dy * dy));
    }
    b.push_back(a[i]);
  }
  return d;
}
 
P _pool[200005];
double minDist(vecP &t){
  int n=t.size();
  for(int i=0;i<n;i++)_pool[i]=t[i];
  sort( _pool, _pool+n);
  return closest_pair(_pool, n);
}
 
int getStateCC(C a,C b){
  double ar=a.second, br=b.second;
  double dist=abs(a.first-b.first);
  if(dist>ar+br+eps)return 4;
  if(dist>ar+br-eps)return 3;
  if(dist>abs(ar-br)+eps)return 2;
  if(dist>abs(ar-br)-eps)return 1;
  return 0;
}
 
P getCrossCC(C a,C b){
  P p1=a.first, p2=b.first;
  double r1=a.second, r2=b.second;
  double cA = (r1*r1+norm(p1-p2)-r2*r2) / (2.0*r1*abs(p1-p2));
  return p1+(p2-p1)/abs(p1-p2)*r1*P(cA,Sqrt(1.0-cA*cA));
}
 
P getTangentCP_(C a,P p,int flg){
  P base=a.first-p;
  double ar=a.second;
  double w=Sqrt(norm(base)-ar*ar);
  P s=p+base*P(w,ar * flg)/norm(base)*w;
  return s;
}
 
vector<S> getTangentCP(C a,P p){
  vector<S> res;
  P s=getTangentCP_(a,p,1);
  P t=getTangentCP_(a,p,-1);
   
  if( eq(s,t) ){
    res.push_back( S(s, s+(a.first-p)*P(0,1) ) ); 
  }else{
    res.push_back( S(p,s) );
    res.push_back( S(p,t) );
  }
  return res;
}
 
S getInTangent(C a,C b,double flg=1.0){
  P ap=a.first,bp=b.first;
  double ar=a.second,br=b.second;
   
  P base=bp-ap;
  double w=ar+br;
  double h=Sqrt(norm(base)-w*w);
  P k=base*P(w,h*flg)/norm(base);
  return S(ap+k*ar,bp-k*br);
}
   
S getOutTangent(C a,C b,double flg=1.0){
  P ap=a.first,bp=b.first;
  double ar=a.second,br=b.second;
   
  P base=bp-ap;
  double h=br-ar;
   
  double w=Sqrt(norm(base)-h*h);
  P k=base*P(w,h*flg)/norm(base)*P(0,flg);
  return S(ap+k*ar,bp+k*br);
}
   
vector<S> getTangentCC(C a,C b){
  P ap=a.first,bp=b.first;
  double ar=a.second,br=b.second;
   
  vector<S> res;
  double dist=abs(ap-bp);
     
  if(dist>ar+br+eps)
    res.push_back(getInTangent(a,b,1));
   
  if(dist>ar+br-eps)
    res.push_back(getInTangent(a,b,-1));
   
  if(dist>abs(ar-br)+eps)
    res.push_back(getOutTangent(a,b,1));
   
  if(dist>abs(ar-br)-eps)
    res.push_back(getOutTangent(a,b,-1));
   
  return res;
}
 
 
vecP getCrossCL(C cir,L l){
  P a=l.first, b=l.second;
  double cr=cir.second;
  P cp=cir.first;
   
  vecP res;
  P base=b-a,  target=project(a,b,cp);
   
  double length=abs(base), h=abs(cp-target);
  base/=length;
   
  if(cr+eps<h)return res;
  double w=Sqrt(cr*cr-h*h);
  double L=getTime( normal(b-a) ,target-a)-w,  R=L+w*2.0;
   
  res.push_back(a+base*L);
  if( eq(L,R) )return res;
  res.push_back(a+base*R);
 
  return res;
}
 
vecP getCrossCS(C cir,S s){
  vecP tmp=getCrossCL(cir,s);
  vecP res;
  for(int i=0;i<(int)tmp.size();i++)
    //  if( ccw(s.first,s.second, tmp[i] ) == 0)
    if( onSP( s, tmp[i] ) )
      res.push_back(tmp[i]);
  return res;
}
 
double getArea(C c,P a,P b){
  P cp=c.first;
  double cr=c.second;
   
  P va=cp-a,  vb=cp-b;
  double A=abs(va), B=abs(vb);
  double f=cross(va,vb), d=distSP( S(a,b) ,cp), res=0;
   
  if( eq(0, f ) )return 0;
  if(A<cr+eps&&B<cr+eps)return f*0.5;
  if(d>cr-eps)return cr*cr*PI*getArg(va,vb)/PI2;
    
  vecP u=getCrossCS(c, S(a,b) );
   
  assert( !u.empty() );
  u.insert(u.begin(), a),  u.push_back(b);
  
  for(int i=0;i+1<(int)u.size();i++) res+=getArea(c,u[i],u[i+1]);
  return res;
}
  
double getCrossArea(vecP t,C c){
  int n=t.size();
  if(n<3)return 0;
  double res=0;
  for(int i=0;i<n;i++){
    P a=t[i], b=t[(i+1)%n];
    res+=getArea(c,a,b);
  }
  return res;
}
 
 
double calcPolygonArea(const vecP &t){
  double res=0;
  int n=t.size();
  for(int i=0;i<n;i++){
    res+= cross( t[ (i+1)%n ],t[i] );
  }
  return abs(res)*0.5;
}

int W,H,N,R;

int main(){
  while(1){
    cin>>W>>H>>N>>R;
    if(W==0&&H==0&&N==0&&R==0)break;
    vector< L > lines;
    vector< L > bo;
    vector< double > bp;
    
    bp.push_back(0);
    bo.push_back( L(P(0,0),P(0,H)) );
    bp.push_back(0);
    bo.push_back( L(P(0,0),P(W,0)) );
    bp.push_back(0);
    bo.push_back( L(P(W,H),P(0,H)) );
    bp.push_back(0);
    bo.push_back( L(P(W,H),P(W,0)) );
    
    lines.push_back(L( P(R,R) , P(R,H-R) ));
    lines.push_back(L( P(R,R) , P(W-R,R) ));
    lines.push_back(L( P(W-R,H-R) , P(W-R,R) ));
    lines.push_back(L( P(W-R,H-R) , P(R,H-R) ));

    for(int i=0;i<N;i++){
      int ax,ay,bx,by,t;
      cin>>ax>>ay>>bx>>by>>t;
      P A=P(ax,ay);
      P B=P(bx,by);
      P v=B-A;
      v/=abs(v);
      
      v*=P(0,t+R);

      bo.push_back( L(A,B) );
      bp.push_back( t );
      lines.push_back( L(A+v,B+v) );
      lines.push_back( L(A-v,B-v) );
    }
    
    bool ans=false;

    for(int i=0;i<(int)lines.size();i++){
      for(int j=0;j<i;j++){
        if( isParallel( lines[i], lines[j] ) )continue;
        P target=getCrossLL(lines[i],lines[j]);

        if( target.real() < 0 )continue;
        if( target.real() > W )continue;
        if( target.imag() < 0 )continue;
        if( target.imag() > H )continue;
        
        bool flg=true;
        for(int k=0;k<(int)bo.size();k++){
          double di=distLP(bo[k],target) - bp[k];

          if( di < R-eps ){
            flg=false;
            break;
          }
        }
        if(flg){
          ans=true;
        }
      }
    }

    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6252
final_rank: 18

code_snippet: #include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pi M_PI
#define inf 1<<30
#define eps (1e-10)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};
typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

Point getCrossPointLL(Line a,Line b){
  double A=cross(a.p2-a.p1,b.p2-b.p1);
  double B=cross(a.p2-a.p1,a.p2-b.p1);
  if(abs(A)<eps || abs(B)<eps)return b.p1;
  return b.p1+(b.p2-b.p1)*(B/A);
}

// Vector???90????????¢
Vector rotateVector90(Vector v){
  swap(v.x,v.y);
  v.y*=-1;
  return v;
}

// dis??????Line??????????§????
pair<Line,Line> getParalellLine(Line L,double dis){
  Vector v=L.p2-L.p1;
  v=rotateVector90(v);
  v=(v*dis)/abs(v);
  return mp(Line(L.p1+v,L.p2+v),Line(L.p1-v,L.p2-v));
}

double getDistanceLP(Line l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

Point rotate(Point base,Point a,double r){
  Point b=a-base;
  a.x=b.x*cos((r/180)*M_PI)-b.y*sin((r/180)*M_PI);
  a.y=b.x*sin((r/180)*M_PI)+b.y*cos((r/180)*M_PI);
  a=a+base;
  return a;
}

int h,w,n;
vector<pair<Line,double> > vl;
vector<pair<Line,Line> > vpl;
vector<Line> vs;

bool in(Circle c){
  double disa=c.c.x-c.r,disb=c.c.x+c.r,disc=c.c.y-c.r,disd=c.c.y+c.r;
  if(disa<-eps || (w-disa)<-eps)return false;
  if(disb<-eps || (w-disb)<-eps)return false;
  if(disc<-eps || (h-disc)<-eps)return false;
  if(disd<-eps || (h-disd)<-eps)return false;
  return true;
}

bool check(Circle c){
  if(!in(c))return false;
  for(int i=0;i<n;i++){
    double dis=getDistanceLP(vl[i].f,c.c);
    if((dis-(c.r+vl[i].s))<-eps)return false;
  }
  return true;
}

bool check(Line L1,Line L2,double R){
  if(isParallel(L1.p1-L1.p2,L2.p1-L2.p2))return false;
  Point origin=getCrossPointLL(L1,L2),temp;
  Point p1=L1.p1,p2=L2.p1;
  Vector v1,v2,v3;
  double s,x;

  if(equals(abs(L1.p1-origin),0.0))p1=L1.p2;
  if(equals(abs(L2.p1-origin),0.0))p2=L2.p2;

  v1=p1-origin,v2=p2-origin;
  s=acos(dot(v1,v2)/(abs(v1)*abs(v2)))/2.0;
  x=(R/sin(s));
  v3=rotate(origin,p1,180-(s*360/(2*pi)))-origin;
  v3=v3*x/abs(v3);
  temp=origin+v3;
  //printf("%.10f %.10f %.10f\n",temp.x,temp.y,R);
  if(check(Circle(origin+v3,R)))return true;

  p1=rotate(origin,p1,180);
  v1=p1-origin,v2=p2-origin;
  s=acos(dot(v1,v2)/(abs(v1)*abs(v2)))/2.0;
  x=(R/sin(s));
  v3=rotate(origin,p2,180-(s*360/(2*pi)))-origin;
  v3=v3*x/abs(v3);
  temp=origin+v3;
  //printf("%.10f %.10f %.10f\n",temp.x,temp.y,R);
  if(check(Circle(origin+v3,R)))return true;

  p2=rotate(origin,p2,180);
  v1=p1-origin,v2=p2-origin;
  s=acos(dot(v1,v2)/(abs(v1)*abs(v2)))/2.0;
  x=(R/sin(s));
  v3=rotate(origin,p1,180-(s*360/(2*pi)))-origin;
  v3=v3*x/abs(v3);
  temp=origin+v3;
  //printf("%.10f %.10f %.10f\n",temp.x,temp.y,R);
  if(check(Circle(origin+v3,R)))return true;

  p1=rotate(origin,p1,180);
  v1=p1-origin,v2=p2-origin;
  s=acos(dot(v1,v2)/(abs(v1)*abs(v2)))/2.0;
  x=(R/sin(s));
  v3=rotate(origin,p2,180-(s*360/(2*pi)))-origin;
  v3=v3*x/abs(v3);
  temp=origin+v3;
  //printf("%.10f %.10f %.10f\n",temp.x,temp.y,R);
  if(check(Circle(origin+v3,R)))return true;

  return false;
}

int main()
{
  int a,b,c,d,e,R;

  while(1){
    cin>>w>>h>>n>>R;
    if(h+w+n+R==0)break;
    vs.clear();
    vl.clear();
    vpl.clear();
    vs.push_back(Line(Point(0,0),Point(0,h)));
    vs.push_back(Line(Point(0,h),Point(w,h)));
    vs.push_back(Line(Point(w,h),Point(w,0)));
    vs.push_back(Line(Point(w,0),Point(0,0)));

    for(int i=0;i<n;i++){
      cin>>a>>b>>c>>d>>e;
      Line L=Line(Point(a,b),Point(c,d));
      vl.push_back(mp(L,e));
      vpl.push_back(getParalellLine(L,e));
    }
    
    string ans="No";
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if(check(vpl[i].f,vpl[j].f,R))ans="Yes";
	if(check(vpl[i].f,vpl[j].s,R))ans="Yes";
	if(check(vpl[i].s,vpl[j].f,R))ans="Yes";
	if(check(vpl[i].s,vpl[j].s,R))ans="Yes";
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<4;j++){
	if(check(vpl[i].f,vs[j],R))ans="Yes";
	if(check(vpl[i].s,vs[j],R))ans="Yes";      
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 1320
final_rank: 4

code_snippet: #include<iostream>
#include<complex>

using namespace std;

typedef complex<double> P;

int W,H,N,R;
int x1[123],y_1[123],x2[123],y2[123],t[123];
double eps=1e-9;

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

pair<pair<P,P>,pair<P,P> > sl(P a1,P a2,double dd){
  P a=a2-a1;
  P d=a/abs(a)*P(0,1)*dd;
  return make_pair(make_pair(a1+d,a2+d),make_pair(a1-d,a2-d));
}

bool safe(pair<P,P> a,pair<P,P> b){
  P ad=a.second-a.first;
  P bd=b.second-b.first;
  double aa=cross(ad,bd);
  if(fabs(aa)<eps)return false;
  P is=a.first+ad/aa*cross(b.first-a.first,bd);
  //    cout<<is<<endl;
  if(is.real()<R-eps||W-R+eps<is.real()||is.imag()<R-eps||H-R+eps<is.imag())return false;
  for(int i=0;i<N;i++){
    P p1=P(x1[i],y_1[i]);
    P p=P(x2[i],y2[i])-p1;
    //    cout<<cross(is-p1,p)/abs(p)<<endl;
    if(fabs(cross(is-p1,p))/abs(p)<R+t[i]-eps)return false;
  }
  //  cout<<is<<endl;
  return true;
}

bool check(P a1,P a2,P b1,P b2){
  auto as=sl(a1,a2,R);
  auto bs=sl(b1,b2,R);
  return safe(as.first,bs.first)||safe(as.first,bs.second)||safe(as.second,bs.first)||safe(as.second,bs.second);
}
  
int main(){
  for(;cin>>W>>H>>N>>R,W|H|N|R;){
    bool f=!N;
    P p1[123][2],p2[123][2];
    for(int i=0;i<N;i++){
      cin>>x1[i]>>y_1[i]>>x2[i]>>y2[i]>>t[i];
      auto s=sl(P(x1[i],y_1[i]),P(x2[i],y2[i]),t[i]);
      p1[i][0]=s.first.first;
      p2[i][0]=s.first.second;
      p1[i][1]=s.second.first;
      p2[i][1]=s.second.second;
    }
    for(int i=0;i<N;i++){
      for(int j=0;j<2;j++){
	f|=check(p1[i][j],p2[i][j],P(0,0),P(W,0));
	f|=check(p1[i][j],p2[i][j],P(W,0),P(W,H));
	f|=check(p1[i][j],p2[i][j],P(W,H),P(0,H));
	f|=check(p1[i][j],p2[i][j],P(0,H),P(0,0));
	for(int k=0;k<i;k++){
	  for(int l=0;l<2;l++){
	    f|=check(p1[i][j],p2[i][j],p1[k][l],p2[k][l]);
	  }
	}
      }
    }
    cout<<(f?"Yes":"No")<<endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3068
final_rank: 7

code_snippet: #include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1);
double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	struct Pt {
	   double x, y;
Pt() {}
     Pt(double x, double y) : x(x), y(y) {}
     Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
     Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
     Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
     Pt operator-() const { return Pt(-x, -y); }
     Pt operator*(const double &k) const { return Pt(x * k, y * k); }
     Pt operator/(const double &k) const { return Pt(x / k, y / k); }
     double ABS() const { return sqrt(x * x + y * y); }
     double abs2() const { return x * x + y * y; }
     double arg() const { return atan2(y, x); }
     double dot(const Pt &a) const { return x * a.x + y * a.y; }
     double det(const Pt &a) const { return x * a.y - y * a.x; }
 };
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
int iSP(Pt a, Pt b, Pt c) {
    int s = sig((b - a).det(c - a));
    if (s) return s;
    if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
    if (sig((a - b).dot(c - b)) < 0) return +2; //   a-b-c
return 0;
}
int iLL(Pt a, Pt b, Pt c, Pt d) {
    if (sig((b - a).det(d - c))) return 1;  // intersect
    if (sig((b - a).det(c - a))) return 0;  // parallel
    return -1;  // correspond
}
bool iLS(Pt a, Pt b, Pt c, Pt d) {
    return (sig(tri(a, b, c)) * sig(tri(a, b, d)) <= 0);
}
bool iSS(Pt a, Pt b, Pt c, Pt d) {
    return (iSP(a, b, c) * iSP(a, b, d) <= 0 && iSP(c, d, a) * iSP(c, d, b) <= 0);
}
bool iSSstrict(Pt a, Pt b, Pt c, Pt d) {
    return (sig(tri(a, b, c)) * sig(tri(a, b, d)) < 0 && sig(tri(c, d, a)) * sig(tri(c, d, b)) < 0);
}
Pt pLL(Pt a, Pt b, Pt c, Pt d) {
    b = b - a; d = d - c; return a + b * (c - a).det(d) / b.det(d);
}
double dLP(Pt a, Pt b, Pt c) {
    return ABS(tri(a, b, c)) / (b - a).ABS();
}
double dSP(Pt a, Pt b, Pt c) {
    if (sig((b - a).dot(c - a)) <= 0) return (c - a).ABS();
    if (sig((a - b).dot(c - b)) <= 0) return (c - b).ABS();
    return ABS(tri(a, b, c)) / (b - a).ABS();
}
double dLL(Pt a, Pt b, Pt c, Pt d) {
    return iLL(a, b, c, d) ? 0 : dLP(a, b, c);
}
double dLS(Pt a, Pt b, Pt c, Pt d) {
    return iLS(a, b, c, d) ? 0 : min(dLP(a, b, c), dLP(a, b, d));
}
double dSS(Pt a, Pt b, Pt c, Pt d) {
    return iSS(a, b, c, d) ? 0 : min(min(dSP(a, b, c), dSP(a, b, d)), min(dSP(c, d, a), dSP(c, d, b)));
}
Pt L[110];
Pt R[110];
Pt vec[110];
double t[110];
int main(){
	int W,H,N;
	double r;
	while(scanf("%d%d%d%lf",&W,&H,&N,&r),W){
		for(int i=0;i<N;i++){
			double X1,X2,Y1,Y2;
			scanf("%lf%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2,t+i);
			L[i]=Pt(X1,Y1);
			R[i]=Pt(X2,Y2);
			vec[i]=(R[i]-L[i])*Pt(0,1);
			vec[i]=vec[i]/(vec[i].ABS())*(t[i]+r);
		}
		vector<Pt> hb;
		hb.push_back(Pt(r,r));
		hb.push_back(Pt(W-r,r));
		hb.push_back(Pt(r,H-r));
		hb.push_back(Pt(W-r,H-r));
		vector<pair<Pt,Pt> > lines;
		for(int i=0;i<N;i++){
			lines.push_back(make_pair(L[i]+vec[i],R[i]+vec[i]));
			lines.push_back(make_pair(L[i]-vec[i],R[i]-vec[i]));
		}
		lines.push_back(make_pair(hb[0],hb[1]));
		lines.push_back(make_pair(hb[0],hb[2]));
		lines.push_back(make_pair(hb[3],hb[1]));
		lines.push_back(make_pair(hb[3],hb[2]));
		for(int i=0;i<lines.size();i++)for(int j=i+1;j<lines.size();j++){
			if(iLL(lines[i].first,lines[i].second,lines[j].first,lines[j].second)!=1)continue;
			Pt p=pLL(lines[i].first,lines[i].second,lines[j].first,lines[j].second);
			if(r-EPS<p.x&&p.x<EPS+W-r&&r-EPS<p.y&&p.y<EPS+H-r)hb.push_back(p);
		}
		bool ok=false;
	//	printf("%d ",hb.size());
		for(int i=0;i<hb.size();i++){
			bool OK=true;
			for(int j=0;j<N;j++){
				if(dLP(L[j],R[j],hb[i])<t[j]+r-EPS)OK=false;
			}
			if(OK)ok=true;
		}
		if(ok)printf("Yes\n");
		else printf("No\n");
	}
}
accuracy: 1
time_ms: 50
memory_kb: 1440
final_rank: 5

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
int W,H,N,R;
D inf=1e50,eps=1e-9;
inline D cro(P a,P b){
	return imag(conj(a)*b);
}
inline D dot(P a,P b){
	return real(conj(a)*b);
}
inline bool ispal(L a,L b){
	return abs(cro(a.fs-a.sc,b.fs-b.sc))<eps;
}
inline P intLL(L a,L b){
	D t=cro(a.sc-a.fs,a.sc-b.fs)/cro(a.sc-a.fs,b.sc-b.fs);
	return b.fs+(b.sc-b.fs)*t;
}
inline P perp(L l,P p){
	D t=dot(p-l.fs,l.fs-l.sc)/norm(l.fs-l.sc);
	return l.fs+t*(l.fs-l.sc);
}
inline D dLP(L l,P p){
	return abs(perp(l,p)-p);
}
D a[100],b[100],c[100],d[100],t[104];
vector<L> war,lines;
void init(){
	war.clear();
	lines.clear();
}
bool solve(){
	init();
	rep(i,N){
		cin>>a[i]>>b[i]>>c[i]>>d[i]>>t[i];
		P p=P(a[i],b[i]),q=P(c[i],d[i]);
		war.pb(L(p,q));
		P v=P(b[i]-d[i],c[i]-a[i]);
		v/=abs(v);
		v*=(R+t[i]);
		lines.pb(L(p+v,q+v));
		lines.pb(L(p-v,q-v));
	}
	lines.pb(L(P(R,0),P(R,H)));
	lines.pb(L(P(W-R,0),P(W-R,H)));
	lines.pb(L(P(0,R),P(W,R)));
	lines.pb(L(P(0,H-R),P(W,H-R)));
	war.pb(L(P(0,0),P(0,H)));
	war.pb(L(P(0,H),P(W,H)));
	war.pb(L(P(W,H),P(W,0)));
	war.pb(L(P(W,0),P(0,0)));
	t[N]=t[N+1]=t[N+2]=t[N+3]=0;
	N+=4;
	int M=lines.size();
//	rep(i,M) cout<<lines[i].fs<<" "<<lines[i].sc<<endl;
//	cout<<endl;
	rep(i,M) rep(j,i){
		L la=lines[i],lb=lines[j];
		if(ispal(la,lb)) continue;
		P p=intLL(la,lb);
		if(p.real()<0||p.real()>W||p.imag()<0||p.imag()>H) continue;
//		show(p);
		bool ok=true;
		rep(k,N){
//			cout<<war[k].fs<<" "<<war[k].sc<<endl;
			if(dLP(war[k],p)+eps<t[k]+R){
				ok=false;
				break;
			}
		}
		if(ok) return true;
	}
	return false;
}
int main(){
	while(true){
		cin>>W>>H>>N>>R;
		if(W==0) break;
		cout<<(solve()?"Yes":"No")<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1268
final_rank: 2

code_snippet: #include<cstdio>
#include<vector>
#include<utility>
#include<complex>
#include<algorithm>

using namespace std;

const double eps=1e-9;

template<class T> bool eq(T a,T b){
	return abs(a-b)<eps;
}

template<class T> int sgn(T r){
	return eq(r,0.0)?0:(r>0?1:-1);
}

typedef complex<double> Point;
typedef complex<double> Vector;
typedef pair<Point,Point> Line;

double crP(Vector a,Vector b){
	return (conj(a)*b).imag();
}

bool isPara(Line l1,Line l2){
	Vector a=l1.second-l1.first;
	Vector b=l2.second-l2.first;
	return eq(crP(a,b),0.0);
}

Point interLL(Line l1,Line l2){
	if(isPara(l1,l2)) return Point(NAN,NAN);
	Point a1=l1.first,a2=l1.second;
	Point b1=l2.first,b2=l2.second;
	double num=crP(b1-a1,a2-a1);
	double den=crP(a2-a1,b2-b1);
	return b1+(b2-b1)*(num/den);
}

int ccw2(Point p1,Point p2,Point p3){
	Vector b=p2-p1;
	Vector c=p3-p1;
	return sgn(crP(b,c));
	//1:counter
	//-1:clock
	//0:on
}

Vector getPerp(Vector v){
	double a=v.real(),b=v.imag();
	return Vector(b,-a)/abs(v);
}

void print(Point p){
	if(isnan(p.real())) printf("NAN point\n");
	else printf("(%f,%f)\n",p.real(),p.imag());
}

int W,H,N,R;

Line ls[110][2];

bool check(Point p){
	for(int i=0;i<N+2;i++){
		int s=1;
		for(int j=0;j<2;j++){
			Line l=ls[i][j];
			s*=ccw2(l.first,l.second,p);
		}
		if(i<N&&s==-1) return false;
		if(i>=N&&s==1) return false;
	}
	return true;
}

int main(){
/*	Point p1=Point(0,-1);
	Point p2=Point(0,1);
	Point p3=Point(1,0);
	Point p4=Point(-1,0);
	Line l1=Line(p1,p2);
	Line l2=Line(p3,p4);
	print(interLL(l1,l2));*/
	while(true){
		scanf("%d%d%d%d",&W,&H,&N,&R);
		if(W==0&&H==0) break;
		for(int i=0;i<N;i++){
			int x1,y1,x2,y2,t;
			scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&t);
			Point p1=Point(x1,y1),p2=Point(x2,y2);
			Vector v=getPerp(p2-p1);
			t+=R;
			ls[i][0]=Line(p1+v*(double)t,p2+v*(double)t);
			ls[i][1]=Line(p1-v*(double)t,p2-v*(double)t);
		}
		ls[N][0]=Line(Point(R,0),Point(R,H));
		ls[N][1]=Line(Point(W-R,0),Point(W-R,H));
		ls[N+1][0]=Line(Point(0,R),Point(W,R));
		ls[N+1][1]=Line(Point(0,H-R),Point(W,H-R));
		bool ans=false;
		for(int i=0;i<N+2;i++) for(int j=i+1;j<N+2;j++){
			for(int k=0;k<2;k++) for(int m=0;m<2;m++){
				Point p=interLL(ls[i][k],ls[j][m]);
		//		printf("%d %d %d %d::",i,k,j,m);
		//		print(p);
				if(isnan(p.real())) continue;
				if(check(p)){
					ans=true;
					goto output;
				}
			}
		}
		output:;
		if(ans) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1036
final_rank: 1

code_snippet: ////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <regex>
using namespace std;

//// MACRO ////
#define countof(a) (sizeof(a)/sizeof(a[0]))

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define RFOR(i,s,n) for (int i = (n)-1; i >= (s); i--)
#define pos(c,i) c.being() + (i)
#define allof(c) c.begin(), c.end()
#define aallof(a) a, countof(a)
#define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define apartof(a,i,n) a + (i), a + (i) + (n)
#define long long long

#define EPS 1e-9
#define INF (1L << 30)
#define LINF (1LL << 60)

#define PREDICATE(t,a,exp) [&](const t & a) -> bool { return exp; }
#define COMPARISON_T(t) bool(*)(const t &, const t &)
#define COMPARISON(t,a,b,exp) [&](const t & a, const t & b) -> bool { return exp; }
#define CONVERTER(TSrc,t,TDest,exp) [&](const TSrc &t)->TDest { return exp; }

inline int sign(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }

//// i/o helper ////

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
struct _Writer { bool f; _Writer() : f(false) { } template <class T> _Writer operator ,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
#define WRITE(...) _Writer(), __VA_ARGS__; cout << endl

template <class T> struct vevector : public vector<vector<T>> { vevector(int n = 0, int m = 0, const T &initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) { } };
template <class T> struct vevevector : public vector<vevector<T>> { vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) { } };
template <class T> struct vevevevector : public vector<vevevector<T>> { vevevevector(int n = 0, int m = 0, int l = 0, int k = 0, const T &initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) { } };
template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; }
template <class T> vevector<T> readjag() { return read<T>(read<int>()); }
template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; }

template <class T1, class T2> inline istream & operator >> (istream & in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; }
template <class T1, class T2> inline ostream & operator << (ostream &out, pair<T1, T2> &p) { out << p.first << p.second; return out; }
template <class T> inline ostream & operator << (ostream &out, vector<T> &v)
{
	ostringstream ss;
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	out << s.substr(0, s.length() - 1) << endl;
	return out;
}

/// 2次元
struct P2
{
	double x, y;
	P2(double x = 0, double y = 0) : x(x), y(y) { }
	P2(complex<double> c) : x(c.real()), y(c.imag()) { }
	P2 operator +() const { return *this; }
	P2 operator +(const P2 &_) const { return P2(x + _.x, y + _.y); }
	P2 operator -() const { return P2(-x, -y); }
	P2 operator -(const P2 &_) const { return *this + -_; }
	P2 operator *(double _) const { return P2(x*_, y*_); }
	P2 operator /(double _) const { return P2(x / _, y / _); }
	double dot(const P2 &_) const { return x*_.x + y*_.y; } // 内積
	double cross(const P2 &_) const { return x*_.y - y*_.x; } // 外積
	double sqlength() const { return x*x + y*y; } // 二乗長さ
	double length() const { return sqrt(sqlength()); } // 長さ
	P2 orthogonal() const { return P2(y, -x); }
	P2 direction() const { return *this / length(); } // 方向ベクトル
};
inline istream & operator>>(istream & in, P2 & p) { in >> p.x >> p.y; return in; }
inline ostream & operator<<(ostream & out, const P2 & p) { out << p.x << ' ' << p.y; return out; }
inline double abs(P2 p2) { return p2.length(); }
inline P2 orthogonal(P2 p) { return p.orthogonal(); }
inline complex<double> orthogonal(complex<double> c) { return  c * complex<double>(0, 1); }

// a,b から ちょうど d だけ離れた点。aとbを円周に持つ円の半径。
inline pair<P2, P2> get_same_distance_points(P2 a, P2 b, double d)
{
	assert(abs(a - b) <= 2 * d + EPS);
	auto v = (a + b) / 2.0 - a; // a から aとbの中点
	auto vl = abs(v);
	auto wl = sqrt(d*d - vl*vl); // 直行Vの大きさ
	auto w = orthogonal(v) * (wl / vl); // 直行V
	return make_pair(a + v + w, a + v - w);
}

// a から b に向かって、cが右手か左手か。
inline int clockwise(P2 a, P2 b, P2 c)
{
	const P2 u = b - a, v = c - a;
	if (u.cross(v) > EPS) { return 1; }
	if (u.cross(v) < -EPS) { return -1; }
	if (u.dot(v) < -EPS) { return -1; }
	if (u.sqlength() < v.sqlength() - EPS) { return 1; }
	return 0;
}

/// 直線
struct Line
{
	P2 p, d;
	explicit Line(P2 pos = P2(), P2 dir = P2()) : p(pos), d(dir) { }
	static Line FromPD(P2 pos, P2 dir) { return Line(pos, dir); }
	static Line From2Point(P2 a, P2 b) { return Line(a, b - a); }
};

/// 線分
struct LineSeg
{
	P2 p, d;
	explicit LineSeg(P2 pos = P2(), P2 dir = P2()) : p(pos), d(dir) { }
	static LineSeg FromPD(P2 pos, P2 dir) { return LineSeg(pos, dir); }
	static LineSeg From2Point(P2 a, P2 b) { return LineSeg(a, b - a); }
	operator Line() { return Line(p, d); }
};

inline P2 projective(P2 a, P2 b) { return a * (a.dot(b) / a.length()); }
inline P2 perpendicular_foot(P2 a, Line b) { Line l = Line(b.p - a, b.d); return a + l.p - projective(l.p, l.d); }
inline LineSeg projective(LineSeg a, Line b) { return LineSeg(perpendicular_foot(a.p, b), projective(a.d, b.d)); }

// 交点
inline P2 crossPoint(Line a, Line b) { return a.p + a.d * (b.d.cross(b.p - a.p) / b.d.cross(a.d)); }

// 包括判定
inline bool contains(LineSeg a, P2 p) { return abs(a.p - p) + abs(a.p + a.d - p) - abs(a.d) < EPS; }

// 交差判定
inline bool isCross(Line a, Line b) { return abs(a.d.cross(b.d)) > EPS; }
inline bool isCross(Line a, LineSeg b) { return sign(a.d.cross(b.p - a.p)) * sign(a.d.cross(b.p + b.d - a.d)) <= 0; }
inline bool isCross(LineSeg a, Line b) { return isCross(b, a); }
inline bool isCross(LineSeg a, LineSeg b)
{
	P2 ae = a.p + a.d, be = b.p + b.d;
	return clockwise(a.p, ae, b.p) * clockwise(a.p, ae, be) <= 0
		&& clockwise(b.p, be, a.p) * clockwise(b.p, be, ae) <= 0;
}

// 重なり判定
inline bool isOverlap(Line a, Line b) { return abs(a.d.cross(b.p - a.p)) < EPS; }
inline bool isOverlap(Line a, LineSeg b) { return isOverlap(a, Line(b.p, b.d)); }
inline bool isOverlap(LineSeg a, Line b) { return isOverlap(b, a); }
inline bool isOverlap(LineSeg a, LineSeg b)
{
	return contains(a, b.p) || contains(a, b.p + b.d)
		|| contains(b, a.p) || contains(b, a.p + a.d);
}

// 距離
inline double getDistance(P2 a, P2 b) { return (a - b).length(); }
inline double getDistance(P2 a, Line b) { return abs(b.d.cross(a - b.p) / b.d.length()); }
inline double getDistance(P2 a, LineSeg b) { return min(getDistance(perpendicular_foot(a, (Line)b), a), min(getDistance(b.p, a), getDistance(b.p + b.d, a))); }
inline double getDistance(Line a, P2 b) { return getDistance(b, a); }
inline double getDistance(Line a, Line b) { return isCross(a, b) ? 0 : getDistance(a, b.p); }
inline double getDistance(Line a, LineSeg b) { return isCross(a, b) ? 0 : min(getDistance(a, b.p), getDistance(a, b.p + b.d)); }
inline double getDistance(LineSeg a, P2 b) { return getDistance(b, a); }
inline double getDistance(LineSeg a, Line b) { return getDistance(b, a); }
inline double getDistance(LineSeg a, LineSeg b) { return isCross(a, b) ? 0 : min(min(getDistance(a.p, b.p), getDistance(a.p, b.p + b.d)), min(getDistance(a.p + a.d, b.p), getDistance(a.p + a.d, b.p + b.d))); }

// a から ta, bから tb だけ離れた点。ta=tb=r なら aとbに内接する円
inline pair<pair<P2, P2>, pair<P2, P2>> get_distance_points(Line a, double ta, Line b, double tb)
{
	assert(isCross(a, b));

	P2 va = a.d.orthogonal().direction() * ta;
	P2 vb = b.d.orthogonal().direction() * tb;
	return make_pair(
		make_pair(
			crossPoint(Line(a.p + va, a.d), Line(b.p + vb, b.d)),
			crossPoint(Line(a.p + va, a.d), Line(b.p - vb, b.d))
		), make_pair(
			crossPoint(Line(a.p - va, a.d), Line(b.p + vb, b.d)),
			crossPoint(Line(a.p - va, a.d), Line(b.p - vb, b.d))
		));
}

/// 円
struct Circle
{
	P2 c;
	double r;
	Circle() : c(), r() { }
	Circle(double x, double y, double r) : c(x, y), r(r) { }
	Circle(P2 c, double r) : c(c), r(r) { }
	bool IntersectWith(const Circle &rhs) const { return abs(c - rhs.c) - (r + rhs.r) < EPS; } // 接してても真。
	bool Contains(const P2 &p) const { return abs(p - c) - r < EPS; } // 接してても真。
};
inline istream & operator>>(istream & in, Circle & c) { in >> c.c >> c.r; return in; }

// 交差している2円の交点を求める。角度の小さい方から出る(右下方向が正なら時計回り)
inline pair<P2, P2> crossPoint(Circle A, Circle B)
{
	P2 v = B.c - A.c;
	P2 dir = v.direction(); // 他方の中心への方向
	double d = v.length(); // 他方の中心への距離
	double lh = (A.r*A.r + d*d - B.r*B.r) / (2 * d); // 垂線の足までの距離
	P2 h = A.c + dir * lh; // 垂線の足
	double lp = sqrt(A.r*A.r - lh*lh); // 垂線の足から交点までの距離
	P2 p = dir.orthogonal() * lp; // 垂線の足から交点へのベクトル
	return make_pair(h + p, h - p); // 交点の組。
}

/// 長方形
struct Rect
{
	P2 l, s;
	Rect() : l(), s() { }
	Rect(double x, double y, double w, double h) : l(x, y), s(w, h) { }
	Rect(P2 location, P2 size) : l(location), s(size) { }
	bool Contains(const P2 &p) const { return p.x - l.x > -EPS && p.y - l.y > -EPS && p.x - (l.x + s.x) < EPS && p.y - (l.y + s.y) < EPS; } // 接してても真。
};

//// start up ////
void solve();
int main()
{
	solve();
	return 0;
}


////////////////////
/// template end ///
////////////////////

void solve()
{
	int cases = INF;
	REP(_, cases)
	{
		READ(int, W, H, N, R);
		if (!W) { break; }

		struct Laser { Line line; double thick; };
		vector<Laser> beams;
		REP(i, N)
		{
			READ(double, x, y, z, w, t);
			beams.push_back({ Line::From2Point(P2(x, y), P2(z, w)), t });
		}
		
		// 画面端も死ぬ
		beams.push_back({ Line::From2Point(P2(0, 0), P2(W, 0)), 0 });
		beams.push_back({ Line::From2Point(P2(W, 0), P2(W, H)), 0 });
		beams.push_back({ Line::From2Point(P2(W, H), P2(0, H)), 0 });
		beams.push_back({ Line::From2Point(P2(0, H), P2(0, 0)), 0 });

		// 移動可能範囲
		Rect screen(R, R, W - R, H - R);
		
		bool ok = false;
		for (auto i : beams) for (auto j : beams)
		{
			//WRITE("i:", i.line.p, i.thick, "j:", j.line.p, j.thick);
			if (isCross(i.line, j.line))
			{
				// 点の候補
				auto cand = get_distance_points(i.line, i.thick + R, j.line, j.thick + R);
				P2 ps[] = { cand.first.first, cand.first.second, cand.second.first, cand.second.second, };

				for (auto p : ps)
				{
					
					// その位置は、移動可能でかつすべてのレーザーに当たらない？
					bool test = true;
					test &= screen.Contains(p);
					if (!test) continue;
					
					//WRITE(p);
					for (auto k : beams)
					{
						//WRITE("k:", k.line.p, k.thick, 
						//	"distance:", getDistance(k.line, p),
						//	"need:", (k.thick + R),
						//	"is ok? ", (getDistance(k.line, p) - (k.thick + R) > -EPS));
						test &= (getDistance(k.line, p) - (k.thick + R) > -EPS);
					}
					ok |= test;
					//WRITE(p, "ok? ", ok);
					if (ok) break;
				}
			}
			else
			{
				// 平行……。今回は画面端があるので、平行は考えなくてよい。
			}
		}

		WRITE(ok ? "Yes" : "No");
	}
}
accuracy: 1
time_ms: 70
memory_kb: 1244
final_rank: 3

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

typedef complex<double> P;

const double eps = 1e-8;

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

double dot(P a, P b) {
  return a.real()*b.real() + a.imag()*b.imag();
}

bool heikou(P a, P b) {
  return equals(cross(a,b), 0.0);
}

P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  return a1 + a * cross(b, b1 - a1) / cross(b, a);
}

int ccw(P p, P a, P b) {
  a -= p;
  b -= p;
  if(cross(a,b) > eps) return 1;
  if(cross(a,b) < -eps) return -1;
  if(dot(a,b) < -eps) return 2;
  if(norm(b)-norm(a) > eps) return -2;
  return 0;
}

double getDistanceLP(P s1, P s2, P p) {
  return abs(cross(s2-s1, p-s1))/abs(s2-s1);
}

double W, H, N, R;
vector<P> S, T;

P getP(P a, P b, P c, P d) {
  P s = a - b;
  s /= abs(s);
  P t = d - c;
  t /= abs(t);
  P M = getCrossP(a,b,c,d);
  P st = s + t;
  double H = abs(cross(s, t));
  return M + st * R / H;
}

int main() {
  while(cin >> W >> H >> N >> R) {
    if(W == 0 && H == 0 && N == 0 && R == 0) break;
    S.clear(); T.clear();
    for(int i = 0; i < N; ++i) {
      P a, b;
      double t;
      cin >> a.real() >> a.imag() >> b.real() >> b.imag() >> t;
      P base = b - a;
      P n(-base.imag(), base.real());
      n /= abs(n);
      S.push_back(a + n*t);
      T.push_back(b + n*t);
      S.push_back(b - n*t);
      T.push_back(a - n*t);
    }
    S.push_back(P(0,0));
    T.push_back(P(W,0));
    S.push_back(P(W,0));
    T.push_back(P(W,H));
    S.push_back(P(W,H));
    T.push_back(P(0,H));
    S.push_back(P(0,H));
    T.push_back(P(0,0));
    vector<P> ps;
    for(int i = 0; i < S.size(); ++i) {
      for(int j = i+1; j < S.size(); ++j) {
	if(heikou(T[i]-S[i], T[j]-S[j])) continue;
	ps.push_back(getP(S[i],T[i],S[j],T[j]));
      }
    }

    bool ans = false;
    for(int k = 0; k < ps.size(); ++k) {
      bool flag = true;
      for(int i = 0; i < 2*N; i += 2) {
	bool a, b;
	{
	  double d = getDistanceLP(S[i],T[i],ps[k]);
	  a = (ccw(S[i],T[i],ps[k]) == 1 && (equals(d, R) || d > R));
	}
	{
	  double d = getDistanceLP(S[i+1],T[i+1],ps[k]);
	  b = (ccw(S[i+1],T[i+1],ps[k]) == 1 && (equals(d, R) || d > R));
	}
	if(!a && !b) {
	  flag = false;
	  break;
	}
      }
      for(int i = 2*N; i < S.size(); ++i) {
	double d = getDistanceLP(S[i],T[i],ps[k]);
	bool a = (ccw(S[i],T[i],ps[k]) == 1 && (equals(d, R) || d > R));
	if(!a) {
	  flag = false;
	  break;
	}
      }
      if(flag) {
	ans = true;
	break;
      }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1896
final_rank: 6