Олимпиадный тренинг

Задача 38201. Runners


Задача

Темы: Целые числа
Two runners train on the 400-meter athletics track. They start running from one point and run according to the instructions of the coach for the specified number of minutes at the specified speed (speed is the number of meters that the athlete runs along the track in a minute). It is required to determine the distance at which the runners will be from each other at the end of the workout (the distance is the length of the shorter part of the arc of the track between the athletes).

Input
The first line contains a single number – the number of tasks that each athlete received from the coach (both athletes receive the same number of tasks). Each of the following lines contains tasks for athletes in the following format:

v1 t1 v2 t2

where v1 – speed  of the first player (in m/min), t1 – the time during which the athlete must run at a speed v1; v2 and t2 – corresponding values ​​for the second player. Speeds – positive numbers if you want to run in a clockwise direction, and negative if you want to run counterclockwise.

Imprint
Print one number – distance between runners at the end of the workout.
Examples
# Input Output
1 2
8000 1 8000 1 
8000 10 8001 10 
10
2 1
50 4 -100 1
100