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):
from sys import stdin
import math
import fractions

n = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]


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

result += b[i]

print(result)

Solution (Python):
def main():
    N = int(input())
    B = list(map(int, input().split()))
    
    if N == 2:
        print(B[0] * 2)
        return

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

Solution (Python):
def main():
    N = int(input())
    B = [int(x) for x in input().split()]
    A = [0] * N
    A[0] = B[0]
    A[N-1] = B[-1]
    for i in range(1, N-1):
        if B[i - 1] <= B[i]:
            A[i] = B[i - 1]
        else:
            A[i] = B[i]
    print(sum(A))


if __name__ == "__main__":
    main()

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()))
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(b) for b in 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 = 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 = [float('inf')]*N
for i in range(N-1):
  b = B[i]
  A[i] = min(A[i], b)
  A[i+1] = b

print(sum(A))

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

ANS.append(b[n-2])
print(sum(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 - 1], b[i]))

a.append(b[-1])

print(sum(a))

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

C = [None] * N
C[0] = B[0]
C[-1] = B[-1]

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

print(sum(C))

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

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

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

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

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

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

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

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

print(total)

Solution (Python):

N = int(input())
B = [10**5 + 1] + list(map(int, input().split())) + [10**5 + 1]
s = 0

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

print(s)

Solution (Python):
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
iix = lambda x:list(int(input()) for _ in range(x))
mix = lambda x:list(li() for _ in range(x))

def main(n,b):
    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))

n = ii()
b = mi()
main(n,b)

Solution (Python):
import sys
import math
from collections import Counter
import itertools
import fractions



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")


 
N=II()
B=LI()

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


print(su)

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

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

C = [None] * N
C[0] = B[0]
C[-1] = B[-1]

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

print(sum(C))

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

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

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

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

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

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

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

Solution (Python):
n=int(input())
bs=list(map(int,input().split()))
a=[10**5]*n
for i,b in enumerate(bs):
    a[i+1]=b
    if a[i]>b:
        a[i]=b
print(sum(a))

Solution (Python):
N=int(input())
B=[int(i) for i in input().split()]
DP=[10**9 for i in range(N)]
for t in range(N-1):
    if DP[t]>B[t]:
        DP[t]=B[t]
    if DP[t+1]>B[t]:
        DP[t+1]=B[t]
print(sum(DP))

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

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

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

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

print(ans)

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

Solution (Python):
a=input()
b=input().split()
sum=int(b[0])

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

print(sum)

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

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

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

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

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



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

Solution (Python):
import os

def main():
	n = int(input())
	b_list = list(map(int, input().split()))
	result_list = [b_list[0]]*2
	for i in range(len(b_list)):
		if b_list[i] >= max(result_list[i],result_list[i+1]):
			pass
		else:
			result_list[i] = b_list[i]
		if i < len(b_list) - 1: 
			result_list.append(b_list[i+1])
	print(sum(result_list))

if __name__ == "__main__":
	main()

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

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

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

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

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

Solution (Python):
n = int(input())
aaa = {}
bbb = list(map(int, input().split(' ')))
bbb.append(999999999999)
for i in range(n-1, -1, -1):
    aaa[i] = min(bbb[i], bbb[i-1])
print(sum([aaa[i] for i in range(n)]))

Solution (Python):

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

A = [0] * N

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

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

print(sum(A))

Solution (Python):
import os, sys, re, math

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

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

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
inf = 10000000
print(sum(min(b1, b2) for b1, b2 in zip(b + [inf], [inf] + b)))

Solution (Python):
n = int(input())
nums = [int(i) for i in input().split()]
nums = [nums[0]] + nums + [nums[-1]]
ans = 0

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

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


print(sum(a))

Solution (Python):
def main(arrayB: list):
    arrayB.reverse()
    arrayA = [arrayB[0]]
    for i in range(len(arrayB)):
        arrayA.append(
            min(arrayB[i], arrayB[i + 1]) if i < len(arrayB) - 1 else arrayB[i]
        )
    print(sum(arrayA))


N = int(input())
line = list(map(int, input().split()))
main(line)

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

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

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

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

S[-1]=b[-1]
print(sum(S))

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

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

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

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 


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

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

l1=list(map(int,input().split()))
l2=[l1[0]]
l=l2+l1
l.append(l1[-1])

res=[]

for i in range(1,n+1):
    res.append(min(l[i],l[i-1]))

print(sum(res))

Solution (Python):
import sys
n = int(input())
b = [int(i) for i in input().split()]
if n == 2:
    print(b[0] * 2)
    sys.exit()

total = 0
for i, j in enumerate(b):
    if i == 0:
        total = j
    else:
        total += min(b[i-1], b[i])
print(total + b[-1])

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):
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

n = I()
B = LI()

A = [0] * n

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

A[0] = B[0]
A[n-1] = B[n-2]
print(sum(A))

