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):
N = int(input())
B = list(map(int, input().split()))
result = B[0] + B[N - 2]
for i in range(1, N - 1):
  result += min(B[i - 1], B[i])
print(result)

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

Solution (Python):
_,b=open(0);*b,=map(int,b.split());print(b[0]+b[-1]+sum(min(i,j)for i,j in zip(b,b[1:])))

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
B = LIST()

A = []
A.append(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 = [int(i) for i in input().split()] 
ans = b[0]
for i in range(1,n-1):
    ans += min(b[i],b[i-1])
ans += b[n-2]
print(ans)

Solution (Python):
N = int(input())
Bs = list(map(int, input().split()))
As = []

for i in range(N):
    if i == N-1:
        As.append(Bs[i-1])
    elif i == 0:
        As.append(Bs[0])
    else:
        As.append(min([Bs[i-1],Bs[i]]))

print(sum(As))

Solution (Python):
import numpy as np

N = int(input())  
B = np.array(input().split(), dtype=np.int64)

ans = 0
ans += B[0] + B[N-2]

for i in np.arange(N-2):
    ans += np.min(np.array([B[i], B[i+1]]))
    
print(int(ans))

Solution (Python):

N = int(input())
B = list(map(int,input().split()))
C = [10**6]
for b in B:
    C.append(b)
B.append(10**6)
sm = 0


for n in range(N):
    sm+=min(B[n],C[n])
print(sm)

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


ans = 0
last = 10**5
for i in range(N - 1):
    b = B[i]
    ans += min(last, b)
    last = b
    if i == N - 2:
        ans += b
print(ans)

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

Solution (Python):
def resolve():
    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[i-1]
        else: ans+=min(B[i-1],B[i])
    print(ans)



resolve()

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


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

print(sum(A))

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

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

print(ans)

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

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

a_list = []
a_list.append(b_list[0])

for i in range(len(b_list)-1):
    a_list.append(min(b_list[i],b_list[i+1]))

a_list.append(b_list[-1])

print(sum(a_list))

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

Solution (Python):

import sys


def solve(N: int, B: "List[int]"):
    B.append(10000000)
    result = 0
    for i in range(N):
        j = N - i - 1
        
        result += min(B[j], B[j-1])
    print(result)



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    B = [int(next(tokens)) for _ in range(N - 1)]  
    solve(N, B)

if __name__ == '__main__':
    main()

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

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

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

B = list(map(int, 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):
import sys
def input():
    return sys.stdin.readline()[:-1]

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

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

Solution (Python):
n = int(input())
b = list(map(int,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, = map(int, input().split())
MAX = 10**10
A = [MAX] * N
A[0] = B[0]
for i, b in enumerate(B):
    if A[i] > b: A[i] = b
    if A[i+1] > b: A[i+1] = b
print(sum(A))

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[-1])
print(sum(A))

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

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

Solution (Python):
import math
import queue

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

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

def main():
    n = int(input())
    b = [x for x in map(int,input().split())]
    ans = [b[0]]
    for i in range(n-1):
        if ans[i]>b[i]:
            ans[i] = b[i]
        ans.append(b[i])
    print(sum(ans))
    return

if __name__ == '__main__':
    main()

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

ans = 0
prev = 10 ** 5
for b in B:
    ans += min(prev, b)
    prev = b

ans += B[-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())
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())
B = list(map(int, input().split()))
ans = B[0] + B[-1]
for i, j in zip(B, B[1:]):
    ans += min(i, j)

print(ans)

Solution (Python):
import sys
import collections
sys.setrecursionlimit(4100000)

n = int(input())
b = [int(i) for i in input().split()]
if n == 2:
    print(b[0]*2)
else:
    ans = 0
    for i in range(n-2):
        ans += min(b[i],b[i+1])
    print(ans+b[-1]+b[0])

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
B.append(10**6)

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

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

Solution (Python):

N = [int(s) for s in raw_input().split(" ")][0]
B = [int(s) for s in raw_input().split(" ")]
res = B[0]
for i in xrange(N-2):
    res += min(B[i], B[i+1])
res += B[-1]
print(res)

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

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

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

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
bbb = na()
ans = bbb[0]
for i in range(n-2):
    ans += min(bbb[i], bbb[i + 1])
print(ans + bbb[-1])

Solution (Python):
N = int(input())




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


ans=0

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

for i,b in enumerate(B):
    if A[i] > b:
        A[i]=b
    if A[i+1] > b:
        A[i+1]=b

ans=sum(A)



print(str(ans))

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt


args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def main():
    N = input(int)
    B = input([int, N - 1])

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

    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Solution (Python):
n = int(input())
b_list = [ int(v) for v in input().split() ]

a_list = [None for i in range(n)]
for i in range(n):
    if i == 0:
        a_list[0] = b_list[0]
    elif i == n - 1: 
        a_list[-1] = b_list[-1]
    else:
        a_list[i] = min(b_list[i-1], b_list[i])

print(sum(a_list))

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

A = [0] * N
for i in range(N):
    Ai_tmp = 10 ** 18
    if i > 0:
        Ai_tmp = min(Ai_tmp, B[i - 1])
    if i < (N - 1):
        Ai_tmp = min(Ai_tmp, B[i])
    A[i] = Ai_tmp

print(sum(A))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
ans = 0
ans += B[0]
ans += 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()))
INF=10**6
c=[INF]+b+[INF]

