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):
if __name__ == '__main__':
    a = int(input())
    li_1 = list(map(int, input().split()))
    res = []
    for x in range(0, a - 1):
        if x == 0:
            res.append(li_1[x])
        else:
            res.append(min(li_1[x], li_1[x - 1]))
res.append(li_1[-1])
result = 0
for x in res:
    result += x

print(result)

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

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

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

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

A += B_list[N-2]
print(A)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
b_arr = list(map(lambda b: int(b), input().split()))
a_arr = list(range(N))

for n in range(N-1, -1, -1):
    if (n == N-1) or (n == N-2):
        a_arr[N-1] = b_arr[N-2]
        a_arr[N-2] = b_arr[N-2]
    elif b_arr[n+1] >= b_arr[n]:
        a_arr[n+1] = b_arr[n]
        a_arr[n] = b_arr[n]
    else:
        a_arr[n] = b_arr[n]

print(sum(a_arr))

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

a = [10**6] * n

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

print(sum(a))

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

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

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

print(x)

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

Solution (Python):
def solve(string):
    n, *b = map(int, string.split())
    b.append(b[-1])
    return str(b[0] + sum([min(b0, b1) for b0, b1 in zip(b, b[1:])]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

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]):
        if a[i] < a[i + 1]:
            a[i + 1] = a[i]
        else:
            a[i] = a[i + 1]
print(sum(a))

Solution (Python):
N = int(input())
B_list = [int(i) for i in input().split()]
A_list = [10000000] * N

for i in range(len(B_list)) :
    B = B_list[i]
    if (min(B,A_list[i]) == B) :
        A_list[i] = B
    
    A_list[i+1] = B


print(sum(A_list))

Solution (Python):
















import sys
input = sys.stdin.readline

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-1):
	a[i] = min(b[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[0])

for i in range(1, N-1):
  a=min(B[i-1], B[i])
  A.append(a)
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):
N = int(input())
Bi = [int(i) for i in input().split(" ")]

res_A = []
Bi = [float('inf')] + Bi + [float('inf')]
for i in range(N):
  res_A += [min(Bi[i], Bi[i+1])]
print(sum(res_A))

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

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

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

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

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

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

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

print(sum(A))

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

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

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

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
b = list(li())
b = [b[0]] + b + [b[-1]]

ans = 0

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

print(ans)

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, B: "List[int]"):
    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))
    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()))

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

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

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

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

ret = 0

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

print(ret)

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

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

Solution (Python):
N = int(input())
Bi  = input().split()
ret = int(Bi[0])
for i in range(1, len(Bi)):
    if(int(Bi[i]) < int(Bi[i - 1])):
        ret += int(Bi[i])
    else:
        ret += int(Bi[i - 1])
print(ret + int(Bi[len(Bi) - 1]))

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

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

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

print(ans)

Solution (Python):
num = int(input())
B_list = [int(item) for item in input().split()]

Ai_cand =[B_list[0]]

for k in range(1, num-1):
    Ai_cand.append(min(B_list[k], B_list[k-1]))

Ai_cand.append(B_list[-1])
    
print(sum(Ai_cand))

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:
    val1=B[i-1]
    val2=B[i]
    ans+=min(val1,val2)
ans+=B[-1]
print(ans)

Solution (Python):
import sys
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    B = string_to_int(inputs[0])
    A = []

    candidate = -1
    for i, b in enumerate(B):
        if i == 0:
            A.append(b)
        else:
            if b > candidate:
                A.append(candidate)
            else:
                A.append(b)
        candidate = b
    A.append(b)
    return sum(A)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

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

sum_a = 0
B = [10**5] + B + [10**5]
for n in range(N ):
    sum_a += min(B[n: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(1, N - 1):
    ans += min(B[i], B[i - 1])
        
print(ans)

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

Solution (Python):
import numpy as np

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

A = [0 for i in range(length)]
for i in range(len(B)):
    
    if i == 0:
        A[i],A[i+1] = B[i],B[i]
    
    else:
        if B[i]<=A[i]:
            A[i] = B[i]
    
    A[i+1] = B[i]

print(np.sum(A))

Solution (Python):

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

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

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

print(total)

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

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

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

print(sum)

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

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

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

for k in range (n):
    goukei += a[k]
print(goukei)

Solution (Python):

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

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

s = 0
for i in range(0,n):
    s = s + a[i]

print(s)

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

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
A = [0 for _ in range(N)]
A[0] = B[0]
A[N-1] = B[N-2]
for i in range(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]]
if n>=2:
    for i,j in zip(b[:-1], b[1:]):
        ans.append(min(i,j))

print(sum(ans))

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

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

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
A = []
B.reverse()
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())
b = list(map(int, input().split()))

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

