Clocks

No attempts yetTime limit1sMemory limit128 MB

Problem

In Byteland lives a clockmaker named Gustaw, who has repaired clocks for many years. His workshop is full of old clocks, and every one of them is an analog clock that shows the time with hands. Each clock has two hands: a byte-hour hand and a byte-minute hand, and both hands only ever move forward (clockwise).

In Byteland one byte-hour always lasts exactly 100100 byte-minutes, so every clock has a minute scale divided into 100100 byte-minutes. However, the length of a day in Byteland has changed many times over the years, so the clocks do not all have the same number of byte-hours on their dials. The dial of clock ii is divided into pip_i byte-hours, numbered 00 through pi1p_i - 1.

The king is about to visit, and Gustaw wants to make the best possible impression, so he decides that every clock should show the exact same time. Right now every clock is stopped. Because the clocks are very old and could break, Gustaw must not turn the hands by hand. Instead he may pick any single clock, start it, let it run forward by as many byte-hours and byte-minutes as he likes, and then stop it. He can never run two clocks at the same time, so he must set them one after another, and the times he waits for each clock all add up.

Gustaw picks one target time that every clock is able to display: a whole byte-hour HH together with a byte-minute MM (with 0M<1000 \le M < 100). Because the dial of clock ii only carries the byte-hours 0,1,,pi10, 1, \ldots, p_i - 1, the target byte-hour must satisfy 0H<pi0 \le H < p_i for every clock. He then runs each clock forward from its current reading to that target time. Since the hands only move forward, a clock whose current position is cc byte-minutes (where c=100gi+mic = 100 \cdot g_i + m_i) must run forward by (H100+Mc)mod(pi100)(H \cdot 100 + M - c) \bmod (p_i \cdot 100) byte-minutes.

Help Gustaw choose the target byte-hour and byte-minute so that the total time he spends running the clocks is as small as possible, and report that minimum total time.

Input

The first line contains one integer nn (1n1061 \le n \le 10^6), the number of clocks. Each of the next nn lines describes one clock with three integers gig_i, mim_i, pip_i: the byte-hour currently shown by clock ii, the byte-minute currently shown, and the number of byte-hours on that clock's dial (0gi<pi1090 \le g_i < p_i \le 10^9 and 0mi<1000 \le m_i < 100).

Output

Print one line with two integers: the number of byte-hours and the number of byte-minutes that Gustaw must wait in total when he uses the smallest possible total time. (A total of tt byte-minutes is written as t/100\lfloor t / 100 \rfloor byte-hours and tmod100t \bmod 100 byte-minutes.)