a=[0]*n

for i in range(n):
  a[i]=min(c[i],c[i+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 = [int(x) for x in input().split()]
B.append(10**6)
A = [0] * N
A[0] = B[0]
for i in range(1, N):
    A[i] = min(B[i-1], B[i])
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(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()))
ans = B[0]+B[N-2]
for i in range(1, N-1):
    ans += min(B[i-1],B[i])
print(ans)

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

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

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())
b=[int(j) for j in 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())
b_list = list(map(int, input().split()))




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

Solution (Python):
import numpy as np
n = int(input())
b = [int(i) for i in input().split(" ")]
ar = np.c_[[10**5]+b, b+[10**5]]
print(np.sum(np.min(ar, axis=1)))

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

print(ans)

Solution (Python):
N, *B = map(int, open(0).read().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())
b = list(map(int, input().split()))
sum_a = b[0] + b[-1]
for i in range(N-2):
  sum_a += min(b[i], b[i+1])
print(sum_a)

Solution (Python):
n=int(input())
da=list(map(int,input().split()))
da.insert(0,1000000)
da.append(10000000)
ans=0
for i in range(n):
    ans+=min(da[i],da[i+1])
print(ans)

Solution (Python):

import sys


def solve(N: int, B: "List[int]"):
    sm = 0
    for i in range(1, N-1):
        sm += min(B[i-1], B[i])
    sm += B[0] + B[-1]
    print(sm)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    B = [int(next(tokens)) for _ in range(N - 1)]  
    solve(N, B)

if __name__ == '__main__':
    main()

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

a[0]=b[0]
a[n-1]=b[n-2]
for i in range(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()))

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)

def main():
    n=int(input())
    bb=list(map(int, input().split()))
    a=[0]*n
    ans=0
    for i,(b0,b1) in enumerate(zip(bb,bb[1:])):
        ans+=min(b0,b1)
    ans+=bb[0]+bb[-1]
    print(ans)

main()

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

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

ans += B[0]
print (ans)

Solution (Python):

N=int(input())

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

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

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

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

print(ans)

Solution (Python):
import sys
n = int(input())
b_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls = [0 for i in range(n)]
a_ls[-1] = b_ls[-1]
for i in range(n-2,-1,-1):
    if i == 0:
        a_ls[0] = b_ls[0]
    else:
        a_ls[i] = min(b_ls[i], b_ls[i-1])
print(sum(a_ls))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
A = [0] * 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=[10**6]+list(map(int,input().split()))+[10**6]
s=0
for i in range(n):
  s+=min(B[i],B[i+1])
print(s)

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

res = 0
for i, e in enumerate(b):
    a[i] = min(a[i], e)
    a[i + 1] = min(a[i + 1], e)

print(sum(a))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
 
inf = 10**10
B = [inf] + B + [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()))

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

print(sum(A))

Solution (Python):
n = int(raw_input())
b = map(int,raw_input().split())
a = []
a.append(b[0])
a.append(b[0])
for i in xrange(1,n-1):
	if b[i] < a[i]:
		a[i] = b[i]
	a.append(b[i])

print sum(a)

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

a_list = [b_list[0]]

for i in range(N - 1):
	b = b_list[i]
	if a_list[i] > b:
		a_list[i] = b
	a_list.append(b)
print(sum(a_list))

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())
B_list = list(map(int, input().split(" ")))

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

print(out)

Solution (Python):

N = int(input())

B = list(map(int,input().split()))
B.append(float("inf"))

for i in range(N):

    if i == 0:
        ans = B[0]

    else:
        ans += min(B[i-1],B[i])

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(ans)

Solution (Python):
N = int(input())
B = [100000] + list(map(int, input().split())) + [100000]

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

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

Solution (Python):


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

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

print(ans)

Solution (Python):
def solve(b, n):
	a = [10**10 for _ in range(n)]

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

	return sum(a)

def main():
	n = int(input())

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

	print (solve(b,n))