print(s)

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

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


result = [B[0]]
for i, e in enumerate(B):
    if i < len(B) - 1:
        result.append(min(B[i], B[i+1]))
    else:
        result.append(B[i])
print(sum(result))

Solution (Python):
N=int(input())
B = list(map(int, input().split()))
B.append(10**5+1)
t=0
for i in range(N-1):
  if B[i]>B[i+1]:
    t+=B[i+1]
  else:
    t+=B[i]
t+=B[0]
print(t)

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

B.reverse()
result = [B[0]]
for i, e in enumerate(B):
    if i < len(B) - 1:
        result.append(min(B[i], B[i+1]))
    else:
        result.append(B[i])
print(sum(result))

Solution (Python):
def maximal():
    N = int(input())
    B = input()
    B = B.split()
    B = [int(i) for i in B]
    
    
    result = []
 
    result.append(B[0])
 
    for i in range(0, len(B) - 1):
        
        compared = B[i]
        if B[i + 1] <= compared:
            result.append(B[i + 1])
        else:
            result.append(B[i])
 
    result.append(B[len(B) - 1])
    return sum(result)
 
 
print(maximal())

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

B.reverse()
result = [B[0]]
for i, e in enumerate(B):
    if i < len(B) - 1:
        result.append(min(B[i], B[i+1]))
    else:
        result.append(B[i])
print(sum(result))

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

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

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

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

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

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

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

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

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

ans = b[0]

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

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

Solution (Python):

N=int(input())

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

A = []


A.append(B[0])

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


A.append(B[N-2])
    



print(sum(A))

Solution (Python):


MOD = 10 ** 9 + 7

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

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

print(ans)

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

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

for i in range(1, n-1):
    a_arr[i] = min(b_arr[i-1], b_arr[i])

print(sum(a_arr))

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):
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    ans = b[0]
    ans += b[-1]
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += min(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Solution (Python):
n = int(input())
lineb = input().split(" ")
total_a = int(lineb[0])

for i in range(n - 2):
    if int(lineb[i]) <= int(lineb[i+1]):
        total_a += int(lineb[i])
    else:
        total_a += int(lineb[i+1])
        
total_a += int(lineb[n-2])
        
print(total_a)

Solution (Python):

import sys

"""
Bs[i] >= max(As[i], As[i+1]) を満たす条件で、

sum(As)の最大値を求める問題
"""

def solve():
    N = int(sys.stdin.readline())
    Bs = list(map(int, sys.stdin.readline().split()))

    if N == 2:
        print(Bs[0]*2)
        return

    
    As = [0] * N
    if Bs[0] <= Bs[1]:
        As[0] = As[1] = Bs[0]
    else:
        As[0], As[1] = Bs[0], Bs[1]

    
    for i in range(1, N-2):
        if Bs[i] > Bs[i+1]:
            
            
            As[i+1] = Bs[i+1]
        else:
            
            
            As[i+1] = Bs[i]
    As[N-1] = Bs[N-2]

    print(sum(As))



if __name__ == "__main__":
    solve()

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())
bl = [int(i) for i in input().split()]
bl.reverse()

v = bl[0]

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

v += bl[n-2]

print(v)

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

count = a[0]

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

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

sum = B[0]
for i in range(N - 1):
	sum += min(B[i],B[i + 1]) if i < N - 2 else B[i]
print('%d' % sum)

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

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

print(maximal)

Solution (Python):
from sys import stdin

N = int(stdin.readline())
B = list((int(wd) for wd in stdin.readline().split()))

ret = B[0] + B[-1]
for i in range(len(B)-1):
    ret += min(B[i], B[i+1])
    pass
print(ret)

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

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

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

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

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

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],B[i-1])
    i+=1
A[0]=B[0]
A[N-1]=B[N-2]
print(sum(A))

Solution (Python):
n = int(input())
b_list = list(map(int, input().split()))
ans_list = []
ans_list.append(b_list[0])
for i in range(n-2):
    v = b_list[i]
    vn = b_list[i+1]
    ans_list.append(min(v, vn))

ans_list.append(b_list[-1])

print(sum(ans_list))

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

A.append(B[-1])


Total = sum(A)
print(Total)

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

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

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

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


if __name__ == "__main__":
    main()

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

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

for i in range(1, len(B), 1):
    if B[i] < A[i]:
        A[i] = B[i]
    A.append(B[i])

print(sum(A))

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



output=0

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



print(sum(A))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
A = [0]*(len(B)+1)
A[0] = B[0]
A[1] = B[0]
cnt = 0
for i, x in enumerate(B):
    if i != 0:
        A[i + 1] = B[i]
        A[i] = min(A[i], B[i])
    cnt += A[i]
