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

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

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())
l=list(map(int,input().split()))
d=[l[0]]
for i in range(n-1):
    if(l[i]>=l[i-1]):
        d.append(l[i])
    else:
        d[i]=l[i]
        d.append(l[i])
print(sum(d))

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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[N-2]

print(ans)

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

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

for j in range(1,N-1):
  A[j] = min(B[j],B[j-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], B[i-1])
print(ans)

Solution (Python):
N = int(input())
if N == 2:
  ans = 2 * int(input())
else:
  B = list(map(int, input().split()))
  ans = B[0] + B[N-2]
  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()))
C = []
C.append(B[0])
for i in range(len(B) - 1):
    C.append(min(B[i], B[i+1]))
C.append(B[-1])
print(sum(C))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
sum=B[0]
for i in range(1,N):
    if i<N-1 and B[i]<=B[i-1]:
        sum=sum+B[i]
    elif i<N-1 and B[i-1]<=B[i]:
        sum=sum+B[i-1]
    else:
        sum=sum+B[N-2]
print(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]
if n >= 3:
    for i in range(2,n):
        a[i-1] = min(b[i-1],b[i-2])
print(sum(a))

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

Solution (Python):

N = int(input())
B = list(map(int,input().split()))
A = [B[0]]
for i in range(1,N-1):
    if B[i] > B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])
A.append(B[-1])
print(sum(A))

Solution (Python):


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

INF = float('inf')
B.append(INF)
B.insert(0, INF)

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

print(count)

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
B.insert(0, B[0])
B.insert(-1, B[-1])

A = []

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

Solution (Python):




def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())

    ans = 0

    prev = 0
    for i, b in enumerate(input().rstrip().split(" ")):
        b = int(b)
        if i == 0:
            ans += b
            prev = b
            continue

        ans += min(b, prev)
        prev = b
    ans += b

    print(ans)


if __name__ == "__main__":
    resolve()

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

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(input())
B=list(map(int,input().split()))
B=eval(f"[{B[0]}]")+B+eval(f"[{B[N-2]}]")
A=[0]*N
for i in range(N-1):
  A[i]=min(B[i],B[i+1])
A[N-1]=B[N-1]
print(sum(A))

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

A = []
ans = 0
for i in range(N-1):
    if i == 0:
        A.append(B[i])
        continue
    if B[i] >= B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])
A.append(B[N-2])
for i in range(N):
    ans += A[i]

print(ans)

Solution (Python):
n = int(input())
b_list = list(map(int, input().split()))
b_list.append(b_list[-1])
a_list = [0] *n
a_list[0] = b_list[0]
for i in range(1,n):
    
    if b_list[i-1] <= b_list[i]:
        a_list[i] = b_list[i-1]
    else:
        a_list[i] = b_list[i]
    
print(sum(a_list))

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-1], B[i])
A[N-1] = B[N-2]

print(sum(A))

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    B=list(mi())

    X = []
    X.append(B[0])
    X.append(B[0])

    for i in range(1,N-1):
        last = X[-1]
        if last <= B[i]:
            X.append(B[i])
        else:
            X[-1] = B[i] 
            X.append(B[i])
    
    
    print(sum(X))







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 += min(b[i], b[i + 1])
ans += b[n-2]
print(ans)

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

import copy
A = copy.deepcopy(B)
for i in range(1,N-1):
    if B[i-1]<B[i]:
        A[i] = B[i-1]
        
A.append(B[-1])
print(sum(A))

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

Solution (Python):
N = int(input())
B = list(map(lambda b : int(b) , input().split(" ")))
A = [B[0], B[-1]]
for i in range(len(B) - 1):
  A.append(min([B[i], B[i + 1]]))

print(sum(A))

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

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

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

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
a = []
a.append(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()))

dp = [10**8]*N
for i in range(N-1):
    if dp[i]>B[i]:
        dp[i]=B[i]
    if dp[i+1]>B[i]:
        dp[i+1]=B[i]
    
