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):
def c():
    N = int(input())
    B = list(map(int, input().split()))

    if N <= 2:
        print(B[0] * 2)
        return
    sum = B[0]
    for i in range(1, N):
        if i == N-1:
            sum += B[N-2]
            break
        sum += min(B[i], B[i-1])

    print(sum)


if __name__ == '__main__':
    c()

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())
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):
import numpy

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

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

cnt += B[0]
cnt += B[-1]
print(cnt)

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

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
score = B[0] + B[N-2]

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

Solution (Python):
n = int(input())
B = list(map(int,input().split()))
A = [0] * n
ans = 0
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 = b[0] + b[n-2]

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

Solution (Python):
import sys
import math
from fractions import gcd





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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_b = list(map(int, sys.stdin.readline().split()))
list_a = [0]*N
list_a[N-1] = list_b[N-2]

for i in range(N-1, 0, -1):
    if(list_b[i-2] < list_b[i-1]):
        list_a[i-1] = list_b[i-2]
    else:
        list_a[i-1] = list_b[i-1]

if(list_a[1] > list_b[0]):
    list_a[0] =list_a[1]
else:
    list_a[0] =list_b[0]

sum = 0

for i in range(N):
    sum += list_a[i]



print(sum)

Solution (Python):



def solve():
    n = int(input())
    bl = [int(i) for i in input().split()]
    bl = [bl[0]] + bl + [bl[-1]]
    ans = 0
    for i in range(n - 1, -1, -1):
        ans += min(bl[i + 1], bl[i])
    print(ans)

if __name__=="__main__":
    solve()

Solution (Python):


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

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

print(num)

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

A=[]
zantei=B[-1]
for i in range(N-1):
    if B[N-2-i] < zantei:
        A.append(B[N-2-i])
    else:
        A.append(zantei)
    zantei = B[N-2-i]


A.append(zantei)

print(sum(A))

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

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

Solution (Python):
N = input()
B = input()
BList = []
BList = B.split(" ")
A = []
outputList = []
output = 0
num = 0

if (int(N)<101) and (int(N) > 1): 
    for i in range(len(BList)):
        if i == 0:
            outputList.append(BList[i])
        else:
            if int(BList[i-1]) <= int(BList[i]):
                outputList.append(BList[i-1])
            else:
                outputList.append(BList[i])
    outputList.append(BList[-1])

    for i in outputList:
        output = output + int(i)
    print(output)

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

answer = 0

for i in range(n - 1):
    answer += b[i] * 2

    if i != n - 2:
        if b[i] < b[i + 1]:
            answer -= b[i + 1]
        else:
            answer -= b[i]

print(answer)

Solution (Python):
while True:
    try:
        N = int(input())
        B = map(int, input().split())
        prev = None
        result = list()
        for i in B:
            if prev is None:
                result.append(i)
            else:
                result.append(min(prev, i))
            prev = i
        result.append(prev)
        print(sum(result))
    except EOFError:
        break

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

A = [0] * n

if n == 2:
  A[0] = A[1] = B[0]
elif n == 3:
  A[0] = B[0]
  A[1] = min(B[0], B[1])
  A[-1] = B[-1]
elif n > 3:
  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()))


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

sum += b[n-2]

print(sum)

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

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

if N >= 3:
  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())
l = list(map(int, input().split()))

ans = []
bef = 1000000
for i in l:
  ans.append(min(i, bef))
  bef = i

ans.append(l[n-2])
print(sum(ans))

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

a=list(map(int,input().split(' ')))

r=[]
for it in a:
    r.append(it)

r.append(a[N-2])

for idx,it in enumerate(a):
    if(r[idx+1]>it):
        r[idx+1]=it
print(sum(r))

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

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

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

if __name__ == "__main__":
    C_MaximalValue()

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

A = []
A_sum = 0

for i in range(N-1):
  if i != 0:
    if B[i-1] > B[i]:
      A[i] = B[i]
    A.append(B[i])
  else:
    A.append(B[i])
    A.append(B[i])
    
for i in range(N):
  A_sum += A[i]
  
print(A_sum)

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


for i in range(N-2,-1,-1):
    if max(A[i+1],A[i]) > B[i]:
            A[i] = B[i]
        
      
print(sum(A))

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

A = 0

