Bridge Pillars
Time limit1sMemory limit128 MB
Pick a modulus m above 1 that keeps the largest group of pillar heights sharing one remainder, with ties broken toward the larger m.
- Level
Medium7 of 10
- Topics
- Number theory, Prefix sum
- Solved
- No attempts yet
Problem
Engineer Bajtazar wants to build a bridge across a canyon. The bridge rests on massive concrete pillars shaped like cylinders.
Each pillar has a positive integer height (measured in bytemeters). For the bridge to be level, every pillar must stick out above the ground by the same height (at least one bytemeter). Assume the ground under the bridge has already been perfectly leveled.
Each pillar is also sunk into the ground by a non-negative integer number of bytemeters, or its base rests directly on the ground (a buried length of ). Building regulations require that every buried length be a multiple of some natural number , and must be greater than . This is the strength coefficient of the bridge.
Not all delivered pillars have to be used. Bajtazar wants to use as many pillars as possible, so he picks so that as many pillars as possible have heights leaving the same remainder when divided by . (If every used pillar sticks out by the same height , then each buried length equals its height minus , and for all of these to be multiples of the used heights must all share the same remainder modulo .) If several values of give the same maximum count, he chooses the largest such .
Input
The first line contains an integer (), the number of delivered pillars. The second line contains integers (), the heights of the pillars, separated by spaces. You may assume the pillars do not all have the same height.
Output
Print two integers and on one line: is the maximum number of pillars that can be used for the bridge, and is the largest possible strength coefficient of a -pillar bridge. You may assume such an exists.