#include #include #include #include #include #include #include #include #include #include #include #include #define FORE(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define FC(aa, bb) FORE(bb, aa) #define debug(x) cerr << #x << " = " << x << endl; #define debugv(x) cerr << #x << " = " ; FORE(it, (x)) cerr << *it << ", "; cerr << endl; #define fup(i, a, b) for(int i = (a); i <= (b); ++i) #define fdo(i, a, b) for(int i = (a); i >= (b); --i) #define FOR fup #define FORD fdo #define REP(i, n) for(int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define CLR(x) memset((x), 0, sizeof(x)) #define MP make_pair #define PB push_back #define siz(a) ((int)(a).size()) #define SZ siz #define inf 1000000000 #define FI first #define SE second using namespace std; typedef long long lli; typedef double ld; typedef lli LL; typedef ld LD; typedef vector VI; typedef pair PII; typedef complex C; typedef complex Cd; namespace std { bool operator < (C const &a, C const &b) { return real(a) < real(b) || (real(a) == real(b) && imag(a) < imag(b)); } } struct segm { segm(C _a = 0, C _b = 0): a(_a), b(_b) { if (b < a) swap(a,b); } C a; C b; bool operator < (segm const &s) const { return a < s.a || (a == s.a && b < s.b); } bool operator==(segm const &s) const { return a == s.a && b == s.b; } void print() { // printf("%lld %lld -- %lld %lld\n", real(a), imag(a), real(b), imag(b)); } }; bool cc(C a, C b) { return imag(b*conj(a)) == 0; } vector seg; vector fine; vector fine2; const double eps=1e-8; pair colin(segm x, segm y) { if (!cc(x.b-x.a, y.b-y.a) || !cc(x.b-x.a, y.b-x.a)) return MP(false, segm()); C mn = min(x.a, y.a), mx = max(x.b, y.b); C a = max(x.a, y.a); C b = min(x.b, y.b); segm res(mn, mx); if (b < a) return MP(false, segm()); else return MP(true, res); } void put(segm s) { s.print(); REP(i, siz(fine)) { pair r = colin(s, fine[i]); if (r.FI) { seg.PB(r.SE); swap(fine[i], fine[siz(fine)-1]); fine.pop_back(); return; } } fine.PB(s); } bool integ(double d) { return abs(d - round(d)) < eps; } C convert(C x, C a, Cd m, bool &ok) { x -= a; Cd res = Cd(real(x), imag(x)); res *= m; if (integ(real(res)) && integ(imag(res))) return res; else { ok = false; return 0; } } bool solve() { fine2.clear(); REP(t, 2) { seg.clear(); fine.clear(); char c[10]; int x, y; C cur = 0; while(true) { scanf("%s", c); if (c[0] == 'L' || c[0] == 'M') { scanf("%d%d", &x, &y); if (c[0] == 'L') seg.PB(segm(cur, cur+C(x,y))); cur += C(x,y); } else if (c[0] == 'E') break; else return false; } REP(i, siz(seg)) { put(seg[i]); } if (siz(fine) > 0) { FOR(i, 1, siz(seg)-1) { fine[i].a -= fine[0].a; fine[i].b -= fine[0].a; } fine[0].b -= fine[0].a; fine[0].a = 0; sort(ALL(fine)); } if (t == 0) swap(fine, fine2); } if (siz(fine) == 0 && siz(fine2) == 0) { printf("YES\n"); return true; } if (siz(fine) != siz(fine2)) { printf("NO\n"); return true; } FORE(it, fine2) { vector S = fine2; segm xv = *it; REP(t, 2) { if (t == 1) swap(xv.a, xv.b); C a = xv.a; C len = xv.b - xv.a; Cd mult = Cd(real(fine[0].b), imag(fine[0].b)) / Cd(real(len), imag(len)); bool ok = true; FORE(it, S) { it -> a = convert(it -> a, a, mult, ok); it -> b = convert(it -> b, a, mult, ok); if (it -> b < it -> a) swap(it -> a, it -> b); if (!ok) break; } if (!ok) continue; sort(ALL(S)); REP(i, siz(S)) { if (!(S[i] == fine[i])) { ok = false; break; } } if (ok) { printf("YES\n"); return true; } } } printf("NO\n"); return true; } int main() { while(solve()) {}; return 0; }