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 (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
B = IL()[::-1]

A = [0 for i in range(N)]
A[0] = B[0]

for i in range(1,N-1):
  A[i] = min(B[i-1],B[i])
A[-1] = B[-1]

P(sum(A))

Solution (Python):




N = int(input())


input_list = list(map(int, input().split()))

ans_list=[input_list[0]]
for i in range(N-2):
    ans_list.append(min(input_list[i], input_list[i+1]))
ans_list.append(input_list[N-2])

print(sum(ans_list))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))

A = [B[0]]

for i in range(1, N-1):
    if B[i-1] >= B[i]:
        A.append(B[i])
    else:
        A.append(B[i-1])

A.append(B[N-2])
print(sum(A))

Solution (Python):
N = int(input())
B = tuple(map(int, input().split(' ')))

s = B[0] + B[-1]
for b1, b2 in zip(B, B[1:]):
    s += min(b1, b2)

print(s)

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
ans = B[0]
for i in range(N-2):
  ans += min(B[i],B[i+1])
ans += B[N-2]
print(ans)

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
a=[0]*n
a[0]=b[0]
a[n-1]=b[n-2]
for i in range(0,n-2):
  a[i+1]=min(b[i],b[i+1])
print(sum(a))

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
A = [B[0]] + [min(B[i],B[i-1]) for i in range(1,N-1)] + [B[-1]]
print(sum(A))

Solution (Python):
n =int(input())
b = list(map(int, input().split()))
a = [b[0]]
for i in range(1,n-1):
    a.append(min(b[i-1],b[i]))
a.append(b[-1])
print(sum(a))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))

max_value = b[0] + b[n - 2]
for i in range(n - 2):
    max_value += min(b[i], b[i + 1])
print(max_value)

Solution (Python):


n = int(input()) - 1
b = list(map(int, input().split()))

max_value = b[0] + b[n - 1]
for i in range(n - 1):
    max_value += min(b[i], b[i + 1])
print(max_value)

Solution (Python):
N=int(input())
B=[int(i) for i in input().split()]
A_sum = B[0]+B[N-2]
for i in range(1,N-1):
  A_sum=A_sum+ min(B[i-1],B[i])
print(A_sum)

Solution (Python):
N = int(input())
B = list(map(int, input().split()))

A = 0
b = 10**5+10
for i in range(N-1):
    a = b if B[i] > b else B[i]
    
    b = B[i]
    A += a
A += B[-1]
print(A)

Solution (Python):
n = int(input())
B = list(map(int,input().split()))
A = []
for i in range(len(B)):
    if i == 0:
        A.append(B[0])
        continue
    A.append(min(B[i-1],B[i]))
A.append(B[-1])
print (sum(A))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
A = [0]* N
A[0] = B[0]
for i, b in enumerate(B):
    if A[i] > b:
        A[i] = b
    A[i+1] = b
print(sum(A))

Solution (Python):
n = int(input())
b_list = list(map(int, input().split()))

a_list = [1e6] * n

for i, b in enumerate(b_list):
    a_list[i] = min(b, a_list[i])
    a_list[i + 1] = min(b, a_list[i + 1])

print(sum(a_list))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
ans = B[0]+B[N-2]
for i in range(N-2):
  ans += min(B[i],B[i+1])
print(ans)

Solution (Python):
import sys

n, *lst = map(int, sys.stdin.read().split())
alst = [lst[0]]
lst += [lst[-1]]
for i in range(n - 1):
  tmp = min(lst[i], lst[i + 1])
  alst += [tmp]
print(sum(alst))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))

A = []
A.append(B[0])
for i in range(0, N-2):
  if B[i] < B[i+1]:
    A.append(B[i])
  else:
    A.append(B[i+1])
A.append(B[N-2])
print(sum(A))

Solution (Python):
def resolve():
    N = int(input())
    B = [int(i) for i in input().split()]
    sumA = B[0] + B[N - 2]
    for i in range(1, N - 1):
        sumA += min(B[i], B[i - 1])
    print(sumA)


resolve()

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = 0
a = []

for i in range(n-1):
  if i == 0:
    a.append(b[i])
  else:
    a.append(min(b[i], b[i-1]))
    
a.append(b[n-2])
print(sum(a))

Solution (Python):
import numpy as np
N = int(input())
B = np.array([10 ** 5] + list(map(int, input().split())) + [10 ** 5], np.int32)
print(np.minimum(B[1:], B[:-1]).sum())

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
B = [float('inf')] + B + [float('inf')]
ans = 0
for i in range(N):
  ans += min(B[i], B[i+1])
