# Programming contests

## ECN programozó csapatverseny, 2017. május 13.

May 13, 2017 10:10 AM – May 13, 2017 3:10 PM

# ECN Buses

For the first edition of the Sapientia ECN contest, continuous bus transport was organized from the train station (A) to Sapientia University (B) and back. The bus line from A to B is divided into N unit-distance (uD) parts (so the total length of the route is N*uD). Any given bus travels a unit distance in a unit time (uT). Departure times from the train station (A) are at times 0*uT, a*uT, 2*a*uT, … (over the years the bus traffic between the train station and Sapientia University has become a permanent and continuous arrangement, so buses will depart continuously at moments multiple of a*uT). When a bus arrives to the University (B), it will wait till the closest time spot which is an integer multiple of a*uT and then it returns to the train station (A). Along the route A>>B there are stops at positions 0*uD, x1*uD, x2*uD, …, xn*uD, N*uD, and on the way back, B>>A, at positions N*uD, yn*uD, yn – 1*uD, …, y1*uD, 0*uD of the bus line. At every stop, the bus waits b*uT time.

Which are those uD multiple points (i*uD, i ∈ {0, 1, …, N}) and uD length open intervals ((i*uD, (i + 1)*uD), i ∈ {0, 1, …, N – 1}) of the bus line, where two buses will meet? Only the meeting point indexes ([i], i ∈ {0, 1, …, N}) and the endpoints indexes of the meeting intervals ((i, (i + 1)), i ∈ {0, 1, …, N – 1}) have to be printed. Which are those segments of the type [i*uD, (i + 1)*uD), i ∈ {0, 1, …, N – 1} of the bus line, where two buses will meet?

## Input Specification

The first line of the input contains the number of test cases. The input format of each test case is the following:
uT uD
N n
a b
x1 x2xn
y1 y2yn

## Output Specification

Print consecutive lines the uT multiple meeting points indexes (in square brackets) and meeting intervals endpoint indexes (in brackets, separated with comma) (sorted in ascending order) followed by the number of meetings.

## Restrictions

• All input values are integers.
• 0 < N < 1000
• 0 < uTuD < 100
• 0 < ab < 50
• 0 < x1 < x2 < … < xn < N
• 0 < y1 < y2 < … < yn < N

## Sample Input

1. `1`
2. `3 11`
3. `100 5`
4. `20 3`
5. `20 40 60 70 90`
6. `20 40 50 80 90`

## Output for Sample Input

1. `[0]`
2. `(7,8)`
3. `(17,18)`
4. `(24,25)`
5. `(34,35)`
6. `(41,42)`
7. `[50]`
8. `[60]`
9. `(68,69)`
10. `[77]`
11. `(85,86)`
12. `(92,93)`
13. `[100]`
14. `13`