if __name__ == "__main__":
	main()

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

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(sample_file = ''):

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter 
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)
    def make_divisors(n, reversed=False):
        """create list of divisors
        
        Args:
            number (int): number from which list of divisors is created
            reversed (bool, optional): ascending order if False. Defaults to False.
        
        Returns:
            list: list of divisors
        """
        divisors = set()
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.add(i)
                divisors.add(n//i)
        return sorted(list(divisors),reverse=reversed)
    
    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    class UnionFindTree:
        """union find tree class
        TODO: fix this description...
        how to use (example):
        >>  uf = UnionFindTree(N) 
        >>  if uf.find_root(a) == uf.find_root(b):
        >>      do something
        >>  else:
        >>      do something
        >>      uf.unite(a, b)
        """
        def __init__(self, N):
            self.root = [-1] * (N+1)
            self.rank   = [0]  * (N+1)
            self.connected_num = [1] * (N+1)
    
        def find_root(self,x):
            root = self.root
            while root[x] != -1:
                x = root[x]
            return x
    
        def unite(self,x,y):
            root = self.root
            rank = self.rank
            connected_num = self.connected_num
            find_root = self.find_root
    
            rx = find_root(x)
            ry = find_root(y)
            if rx != ry:
                if rank[rx] < rank[ry]:
                    root[rx] = ry
                    rx,ry = ry,rx
                else:
                    if rank[rx] == rank[ry]:
                        rank[rx] += 1
                    root[ry] = rx       
                connected_num[rx] += connected_num[ry]

    
    
    
    
    

    def BellmanFord(N, M, ABC, vertex_start, vertex_end, value_if_inf = -1, find_shortest = False):
        """to calculate furthest or shortest length between vertex_start and vertex_end using BellmanFord algorithm
        
        Args:
            N (int): number of vertices
            M (int): number of edges
            ABC (list): [(ai, bi, ci) for _ in range(N)] where i-th edge is directed from vertex ai to vertex bi and the length is ci 
            vertex_start (int): start vertex. usually use 0.
            vertex_end (int): end vertex. usually use N-1.
            value_if_inf (int or string as you like, optional): value you want when the furthest (or shortest) distance is infinite (or -infinite). Defaults to -1.
            find_shortest (bool, optional): choose False to find furthest path. Defaults to False.
        
        Returns:
            int or string: normally int (but can be str if you set value_if_inf to str)
            
        Example:
                N, M, P = R()
                ABC = [R() for _ in range(M)]
                ABC = [(a-1, b-1, c-P) for a, b, c in ABC]
                print(BellmanFord(N, M, ABC, 0, N-1, value_if_inf = 'inf'))

        """

        def make_reachable_list(N, M, ABC, vertex_start, vertex_end):
            reachable_to_direct = defaultdict(list)
            reachable_from_direct = defaultdict(list)
            reachable_from_start = [False] * N
            reachable_to_end = [False] * N
            reachable_from_start[vertex_start] = True
            reachable_to_end[vertex_end] = True
            reachable_from_both_sides = [False] * N
            dfs_from_start = []
            dfs_to_end = []
            for a, b, c in ABC:
                reachable_to_direct[a].append(b)
                reachable_from_direct[b].append(a)
                if a == vertex_start:
                    dfs_from_start.append(b)
                    reachable_from_start[b] = True
                if b == vertex_end:
                    dfs_to_end.append(a)
                    reachable_to_end[a] = True
            while dfs_from_start:
                v = dfs_from_start.pop()
                for i in reachable_to_direct[v]:
                    if not reachable_from_start[i]:
                        reachable_from_start[i] = True
                        dfs_from_start.append(i)
            while dfs_to_end:
                v = dfs_to_end.pop()
                for i in reachable_from_direct[v]:
                    if not reachable_to_end[i]:
                        reachable_to_end[i] = True
                        dfs_to_end.append(i)
            for i in range(N):
                reachable_from_both_sides[i] = reachable_from_start[i] and reachable_to_end[i]
            return reachable_from_both_sides
        
        reachable_from_both_sides = make_reachable_list(N, M, ABC, vertex_start, vertex_end)
        
        if find_shortest:
            dist = [INF for i in range(N)]
        else:
            dist = [-INF for i in range(N)]
        
        dist[vertex_start] = 0
        for i in range(N):
            updated = False
            for a, b, c in ABC:
                if not reachable_from_both_sides[a]:
                    continue
                elif find_shortest:
                    update_condition = dist[a] + c < dist[b]
                else:
                    update_condition = dist[a] + c > dist[b]
                if dist[a] != INF and update_condition:
                    dist[b] = dist[a] + c
                    updated = True
                    if i == N-1:
                        return value_if_inf
            if not updated:
                break
        return dist[vertex_end]

    """ initialize variables and set inputs
    
        
        
    
        
        
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    
    if sample_file:
        sys.stdin = open(sample_file)
        
    
    

    N = r_int()
    B = R()
    A = [0] * N
    for i in range(1, N-1):
        A[i] = min(B[i], B[i-1])
    A[0] = B[0]
    A[N-1] = B[N-2]
    print(sum(A))
    
    
    
    

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """
    
    """memo: how to solve binary problems
    
    >>> a = 5
    >>> bin_str_a = format(a, '
    >>> print(bin_str_a)
    0b0101 
    """
    
    """memo: how to solve the problem
    creating simple test/answer
    greed
    simple dp
    graph
    """

if __name__ == '__main__':
    main()

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())
A=list(map(int,input().split()))
count=A[0]+A[N-2]
for i in range(1,N-1):
    count+=min(A[i-1],A[i])
print(count)