print(ans)

Solution (Python):
N = int(input())
B = list(map(int, input().split()))

if N == 2:
  print(2 * B[0])
  exit()

A = []
A.append(B[0])
A.append(B[N-2])

for i in range(N-2):
  A.append(min(B[i], B[i+1]))

print(sum(A))

Solution (Python):
n=int(input())
b=[0]*(n-1)
b[:]=map(int,input().split())
r=b[0]
for ii in range(n-2):
  r+=min(b[ii],b[ii+1])
r+=b[n-2]
print(r)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = int(input())
    B = list(map(int, input().split()))
    for i in range(N-2):
        ans += min(B[i], B[i+1])
    ans += B[-1] + B[0]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
A = [0]*N
A[0]=B[0]
A[N-1]=B[N-2]
for i in range(1,N-1):
    A[i] = min(B[i-1],B[i])
print(sum(A))

Solution (Python):
N = int(input().rstrip())
b = list(map(int, input().rstrip().split()))
a = [0 for i in range(N)]

for i in range(N - 1):
	v = b[i]
	a[i + 1] = v
	if i == 0:
		a[i] = v
	else:
		if v <= a[i]:
			a[i] = v

r = sum(a)
print(r)

Solution (Python):
n = int(input())
B = list(map(int, input().split()))

A = [B[0]]

for i in range(1, n):
    if i < n - 1:
        A.append(min(B[i-1], B[i]))
    else:
        A.append(B[n-2])
print(sum(A))

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
A=[0]*(N+1)
if N==2:
    print(2*sum(B))
    exit()
for i in range(N-1):
    if i==0:
        A[i]=B[i]
        tmp=B[i]
    elif i!=(N-2):
        A[i]=min(tmp,B[i])
        tmp=B[i]
    elif i==(N-2):
        A[i]=min(tmp,B[i])
        A[i+1]=B[i]
print(sum(A))

Solution (Python):
n=int(input())
b=[int(x) for x in input().split()]
ans=0

for i in range(n-2):
  ans+=min(b[i],b[i+1])
  
ans +=b[0]
ans+=b[-1]

print(ans)

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
b.append(b[-1])
ans = [0] * n
ans[0] = b[0]
for i in range(1,n):
    if(i == n-1):
        continue
    ans[i] = min(b[i-1], b[i])
ans[n-1] = b[n-1]
print(sum(ans))

Solution (Python):
INF = 10**6

N = int(input())
Bs = [INF] + list(map(int, input().split())) + [INF]

As = [0] * N
for i in range(N):
    As[i] = min(Bs[i], Bs[i+1])

print(sum(As))

Solution (Python):
n = int(input())
b = list(map(int , input().split()))
a = [b[0]] + b
for i in range(1 , n - 1):
  a[i] = min(b[i - 1] , b[i])
print(sum(a))

Solution (Python):

N = int(input())
B = list(map(int, input().split()))


A = []
append = A.append
for i, b in enumerate(B):
    while len(A[i:]) < 2:
        if not A:
            append(b)
        elif i < len(B) - 1 and max([A[i], b]) >= B[i + 1]:
            append(B[i + 1])
        else:
            append(b)

print(sum(A))

Solution (Python):

N=int(input())
B=list(map(int, input().split()))

ANS=0
i=0
while i<N:
    if i==0:
        ANS+=B[i]
        mae=B[i]
    elif i==N-1:
        ANS+=mae
    else:
        ANS+=min(B[i],mae)
        mae=B[i]
    i+=1
    
print(ANS)

Solution (Python):
import itertools
import math
import fractions
import functools
n = int(input())
b = list(map(int, input().split()))
a = [0]*n
a[0] = b[0]
for i in range(1,n-1):
    a[i] = min(b[i-1],b[i])

a[n-1]=b[n-2]
print(sum(a))

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
a=[0]*n
a[0]=b[0]
for i in range(n-1):
  if b[i]<a[i]:
    a[i]=b[i]
  a[i+1]=b[i]

print(sum(a))

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
ans = 0
ans += b[0]+b[-1]
for i in range(n-2):
  ans += min(b[i],b[i+1])
print(ans)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = [b[0], ]
for i in range(n - 2):
    a.append(min(b[i], b[i + 1]))
a.append(b[-1])
print(sum(a))

Solution (Python):
n = int(input())
a = [0]*n
b = list(map(int,input().split()))+[10**5+1]

