Couriers

No attempts yetTime limit1sMemory limit1024 MB

Problem

A food-delivery company employs two couriers. Both couriers start work at the same moment every morning, at the start of the day, time t=0t = 0 minutes. Orders arrive during the day, and for each order the following is known:

  • the time the order was received (in minutes);
  • the value the courier earns for completing it;
  • the times it would take each courier to complete the order (in minutes). For a single order the two couriers' times are different.

An order is assigned to a free courier (one not currently working on any order at that moment) who could complete it the fastest. If both couriers are busy at that moment, the customer turns to another company and the order is lost.

If a courier finishes a previous order at exactly the minute a new order arrives, that courier is considered free at that moment.

The couriers finish work once they have completed every order received during the day.

Compute how much each courier earns during the day.

Input

The first line contains the number of orders MM. Each of the next MM lines describes one order, in the order t v z1 z2t\ v\ z_1\ z_2:

  • tt — the time the order is received, in minutes from the start of the workday. All order times are distinct and given in increasing order.
  • vv — the value the courier earns for completing the order.
  • z1, z2z_1,\ z_2 — the times it takes the first and the second courier, respectively, to complete this order (in minutes). The two values for one order are different.

Output

Print two integers on one line: the total earnings of the first and of the second courier that day, respectively.

Constraints

  • 1M10001 \le M \le 1000
  • 1t1<t2<<tM10001 \le t_1 < t_2 < \dots < t_M \le 1000
  • 1vi10001 \le v_i \le 1000
  • 1zi1001 \le z_i \le 100