This page is still under construction.

Parts of this page are still being built. What you see may change.

Ship Traffic

Time limit3sMemory limit256 MB

Summary
Find the longest subinterval of start times in [t1, t2] during which a northbound ferry avoids every moving ship in each lane.
Level

Medium6 of 10

Topics
Intervals, Sorting, Math
Solved
No attempts yet

Problem

A ferry crossing the Strait of Gibraltar from Morocco to Spain has to steer clear of the ships that run along the strait. Write a program that finds the longest span of time in which the captain can cross safely.

The model is this. The strait holds several parallel shipping lanes running east and west. Every ship moves at the same speed uu, and all ships in one lane move the same way, either eastbound or westbound. Ships may have different lengths. A ship never changes lane and never changes speed for the crossing ferry.

The ferry waits for a quiet moment, then crosses northbound along a north-south line at speed vv. From the moment the ferry enters a lane until the moment it leaves that lane, no ship in that lane may touch the line. The ferry is small enough that its size is ignored. Every lane has the same width ww and there is no space between lanes, so a ferry that starts at time tt enters lane ii at time t+(i−1)w/vt + (i-1)w/v and leaves it at time t+iw/vt + iw/v.

The figure below shows the lanes and the ships of the first example.

Input

The first line contains six integers nn, ww, uu, vv, t1t_1, t2t_2. Here nn is the number of lanes (1≤n≤1051 \le n \le 10^5), ww is the width of one lane (1≤w≤10001 \le w \le 1000), uu is the speed of the ships, vv is the speed of the ferry (1≤u,v≤1001 \le u, v \le 100), and t1t_1 and t2t_2 are the earliest and the latest start time of the ferry (0≤t1<t2≤1060 \le t_1 < t_2 \le 10^6). Lengths are in meters, speeds are in meters per second, and times are in seconds.

Each of the next nn lines describes one lane. The line starts with E or W. E means the ships in this lane are eastbound, W means they are westbound. Next comes the number of ships in the lane, mim_i (0≤mi≤1050 \le m_i \le 10^5), followed by mim_i pairs of integers lijl_{ij} and pijp_{ij} (1≤lij≤10001 \le l_{ij} \le 1000, −106≤pij≤106-10^6 \le p_{ij} \le 10^6). The length of ship jj in lane ii is lijl_{ij}, and pijp_{ij} is the position at time 0 of its forward end, that is, its front in the direction it moves.

Ship positions are measured from the line the ferry crosses along. A negative position is west of the line and a positive one is east of it. Ships within one lane neither overlap nor touch, and they are given in increasing order of position. Lanes are given by increasing distance from the starting point of the ferry, which lies just south of the first lane. The total number of ships is at least 1 and at most 10510^5.

Output

Let SS be the set of all start times tt with t1≤t≤t2t_1 \le t \le t_2 at which the ferry can cross safely. SS is a union of finitely many intervals. Print the length of the longest of those intervals as an irreducible fraction on one line. If the length is an integer, print that integer alone. Otherwise print it as p/q, where pp and qq are coprime positive integers. The answer is always an integer multiple of 1/(uv)1/(uv). You may assume the longest interval is longer than 0.1.

Examples3

  1. Example 1

    Input
    3 100 5 10 0 100
    E 2 100 -300 50 -100
    W 3 10 60 50 200 200 400
    E 1 100 -300
    
    Expected output
    6
    
  2. Example 2

    Input
    1 100 5 10 0 200
    W 4 100 100 100 300 100 700 100 900
    
    Expected output
    50
    
  3. Example 3

    Input
    1 1 3 7 0 10
    W 2 1 3 1 21
    
    Expected output
    116/21