Problem:
Score : 300 points

Problem Statement

There is an integer sequence A of length N whose values are unknown.

Given is an integer sequence B of length N-1 which is known to satisfy the following:

B_i \geq \max(A_i, A_{i+1})

Find the maximum possible sum of the elements of A.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq B_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
B_1 B_2 ... B_{N-1}

Output

Print the maximum possible sum of the elements of A.

Sample Input 1

3
2 5

Sample Output 1

9

A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.

Sample Input 2

2
3

Sample Output 2

6

Sample Input 3

6
0 153 10 10 23

Sample Output 3

53

Solution in Fortran (gfortran v4.8.4) (judge verdict: Accepted)

module ABC140

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_C

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_C

    ! variables for this <subroutine>
    integer(INT64) :: len_sequence_A
    integer(INT64) :: val_sum_sequence_A

    ! arrays for this <subroutine>
    integer(INT64), dimension(:), allocatable :: val_sequence_B

    ! support variables for this <subroutine>
    integer :: itr

    ! STEP.01
    ! read out the given data
    ! (the length of the sequence B)
    read(unit=INPUT_UNIT, fmt=*) len_sequence_A

    ! STEP.02
    ! allocate the arrays to store the given data
    allocate( val_sequence_B(1:len_sequence_A - 1) )

    ! STEP.03
    ! read out the given data
    ! (the values of the sequence B)
    read(unit=INPUT_UNIT, fmt=*) val_sequence_B(:)

    ! STEP.04
    ! calculate the answer of this task
    val_sum_sequence_A &!
    = val_sequence_B(len_sequence_A - 1) &!
    + val_sequence_B(1)

    do itr = len_sequence_A - 1, 2, -1
      val_sum_sequence_A = val_sum_sequence_A + min(val_sequence_B(itr), val_sequence_B(itr - 1))
    end do

    ! STEP.05
    ! output the answer of this task
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') val_sum_sequence_A

    ! STEP.06
    ! deallocate the arrays to store the given data
    deallocate( val_sequence_B )

    ! STEP.END
    return

  end subroutine task_C

end module ABC140


program main

  ! <module>s to import
  use, non_intrinsic :: ABC140

  ! require all variables to be explicitly declared
  implicit none

  call task_C

end program main