#include using namespace std; typedef long long ll; typedef long double ld; #define REP(i, N) for(int i=0;i<(N);++i) #define FOR(i, a, b) for(int i=(a);i<=(b);++i) #define FORI(i, a, b) for(int i=(a);i<(b);++i) #define FORD(i, a, b) for(int i=(b)-1;i>=(a);--i) int N; struct Line{ int xf, yf, xt, yt; bool operator==(const Line& l)const{ return xf == l.xf && yf==l.yf && xt==l.xt && yt==l.yt; } }; bool in_line[5500]; Line lines[5500]; struct Segment{ int xd, yd; int norma; int line; void canorma(){ norma = lines[line].xf * yd - lines[line].yf * xd; } bool noteq(const Segment& b)const{ return xd!=b.xd || yd!=b.yd || norma!=b.norma; } bool operator<(const Segment& b)const{ if(xd < b.xd) return true; if(xd > b.xd) return false; if(yd < b.yd) return true; if(yd > b.yd) return false; return norma < b.norma; } }; struct Event{ int line; int time; int x, y; bool operator<(const Event& e)const{ return time resultA; vector resultB; void doEvents(Segment* segs, int ls, vector& output){ REP(i, ls){ events[i*2].line=i; events[i*2].x = lines[segs[i].line].xf; events[i*2].y = lines[segs[i].line].yf; events[i*2].time = events[i*2].x * segs[i].xd + events[i*2].y * segs[i].yd; events[i*2+1].line=i; events[i*2+1].x = lines[segs[i].line].xt; events[i*2+1].y = lines[segs[i].line].yt; events[i*2+1].time = events[i*2+1].x * segs[i].xd + events[i*2+1].y * segs[i].yd; } sort(events, events+ ls*2); int linecount = 0; Line outline; int lastlinecount = 0; REP(i, ls*2){ //printf("e %d %d (%d)\n",events[i].x, events[i].y, events[i].time); if(!in_line[events[i].line]){ linecount++; in_line[events[i].line] = true; } else{ --linecount; in_line[events[i].line] = false; } if(i == ls*2-1 || events[i+1].time!=events[i].time){ if(linecount == 0 && lastlinecount!=0){ //printf("e\n"); outline.xt = events[i].x; outline.yt = events[i].y; output.push_back(outline); } if(linecount != 0 && lastlinecount == 0){ //printf("b\n"); outline.xf = events[i].x; outline.yf = events[i].y; } lastlinecount = linecount; } } } bool compare(){ return resultA == resultB; } void normalizeOffset(int ln){ int mix = lines[0].xf; int miy = lines[0].yf; REP(i, ln){ mix = min(mix, lines[i].xf); mix = min(mix, lines[i].xt); miy = min(miy, lines[i].yf); miy = min(miy, lines[i].yt); } REP(i, ln){ lines[i].xf-=mix; lines[i].xt-=mix; lines[i].yf-=miy; lines[i].yt-=miy; } } void loadNormalize(int n, vector& output){ int cx=0, cy=0; int lineN = 0; REP(i, n){ char c; int x, y; scanf("%c%d%d ",&c, &x,&y); if(c=='L' && (x!=0 || y!=0)){ Line l = {cx, cy, cx+x, cy+y}; //printf("l %d %d %d %d\n", l.xf, l.yf, l.xt, l.yt);//TODO:::: lines[lineN ++ ] = l; } cx+=x; cy+=y; } normalizeOffset(lineN); /*REP(i, lineN){ Line l = lines[i]; printf("l %d %d %d %d\n", l.xf, l.yf, l.xt, l.yt); }*/ /*REP(i, lineN){ printf("g %d %d %d %d\n", segs[i].xd,segs[i].yd); }*/ //------------------------------------------------ REP(i, lineN){ in_line[i] = false; segs[i].line= i ; segs[i].xd = lines[i].xt - lines[i].xf; segs[i].yd = lines[i].yt - lines[i].yf; int g = gcd(myabs(segs[i].xd), myabs(segs[i].yd)); segs[i].xd /= g; segs[i].yd /= g; // X is always positive if(segs[i].xd < 0){ segs[i].xd = -segs[i].xd; segs[i].yd = -segs[i].yd; } // X is 0 then Y positive else if(segs[i].xd == 0 && segs[i].yd<0){ segs[i].yd = -segs[i].yd; } } /*REP(i, lineN){ printf("g %d %d\n", segs[i].xd,segs[i].yd); }*/ //------------------------------------------------ // Serad dle vektoru REP(i, lineN){ segs[i].canorma(); } sort(segs, segs+lineN); int beg = 0; REP(i, lineN){ if(i==lineN-1 || segs[i+1].noteq(segs[i])){ //printf("EVENTS %d:\n", i+1 - beg); doEvents(segs + beg, i+1 - beg, output); beg=i+1; } } //------------------------------------------------ } void solve(){ resultA.clear(); resultB.clear(); loadNormalize(N, resultA); scanf("%d ",&N); loadNormalize(N, resultB); if(compare()){ printf("YES\n"); } else{ printf("NO\n"); } } int main(){ while(scanf("%d ",&N)>0){ solve(); } return 0; }