Power of Power
Time limit2sMemory limit512 MB
Given N integers, rearrange them so the power tower B1^(B2^(...^BN)) is maximized, and print the lexicographically smallest optimal order.
Problem
Good results at ICPC require training, so Usagi decided to train today in order to win at ICPC.
Today's training is to compute very large numbers, which builds calculation ability and raises awareness. Exponentiation is an operation that produces large numbers easily.
You are given non-negative integers . Find a rearrangement that maximizes . This is common knowledge for the rabbits, but the evaluation proceeds from the top right. We define .
If several rearrangements achieve the maximum, output the lexicographically smallest one.
Input
N
A1
...
AN
, .
Output
The output consists of lines. The -th line prints .