#P8587. Equal Height Pillars

    ID: 21753 Type: Default 1000ms 256MiB

Equal Height Pillars

Equal Height Pillars

You are one of the first researchers arriving early at the base on star \(\beta\). The planet \(\beta\) is rich in manganotitanite ore. At the base, you are required to construct pillars of equal height, where each pillar is formed by connecting exactly two ore pieces in sequence. For example, if you have two ore pieces with heights \(h_x\) and \(h_y\), they can be combined to form a pillar of height \(h_x+h_y\). Note that each ore piece can be used at most once.

You are presented with \(n\) ore pieces with heights \(h_i\). After careful thought, you conclude that the stability of the base is determined by the number of pillars rather than the height of the pillars. Thus, you wish to know: what is the maximum number of pillars of equal height you can construct using these \(n\) ore pieces?

However, as if that were not enough, your colleague adds an extra twist: suppose that for a certain pillar height \(h\) you can build \(\mathrm{res}\) pillars (which is the maximum possible). How many different values of \(h\) can achieve this maximum count \(\mathrm{res}\) of pillars?

Note: Each pillar must be made by connecting exactly two ore pieces, and each ore piece can be used in at most one pillar.

inputFormat

The first line contains a single integer \(n\) (\(2 \le n\)), representing the number of ore pieces. The second line contains \(n\) space-separated integers \(h_1, h_2, \ldots, h_n\), where \(h_i\) denotes the height of the \(i\)-th ore piece. You may assume \(1 \le h_i \le 10^3\) for all \(i\).

outputFormat

Output two integers separated by a space. The first integer is the maximum number of pillars (i.e. disjoint pairs) that can be constructed such that all pillars have the same height, and the second integer is the number of different pillar heights \(h\) that yield this maximum number.

sample

7
1 3 3 4 3 2 6
2 3