cho.sh
Notes
Loading...

Elevator

Time limit

2s

Memory limit

128 MB

Problem

A company's employees work on different office floors in a 31-story building. The building has only one elevator, so during the morning rush the company wants the elevator to stop only at a chosen set of floors.

The elevator takes 4 seconds to move up by one floor. When it stops at a floor, it remains there for 10 seconds before moving again. However, the waiting time at the floor where a person gets off is not included in that person's arrival time, because the person has already arrived. Moving one floor by stairs takes 20 seconds.

Each employee gets off at the scheduled elevator stop closest to their office floor, then uses the stairs if needed. The company wants to minimize the arrival time of the last employee to arrive.

Given the floors that employees need to reach, find the minimum possible arrival time of the last employee.

Input

The first line contains an integer N (1 <= N <= 30).

The second line contains N distinct integers, the floors that employees need to reach. Each floor is between 2 and 31, inclusive.

Output

Print the minimum possible arrival time, in seconds, of the last employee to arrive.