Problem:
 Score : 300 points    Problem Statement There is an integer sequence A of length N whose values are unknown.  Given is an integer sequence B of length N-1 which is known to satisfy the following:  B_i \geq \max(A_i, A_{i+1})  Find the maximum possible sum of the elements of A .      Constraints  All values in input are integers.  2 \leq N \leq 100  0 \leq B_i \leq 10^5         Input Input is given from Standard Input in the following format:  N  B_1  B_2  ...  B_{N-1}       Output Print the maximum possible sum of the elements of A .        Sample Input 1 3
2 5      Sample Output 1 9  A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.       Sample Input 2 2
3      Sample Output 2 6       Sample Input 3 6
0 153 10 10 23      Sample Output 3 53

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

print(sum(A))

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

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

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

print(result)

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[-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 = [0] * N

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

pre_b = 0
output = []
for index, b in enumerate(b_list):
    if index == 0:
        output.append(b)
    else:
        if pre_b <= b:
            output.append(pre_b)
        else:
            output.append(b)
    pre_b = b
output.append(b_list[-1])
print(sum(output))

Solution (Python):
def calc(n, b):
    r = b[0]
    for i in range(1, n-1):
        r += min(b[i-1], b[i])
    r += b[len(b)-1]
    return r


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

r = calc(n, b)
print(r)

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

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

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

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

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

ans = 0
for i in range(n):
    ans = ans + al[i]

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input().strip())
blist = list(map(int,input().strip().split()))

alist = []
alist.append(blist[0])
for i in range(N-2):
    addnum = min(blist[i],blist[i+1])
    alist.append(addnum)
alist.append(blist[N-2])

ans = sum(alist)
print(ans)

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

Alist = [0 for i in range(N)]
for i in range(N):
    if i == 0:
        A_left = 1000000
    else:
        A_left = Blist[i-1]
    if i == N-1:
        A_right = 1000000
    else:
        A_right = Blist[i]
    Alist[i] = min(A_left,A_right)

print(sum(Alist))

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

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

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

MAX = 10**5+1

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

b_new = [MAX]
b_new.extend(b)
b_new.append(MAX)

a = []
for i in range(n):
    a.append(min(b_new[i], b_new[i+1]))

print(sum(a))

Solution (Python):
n = int(input())
b = input().split()
for i in range(n-1):
    b[i]=int(b[i])
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 = [10**5+1]*N
for i in range(N - 1):
    A[i] = A[i] if A[i]<B[i] else B[i]
    A[i + 1] = A[i + 1] if A[i + 1]<B[i] else B[i]
    
print(sum(A))

Solution (Python):
def main():
    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[-1]
        else:
            ans += min(b[i-1],b[i])
    print(ans)
if __name__ == '__main__':
    main()

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

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

Solution (Python):
import numpy as np

N = int(input())
B = np.fromstring(input(), dtype=np.int64, sep=' ')
A = np.zeros(N, dtype=np.int64)
A[:-1] = B
A[-1] = 100000
for i in range(1, N):
    A[i] = min(A[i], B[i - 1])
print(A.sum())

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

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

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

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

Solution (Python):


import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
B = LI()

B.reverse()

ans = B[0] + B[-1]

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

print(ans)

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


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

print(ans)

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

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

if __name__ == '__main__':
    main()

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

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

print(ans)

Solution (Python):
N = int(input())
B = [int(x) for x in input().split()] + [10 ** 5]
pre = 10 ** 5
sumA = 0
for b in B:
  sumA += min(pre, b)
  pre = b
print(sumA)

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

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

print(ans)

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

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

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

val = []
val.append(b[0])
for i in range(1, N-1):
  val.append(min(b[i-1], b[i]))
  
val.append(b[-1])
print(sum(val))

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

res = bs[0]

for i, b in enumerate(bs[:-1]):
  if b < bs[i+1]:
    res += b
  else:
    res += bs[i+1]

res += bs[-1]
print(res)

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

b = [int(x) for x in input().split()]

b = [100000] + b + [100000]

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

print(score)

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

sumA = B[0]

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

sumA += B[n-2]
    
print(sumA)

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

Solution (Python):
N = int(input())
Blist = list(map(int,input().split()))
ans = 0

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

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 reversed(range(1, N - 1)):
    A[i] = min(B[i], B[i - 1])
print(sum(A))

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

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

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

A=[0]*N

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

print(sum(A))

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

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

for j in range(N):
  Ans = Ans + A[j]

print(Ans)

Solution (Python):
import sys

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

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

Solution (Python):

import sys


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




ans=B[0]

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

print(ans)

Solution (Python):



def solve(N, B):
    ans = 0
    last_b = float('inf')
    for b in B:
        ans += min(b, last_b)
        last_b = b
    ans += B[-1]
    return ans


if __name__ == '__main__':

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

    ans = solve(N, B)

    print(ans)

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

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





B = [10**6]+B+[10**6]
ans=0
for i in range(len(B)-1):
    ans += min(B[i],B[i+1])
print(ans)

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

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

print(ans)

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

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

  
  

print(ans)

Solution (Python):
n  = int(input())
bs = [int(x) for x in input().split()]
bs = [bs[0]] + bs + [bs[-1]]
a  = 0

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

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



print(sum(A))

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

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

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

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

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

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

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

print(sum(A))

Solution (Python):
def main():
    N = int(input())
    B = [0] + list(map(int, input().split()))
    
    A = [float('inf')] * N
    for i in range(N-1,0,-1):
        A[i] = min(A[i],B[i])
        A[i-1] = min(A[i-1],B[i])

    print(sum(A))

