A science kit lets you run experiments with wheels and belts. The kit holds wheels of several sizes, a set of belts, and a board with sockets for the wheels.
The board has one row of axles, and each axle takes a single wheel. Neighboring axles sit far enough apart that no two wheels touch, even when every axle is filled. The wheels are numbered 1, 2, and so on from the left.
Two wheels that sit next to each other are always joined by exactly one belt. You can loop a belt without twisting it, in an O shape, or twist it once, in a figure-eight shape. Turning one wheel turns the wheel joined to it, and the two rotation counts differ when the wheels have different sizes. Wheels joined by an untwisted belt turn in the same direction, and wheels joined by a twisted belt turn in opposite directions.
Consider four wheels and three belts given as follows. The shape of a belt is written as 0 for the untwisted O shape and 1 for the twisted figure-eight shape.

| Belt i | Rotations of wheel i | Rotations of wheel i+1 | Belt shape |
|---|---|---|---|
| 1 | 1 | 2 | 0 |
| 2 | 1 | 5 | 1 |
| 3 | 2 | 1 | 0 |
Belt 1 joins wheel 1 and wheel 2 in the O shape, and wheel 2 turns twice while wheel 1 turns once. Turning wheel 1 one full turn clockwise turns wheel 2 two full turns clockwise.
Belt 2 joins wheel 2 and wheel 3 in the figure-eight shape, and wheel 3 turns five times while wheel 2 turns once. Turning wheel 2 one full turn clockwise turns wheel 3 five full turns counterclockwise.
Belt 3 joins wheel 3 and wheel 4 in the O shape, and wheel 4 turns once while wheel 3 turns twice. Turning wheel 3 two full turns clockwise turns wheel 4 one full turn clockwise.
So turning wheel 1 one full turn clockwise makes wheel 4 turn five full turns counterclockwise, through wheel 2 and wheel 3.
The rotation ratio and the shape of every belt are given in order. Write a program that prints the rotation direction and the rotations per minute of the last wheel when the first wheel turns clockwise at one rotation per minute.
The first line contains the number of belts M (1≤M≤1000). Each of the next M lines describes one belt, starting from belt 1. The i-th of those lines contains three integers a, b, and s separated by spaces. Belt i joins wheel i and wheel i+1, wheel i+1 turns b times while wheel i turns a times, and s is the shape of the belt: 0 for the untwisted O shape and 1 for the twisted figure-eight shape.
a and b are positive integers not greater than 109, and they are coprime. The input is such that the rotations per minute of every wheel is a positive integer not greater than 109.
Print the rotation direction and the rotations per minute of wheel M+1 on one line, separated by a space. The direction is 0 for clockwise and 1 for counterclockwise.