#BS0000077. Kế hoạch dừng thang máy (Elevator Stopping Plan)

Kế hoạch dừng thang máy (Elevator Stopping Plan)

Elevator Stopping Plan

Source: LiveArchive

Version: Phuoc Hung OJ Extended

Problem Statement

A 31-floor building has requested office floors. Everyone starts at floor 1. The elevator takes 4 seconds per floor upward; each intermediate stop adds 10 seconds before it continues. After leaving at a chosen stop, a person may walk up or down at 20 seconds per floor. Choose stops to minimize the arrival time of the last person. The PHOJ version asks only for the optimal time.

Input

The first line contains nn. The second line contains strictly increasing requested floors.

Output

Print the minimum time in seconds.

Subtasks

  • Subtask 1 — 20%: n≤5n\le5.
  • Subtask 2 — 30%: n≤15n\le15.
  • Subtask 3 — 50%: n≤30n\le30, requested floors in [2,31][2,31].

Example

Input

3
4 5 10

Output

46

Explanation

Stopping at floors 4 and 10 lets everyone arrive by time 46.