for i in range(n):
    a[i] = min(b[i-1],b[i]) if i != 0 else b[0]

print(sum(a))

Solution (Python):
N = int(input())
B= [int(j) for j in input().split()]
B.insert(0,B[0])
ans = 0
for i in range(N-1):
    ans += (min(B[i],B[i+1]))
ans +=B[-1]
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    B=[int(_) for _ in input().split()]
    ans=B[0]+B[-1]
    for i in range(n-2):
        ans+=min(B[i],B[i+1])
    print(ans)
if __name__=='__main__':
    main()

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
ans=[b[0]]
for i in range(n-2):
    ans.append(min(b[i],b[i+1]))
ans.append(b[-1])
print(sum(ans))

Solution (Python):
N = int(input())
B = [int(x) for x in input().split()]
A = [B[0]]
for i, b in enumerate(B):
    if A[-1] > b:
        A[-1] = b
    A.append(b)
print(sum(A))

Solution (Python):
n=int(input())
b = list(map(int,input().split()))
a1 = b[0]
an = b[-1]
aj = []

for j in range(1, n-1):
    aj.append(min(b[j-1],b[j]))

answer = a1 + an + sum(aj)
    
print(answer)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = [b[0]]
for i in range(1, n - 1):
    a.append(min(b[i - 1], b[i]))
a.append(b[-1])
print(sum(a))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = [b[0]] * 2
for i in range(1, n - 1):
    a.append(b[i])
    if b[i - 1] >= b[i]:
        a[i] = b[i]
print(sum(a))

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
ans = 0

for i in range(N):
    if i == 0:
        ans += B[0]
    elif i == N-1:
        ans += B[-1]
    else:
        ans += min(B[i-1],B[i])
print(ans)

Solution (Python):
N = int(input())
B = list(map(int,input().split()))

A = [0]*N
A[0] = B[0]
A[-1] = B[-1]

for i in range(1,N-1):
    A[i] = min(B[i-1],B[i])
    
print(sum(A))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = b[0] + b[n - 2]
for i in range(1, n - 1):
    ans += min(b[n - i - 1], b[n - i - 2])
print(ans)

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
A=[None]*N
A[0]=B[0]
for i in range(N-2):
  A[i+1]=min(B[i],B[i+1])
A[-1]=B[-1]
print(sum(A))

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
A=[]
B.insert(0,1000000)
B.append(1000000)
for i in range(1,N+1):
  a=min(B[i],B[i-1])
  A.append(a)
print(sum(A))

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
A=[0]*N
for i in range(N):
    if i==0: A[i]=B[i]
    elif i<N-1: A[i]=min(B[i-1],B[i])
    else: A[i]=B[i-1]
print(sum(A))

Solution (Python):
n=int(input())
B=list(map(int,input().split()))
A=[0]*n
A[0]=B[0]
A[1]=B[0]
for i in range(1, n-1):
  if B[i]>=B[i-1]:
    A[i+1] = B[i]
  else:
    A[i]=B[i]
    A[i+1]=B[i]
print(sum(A))

Solution (Python):
import sys
import math
import bisect

def solve(B):
    n = len(B) + 1
    A = [-10 ** 18] * n
    for i in range(n):
        min_val = 10 ** 18
        if i < n - 1:
            min_val = min(min_val, B[i])
        if i - 1 >= 0:
            min_val = min(min_val, B[i-1])
        A[i] = min_val
    '''
    print('n: ' + str(n))
    print('A: %s' % str(A))
    print('B: %s' % str(B))
    '''
    return A

def main():
    n = int(input())
    B = list(map(int, input().split()))
    A = solve(B)
    print(sum(A))

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
b = list(map(int, input().split()))

num = [b[0]]

for i in range(1, n - 1):
  if(b[i] <  b[i - 1]):
    num[-1] = b[i]
    num.append(b[i])
  else:
    num.append(b[i])

num.append(b[0])

print(sum(num))

Solution (Python):
n= int(input())
L=list(map(int, input().split()))
sum=L[0]+L[n-2]
for i in range(n-2):
	a=min(L[i],L[i+1])
	sum+=a
print(sum)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
lia = [li[0]]
li.append(100001)
for i in range(n-1):
    lia.append(min(li[i],li[i+1]))
print(sum(lia))

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
ans = 0
ans += b[0]
ans += b[n-2]
for i in range(0,n-2):
    ans += min(b[i],b[i+1])