Solution (Python):
n = int(input())
list_b = list(map(int,input().split()))
b_len = len(list_b)
ans_list = [0]*n
ans_list[0] = list_b[0]
dum = 0
for i in range(1,b_len):
    dum = min(list_b[i-1],list_b[i])
    ans_list[i] = dum
ans_list[n-1] = list_b[b_len-1]

print(sum(ans_list))

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

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

print(ans)

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

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

print(sum(a))

Solution (Python):
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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


if __name__ == '__main__':
    main()

Solution (Python):
import math
import itertools

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

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

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

print(res)

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

Solution (Python):
import math
import itertools

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

a=[0] * n 

for i in range(n):

    if(i==0):
        a[i] =b[i]
    elif(i==n-1):
        a[i] = b[i-1]
    else:
        a[i] = min(b[i],b[i-1])

print(sum(a))

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

Solution (Python):

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

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

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

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

Solution (Python):


n = int(input())

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

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

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

print(sum(A))

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

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

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

Solution (Python):
n = int(input())
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):
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()))
ret = B[0]
a = B[0]
for i in range(N-2):
  a = min(B[i],B[i+1])
  ret += a
ret += B[N-2]
print(ret)

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

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

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

Solution (Python):

N = int(input())

B = [10**5] + list(map(int,input().split())) + [10**5]

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

print(sum(A[1:]))

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


a = [b[0]]+ b 

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

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

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

print(sum(a)+b[0]+b[n-2])

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

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

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

ans = sum(a_list)
print(ans)

Solution (Python):


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

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

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

Solution (Python):
n, *b = map(int, open(0).read().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 in range(1, n-1):
    result += min(b[i], b[i-1])

print(result+b[n-2])

Solution (Python):

import sys
import numpy as np


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[-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):
def main():
    N = int(input())
    B = [int(a) for a in input().split()]
    A = [0]*N
    A[0] = B[0]
    A[1] = B[0]
    for i in range(1, N-1):
        if A[i] < B[i]:
            A[i+1] = B[i]
        else:
            A[i] = B[i]
            A[i+1] = B[i]
    print(sum(A))
if __name__ == "__main__":
    main()

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

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

print(sum(a)+b[0]+b[n-2])

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

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

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

a[N-1]=b[N-2]
print(sum(a))

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


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
n = int(input())
big = 10**18
bb = list(map(int, input().split()))
aa = np.zeros(n+1)
aa = np.minimum([big] + bb, bb + [big])
print(sum(aa))

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

result = B[0]

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

result += B[N - 2]

print(result)

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

result = B[0]

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

result += B[N - 2]

print(result)

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

inf = float('inf')
A = [inf] * N

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

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

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

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

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

Solution (Python):

def main():
    n = int(input())
    b = list(map(int, input().split()))
    a = []

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

    print(sum(a))


if __name__ == '__main__':
    main()

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

A=[0]*N
A[0] = B[0]

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

print(sum(A))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
B = LIST()
A = []

A.append(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)

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

import io
import math

data = int(input())
array=list(map(int, input().split()))
counter=0
for i in range(data-2):
  counter+=min(array[i],array[i+1])
print(counter+array[0]+array[data-2])

Solution (Python):
n=int(input())
B = list(map(int,input().split(' ')))
total = B[0] + B[-1]
i = 1
while i < len(B):
    total += min(B[i-1],B[i])
    i += 1
print(total)

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):
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):
import sys
inf = float('inf')

n, *b = map(int, sys.stdin.read().split())
b = [inf] + b + [inf]

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

if __name__ ==  '__main__':
    main()

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

res = 0
count = 0

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

if count == n:
  print(res)
else:
  while count < n:
     if b[0] >= b[1]:
      res += b[1]
      count += 1
     else:
       res += b[0]
       count += 1
  print(res)

Solution (Python):
import numpy as np

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

A = np.zeros(N,dtype=int)
A[0] = B[0]
A[-1] = B[-1]

if N == 2:
    print(A.sum())
    exit(0)

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

print(A.sum())

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

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

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    B = readInts()
    ans = B[0] + B[-1]
    for i in range(1,n-1):
        ans += min(B[i],B[i-1])
    print(ans)
if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
*b, = map(int, input().split())
a = [1001001001]*n
a[:-1] = [min(ai, bi) for ai, bi in zip(a, b)]
a[1:] = [min(ai1, bi) for ai1, bi in zip(a[1:], b)]
print(sum(a))

Solution (Python):


import sys


















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = [None] * n
    b = lmi()
    b.reverse()
    a[0] = b[0]
    for i in range(1, n-1):
        a[i] = min(b[i-1], b[i])
    a[n-1] = b[n-2]
    print(sum(a))

if __name__ == "__main__":
    main()

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

print(str(sum(a)))

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

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

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

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

print(sum(a))