PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000356. Lịch dừng thang máy (Elevator Stopping Plan)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Lịch dừng thang máy (Elevator Stopping Plan)

Elevator Stopping Plan

Source: ICPC Live Archive

Version: Phuoc Hung OJ Extended

Problem Statement

GaoKe Hall has 31 floors, numbered 1 through 31. Hal of ZSoft wants to improve travel times using the building's only elevator.

Everyone starts on floor 1 at time zero. The elevator travels upward at four seconds per floor and pauses for ten seconds at each selected stop before continuing. Passengers may leave as soon as the elevator reaches a stop. Walking one floor in either direction takes twenty seconds. A worker may walk directly from floor 1 or ride to a stop and walk from there to the destination.

Given distinct destination floors f1,…,fnf_1,\ldots,f_n, choose strictly increasing stops between floors 2 and 31, not necessarily destination floors. Minimize the latest arrival time among the workers, each of whom uses the quickest route under that stopping plan.

Input

One line contains the integer nn followed by nn integers f1,…,fnf_1,\ldots,f_n: the number of destinations and their floors in increasing order.

Output

Print the minimum time in seconds on the first line. On the second line print the number of stops mm followed by the mm stop floors in strictly increasing order. Any optimal plan is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤71\le n\le 7; 2≤f1<f2<⋯<fn≤82\le f_1<f_2<\cdots<f_n\le 8.
  • Subtask 2 (30 points): 1≤n≤171\le n\le 17; 2≤f1<f2<⋯<fn≤182\le f_1<f_2<\cdots<f_n\le 18.
  • Subtask 3 (50 points): 1≤n≤301\le n\le 30; 2≤f1<f2<⋯<fn≤312\le f_1<f_2<\cdots<f_n\le 31.

Examples

Input 1

3 4 5 10

Output 1

46
2 4 10

Explanation 1

The elevator reaches floor 4 at time 12. The floor-5 passenger walks 20 more seconds, arriving at time 32. After a ten-second pause and 24 seconds of travel, it reaches floor 10 at time 46. Finishing earlier requires serving floor 10 at the first stop, because the second or later stop requires at least 46 seconds to serve it. The first stop must be floor 10 itself: floor 9 requires 52 seconds including walking and floor 11 requires 60; more distant stops take longer. But floor 4 then cannot be reached before 46 seconds: walking directly takes 60 seconds, and walking down from floor 10 takes another 120 seconds. Thus 46 is optimal.

Input 2

1 2

Output 2

4
1 2

Explanation 2

The elevator needs four seconds to reach floor 2; walking takes twenty seconds. Four seconds is the minimum.