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 main():
    n = int(input())
    b = [int(x) for x in input().split()]

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



if __name__ == '__main__':
    main()

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


print(ans)

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

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

Solution (Python):
n = int(input())
list1 = list(map(int,input().split()))
cout = list1[-1]
min_int = list1[-1]
for i in range(n-3,-1,-1):
    cout += min(list1[i:i+2])

cout += list1[0]

print(cout)

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

Solution (Python):
n = int(input())
b = [int(x) for x in input().split()]
total = b[0]
for i, val in enumerate(b[1:]):
	total += min(b[i], val)
total += b[-1]
print(total)

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

a=[b[0] for i in range(n)]

for i in range(len(a)-1):
    if a[i] <= b[i]:
        a[i+1]=b[i]
        
    if a[i] > b[i]:
        a[i]=b[i]
        a[i+1]=b[i]
    
print(sum(a))

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

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

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

print(ans)

Solution (Python):
import numpy as np
n=int(input())
b=np.array(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):
n = int(input())
bl = list(map(int, input().split()))
al = [0] * n

al[0] = bl[0]
al[1] = bl[0]

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

print(sum(al))

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


last_value = 100000000

res=0
for B in B_list:
        val = min(B,last_value)

        res += val
        last_value = B

res += last_value

print(res)

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

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

Solution (Python):
n = int(input())
a = [float("inf")] * n
b = list(map(int, input().split()))


def solve():
    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)


print(solve())

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

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

A[n-1] = B[n-2]

print(sum(A))

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

la[0] = lb[0]
for i in range(N-2):
    if lb[i] > lb[i + 1]:
        la[i + 1] = lb[i + 1]
    else:
        la[i + 1] = lb[i]
la[N-1] = lb[N-2]

print(sum(la))

Solution (Python):
N = int(input())
lst = list(map(int, input().split()))
ret = [lst[0]]
for idx, n in enumerate(lst[:-1]):
    ret.append(min(lst[idx], lst[idx + 1]))
ret.append(lst[-1])
print(sum(ret))

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

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

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

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

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

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

Solution (Python):
n = int(input())
l = [int(x) for x in input().split()]
l1 = [0 for x in range(n)]
for i in range(n-1):
	if l[i] > max(l1[i], l1[i+1]):
		if i == 0:
			l1[i] = l[i]
			l1[i+1] = l[i]
		else:
			l1[i+1] = l[i]
	else:
		l1[i] = l[i]
		l1[i+1] = l[i]
	
print(sum(l1))

Solution (Python):

n = int(input())
bx = [float("inf")] + list(map(float, input().split())) + [float("inf")]
out = 0
for i in range(n):
    out += int(min(bx[i], bx[i+1]))
print(out)

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

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

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

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

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

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


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

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

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

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

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

print(answer)

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

def min(x,y):
	if x>=y:
		return y
	else:
		return x
s=B[0]
for i in range(0,N-2):
    s=s+min(B[i],B[i+1])
print(s+B[N-2])

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

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

print(ans)

Solution (Python):
n = int(input())
data = [int(s) for s in input().split()]










ans = []
ans.append(data[0])
if len(data) >= 2:
  for i in range(1,n-1):
    ans.append(min(data[i],data[i-1]))
ans.append(data[len(data)-1])

print(sum(ans))

"""for i in ans:
  print(i)
"""

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):
n = int(input())
b_l = list(map(int, input().split()))
sum_a = 0

for i in range(n):
    if i is 0:
        sum_a += b_l[i]
    elif i == n-1:
        sum_a += b_l[i-1]
    else:
        sum_a += min(b_l[i],b_l[i-1])

print(sum_a)

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

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

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

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

print(ans)

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

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

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

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

print(B[0]+B[-1]+sum(min(x,y) for x,y in zip(B,B[1:])))

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])
print(ans + b[n-2])

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], B[i-1]))

print(sum(A))

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

A = []

i=0
while i<N-2:
    if B[i]>B[i+1]:
        A.append(B[i+1])
    else :
        A.append(B[i])
    i+=1

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


print(sum(A))

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

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

