This page is still under construction.

Parts of this page are still being built. What you see may change.

Addon

Time limit1sMemory limit128 MB

Summary
Given the stable heights, find the largest chamber height admitting a safe and complete set of rod lengths, and output a smallest such set.
Level

Hard8 of 10

Topics
Number theory, Combinatorics, Greedy
Solved
No attempts yet

Statement

Scientists discovered a new radioactive element called addon. It turned out to be the most efficient nuclear fuel ever known, so it was decided to build an addon reactor. According to the design, a fuel chamber is a vertical pipe. Fuel rods, that is addon cylinders, are placed in the chamber one above another. Fuel rods can have various lengths.

A reactor cycle begins with putting fuel rods into the chamber and then igniting them. Unfortunately, the height of a column of fuel cannot be arbitrary: only certain heights keep the reaction safe. Such heights are called stable heights.

The designers have two things to decide: the height of the fuel chamber and the set of lengths in which addon rods will be produced. A set of lengths is safe (for a given chamber) if for every column built from rods whose lengths belong to this set and that is not taller than the chamber, the height of the column is stable. A set of lengths is complete (for a given chamber) if every column of a stable height that is not taller than the chamber can be built from rods whose lengths are taken from this set.

Write a program that:

  • reads the set of stable heights from standard input,
  • computes the maximal height of a chamber for which a safe and complete set of lengths exists,
  • finds, for such a chamber, a safe and complete set of lengths with the smallest possible number of elements,
  • writes the result to standard output.

Input

The first line of standard input contains a natural number nn (1≤n≤10 0001 \le n \le 10\,000), the number of given stable heights. Each of the next nn lines contains one positive integer no greater than 10 00010\,000. These numbers are the stable heights, given in increasing order.

Output

The first line of standard output should contain one integer: the maximal height of a chamber. The following lines should contain the computed set of lengths in increasing order, one number per line.

Examples4

  1. Example 1

    Input
    14
    5
    10
    12
    15
    17
    20
    21
    22
    24
    26
    27
    30
    31
    33
    
    Expected output
    24
    5
    12
    21
    
  2. Example 2

    Input
    1
    7
    
    Expected output
    13
    7
    
  3. Example 3

    Input
    2
    2
    3
    
    Expected output
    3
    2
    3
    
  4. Example 4

    Input
    3
    2
    4
    6
    
    Expected output
    7
    2