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

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

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

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

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

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

Solution (Python):
import sys; from collections import deque ; readline = sys.stdin.readline

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

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

print(sum(A))

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

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

Solution (Python):
def main():

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


if __name__ == '__main__':
    print(main())

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

ans = 0

ans += B[0]

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

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

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

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

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

print(ans)

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

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

score = 0
prev_max = 1000000

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

score = score + B[N-2]

print(score)

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

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

print(tot)

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

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

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



s=B[0]

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

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()))
ans = b[0] + b[-1]
for b1, b2 in zip(b, b[1:]):
    ans += min(b1,b2)
print(ans)

Solution (Python):
import numpy as np
n=int(input())
b=list(map(int,input().split()))

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

sum=0
for i in range(n):
  sum += a[i]
  
print(sum)

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

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

INF = float("inf")
vB += [INF,]

res = 0

p = INF
for b in vB:
    res += min(p, b)
    p = b

print(res)

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

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

    print(sum)

if __name__ == '__main__':
    func()

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

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

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

print(sum(alist))

Solution (Python):
n = int(input())
*bl, = map(int,input().split())
al = [10**6]*n
for i in range(len(bl)):
  al[i] = min(bl[i],al[i])
  al[i+1] = bl[i]
print(sum(al))

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

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

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]

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

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

if __name__ == "__main__":
    main()

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

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

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

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

print(ans)

Solution (Python):
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

a = l()

co = []

co.append(a[0])

for i in range(n-1):
    if i == n-2:
        co.append(a[i])
    else:
        co.append(min(a[i],a[i+1]))
print(sum(co))

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

ans=blist[0]
for idx in range(n-2):
    if blist[idx]<=blist[idx+1]:
        ans+=blist[idx]
    else:
        ans+=blist[idx+1]
ans+=blist[-1]
print(ans)

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

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

print(cnt)

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

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

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

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

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

ans += b[n-2]
print(ans)

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


print(sum(A))

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

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

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

ans = [0] * N

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

print(sum(ans))

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

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

before = 10**6
s = 0
for i in b:
    if i < before:
        s += i
    else:
        s+= before
    before = i
s += b[-1]
print(s)

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

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

ans[0] = b[0]
ans[n-1] = b[n-2]
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(int, input().split()))


A = [B[-1]]

for b in reversed(B):
    if A[-1] > b:
        A[-1] = b
    A.append(b)
print(sum(A))

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

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

print(sum(a))

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

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

a_sum = 0

a_sum += b[0]

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

print(a_sum)

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


def main(n, b):
    total = b[0] + b[-1]

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

    return total


if __name__ == "__main__":
    n = int(input())
    b = list(map(int, input().split()))
    print(main(n, b))

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

total = Bs[-1] + Bs[0]
Bs = Bs[::-1]

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

print(total)

Solution (Python):
N=int(input())
B=[int(x) for x in input().split()]
A=[-1 for x in range(N)]
ans=0
bef=0
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(map(int, input().split()))
A = [0] * N
for i in range(N-1):
    if i == 0:
        A[i] = B[i]
        A[i+1] = B[i]
    else:
        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_list = [10**18]*N
for i, b in enumerate(B):
    a_list[i] = min(a_list[i], b)
    a_list[i+1] = min(a_list[i+1], b)

print(sum(a_list))

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

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

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

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

print(count)

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

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

print(sum(a))

Solution (Python):
n = int(input())
b = [int(item) for item in input().split()]
ans = b[0] + b[-1]
for p, q in zip(b, b[1:]):
    ans += min(p, q)
print(ans)

Solution (Python):
def main():
    n = int(input())
    b_s = list(map(int, input().split(' ')))
    b_pre = 10**5 + 1
    a_s = []
    
    for b in b_s:
        a_s.append(min(b_pre, b))
        b_pre = b
    a_s.append(b)

    print(sum(a_s))


if __name__ == '__main__':
    main()

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

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

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

print(ans+B[0])

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


ans = B[0]

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

ans += B[-1]

print(ans)

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

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

