Under construction

Still being built. Things may change

Cars

Time limit1sMemory limit512 MB

Summary
Two axis-aligned rectangular cars move at constant speed in a grid city for t seconds; decide whether they ever overlap in a positive-area region, treating edge-only touches as safe.
Level

Medium7 of 10

Topics
Geometry, Implementation, Math, Simulation
Solved
No attempts yet

Problem

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.

Figure B.1: Illustration of Sample Input 1.

Input

The first line of input contains an integer 1≤t≤1041 \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 dd and five integers xx, yy, ss, ww and ll. The starting position of the car is (x,y)(x, y) (0≤x,y≤1040 \le x, y \le 10^4) and its direction is dd which is either N (positive yy direction), S (negative yy direction), W (negative xx direction) or E (positive xx direction). The car is travelling at a speed of 1≤s≤1041 \le s \le 10^4 units per second, is 1≤w≤1041 \le w \le 10^4 units wide, and 1≤l≤1041 \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.

Examples4

  1. Example 1

    Input
    5
    E 0 0 2 1 2
    S 3 2 1 1 3
    
    Expected output
    crash
    
  2. Example 2

    Input
    1
    E 0 0 1 1 1
    N 0 2 1 1 1
    
    Expected output
    safe
    
  3. Example 3

    Input
    2
    N 0 0 7 3 1
    S 3 20 12 4 1
    
    Expected output
    crash
    
  4. Example 4

    Input
    1
    N 0 0 7 3 1
    S 3 20 12 4 1
    
    Expected output
    safe