print(sum(dp))

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

for i in range(N-2):
    if B[i] <= B[i+1]:
        A.append(B[i+1])
    else:
        A[i+1] = B[i+1]
        A.append(B[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[N - 2])
print(sum(A))

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = I()
B = LI()

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):
from sys import stdin

n = int(stdin.readline().rstrip())
B = [int(x) for x in stdin.readline().rstrip().split()]

B.append(1e+5 + 3)

sum = B[0]

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

print(sum)

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
a = [0] * N
ans = 0
x = 0
if N == 2:
    ans = B[0] * 2
elif N == 3:
    ans = sum(B) + min(B)
else:
    for i in range(N - 1):
        if i == 0:
            a[0] = B[0]
            
        
        else:
            x = min(B[i],B[i - 1])
            a[i] = x
            
            if i == N - 2:
                a[i + 1] = B[N - 2]
                
        
        ans = sum(a)
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[N-2])
print(sum(A))

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

A=[0]*n
i=0
A[i]=B[i]
while 1 :
    i+=1
    if i>=n-1:
        break
    A[i]=min(B[i],B[i-1])
A[i]=B[i-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 0<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=[10**6]*N

for i in range(N-1):
    if A[i] >= B[i]:
        A[i] = B[i]
    if A[i+1] >= B[i]:
        A[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]
for i in range(1, n - 1):
    a[i] = min(b[i - 1], b[i])
a[n - 1] = b[-1]
print(sum(a))

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

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()))
s = B[0]
for i in range(N-2):
    
    if i == N - 2:
        s += B[i]
        
        break
    else:
        if B[i] > B[i + 1]:
            s += B[i+1]
        else:
            s += B[i]
    
s += B[N-2]
print(s)

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

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

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

a = []

for i in range(n):
    if i == 0:
        a.append(b[0])
    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()))
if N==1:
    print(B[0]*2)
else:
    ans=B[0]
    for i in range(N-2):
        ans+=min(B[i],B[i+1])
    ans+=B[-1]
print(ans)

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    b = list(map(int, input().split()))
    b.insert(0,INF)
    b.append(INF)
    ans = []
    for i in range(len(b)-1):
        ans.append(min(b[i],b[i+1]))
    print(sum(ans))


if __name__=="__main__":
    main()

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

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

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

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



if __name__=="__main__":
    main()

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
B = inintl()

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

Solution (Python):
import math
from collections import defaultdict,deque

ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

n=ii()
a=ll()
lol=[]
lol.append(a[0])
for i in range(1,n-1):
    lol.append(min(a[i-1],a[i]))
lol.append(a[n-2])
print(sum(lol))

Solution (Python):
n=int(input())
b= list(map(int, input().strip().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 = list(map(int, input().split()))
ans = b[0]
for i in range(1, n-1):
    ans += min(b[i], b[i-1])
ans += b[-1]
print(ans)

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


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

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

Solution (Python):


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

a = [0] * (len(b) + 1)
a[0] = max(b)

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

print(sum(a))

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

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

Solution (Python):
N = int(input())
B = tuple(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()))
ls = [0]*N
ls[0] = B[0]

for i in range(1,N-1):
    if B[i-1] <= B[i]:
        ls[i] = B[i-1]
    else:
        ls[i] = B[i]
ls[N-1] = B[N-2]
print(sum(ls))

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

A = []

for i in range(N):
    if i == 0:
        A.append(B[0])
    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 = [0]*n
for i in range(n-1):
  if i == 0:
    ans[i] = b[i]
  else:
    ans[i] = min(b[i-1],b[i])
print(sum(ans)+b[-1])

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    B = LI()

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

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
A = N*[0]

for n in range(N-1):
  if n==0:
    A[n]=B[n]
  else:
    A[n] = min(B[n-1],B[n])

print(sum(A)+B[-1])

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

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

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()))
A = [0]*N
Bp = 1<<100
for i in range(N-1):
    A[i] = min(B[i], Bp)
    Bp = B[i]
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+=min(B[i-1], B[i])
A+=B[N-2]
print(A)

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(input())
B = tuple(map(int, input().split()))

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

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

