Biologist

Time limit1sMemory limit128 MB

Problem

Kangsan, who dreams of becoming a biologist, received a microscope as a New Year gift.

One day, while observing bacteria in water, Kangsan noticed that their movement follows a fixed rule.

Model the water drop as an infinite square grid. Each bacterium is in one grid cell, and its direction is represented by a number in the table below.

123
8B4
765

All bacteria move simultaneously. Every second, each bacterium moves one cell in its own fixed direction. Multiple bacteria may occupy the same cell.

Given every bacterium's starting position and direction, find the maximum number of bacteria that ever occupy one cell at the same time, and the first time when that maximum occurs. If the same maximum occurs at several times, output the earliest time.

Input

The first line contains the number of bacteria N. 1 ≤ N ≤ 5,000

Each of the next N lines contains three integers X, Y, and D. -1,000,000 ≤ X, Y ≤ 1,000,000, 1 ≤ D ≤ 8

X and Y are the starting coordinates of a bacterium, and D is its direction. The value of X increases from left to right, and the value of Y increases upward.

No two bacteria start at the same position. At least once, two or more bacteria occupy the same cell.

Output

On the first line, output the maximum number of bacteria that occupied one cell at the same time.

On the second line, output the first time when that maximum occurred.