Belts

No attempts yetTime limit1sMemory limit256 MB

Problem

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 00 for the untwisted O shape and 11 for the twisted figure-eight shape.

Belt iiRotations of wheel iiRotations of wheel i+1i+1Belt shape
1120
2151
3210

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.

Input

The first line contains the number of belts MM (1M10001 \le M \le 1000). Each of the next MM lines describes one belt, starting from belt 1. The ii-th of those lines contains three integers aa, bb, and ss separated by spaces. Belt ii joins wheel ii and wheel i+1i+1, wheel i+1i+1 turns bb times while wheel ii turns aa times, and ss is the shape of the belt: 00 for the untwisted O shape and 11 for the twisted figure-eight shape.

aa and bb are positive integers not greater than 10910^9, and they are coprime. The input is such that the rotations per minute of every wheel is a positive integer not greater than 10910^9.

Output

Print the rotation direction and the rotations per minute of wheel M+1M+1 on one line, separated by a space. The direction is 00 for clockwise and 11 for counterclockwise.