main()

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

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

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

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

print(sum(a))

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

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

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

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

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

    print(sum(A))

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

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

max_int = 10**5 + 1
print(sum(min(bi, bj) for bi, bj in zip([max_int] + B, B + [max_int])))

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

a=[0]*n
a[0]=bs[0]
a[n-1]=bs[n-2]

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

Solution (Python):

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, B):
    B.append(sys.maxsize)
    ans = 0
    for i in range(N):
        ans += min(B[i-1], B[i])
    return ans



def main():
    N = read_int()
    B = read_int_n()
    print(slv(N, B))


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):


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

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

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

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

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

print(sum(A))

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

Solution (Python):
n = int(input())
B = map(int, input().split())
A = [100000]*n
for i,b in enumerate(B):
    A[i] = min(b,A[i])
    A[i+1] = b
print(sum(A))

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()

b = readl()
p = max(b)
a = [p] * (n + 1)

for i in range(n - 1):
    t = b[i]
    if t <= a[i]:
        a[i] = t
    if t <= a[i + 1]:
        a[i + 1] = t
ans = 0
for i in range(n):
    ans += a[i]
print(ans)

Solution (Python):
import sys

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

AList=[]
bBefore=10**5+1
for b in BList:
  AList.append(min(bBefore,b))
  bBefore=b
AList.append(BList[-1])
print(sum(AList))

Solution (Python):
from sys import exit, stderr, stdin
input = stdin.readline


def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    B = list(map(int,input().split()))
    A = [[] for _ in range(N)]
    A[0].append(B[0])
    for i in range(1,N-1):
        A[i].append(B[i-1])
        A[i].append(B[i])
    A[-1].append(B[-1])
    
    print(sum([min(a) for a in A]))

if __name__ == "__main__":
    main()

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

ans = B[0]+B[-1]
i = 0
while i <= N-3:
    ans += min(B[i],B[i+1])
    i += 1
print(ans)

Solution (Python):
def main():
    n = int(input())
    b = [int(x) for x in input().split()]
    ans = 0
    for i in range(n-2):
        ans += min(b[i],b[i+1])
    ans += b[0]
    ans += b[-1]
    print(ans)
if __name__ == "__main__":
    main()

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

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

s = B[0]

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

ans = s + sum(B)

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 = B[0]+B[N-2]

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

print(ans)

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

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

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

print(ans)

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])
  
print(sum(a))

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

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

score = B[0]+B[-1]

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

Solution (Python):
from sys import stdin

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

ans = bn[0]

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

ans += bn[n-2]

print(ans)

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

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

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

print(ans)

Solution (Python):
N=int(input())
B=[int(x) for x in input().split()]
A=[B[0]]
for i,b in enumerate(B):
    a=b
    if i<N-2:
        if b>B[i+1]:
            a=B[i+1]
    A.append(a)
print(sum(A))

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

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

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

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

for i in range(len(b)):
    if a[i+1] >= b[i]:
        a[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[N-2]

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

print(ans)

Solution (Python):
N = int(raw_input())
B = raw_input().split()


sum = int(B[0])


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


sum = sum + int(B[N-2])


print sum

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

B.insert(0, 1000000)
B.append(1000000)

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

print(ans)

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

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

Solution (Python):
n=int(input())
B=list(map(int,input().split()))
if n==2:
    print(B[0]*2)
    exit()
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=[int(i) for i in 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],b[i-1])
print(sum(a))

Solution (Python):
N = int(input())
B = [int(x) for x in input().split()]
ans = 0
B.append(10 ** 9)

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

Solution (Python):
def main():    
    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[-1] = b[-1]
    print(sum(a))
    
if __name__ == '__main__':
    main()

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

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

Solution (Python):

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

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

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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
B = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
ans += (B[0] + B[-1])
for i in range(0,N-2):
    ans += min(B[i],B[i+1])
print(ans)

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

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

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

else:
    ans += Blist[0]

print(ans)

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


S = sum(list(map(min,B[:-1],B[1:])))+B[0]+B[-1]

print(S)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
b = list(map(int,input().split()))
count = b[0]
for i in range(n-2):
  if b[i] >= b[i+1]:
    count += b[i+1]
  else:
    count += b[i]
count += b[n-2]
print(count)

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

def main():
    A = [10**8]*(N)
    A[0] = B[0]
    for i in range(N - 2, -1, -1):
        A[i+1] = min(A[i + 1],B[i])
        A[i] = B[i]
    print(sum(A))
    return
main()

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

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

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

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

    A.append(B[-1])

    print(sum(A))


if __name__ == '__main__':
    p_c()

Solution (Python):
def resolve():
    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__':
    resolve()

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

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

Solution (Python):
import math
import copy

n = int(input())



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








kotae = 0

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

print(kotae)

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

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

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

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

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

print(result)

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

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

Solution (Python):
N = int(input())
B = [int(a) for a in input().split()]
B = [B[0]] + B + [B[-1]]

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

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

Solution (Python):


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


output = B[0]  

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

output += B[N-2]



print(output)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
b_lst = [int(x) for x in stdin.readline().rstrip().split()]
a_sum = b_lst[0] + b_lst[-1]

for i in range(len(b_lst)-1):
  a_sum += min(b_lst[i], b_lst[i+1])
  
print(a_sum)

Solution (Python):

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

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

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

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

ans = sum(A)
print(ans)