print(ans)

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
l=[]
for i in range(n-2):
  l.append(min(b[i],b[i+1]))
print(sum(l)+b[0]+b[n-2])

Solution (Python):
n = int(input())
b_list = list(map(int,input().split()))

a_list = [0]*n
a_list[0] = b_list[0]
k = 0
while k <= n-2:
  if a_list[k] > b_list[k]:
    a_list[k] = b_list[k]
  a_list[k+1] = b_list[k]
  k += 1
print(sum(a_list))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))

a = [b[0]] * (n)
for i in range(1,n):
    a[i] = b[i-1]
    if a[i-1] > b[i-1]:
        a[i-1] = b[i-1]

print(sum(a))

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
a=[0]*n
a[0]=b[0]
a[n-1]=b[n-2]
for i in range(1,n-1):
    a[i]=min(b[i],b[i-1])
print(sum(a))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))

res = 0

for i in range(n - 1):
    
    if i + 1 < n - 1:
        if b[i] > b[i + 1]:
            if i == 0:
                res = b[0] + b[1]
                
                
            else:
                res += b[i + 1]
                
        else:
            if i == 0:
                res = b[0] + b[0]
                
                
            else:
                res += b[i]
                
    elif i == 0:
        res = b[0] + b[0]
        
        
    else:
        res += b[i]
        
print(res)

Solution (Python):
n = int(input())
b = list(map(int,input().split()))

a = [b[-1],b[0]]
for i in range(n-2):
  a.append(min(b[i],b[i+1]))

print(sum(a))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
maxa = [0] * n
maxa[0], maxa[n - 1] = b[0], b[n - 2]
for i in range(1, n - 1):
  maxa[i] = min(b[i - 1], b[i])
print(sum(maxa))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = b[0] + b[n-2]
for i in range(n-2):
    ans += min(b[i], b[i+1])
print(ans)

Solution (Python):

n = int(input())
b = [-1 for _ in range(n)]
b[0] = b[n-1] = int(1e6)
c = list(map(int, input().split()))
for i in range(n-1):
    b[i+1] = c[i]

ans = 0 
for i in range(n):
    ans += min([b[i-1], b[i]])
print(ans)

Solution (Python):


n = int(input())
b = list(map(int, input().split()))

ans = 0 
for i in range(n):
    if i==0:
        ans += b[0]
    elif i==n-1:
        ans += b[n-2]
    else:
        ans += min([b[i-1], b[i]])
print(ans)

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
ans = b[0]
for i in range(n-2):
    ans += min(b[i],b[i+1])
print(ans+b[n-2])

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
ans = b[0] + b[-1]
for i in range(n - 2):
    ans += min(b[i], b[i + 1])
print(ans)

Solution (Python):
N = int(input())
arr = list(map(int, input().split()))

sum = 0
for i in range(N-2):
    sum += min(arr[i], arr[i+1])

print(arr[0]+arr[-1]+sum)

Solution (Python):

n=int(input())
b=list(map(int,input().split()))

a=[0]*n

a[0]=b[0]
a[n-1]=b[n-2]

for i in range(1,n-1):
    a[i]=min(b[i-1],b[i])

print(sum(a))

Solution (Python):
N=int(input())
B=list(map(int, input().split()))

ans = B[0] + B[N-2]
for i in range(1,N-1):
  ans += min([B[i-1],B[i]])  
print(ans)

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
c=[min(b[i-1],b[i]) for i in range(1,n-1)]
c=[b[0]]+c+[b[n-2]]
print(sum(c))

Solution (Python):
N = int(input())
lb = list(map(int, input().split()))

la = list()
la.append(lb[0])

for i in range(1, N-1):
    la.append(min(lb[i-1], lb[i]))

la.append(lb[-1])

print(sum(la))

Solution (Python):
n=int(input())
B=list(map(int,input().split()))
sum=0
for i in range(n):
    if i==0:
        sum+=B[0]
    elif i==n-1:
        sum+=B[n-2]
    else:
        sum+=min(B[i],B[i-1])
print(sum)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))

a =[0]*n
a[0] = b[0]

if n == 2:
    a[1] =b[0]
    print(sum(a))

else:

    for i in range(n-2):
        if b[i+1] >= b[i]:
            a[i+1] = b[i]
            a[i+2] = b[i+1]

        else:
            a[i+1] = b[i+1]
            a[i+2] = b[i+1]

    print(sum(a))

