Problem G
Merging Items
Recently Sam was playing the game “InCreasing Product Courierx” (ICPC). In this game, you merge 2 identical items to make a more valuable item. Items will be referred to by their value in the hierarchy, so two value 1 items, when merged, will become a single value 2 item. Similarly two value 5 items, when merged, will become a single value 6 item. A player can choose when to merge pairs of items with identical value. A player may also request and receive an additional three value 0 items.
While playing, Sam decides he wants to create a value 10 item and wonders how to proceed, starting with the items he has available. Sam thinks it would be nice to have a program that will tell him what values of items he will have remaining after requesting additional items and merging all possible pairs. He would input the values of the items currently on the board, and how many times he intends to request additional sets of three value 0 items.
Input
The first line will contain an integer $k: 0 \le k \le 10$ representing the number of items on the board initially. The next $k$ lines, each with a single integer indicating the value of an item on the board initiallly. These numbers will be unique over the $k$ lines. Finally there will be a line with a single number $n: 0 \le n \le 300$. This is the number of times that more items will be requested.
Output
Print one line with the integers, space delimited, representing the values at which items will be present after everything possible has been merged and requested. If the value would go over 10 for any item, that is fine - just output the resultant values of the items in increasing order.
Note: At no point during the round, including while merging, will there be more than one item of value 10.
| Sample Input 1 | Sample Output 1 |
|---|---|
3 7 5 3 5 |
0 1 2 4 5 7 |
