#K42227. Finding the Heaviest Pumpkins

    ID: 27041 Type: Default 1000ms 256MiB

Finding the Heaviest Pumpkins

Finding the Heaviest Pumpkins

You are given several datasets where each dataset is provided as a line of space separated integers representing the weights of pumpkins. For each dataset, your task is to determine the heaviest and the second heaviest pumpkin. The input is terminated when a line with a single "0" is encountered; this line should not be processed.

For each valid dataset, output two lines: the first line containing the heaviest pumpkin weight and the second line containing the second heaviest pumpkin weight.

Note: It is guaranteed that each dataset contains at least two numbers.

The mathematical idea behind selecting the top two weights can be described as follows: Given a set \( S = \{w_1, w_2, \dots, w_n\} \), find \( M_1 \) and \( M_2 \) such that \[ M_1 = \max_{1 \leq i \leq n} \{w_i\} \quad \text{and} \quad M_2 = \max_{\substack{1 \leq i \leq n \\ w_i \neq M_1}} \{w_i\}. \] This ensures that \( M_1 \) is the heaviest and \( M_2 \) is the second heaviest pumpkin.

inputFormat

The input is read from standard input (stdin) and consists of multiple lines. Each line (except the last terminating line) contains a dataset represented by space separated integers, where each integer denotes the weight of a pumpkin.

The input terminates when a line containing only a single 0 is encountered. This line should not be processed.

outputFormat

The output should be printed to standard output (stdout). For each dataset processed, print two lines. The first line should contain the heaviest pumpkin weight and the second line should contain the second heaviest pumpkin weight, in the order in which the datasets are provided.

## sample
155 200 123 301 276
450 123 789 656 341
301

276 789 656

</p>