시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 6 2 2 33.333%

문제

비행기에 탑승하고 좌석을 찾고 있는 승객들과 행을 따라 단 하나의 복도(열)가 있는 비행기를 상상해보자.

각 승객은 반드시 좌석에 앉아야 하며, 비행기 탑승구는 첫 번째 좌석 행 바로 앞에 있다. 승객은 불필요한 정지 없이 순차적으로 진입하고 있다.

승객은 복도를 걷고 있으며, 각 열에서 승객은 자신의 행에 도착할 때까지 정확히 1초씩 소비하며 전진한다. (그 앞에 다른 승객이 있는 경우 더 머문다.) 자신에 행에 도착한 순간부터 짐을 넣기 위해 5초를 소비한다.

복도의 각 행에는 한 명의 승객만 있을 수 있다. 비행기가 이륙하기 위해 준비하는 시간 즉, 모든 승객이 좌석에 앉는 데 필요한 시간을 계산하는 프로그램을 만들어보자.

입력

입력의 첫 줄에는 승객 수 N, (1 ≤ N ≤ 1000)가 주어진다. 그 다음 줄부터 각 승객이 앉아야 하는 좌석의 행 R이 주어진다. ( 1 ≤ R ≤ 1000)이 주어진다.

승객은 1에서 N까지 숫자로 숫자가 매겨지고 그 순서대로 입력된다. 같은 열에 앉는 승객의 수는 제한되지 않는다.

출력

출력 첫 줄에는 모든 승객이 좌석에 앉는 데 필요한 시간 (초)를 나타낸다.

예제 입력 1

1
3

예제 출력 1

7

예제 입력 2

2
3
3

예제 출력 2

12

예제 입력 3

4
4
4
1
5

예제 출력 3

19

힌트

4행으로 향하는 승객 바로 뒤에 1행으로 출발하는 승객이 있다면, 먼저 짐을 싣고, 앉을 수 있다!

W3sicHJvYmxlbV9pZCI6IjMyNTYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJlNDRcdWQ1ODlcdWFlMzAiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YmU0NFx1ZDU4OVx1YWUzMFx1YzVkMCBcdWQwZDFcdWMyYjlcdWQ1NThcdWFjZTAgXHVjODhjXHVjMTFkXHVjNzQ0IFx1Y2MzZVx1YWNlMC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