Solution (Python):
N = int(input())
B = [int(i) for i in input().split(' ')]
A = 0
for i in range(N):
    if i == 0:
        A += B[i]
    elif i == N - 1:
        A += B[i - 1]
    else:
        A += min(B[i-1], B[i])
print(A)

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
SUM = 0
tmp = 10**5
for i,b in enumerate(B[::-1]):
    SUM += min(tmp,b)
    tmp = b
print(SUM+b)

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
ans = B[0]
for i in range(N-2):
    ans += min(B[i],B[i+1])
ans += B[-1]
print(ans)

Solution (Python):
def main():
    _ = int(input())
    B = list(map(int, input().split()))
    A = []
    A.append(B[0])
    A.append(min(B[0:2]))
    
    for i in range(1, len(B[:-1])):
        A.append(min(B[i], B[i+1]))
    if len(B) > 1:
        A.append(B[-1])

    print(sum(A))

    
if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
B = LI()
A = []
A.append(B[0])
for i in range(1, n-1):
    A.append(min(B[i-1], B[i]))
A.append(B[n-2])
print(sum(A))

Solution (Python):
n=int(input())
t = list(map(int, input().split()))
a = [t[0]]*2
for i in range(1, n-1):
 if t[i]<a[-1]: a[-1]=t[i]
 a+=[t[i]]
print(sum(a))

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
A=[None]*N
for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])
A[0]=B[0]
A[N-1]=B[N-2]
print(sum(A))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))

a = [b[0]]
for i in range(1, n-1):
  a.append(min(b[i], b[i-1]))
a.append(b[-1])

print(sum(a))

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = [0] * n
for i in range(n):
    if i == 0:
        a[i] = b[i]
    elif i == n-1:
        a[i] = b[i-1]
    else:
        a[i] = min(b[i-1], b[i])

print(sum(a))

Solution (Python):
n = int(input())
b = list(map(int,input().split()))


a = []
for i in range(n):
    if i == 0:
        a.append(b[i])
        
    elif i == n-1:
        a.append(b[-1])
    
    else:
        a.append(min(b[i-1],b[i]))
    
print(sum(a))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))

ans = [B[0]] + [min(B[i-1],B[i]) for i in range(1,N-1)] + [B[-1]]

print(sum(ans))

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
sum = b[0]+b[n-2]
for i in range(n-2):
  sum += min(b[i],b[i+1])
print(sum)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
B = list(map(int,input().split()))
A = []
for i in range(N-1):
    if i == 0:
        A.append(B[0])
    else:
        A.append(min(B[i],B[i-1]))
A.append(B[-1])
print(sum(A))

Solution (Python):


N = int(input())
B = [int(b) for b in input().split()]

A = [float('inf')] * N
for i in range(N - 1):
    A[i + 1] = B[i]
    if B[i] < A[i]:
        A[i] = B[i]

print(sum(A))

Solution (Python):
n = int(input())
bi = list(map(int,input().split()))
ai = 0
before = 200000
for i in range(len(bi)):
    ai += min(bi[i],before)
    before = bi[i]
ai += bi[-1]
print(ai)

Solution (Python):
n =int(input())
ls = list(map(int,input().split()))
a = [0 for i in range(n)]
a[0] = ls[0] 
a[n-1] = ls[n-2]
for j in range(n-2):
    b = min(ls[j],ls[j+1])
    a[j+1] = b
print(sum(a))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    ans=0
    n=int(input())
    l=list(map(int,input().split()))
    ans+=l[0]+l[-1]
    for i in range(n-2):
        ans+=min(l[i],l[i+1])
    print(ans)
resolve()

Solution (Python):
N=int(input())
B = list(map(int,input().split()))
C=0
C+=(B[0]+B[N-2])
if N>2:
 for i in range(N-2):
  C+=min(B[i],B[i+1])
print(C)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = [0] * n
b += [max(b)]
a[0] = b[0]
for i in range(1, n):
  a[i] = min(b[i-1], b[i])
print(sum(a))

Solution (Python):
def main():
    N = int(input())
    B = list(map(int, input().split()))

    res = 0
    for i in range(N-2):
        res += min(B[i], B[i+1])

    res += B[0]
    res += B[-1]
    print(res)
    
main()

Solution (Python):
n=int(input())
b=list(map(int,input().split()))

lis=[0]*n

for i in range(0,n-1):
  if i==0:
    lis[0]=b[0]
  temp=b[i]
  if lis[i]>b[i]:
    lis[i]=b[i]
  lis[i+1]=b[i]
print(sum(lis))

