The company Insumax produces multilayer thermal insulators. Each of the
layers, , of such an insulator
is characterized by positive insulation coefficient . The layers
are numbered according to the direction the heat leaks.
The insulation coefficient of the whole insulator, , is described by
the sum of insulation coefficients of its layers. Moreover, the coefficient
raises if a layer with a smaller insulation coefficient is followed
by a layer with a larger coefficient, according to the formula:
For example, the insulation coefficient of the insulator of the form
Write a program which, for given insulation coefficients of layers determines such an ordering of the layers that the
insulation coefficient of the whole insulator is maximised.
In the first line of the standard input there is the number of layers
, . In the successive
lines there are coefficients , one per line. Those coefficients are integers satisfying the
In the first and only line of the standard output your program should write
one integer equal to the largest possible value of the insulation coefficient
of the insulator built of the layers of the given coefficients, put
in a particular order.