A = [0]*N
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 = list(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[n-2])
print(sum(a))

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

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

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

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[-1]
  else:
    res += min(B[i], B[i-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-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 += min(b[i], b[i+1])

print(ans)

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
B = [int(x) for x in stdin.readline().rstrip().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 = N*[0]

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

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

Solution (Python):
N = int(input())
B_list = [int(x) for x in 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 = list(map(int, input().split()))

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

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

def solve():
    for i, b in enumerate(B):
        A[i] = min(A[i], b)
        A[i+1] = min(A[i+1], b)
    print(sum(A))

if __name__ == "__main__":
    solve()

Solution (Python):

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

sum = b[0]
for i in range(n-2):
  if b[i] >= b[i+1]:
    sum += b[i+1]
  else:
    sum += b[i]
sum += b[n-2]
print(sum)

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

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

r1 = 0

for i1 in range(n1):
    if i1 == 0:
        r1 += n2[0]
    elif i1 == n1 - 1:
        r1 += n2[n1 - 2]
    else:
        r1 += min(n2[i1 - 1],n2[i1])

print(r1)

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

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

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

Solution (Python):
n = int(input())
b = [int(i) for i in input().split()]
b_list = []
for i in range (n-1):
  b_list.append([b[i],i])
b_list.sort()

a_list = []
for i in range(n):
  a_list.append("Yet")

for i in range(n-1):
  idx = b_list[i][1]
  if a_list[idx]=="Yet":
    a_list[idx]=b_list[i][0]
  if a_list[idx+1]=="Yet":
    a_list[idx+1]=b_list[i][0]

print(sum(a_list))

Solution (Python):
n = int(input())
li = list(map(int, input().split()))
r = li[0] + li[-1]
for i, j in enumerate(li):
    if i != len(li)-1:
        r += min(j, li[i + 1])
print(r)

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

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

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 = 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):
from collections import defaultdict
from heapq import heappush, heappop, heapify
from bisect import bisect_left

class Solution:
    def main(self):
        N = int(input())
        B = [float('inf')] + list(map(lambda x: int(x), input().split())) + [float('inf')]

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

        print(res)


if __name__ == '__main__':
    Solution().main()

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

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

print(sum(A))

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

print(sum(a))

Solution (Python):
n = int(input())
li = list(map(int, input().split()))
r = li[0] + li[-1]
for i, j in enumerate(li):
    if i != len(li)-1:
        r += min(j, li[i + 1])
print(r)

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

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[-1]

print(sum(A))

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(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().strip())
B = list(map(int, input().strip().split(' ')))
A = [float('inf')]*N

for i,b in enumerate(B):
  A[i] = min(A[i], b)
  A[i+1] = min(A[i+1], b)

print(sum(A))

Solution (Python):
N = int(input())
B = [int(_) for _ in 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 - 1], B[n])
print(sum(A))

Solution (Python):
import sys
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
Arr=get_array()
new_Arr=[0]*n
new_Arr[-1]=Arr[-1]
new_Arr[-2]=Arr[-1]
for i in range(n-3,-1,-1):
    if Arr[i]>=Arr[i+1]:
        new_Arr[i]=Arr[i]
    elif Arr[i]<Arr[i+1]:
        new_Arr[i]=Arr[i]
        new_Arr[i+1]=Arr[i]
print(sum(new_Arr))

Solution (Python):
import collections as c
ip = lambda : map(int, input().split())

N = int(input())
B = list(ip())
B.insert(0,B[0])
B.append(B[-1])

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

Solution (Python):
def MAP(): return list(map(int,input().split()))

n = int(input())
b = MAP()

a = [0]*n
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 = list(map(int, input().split()))
a = [None]*n
a[0] = b[0]
ans = a[0]

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

Solution (Python):


if __name__ == "__main__":
    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]))
    else:
        A.append(B[-1])
    print(sum(A))

Solution (Python):



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

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

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

ans = b[0]
for i in range(len(b)-1):
    ans += min(b[i], b[i+1])
ans += b[-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())
Bs= [10**10] + list(map(int,input().split(" ")))  + [10**10]

As = []
for b1,b2 in zip(Bs[0:N],Bs[1:N+1]):
    As.append(min(b1,b2))

print(sum( As))

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

Solution (Python):
def calc(N, B):
    B = [10 ** 6] + B + [10 ** 6]
    r = 0
    for i in range(N):
        r += min(B[i], B[i + 1])
    return r


N = int(input())
B = [int(s) for s in input().split()]
print(calc(N, B))

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

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

print(a)

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

Solution (Python):


import sys



n=int(input())
tmp = input().split()
b = list(map(lambda a: int(a), tmp))

a=[]



ans=0
tmp=0
a.append(b[0])
for i in range(1,n-1):
	a.append(min(b[i-1],b[i]))
a.append(b[n-2])

total=0
for i in range(n):
	total+=a[i]
print(total)

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 = 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[-1]
print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

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

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

Solution (Python):

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

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

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

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

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

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


ct=0
bt=10**6
for b in B:
    if bt>=b:
        ct+=b
    else:
        ct+=bt
    bt=b
ct+=B[-1]
print(ct)

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

Solution (Python):
import sys

def main():
    _ = int(sys.stdin.readline())
    *B, = map(int, sys.stdin.readline().split())

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

    for b1,b2 in zip(B[:-1],B[1:]):
        sumA += min(b1,b2)

    print(sumA)

if __name__=='__main__':
    main()

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

a_list = []

for i in range(N):
    if i == 0:
        a = b_list[0]
        a_list.append(a)
        continue
    if i == N - 1:
        a = b_list[i-1]
        a_list.append(a)
        continue

    
    a = min(b_list[i-1], b_list[i])
    a_list.append(a)

ans = sum(a_list)
print(ans)

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


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

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

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

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

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

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

Solution (Python):


import sys

class CMaximalValue:
    def solve(self):
        n = int(input())
        b = [int(_) for _ in input().split()] + [float('inf')]
        ans = 0
        for i in range(n):
            ans += min(b[i], b[i - 1])
        
        print(ans)

solver = CMaximalValue()
input = sys.stdin.readline

solver.solve()

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

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

dp = [10**8] * n

for i in range(n-1):
    if dp[i] > b_list[i]:
        dp[i] = b_list[i]
    if dp[i+1] > b_list[i]:
        dp[i+1] = b_list[i]
        
print(sum(dp))

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

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

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

Solution (Python):

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

A = []

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

print(sum(A))

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

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

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], b[i - 1])
print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
def LILI(n): return [LI() for _ in range(n)]
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()
    B = LI()

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

main()