Leapfrog

Given up to 40 frogs, each starting at x_i with prime jump d_i, find the smallest position where the number of frogs that land there is largest.

Hard9Number theoryMathBrute forceNo attempts yetTime limit2sMemory limit512 MB

Problem

Frogs gather on the wide road that cuts through the forest. Whenever frogs meet at the same position, they climb on top of each other and form a tower.

Frog ii starts at position xix_i and moves exactly did_i forward on every jump. Each did_i is a prime, and a frog never jumps backwards, so frog ii can only stand at xix_i, xi+dix_i + d_i, xi+2dix_i + 2 d_i, \dots.

The size of the tower at position pp is the number of frogs that can reach pp, that is the number of indices ii with xipx_i \le p and pxip - x_i divisible by did_i.

The frog king wants to present the largest tower. If several positions carry a tower of that largest size, he picks the smallest such position. Report that position and the size of the tower.

Input

The first line contains the number of frogs nn (1n401 \le n \le 40).

Each of the next nn lines contains the start position xix_i and the jump distance did_i of one frog, separated by a space (0xi2600 \le x_i \le 2^{60}, 2di1082 \le d_i \le 10^8).

Every did_i is prime, and the product of all distinct jump distances is less than 10910^9.

Output

Print one line with the smallest position that carries a largest tower and the size of that tower, separated by a space.