Solution (Python):
n = int(input())
B = [int(_) for _ in input().split()]

B.append(10**5)
B.insert(0,10**5)

res = 0

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

print(res)

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

Solution (Python):

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

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

print(sum(A))

Solution (Python):

import sys


def solve(N: int, B: "List[int]"):
    B_ex = [B[0]] + B + [B[-1]]
    print(sum([min(B_ex[i], B_ex[i+1]) for i in range(N)]))
    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] * N
A[0], A[1] = B[0], B[0]

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

print(sum(A))

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

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

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

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


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

a = sum(A)

print(a)

Solution (Python):



a_count = int(input())
b_value = list(map(int, input().strip().split()))

a_value = 0
a_value += b_value[0]

for i in range(1,a_count-1):
    if b_value[i - 1] > b_value[i]:
       a_value += b_value[i]
    else:
       a_value += b_value[i - 1]

a_value += b_value[a_count-2]
print(a_value)

Solution (Python):
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)
n = ip()
a=iprow()

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

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

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

A = [0] * N

A[0] = B[0]
A[1] = B[0]

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

print(sum(A))

Solution (Python):
def main():
    N = int(input())
    B = [int(i) for i in 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))

if __name__ == '__main__':
    main()

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

i = 0
sum = B[0]
while(i < N-2):
  tuika = min(B[i],B[i+1])
  
  sum += tuika
  i += 1

sum += B[i]
print(sum)

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

print(sum(a))

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

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

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

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

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

print(sum(a))

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

ans = B[0]

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

print(ans)

Solution (Python):



def main():



    n = int(input())
    bList = list(map(int,input().split()))
    ansList = []
    ansList.append(bList[0])

    for i in range(0,len(bList)-1):
        if bList[i] >= bList[i+1]:
            ansList.append(bList[i+1])
        else:
            ansList.append(bList[i])

    ansList.append(bList[-1])
    print(sum(ansList))




if __name__ == "__main__":
    main()

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

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

count = 0
for idx, b in enumerate(B):
	if(idx == 0):
		count += B[idx]
	else:
		count += min(B[idx], B[idx - 1])
count += B[len(B) - 1]
print(count)

Solution (Python):


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

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

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

Solution (Python):
from sys import stdin

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

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

print(sum)

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

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

print(sum(ans))

Solution (Python):
n = int(input())
b = list(map(lambda x:int(x),input().split()))
ans = 0
a = [float('inf')]*n
for i in range(1,len(a)-1):
    a[i] = min(b[i-1],b[i])
a[0] = b[0]
a[-1] = b[-1]
print(sum(a))

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


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
b = [int(x) for x in 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()))
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()))

a = 0

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

for n in range(N):
    if n == 0 or n == N-1:
        pass
    else:
        a += min(B[n-1], B[n])

print(a)

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

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

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

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

B_lst = list(map(int,input().split()))
A_lst = [0] * n

A_lst[0] = B_lst[0]
A_lst[n-1] = B_lst[n-2]

if n >= 3:
    for i in range(1,n-1):

        if B_lst[i-1] > B_lst[i]:
            A_lst[i] = B_lst[i]
        else:
            A_lst[i] = B_lst[i-1]

print(sum(A_lst))

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

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

result = B[0]

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

print(result)

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

Solution (Python):
N=int(input())
B=[int(x) for x in input().split()]
M=0
for i in range(N):
    if i==0:
        M+=B[0]
    elif i==N-1:
        M+=B[i-1]
    else:
        M+=B[i-1] if B[i-1]<B[i] else B[i]
print(M)

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

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

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

print(ans)

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

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

bb_list = b_list+[100000]
bbb_list = [100000]+b_list

c = 0
for bb, bbb in zip(bb_list, bbb_list):
    c += min(bb, bbb)

print(c)

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

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

Solution (Python):






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

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

print(sum(a)+B[0]+B[N-2])

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 




 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    B = inputList()
    
    ans = 0
    for i,val in enumerate(B):
        if i == len(B)-1:
            ans += val
        else:
            if val <= B[i+1]:
                ans += val
            else:
                ans += B[i+1]
            
    print(ans+B[0])
    