Solution (Python):
n = int(input())
pre = 100000
ans = 0
for bi in map(int, input().split()):
    ans += min(pre, bi)
    pre = bi
ans += pre
print(ans)

Solution (Python):
N=int(input())
B=list(map(int,(input().split())))
ans=B[0]+B[-1]
for i in range(len(B)-1):
    ans+=min(B[i],B[i+1])
print(str(ans))

Solution (Python):
import sys, heapq
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
B = LI()

res = B[0] + B[-1]
for i in range(N - 2):
    res += min(B[i], B[i + 1])

print(res)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    if i == 0:
        ans += b[i]
    elif i == n - 1:
        ans += b[-1]
    else:
        ans += min(b[i - 1], b[i])
print(ans)

Solution (Python):
def resolve():
    """
    b: 2, 5
    a: 2, 2, 5


    b: 0, 153, 10, 10, 23
    a: 0, 0, 10, 10, 10, 23
    """
    n = int(input())
    b = [int(i) for i in input().split()]
    a = [b[0]]
    for i, v in enumerate(b):
        if i < len(b)-1:
            a.append(min(b[i], b[i + 1]))

    a.append(b[-1])
    print(sum(a))


resolve()

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = [0] * n
a[0] = b[0]
for i in range(n - 1):
    a[i] = min(a[i], b[i])
    a[i + 1] = b[i]
print(sum(a))

Solution (Python):
N=int(input())
B=list(map(int,input().split()))

from collections import deque


A=deque([])

for i in range(N-1):
    B_i = B[i]

    
    if i==0:
        A.append(B_i)
        A.append(B_i)

    
    else:
        if B_i<=pre_B_i:
            A.pop()
            A.append(B_i)
            A.append(B_i)
        else:
            A.append(B_i)

    
    pre_B_i = B[i]

print(sum(A))

Solution (Python):
N = int(input())
B = []
B = list(map(int, input().split(' ')))
sum = B[0]
for i in range(N - 2):
  sum += min(B[i], B[i + 1])
sum += B[N - 2]
print(sum)

Solution (Python):

import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter





j=0
k=0
n=3
r=1
a=[0]






"1行1つの整数を入力を取得し、整数と取得する"




"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''


'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        
        if n % k == 0:
            return False
            
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  

'''












def main():

    w=1
    j=0
    k=0
    n=int(input())
    bl=list(map(int, input().split(" ")))
    al=[]
    al.append(bl[0])
    for i in range(n-2):
        
        al.append(min(bl[i],bl[i+1]))
    al.append(bl[n-2])
    print(sum(al))
    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    
        
        
    
    
        
        
    


    "1行1つの整数を入力を取得し、整数と取得する"
    
    
    "12 21 332 とか入力する時に使う"
    "1行に複数の整数の入力を取得し、整数として扱う"
    
    
    


    
    
    
    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    ls = ["a", "b", "c", "d", "e"]


    
    

    
    

    
    
    
    
    
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
B = list(map(int, input().split()))

def solve(B):
    ans = B[0]+B[N-2]
    for i in range(N-2):
        ans += min(B[i],B[i+1])
    return ans
print(solve(B))

Solution (Python):
n = int(input())
B  = list(map(int, input().split()))
A = [0] * n
A[0] = B[0]
A[-1] = B[-1]
for i in range(1, n - 1):
    A[i] = min(B[i - 1], B[i])

print(sum(A))

Solution (Python):
import numpy as np

n = int(input())
B = list(map(int, input().split()))
A = [0]*n
A[0] = B[0]
A[n-1] = B[n-2]
for i in list(range(1,n-1)):
    A[i] = min(B[i-1], B[i])
print(sum(A))

Solution (Python):
n=int(input())
B=list(map(int, input().split()))

answer = B[0] + B[-1]
for i in range(n - 2):
    answer += min([B[i], B[i + 1]])
print(answer)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
r = b[0]+b[n-2]
for i in range(n-2):
    if b[i]<b[i+1]:
        r+=b[i]
    else:
        r+=b[i+1]
print(r)

Solution (Python):
def main():
    N = int(input())
    B = list(map(int, input().split(' ')))
    answer = B[0] + B[-1]
    for i in range(N - 2):
        answer += min([B[i], B[i + 1]])
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):

n=int(input())
binf=10**6
b=[binf]+list(map(int,input().split()))+[binf]

asum=0
for i in range(len(b)-1):
    ai=min(b[i],b[i+1])
    asum+=ai
    
print(asum)