for i in range(N):
    if i == 0:
        A += B[0]
    elif i < len(B):

        A += min(B[i-1], B[i])
    elif i == N-1:
        A += B[i-1]
        
print(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[n-2])
print(sum(a))

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

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

print(sum(A))

Solution (Python):
N = int(input())
Bs = list(map(int, input().split()))
As = [Bs[0]] + Bs
for i in range(N-1):
    if max(As[i], As[i+1])>Bs[i]:
        As[i] = Bs[i]
print(sum(As))

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

print(sum(A))

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

Solution (Python):


def main():
    N = int(input())
    B = list(map(int,input().split()))
    B.reverse()
    Ap = B[0]
    S = 0
    for Bi in B:
        A = min(Bi,Ap)
        if Bi > Ap:
            Ap = Bi
        else:
            Ap = A
        S += A
    S += Ap
    print(S)
          

if __name__ == "__main__":
    main()

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

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

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

str = input()
strList = str.split()
b = []
for x in strList:
    b.append(int(x))

l = len(b)
sum = b[l-1] + b[0]

for i in range(l-1):
    if b[i] < b[i+1]:
        sum += b[i]
    else:
        sum += b[i+1]

print(sum)

Solution (Python):
n = int(input())
list_b = list(map(int, input().split()))
list_a = [0]*n

list_a[0] = list_b[0]
list_a[1] = list_b[0]
for i in range(1, n-1):
  if list_b[i] < list_a[i]:
    list_a[i] = list_b[i]
    list_a[i+1] = list_b[i]
  else:
    list_a[i+1] = list_b[i]

print(sum(list_a))

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

s = input().split()

lis = [int(s[0]),int(s[a-2])]

for i in range(a-1)[1:]:
    inp = min(int(s[i]),int(s[i-1]))
    
    lis.append(inp)

count = 0
for p in lis:
    count += p
    
print(count)

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

print(s)

Solution (Python):
N = int(input())
AList = [ 0 for i in range(N)]
BList = [int(i) for i in input().split()]
AList[1-1] = BList[1-1]
AList[N-1] = BList[N-1-1]
for k in range(N):
    if 2 <= k and k <= N-1 and BList[k-1-1] <= BList[k-1]:
        AList[k-1] = BList[k-1-1]
    elif 2 <= k and k <= N-1 and BList[k-1-1] > BList[k-1]:
        AList[k-1] = BList[k-1]
print(sum(AList))

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

Solution (Python):
import sys
import math
from fractions import gcd





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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
n =  int(sys.stdin.readline())
b =  list(map(int, sys.stdin.readline().split()))

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

for i in range(1,n):
    if i !=n-1:
        a[i] = min(b[i],b[i-1])
    else:
        a[i] = b[i-1]
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[i-1])
    else:
        A.append(min(B[i-1], B[i]))

print(sum(A))

Solution (Python):

N = int(input())
B = list(map(int,input().split()))
A = [10**6]*N

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

print(sum(A))

Solution (Python):
n = int(input())
B = list(map(int,input().split()))+[float('inf')]

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

Solution (Python):


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

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

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

print(result)

Solution (Python):
N=int(input())
B = list(map(int,input().split()))
mA = []
aa=0
for i in range(N-1):
    if i==0:
        mA.append(B[i])


    else:
        if B[i-1]<B[i]:
            mA.append(B[i-1])
        else:
            mA.append(B[i])


mA.append(B[N-2])
for i in range(N):
    aa+=mA[i]
print(aa)

Solution (Python):
_ = input()
b = list(map(int, input().split()))
s = b[0] + b[-1]
for be, af in zip(b[:-1], b[1:]):
  if be < af:
    s += be
  else:
    s += af
print(s)

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

sum = 0

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

print(sum)

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

n = n-1

out = b[0]

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

print(out)

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

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

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

_b = 101
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=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)

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

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = [b[0], 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())
Blist = list(map(int, input().split()))
Alist = []
for i in range(0,N):
    Alist.append(0)
Alist[0] = Blist[0]
Alist[-1] = Blist[-1]



for i in range(1,N-1):
    Alist[i] = min(Blist[i-1],Blist[i])

ans = 0
for i in Alist:
    ans += i 

print(ans)

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

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

for i in range(N-2):
    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()))
B.append(-1)
A =[-1]*N
result=0

