问题2696--Design the stop of the Elevator

2696: Design the stop of the Elevator

[命题人 : ]
时间限制 : 5.000 sec  内存限制 : 64 MB

题目描述

The building in the ZstuYs Company has only one elevator. This drives the employees crazy. They should spend much time on the elevator evry morning.It takes the elevator 4 seconds to go one stair upwards,The elevator stays 10 seconds for the employee to get out. If some employees want to walk staircase(walk upwards or downwards), It takes them 20 seconds to go one stair. But now, you should design the stop of the Elevator to change this status. You shold help the employees let the time of the last employee reaches his office is minimal. For example, 3 employees want to the 4th floor, 5th floor and 10th floor. The best method is to stop at the 4th floor and the 10th floor. It takes 3*4 = 12 seconds from the first floor to the 4th floor, and the man who wants to go to the 5th floor takes 12 + 20 =32 seconds. The man wants to go to the 10th floor needs 3*4+10+6*4=46 seconds.

输入

There are multiple test cases. Each case contains a line with one positive integer N ( 1 <= N <= 30000 ), followed by N positive numbers f1 f2 ... fn (2 <= f1 <= f2 <= ... <= fn <= 30000 ).f1 ...fn are the floors the employees want to go. A test case with N = 0 denotes the end of input. This test case is not to be processed.

输出

Print the time the last man used on a single line for each test case.

样例输入 Copy

3 4 5 10
1 2
0

样例输出 Copy

46
4