Under construction

Still being built. Things may change

Cruise Control (Small)

Time limit5sMemory limit512 MB

Summary
Cars on two lanes hold fixed speeds and may change lanes freely, so decide if all can drive forever or report the latest moment a slowdown is forced.
Level

Medium7 of 10

Topics
Brute force, Simulation
Solved
No attempts yet

Problem

Cruise control is a system that lets a car hold a constant speed while the driver only steers. The driver can of course switch cruise control off to avoid a collision.

This problem uses a one way road with two lanes and NN cars driving on it with cruise control. Every car is 5 meters long and drives at its own constant speed. A car may change lanes at any moment as long as the change causes no collision. Two cars touching is not a collision. A lane change is instantaneous and only moves the car to the other lane. Two cars driving side by side cannot swap places by changing lanes at the same moment. Decide whether somebody eventually has to switch cruise control off to avoid a collision, or whether every car can keep its speed forever while changing lanes whenever it needs to.

Input

The first line has the number of test cases TT. The first line of each test case has the number of cars NN. The next NN lines describe one car each. A line has a character CiC_i that tells which lane the car starts in, the speed SiS_i of the car in meters per second, and the starting position PiP_i of the car in meters. PiP_i is the distance from the rear end of the car to a fixed line drawn across the road. Every car drives away from that line and no car is behind it.

Limits

  • 1≤T≤301 \le T \le 30
  • 1≤N≤61 \le N \le 6
  • 1≤Si≤10001 \le S_i \le 1000
  • 0≤Pi≤100000 \le P_i \le 10000
  • CiC_i is either L for the left lane or R for the right lane.
  • The cars do not collide at the start, so if cars ii and jj start in the same lane (Ci=CjC_i = C_j) then ∣Pi−Pj∣≥5|P_i - P_j| \ge 5.

Output

For each test case print one line in the form "Case #x: y", where xx is the test case number starting from 1. If every car can keep its given speed forever, yy is the word Possible. Otherwise yy is the largest number of seconds the cars can drive before somebody has to change speed.

That time is always rational, so print it exactly as an irreducible fraction. If the answer is an integer aa, print only aa. Otherwise print a/ba/b with b≥2b \ge 2 and gcd⁡(a,b)=1\gcd(a, b) = 1. For example, print 7/5 for an answer of 1.4 seconds and 12 for an answer of 12 seconds. A decimal answer is judged wrong.

Note

In the first test case of the first example the faster car moves to the right lane and passes the slower one without trouble. In the second test case the two cars driving side by side at 100 meters per second reach the car driving at 50 meters per second after 10 seconds, and both lanes are blocked, so somebody has to change speed.

The first test case of the second example has an answer that is not an integer. Two pairs of cars overlap at the start and cannot leave their lanes, and the road is blocked after 13/6 seconds.

Examples2

  1. Example 1

    Input
    4
    2
    L 5 10
    L 100 0
    3
    L 100 0
    R 100 0
    L 50 505
    6
    L 30 0
    R 30 2
    L 10 39
    R 10 42
    L 25 13
    L 15 29
    4
    L 4 0
    L 2 29
    L 1 35
    L 1 44
    
    Expected output
    Case #1: Possible
    Case #2: 10
    Case #3: 7/5
    Case #4: 12
    
  2. Example 2

    Input
    4
    5
    R 6 37
    R 8 20
    L 4 10
    L 4 38
    L 10 20
    3
    L 3 0
    R 1 2
    L 1 5
    1
    L 1000 10000
    2
    L 7 4000
    R 7 4000
    
    Expected output
    Case #1: 13/6
    Case #2: 0
    Case #3: Possible
    Case #4: Possible