for i in range(N):
    if i==0:
        A[0]=B[0]
    else:
        if B[i]==-1:
            A[i]=B[i-1]
        else:
            if B[i]>=B[i-1]:
                A[i]=B[i-1]
            else:
                A[i]=B[i]
    result += A[i]

print(result)

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

for i in range(a):
    if i == 0:
        ans += b[0]
    elif i != a-1:
        A = b[i-1]
        B = b[i]
        if A > B:
            ans += B
        else:
            ans += A
    else:
        ans += b[-1]
print(ans)

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

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

Solution (Python):
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    Bs = [int(x) for x in stdin.readline().rstrip().split()]
    result = Bs[0]
    for i, B in enumerate(Bs[:-1]):
        result += min(B, Bs[i + 1])
    result += Bs[-1]
    print(result)


if __name__ == "__main__":
    main()

Solution (Python):

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

an = []

if n == 2:
    print(bn[0] * n)
    exit(0)

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

an.append(max(an[-1], bn[-1]))

print(sum(an))

Solution (Python):
num = int(input())
array = list(map(int, input().split()))
sum = 0
 
for i in range(num):
	if i == 0:
		sum += array[i]
	elif i < (num-1):
		if array[i] > array[i-1]:
			sum += array[i-1]
		else:
			sum += array[i]
	else:
		sum += array[i-1]
        
print(sum)

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

for i in range(n - 2):
    x = min(b[i], b[i + 1])
    a.append(x)
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]
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()))

a = []
b = [10**6] + b
for i in range(1, len(b)):
    b0, b1 = b[i - 1], b[i]
    if b0 > b1:
        a.append(b1)
    else:
        a.append(b0)
a.append(b[-1])
print(sum(a))

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

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

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

Solution (Python):
import copy 
import numpy as np

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

A = [0]*N

for i in range(1, N, 1):
    if i-1==0:
        A[i-1]   = B[i-1]
        A[i] = B[i-1]
    else:
        if B[i-1] >= A[i-1]:
            A[i] = max(A[i-1], B[i-1])
        else:
            A[i] = B[i-1]
            A[i-1] = B[i-1]
print(sum(A))

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

ret=0
bs=0
for i,b in enumerate(B):
  if i==0:
    ret+=b
  else:
    if bs<b:
      ret+=bs
    else:
      ret+=b
  bs=b

ret+=B[-1]
print(ret)

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

Solution (Python):
n = int(input())
b = [int(i) for i in 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()))
ans=b[0]
for i in range(n-2):
    if(b[i]>b[i+1]):
        b[i]=b[i+1]

ans+=sum(b)

print(ans)

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

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

x+= int(b[n-2])

print(x)

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

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

print(sum(A))

Solution (Python):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
import math
import time
ts=time.time()
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7

n=I()
b=LI()
ans=0

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

ans+=b[0]
ans+=b[-1]
    
print(ans)

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

a.append(b[0])

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

a.append(b[n-2])
print(sum(a))

Solution (Python):
import sys
import math
from fractions import gcd


from itertools import accumulate


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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N =  int(sys.stdin.readline())
L =  list(map(int, sys.stdin.readline().split()))

"""
for i in range(N - 2, 0, -1):
    if L[i] < L[i -1]:
        L[i - 1] = L[i]
print(L)
X = accumulate(L)
print(list(X)[-1] + L[0])
"""

X = [L[0]]

for l1, l2 in zip(L, L[1::]):
    X.append(min(l1, l2))
X.append(L[-1])
print(sum(X))

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

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

Solution (Python):
import numpy as np

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

testA = B + [0]
testB = [0] + B



temp = (np.array(testA)-np.array(testB))[:len(B)]

res = sum(temp[temp < 0])

print(B[0] + sum(B) + res)

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

print(sum(A))

Solution (Python):
def main():
    n = int(input())
    b = [int(i) for i in 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))
if __name__ == "__main__":
    main()

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

b2 = [b[0]]
b2.extend(b)
b.append(b[n-2])

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

print(ans)

Solution (Python):
def main():

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

if __name__ == "__main__":
    main()

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

result = 0

for index in range(N-1):
    if index == 0:
        result += A[0]
    else:
        result += min(A[index], A[index-1])

result += A[len(A)-1]

print(result)

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

a_sub = input().split(" ")
a = [int(n0) for n0 in a_sub]


s = a[0]+a[N-2]