Solution (Python):

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

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

print(ans)

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
A=[0 for i in range(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(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()))

ans = b[0] + b[-1]
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()))
a = [None]*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(input())
B = list(map(int, input().split()))
ans = []
for i in range(N):
    if i == 0:
        ans.append(B[0])
    elif 0 < i < N - 1:
        temp = min(B[i - 1], B[i])
        ans.append(temp)
    elif i == N - 1:
        ans.append(B[-1])

print(sum(ans))

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

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

Solution (Python):
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n = int(lines.pop(0))
b_list = [int(b) for b in lines.pop(0).split(" ")]
b_list.append(sys.maxsize)
def _iter():
    prev_b = sys.maxsize
    for b in b_list:
        yield min(prev_b, b)
        prev_b = b
answer = sum(_iter())
print(answer)

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

ans = b[-1]+b[0]
for i in range(n-2):
    if b[-i-2] <= b[-i-1]:
        ans += b[-i-2]
    else:
        ans += 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 - 1], B[i])
A[n - 1] = B[-1]

print(sum(A))

Solution (Python):



N=int(input())
Bfirst=[10**5+3]
B=list(map(int,input().split()))
Blast=[10**5+3]
BL=Bfirst+B+Blast

ans=0

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

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(1, n-1):
	if b[i]>=b[i-1]:
		a[i]=b[i-1]
	else:
		a[i]=b[i]
s = 0
for i in range(n):
	s += a[i]
	
print(s)

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):
import heapq
t = 1
def max(a,b):
	if a > b:
		return a
	return b
while t > 0:
	t -= 1
	
	n = int(input())
	
	
	c = list(map(int,input().strip().split()))[0:n-1]
	b = []
	for i in range(n):
		b.append(0)
	b[0] = c[0]
	b[n-1] = c[n-2]
	for i in range(1,n-1):
		b[i] = min(c[i],c[i-1])
	ans = 0
	for i in range(n):
		ans += b[i]
	print(ans)

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 a[i] <= b[i]:
        pass
    else:
        a[i] = b[i]
    a[i + 1] = b[i]

print(sum(a))

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

A = []
A.append(B[0])
for i in range(len(B) - 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 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[n-2]
ans = 0
for i in range(n):
    ans += a[i]
print(ans)

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

Solution (Python):


















































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    N = int(lines[0])
    
    values = list(map(int, lines[1].split()))
    
    
    
    
    
    
    

    lst = [0] * N
    lst[0] = values[0]
    lst[N-1] = values[N-2]
    for n in range(1, N-1):
        lst[n] = min(values[n-1], values[n])

    return [sum(lst)]



def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '2 5']
        lines_export = [9]
    if pattern == 2:
        lines_input = ['2', '3']
        lines_export = [6]
    if pattern == 3:
        lines_input = ['6', '0 153 10 10 23']
        lines_export = [53]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

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

print(ans+b[0]+b[int(len(b)-1)])

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

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

Solution (Python):
n=int(input())
b=[int(x) for x in input().rstrip().split()]
a=[b[0]]
for i in range(1,n-1):
    a.append(min(b[i],b[i-1]))
a.append(b[n-2])

print(sum(a))

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
A=[]
for c in B:
    A.append(c)
A.append(B[-1])

for a in range(len(B)):
   
    if A[a]>B[a]:
        A[a]=B[a]
    elif A[a+1]>B[a]:
        A[a+1]=B[a]

print(sum(A))

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

for p in range(N):
    A[p] = min(B[p], B[p+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],b[i-1])
print(ans)

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