cnt += A[-1]
print(cnt)

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

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

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

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

i = 0
while i < n - 2:
	s += min(b[i], b[i + 1])
	i += 1

print(s)

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

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

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

A_list[0] = B_list[0]

for i in range(1,N-1):
    A_list[i] = min(B_list[i],B_list[i-1])

A_list[-1] = B_list[-1]
print(sum(A_list))

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


sum_aaa = B_list[0]

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

sum_aaa += B_list[-1]
print(sum_aaa)

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

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

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

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

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

print(sum(A))

Solution (Python):

import numpy as np
if __name__ == "__main__":
    
   
    dim = int(input())
    B = [int(x) for x in input().split()]
    
    A =[B[0]]

    for x in range(dim-2):
        A.append(np.amin((B[x],B[x+1])))
    
    A.append(B[-1])

    print(np.sum(A))

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

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

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

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

Solution (Python):



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

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

    print(ans)


if __name__ == '__main__':
    main()

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

ans = [0]*(len(a) + 1)
for i, name in enumerate(a):
    if i == 0:
        ans[i] = name
        ans[i+1] = name
    else:
        ans[i] = min(name, a[i - 1])
        ans[i+1] = name

print(sum(ans))

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

Solution (Python):
class ABC140C:

    def __init__(self):
        self.nNum = int(input())
        self.bList = list(map(int, input().split()))

    def solve(self):
        aList = [0] * self.nNum
        aList[0] = self.bList[0]
        for i in range(self.nNum - 1):
            if self.bList[i] < aList[i]:
                aList[i] = self.bList[i]
            aList[i + 1] = self.bList[i]

        print(sum(aList))


if __name__ == '__main__':
    ABC140C().solve()

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

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

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

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

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

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

print(sum(A))

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

Solution (Python):
n=int(input())
B=list(map(int,input().split()))
A=[]
A.append(B[0])
if n>=3:
    for i in range(n-2):
      m=min(B[i],B[i+1])
      A.append(m)
    last=B[n-2]
    A.append(last)
else:
    A.append(B[0])

print(sum(A))

Solution (Python):
import sys

input = sys.stdin.readline

MAX_VALUE = 10e9


def solve(B, n):
    B = [MAX_VALUE] + B + [MAX_VALUE]
    result = 0
    for i in range(n):
        result += min(B[i], B[i + 1])

    return result


if __name__ == '__main__':
    n = int(input())
    B = list(map(int, input().split()))

    answer = solve(B, n)
    print(answer)

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

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

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
b = list(map(int, stdin.readline().rstrip().split()))
b.append(float('inf'))
res = []
for i in range(n-1, -1, -1):
    if i != 0:
        res.append(min(b[i], b[i-1]))
    else:
        res.append(b[i])
print(sum(res))

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

if __name__ == "__main__":
    main()

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

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

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

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

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


a = [1]
a[0] = 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 numpy as np
input()
a = list(map(int,input().split()))
print(np.minimum(np.insert(a,0,a[0]),np.append(a,a[-1])).sum())

Solution (Python):
def main():
  n = int(input())
  restrictionArray = list(map(int,input().split()))
  resultArray = [0] * (n+1)
  restrictionArray.append(10000000)
  
  for i in range(n):
    resultArray[i] = min(restrictionArray[i],restrictionArray[i-1])
   
  resultSum = sum(resultArray)
  
  print(resultSum)
  
main()

Solution (Python):
def solve_c(n, b_list):
    
    a_list = [0] * n
    
    a_list[0] = b_list[0]
    a_list[-1] = b_list[-1]
    for i in range(1, n - 1):
        a_list[i] = min(b_list[i - 1], b_list[i])
        
    return sum(a_list)


def main():
    
    n = int(input())
    b_list = list(map(int, input().split()))
    
    print(solve_c(n, b_list))


if __name__ == "__main__":
    main()

Solution (Python):
if (__name__ == '__main__'):
    n = int(input())
    dataline = input().strip().split()

    b = []
    for i in range(n-1):
        b.append(int(dataline[i]))

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


    print(thesum)

Solution (Python):
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


INT_MAX = 10 ** 10


if __name__ == "__main__":
    N = read()
    B = [INT_MAX]
    B.extend(readlist())
    B.append(INT_MAX)

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

Solution (Python):
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


def readlist():
    return list(map(int, input().split()))


INT_MAX = 10 ** 10


if __name__ == "__main__":
    N = read()
    B = [INT_MAX]
    B.extend(readlist())
    B.append(INT_MAX)

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

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

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

print(sum(b))

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

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

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