for xi in range(1,N-1):
    if a[xi-1]<a[xi]:
        s = s+a[xi-1]
    else:
        s = s+a[xi]

print(s)

Solution (Python):
def main(): 
    
    N = int(input())
    A = []
    B = list(map(int, input().split()))
    B.insert(0, 100000)
    B.append(100000)

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

if __name__ == "__main__":
    main()

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[0]
    elif i == N - 1:
        A[i] = B[N - 2]
    else:
        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[1] = B[0]

for i in range(1, N-1):
    if A[i] <= B[i]:
        A[i+1] = B[i]
    else:
        A[i] = B[i]
        A[i+1] = B[i]

print(sum(A))

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

def main(n, b_list):
    b_list.append(b_list[-1])
    result = b_list[0] + b_list[-1]
    for i in range(n-2):
        result += min(b_list[i], b_list[i+1])
    return result

print(main(n, b_list))

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

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

print(t + B[N - 2])

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

a = []
sum_a = b[0] + b[-1]
for i,b_i in enumerate(b):
    
    if i+1 < n-1:
        if b[i+1] >= b[i]:
            a.append(b[i])
            sum_a += b[i]
        else:
            a.append(b[i+1])
            sum_a += b[i+1]
print(sum_a)

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

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

count=0

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

count+=B[0]+B[n-2]

print(count)

Solution (Python):


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

Solution (Python):
N = int(input())
BBB = list(map(int, input().split()))
BBB += [10**5]

AAA = [0] * N

AAA[0] = BBB[0]

for i, B in enumerate(BBB[:-1]):
    AAA[i + 1] = min(B, BBB[i + 1])

print(sum(AAA))

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

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

a = [B[0]]
for i, no in enumerate(B):
    if i == len(B) - 1:
        a.append(B[i])
    else:
        a.append(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]

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

a[-1] = max(a[-1], b[-1])

print(sum(a))

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

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

A = [0] * N
for i in range(N - 1):
    if i == 0:
        A[i] = B[i]
    elif A[i] > B[i]:
        A[i] = B[i]
    A[i + 1] = B[i]
print(sum(A))

Solution (Python):
from itertools import accumulate
import sys

def main():
    input = sys.stdin.readline
    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))


if __name__ == '__main__':
    main()

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

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

out += B[N-2]
    
print(out)

Solution (Python):
import numpy as np

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

result=0
A=[]
A.append(B[0])
for i in range(len(B)):
    if i!=0:
        A.append(min(B[i],tmp))
    tmp=B[i]
A.append(B[N-2])
result=np.sum(A)
print(result)

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

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

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

a = [b[0]]
tmp = 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()))

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

Solution (Python):


n =int(input())
b = list(map(int,input().split()))
b.insert(0,10 ** 5)
b.append(10 ** 5)
a=[]

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

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

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

ans += b[0] + b[n-2]

print(ans)

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

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


target =  [0] * N
target[0] = B_list[0]
target[1] = B_list[0]
for i in range(1,N-1):
    
    if B_list[i-1] > B_list[i]:
        target[i] = B_list[i]
        target[i+1] = B_list[i]
    else:
        target[i+1] = max(B_list[i-1],B_list[i])

print(sum(target))

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[-1] + B[0]
print(ans)

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

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[i-1])
  else:
    a.append(min(b[i], b[i-1]))
print(sum(a))

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

arr1=[0]*(n)
arr1[0]=arr[0]
arr1[-1]=arr[-1]
for i in range(1,n-1):
	arr1[i]=min(arr[i],arr[i-1])

print(sum(arr1))

Solution (Python):
N = int(input())
B_list = list(int(Bi) for Bi in input().split(' '))

num=0
B_pre=0

for i in range(len(B_list)):
  if i==0:
    num+=B_list[i]
    B_pre=B_list[i]
  else:
    if B_list[i]>=B_pre:
      num+=B_pre
    else:
      num+=B_list[i]
    
    B_pre=B_list[i]
    
num+=B_list[-1]

print(num)

Solution (Python):
import sys

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

a = [0] * N
a[0] = b[0]
for i in range(len(b) - 1):
    if b[i] > b[i + 1]:
        a[i + 1] = b[i + 1]
    else:
        a[i + 1] = b[i]
a[-1] = b[-1]

print(sum(a))

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

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

print(sum(a))