Solution (Python):
n = int(input())
b = list(map(int, 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):
def readinput():
    n=int(input())
    b=list(map(int,input().split()))
    return n,b

def main(n,b):
    sum=b[0]
    for i in range(1,n-1):
        sum+=min(b[i-1],b[i])
    sum+=b[n-2]
    return sum

if __name__=='__main__':
    n,b=readinput()
    ans=main(n,b)
    print(ans)

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

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

Solution (Python):
N,*B,=open(0).read().split()
N=int(N)
B=list(map(int,B))
ans=B[0]
if N==2:
    ans+=B[0]
else:
    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 = [10 ** 9] + list(map(int, input().split())) + [10 ** 9]
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()))
print(b[0] + b[-1] + sum([ min(i, j) for i, j in zip(b, b[1:]) ]))

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

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [100000] * N
    B = [int(i) for i in input().split()]
    for i in range(N-1):
        if A[i] > B[i]: A[i] = B[i]
        A[i+1] = B[i]
    print(sum(A))
   
    return 0

if __name__ == "__main__":
    solve()

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

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

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

print(sum(A))

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

lsA = [0]*N
lsA[0] = lsB[0]
lsA[N-1] = lsB[N-2]
for i in range(1,N-1):
    lsA[i] = min(lsB[i-1],lsB[i])
print(sum(lsA))

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


def solve(N, B):
    ans = 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])
        ans += a
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

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

print(ans+B[-1])

Solution (Python):
N = int(input())
B = input().split(' ')
B = [int(B[i]) for i in range(N-1)]
SUM = [B[0], B[-1]]
for i in range(N-2):
  if B[i]>=B[i+1]:
    SUM.append(B[i+1])
  else:
    SUM.append(B[i])
print(sum(SUM))

Solution (Python):
N = int(input())
B = input().split(' ')
B = [int(B[i]) for i in range(N-1)]
SUM = [B[0], B[-1]]
for i in range(N-2):
  if B[i]>=B[i+1]:
    SUM.append(B[i+1])
  else:
    SUM.append(B[i])
print(sum(SUM))

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

if N==2:print(B[0]*2)
else:
  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())
bbb = list(map(int, input().split()))
aaa = []
for i in range(1, N - 1):
    a = min(bbb[i - 1], bbb[i])
    aaa.append(a)
print(sum(aaa) + bbb[0] + bbb[-1])

Solution (Python):

N = int(input())
b = list(map(int,input().split()))
a = [0 for i in range(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):

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

    a = [0]*n

    for i,e in enumerate(b):
        if i == 0:
            a[0] = b[0]
        else:
            a[i] = min(b[i-1], b[i])

    a[-1] = b[-1]
            
            
            
            

    print(sum(a))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
B = [int(i) for i in input().split()]

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

Solution (Python):

import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    input = sys.stdin.readline
    
    
    

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

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


if __name__ == '__main__':
    main()

Solution (Python):
def main() -> None:
    N = int(input())
    B = [int(x) for x 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()))
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]]+[0]*(n-1)

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

Solution (Python):
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
B = list(map(int,readline().split()))
ans = 0 
ans += B[0]
for i in range(N-2):
    ans += min(B[i],B[i+1])
ans += B[N-2]
print(ans)

Solution (Python):








def solve(N, Bs):
    Bss = [Bs[0]] + Bs + [Bs[-1]]
    As = []
    for i in range(len(Bss) - 1):
        As.append(min(Bss[i], Bss[i + 1]))
    print(sum(As))


if __name__ == '__main__':
    
    N = int(input())
    
    
    Bs = [int(i) for i in input().split()]
    solve(N, Bs)

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[N-2]
print(ans)

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

Solution (Python):
N = int(input())
B = [int(i) for i in input().split(' ')]
A = [0]*(N)
for i,a in enumerate(B):
    if i == 0: 
        A[i] = a
        A[i+1] = a
    else:
        if B[i-1] < B[i]:
            A[i+1] = a
        else:
            A[i] = a
            A[i+1] = a

print(sum(A))