Hide

Problem B
Cars

/problems/cars/file/statement/en/img-0001.jpg
Picture by Sammmerbatter via Wikimedia Commons, cc by-sa
You work as an engineer at the leading self-driving car company Wayber. Wayber just got approval from the government of Sweden for their cars to drive in the streets of Stockholm. Unfortunately, all your tests so far have been with one car at a time on a closed dirt track. You are not really prepared for what will happen when two of the cars encounter each other in the city, and want to write some code to handle this.

The cars are already good at staying inside the lines and turning. However, they are not very good at detecting other moving vehicles. Fortunately, the government of Sweden is so enthusiastic about self-driving cars that they have banned all other forms of transportation in Stockholm, including human-driven cars, biking, and walking. If you can just detect whether two cars will collide you will be able to build a safe system.

You know that all cities consist of only north-south and east-west oriented streets in a perfect grid, and all cars are perfect rectangular prisms. When detecting collisions you only need to worry about cars traveling at a constant speed without turning.

\includegraphics[width=0.35\textwidth ]{sample1}
Figure 1: Illustration of Sample Input 1.

Input

The first line of input contains an integer $1 \le t \le 10^4$, the duration in seconds of the trajectory of the two cars. Then follow the description of the trajectory of two cars.

A trajectory consists of a line containing a character $d$ and five integers $x$, $y$, $s$, $w$ and $l$. The starting position of the car is $(x,y)$ ($0 \le x, y \le 10^4$) and its direction is $d$ which is either N (positive $y$ direction), S (negative $y$ direction), W (negative $x$ direction) or E (positive $x$ direction). The car is travelling at a speed of $1 \le s \le 10^4$ units per second, is $1 \le w \le 10^4$ units wide, and $1 \le l \le 10^4$ units long.

Cars start out centred on their starting coordinates and do not initially overlap in a nonzero area.

Output

For each line of input, output a line “crash” if the two cars will crash or “safe” if they will not crash. If two cars overlap in an area of size zero (only on an edge or corner) they do not crash.

Sample Input 1 Sample Output 1
5
E 0 0 2 1 2
S 3 2 1 1 3
crash
Sample Input 2 Sample Output 2
1
E 0 0 1 1 1
N 0 2 1 1 1
safe
Sample Input 3 Sample Output 3
2
N 0 0 7 3 1
S 3 20 12 4 1
crash

Sample Input 4 Sample Output 4
1
N 0 0 7 3 1
S 3 20 12 4 1
safe

Please log in to submit a solution to this problem

Log in