{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n HEU的学生,进行军训机动演习... \n \u003cbr\u003e今天,红军和蓝军打战啦。蓝军发现小A是红军派来的25仔,所以小A要逃啊。战场是一个大小为m*n的矩形,蓝军的总部在(0,0)处而红军的在(m,n)处。 如下图,展示了战场的形状以及,我们接下来将会使用到的方向的符号。\n \u003cbr\u003e \n \u003cbr\u003e \n \u003ccenter\u003e \n \u003cimg style\u003d\"max-width:100%;\" SRC\u003d\"CDN_BASE_URL/252c1e6068582b02d3526585012ca47e?v\u003d1545834681\"\u003e \n \u003c/center\u003e \n \u003cbr\u003e \n \u003cbr\u003e蓝军在地图上放置了许多会在固定方向\u0026定期地发射子弹的堡垒。小A不过走不走,每一秒都会耗费一点hp,如果他hp用尽,或者被子弹射到,那他就gg了。 小A能走北南西东四个方向,每秒可走一个单元。值得注意的是,为了不被射到,小A可能会在呆在原地不动,选择苟活。\n \u003cbr\u003e让我们简化一下问题, 让我们假设当前小A不会在某一个中停留。小A在移动时,既不会被射中,也不会能阻止子弹的运动。这意味着,子弹仅仅能在小A在整数格时,干掉他。考虑如下例子,子弹从(0,3)射到(0,0),以一秒3个单元的速度金发碧眼,并且当前小A从(0,0)点以一秒一个单元的速度往(0,1)点前进。那么,当前这种情况下,小A不会被射死(WTF)。但如果子弹以一个两个单元的速度前进,则小A会在(0,1)单元被射死。 \n \u003cbr\u003e请告诉我们,小A会死不会死\n \u003cbr\u003e \n\u003c/div\u003e"}},{"title":"Input","value":{"format":"MD","content":"For every test case, the first line has four integers, m, n, k and d (2\u0026lt;\u003dm, n\u0026lt;\u003d100, 0\u0026lt;\u003dk\u0026lt;\u003d100, m+ n\u0026lt;\u003dd\u0026lt;\u003d1000). m and n are the size of the battle ground, k is the number of castles and d is the units of energy Little A initially has. The next k lines describe the castles each. Each line contains a character c and four integers, t, v, x and y. Here c is ‘N’, ‘S’, ‘E’ or ‘W’ giving the direction to which the castle shoots, t is the period, v is the velocity of the bullets shot (i.e. units passed per second), and (x, y) is the location of the castle. Here we suppose that if a castle is shot by other castles, it will block others’ shots but will NOT be destroyed. And two bullets will pass each other without affecting their directions and velocities. \n\u003cbr\u003eAll castles begin to shoot when Little A starts to escape. \n\u003cbr\u003eProceed to the end of file. \n\u003cbr\u003e"}},{"title":"Output","value":{"format":"MD","content":"如果小A能逃跑,在一行中输入其所需的最小秒数。否则,在一行中输出\"Bad luck!\"(无需带引号)"}},{"title":"Sample Input","value":{"format":"MD","content":"\u003cpre\u003e4 4 3 10\nN 1 1 1 1\nW 1 1 3 2\nW 2 1 2 4\n4 4 3 10\nN 1 1 1 1\nW 1 1 3 2\nW 1 1 2 4\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"MD","content":"\u003cpre\u003e9\nBad luck!\u003c/pre\u003e"}}]}