if __name__ == "__main__":
	main()

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

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

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

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

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

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

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

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


print(sum(anslist))

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

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

Solution (Python):

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

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

print(sum(a))

Solution (Python):

import sys
import math
import numpy as np


args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False


N = int(input())

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





if em: sys.stdin = open('/dev/tty')







As = [Bs[0]]

for i in range(0, len(Bs) - 1):
  As.append(min(Bs[i], Bs[i + 1]))

As.append(Bs[-1])
print(sum(As))

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

score = b_list[0] + b_list[n-2]

if n > 2:
	for val in range(n-2):
		c_list = [b_list[val], b_list[val+1]]
		score += min(c_list)
else:
	pass

print(score)

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

ans = 0
pre = 1e8

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

ans += B[N-2]

print(ans)

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

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

Solution (Python):


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

A = []

A.append(B[0])

for i in range(N):
    if i > 0 and i <= N-2:
        A.append(min(B[i-1], B[i]))
    
A.append(B[N-2])

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

if __name__ == '__main__':

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

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

	print(sumA)

Solution (Python):
def func(N, B_i):
    sum = B_i[N-2]
    for i in reversed(range(N-1)):
        if i >= 1:
            sum += min(B_i[i], B_i[i-1])
        else:
            sum += B_i[i]
    return sum

N = int(input())
B_i = list(map(int, input().split(" ")))
print(func(N, B_i))

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

Solution (Python):



def solve():
    N, *bl = map(int, open(0).read().split())
    al = [0] * N
    al[0], al[-1] = bl[0], bl[-1]
    
    for i in range(N-2, 0, -1):
        al[i] = min(bl[i], bl[i-1])
    
    print(sum(al))


if __name__ == '__main__':
    solve()

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

Solution (Python):
def main():
    N, *B = map(int, open(0).read().split())
    print(B[0] + B[-1] + sum(min(b1, b2) for b1, b2 in zip(B[:-1], B[1:])))
    return


main()

Solution (Python):

B_MAX = 100000
N = int(input().strip())
B = input().strip().split()


B = [B_MAX + 1] + [int(b) for b in B] + [B_MAX + 1] 

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

print(sum)

Solution (Python):
MAX_N = 100000


def main():
    N, *B = map(int, open(0).read().split())
    B.insert(0, MAX_N)
    B.insert(N, MAX_N)
    print(sum(min(b1, b2) for b1, b2 in zip(B[:-1], B[1:])))
    return


main()

Solution (Python):
MAX_N = 100000


def main():
    N, *B = map(int, open(0).read().split())
    B.insert(0, MAX_N)
    B.insert(N, MAX_N)
    print(sum(min(B[i - 1], B[i]) for i in range(1, N + 1)))
    return


main()

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

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

sums=0
cnt=N-2

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

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

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

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

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

Solution (Python):

"""
Created on Thu Sep 26 12:13:54 2019

@author: hiros
"""

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

ans = B[0]
i = 1

while (i < N-1):
    if (B[i-1] <= B[i]):
        ans += B[i-1]
    else:
        ans += B[i]
    i += 1
    

ans += B[-1]

print(ans)

Solution (Python):


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

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

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

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

A = [0]*N
A[0] = B[0]
for x in range(len(B)):
	if A[x] > B[x]:
		A[x] = B[x]
	A[x+1] = B[x]

print(sum(A))

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

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

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

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

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

Solution (Python):
n = int(input())
li_b = list(map(int, input().split()))
li_a = [9999999] * n

for idx, b in enumerate(li_b):
    li_a[idx] = min(li_a[idx], b)
    li_a[idx + 1] = min(li_a[idx + 1], b)

print(sum(li_a))

Solution (Python):
n = int(input())
li_b = list(map(int, input().split()))
li_a = [9999999] * n

for idx, b in enumerate(li_b):
    if idx == 0:
        li_a[0] == b
    if idx == n - 1:
        li_a[-1] == b
    else:
        li_a[idx] = min(li_a[idx], b)
        li_a[idx + 1] = min(li_a[idx + 1], b)
print(sum(li_a))