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())
bl = list(map(int, input().split()))
al = [0]*n
al[0] = bl[0]
al[-1] = bl[-1]

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

print(sum(al))

Solution (Python):
N, *B = map(int, open(0).read().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 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 = [B[0]]
for i in range(n-1):
    if i != n-2:
        a = min(B[i], B[i+1])
    else:
        a = B[i]
    A.append(a)
print(sum(A))

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

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

tmp = B[0]
ans = 0
B.append(B[-1])
for b in B:
    ans += min(tmp, b)
    tmp = b
print(ans)

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

Solution (Python):
N = int(input())
A = []
B = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    if(i == 0):
        A.append(B[0])
        continue
    if(i == N-1):
        A.append(B[N-2])
        continue
    a = B[i-1]
    b = B[i]
    if(a < b):
        A.append(a)
    else:
        A.append(b)
for i in A:
    ans += i
print(ans)

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

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

list_a= [bs[0]]

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

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

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

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
a=[0 for _ in range(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]))
print(sum(a))

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

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

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

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

Solution (Python):
N = int(input())
B = tuple(map(int, input().split()))
assert len(B) == N - 1

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

Solution (Python):

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

print(ans)

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

ans = 0
last_n = 0
for i in l:
    if i >= last_n:
        ans += i
        last_n = i
    else:
        ans -= last_n
        ans += i*2
        last_n = i
ans += l[0]
print(ans)

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,n-1):
    s=min(b[i],b[i-1])
    a.append(s)
    
print(sum(a))

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

c=0

c+=b[0]+b[-1]

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

print(c)

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

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

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
A = [B[0], B[0]]
for i in range(1, N-1):
    b = B[i]
    A.append(b)
    a = max([A[i],A[i+1]])
    if a > b:
        A[A.index(a)] = b
print(sum(A))

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

ans = B[0]
before = B[0]
for k in range(N-1):
  if before > B[k]:
    ans -= before
    ans += B[k]+B[k]
    before = B[k]
  else:
    ans += B[k]
    before = B[k]
print(ans)

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

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

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

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


al = [0]*n
al[-1] = bl[-1]
for i in range(n-2, -1, -1):
    if bl[i] < al[i+1]:
        al[i+1] = bl[i]
    al[i] = bl[i]
print(sum(al))

Solution (Python):
N = int(input())
B = list((int(x) for x in input().split()))
A1 = B + [100001]
A2 = [100001] + B
A = [min(A1[i],A2[i]) for i in range(N)]
print(sum(A))

Solution (Python):

import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers= list(map(int,input().split()))
    dp=[0]*n

    dp[0]=numbers[0]
    dp[-1]=numbers[-1]

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

if __name__=="__main__":
    main()

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

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

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

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

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

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

if __name__ == "__main__":
    main()

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

a =[b[0]]

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

print(sum(a))

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

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

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

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

print(sum(A))

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



A = [B[0]]

for i in range(N-1):
    if i+1 != len(B):
        A.extend([min(B[i],B[i+1])])
    else:
        A.extend([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(N-2):
  if B[i] <= B[i+1]:
    A[i+1] = B[i]
  else:
    A[i+1] = B[i+1]
    
print(sum(A))

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

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

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

Solution (Python):



a=int(input())





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





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

print(sum(ans))

Solution (Python):
def abc140c():
    n = int(input())
    b = list(map(int, input().split()))
    ans = 0
    for i in range(len(b)):
        if i == 0:
            ans += b[i]

        if i == n-2:
            ans += b[i]

        if 0 < i :
            ans += min(b[i-1], b[i])
    print(ans)
abc140c()

Solution (Python):
n = int(input())
alist=list(map(int,input().split()))
alist.insert(0,1e7)
alist.append(1e7)
core = 0
for i in range(n):
  core +=min(alist[i],alist[i+1])
print(core)

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

Solution (Python):
import math
import collections
import itertools

def resolve():

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

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

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

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

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

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

ANS = 0

for i in range(len(A)):
    ANS = ANS + A[i]
print(ANS)

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

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

res = 0

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

print(res + B[0] + B[-1])

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

A = [0] * N

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

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

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

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

a_list = [0]*n
a_list[0] = num_list[0]

for i in range(1, n, 1):
	if i != n-1:
		a_list[i] = min(num_list[i-1], num_list[i])
	else:
		a_list[i] = num_list[-1]

sum = 0
for j in a_list:
	sum += j

print(sum)

Solution (Python):
N = int(input())
li = list(map(int, input().split()))
rli = li[::-1]
rli.append(100001)
ans = [0] * N

ans[0] = rli[0]
for i in range(0, len(li)):
    ans[i+1] = min(rli[i], rli[i+1])


print(sum(ans))

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

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

print(A)

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

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

Solution (Python):

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

an =[bn[0]]


for x in range(n-2):
    if bn[x+1] >= bn[x] :
        an.append(bn[x])
    else:
        an.append(bn[x+1])

an.append(bn[-1])

print(sum(an))

Solution (Python):


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

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

Solution (Python):
N = int(input())
ls = [int(i) for i in input().split()]
if len(ls) == 1:
  print(ls[0]*2)
else:
  als = [ls[0]]
  for n in range(1, N-1):
    als.append(min(ls[n-1], ls[n]))
  als.append(ls[-1])
  print(sum(als))

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

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

print(ans)

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







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

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

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

print(sum(A))

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

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

Solution (Python):

"""
Created on Wed Sep  9 16:47:54 2020

@author: liang
"""
INF = 10**6
N = int(input())
B = [INF]+list(map(int,input().split()))+[INF]

ans = 0

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

print(ans)

Solution (Python):

"""
Created on Wed Sep  9 16:47:54 2020

@author: liang
"""
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(i) for i in input().split()]
prev = b[0]
cnt = 0
for i in b:
    cnt += min(i, prev)
    prev = i
cnt += b[-1]
print(cnt)

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

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

print(sum(A_List))

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

ans = 0

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

print(ans)

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

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

print(sum(a))

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

Solution (Python):
import math
N = int(input())
B = list(map(int, input().split()))
pre = math.inf
ans = 0
for b in B:
    ans += min(pre, b)
    pre = b
ans += B[-1]
print(ans)

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

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

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

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

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

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

ans += B[-1]

print(ans)

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

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

Solution (Python):

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

n=int(input())
B=input_array()
A=[B[0]]
ans=B[0]

for i in range(1,n):
	if A[i-1] > B[i-1]:
		ans=ans-A[i-1]+B[i-1]
		A[i-1]=B[i-1]
	ans+=B[i-1]
	A.append(B[i-1])

print(ans)

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

Solution (Python):
import copy
n = int(input())
b = list(map(int,input().split()))
a = copy.copy(b)
a.insert(0,b[0])
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= 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())
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]
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())
L = list(map(int, input().split()))
s = L[0]
for i in range(len(L)-1):
  s += min(L[i], L[i+1])
print(s + L[N-2])

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=[B[0]]
for i in range(N-2):
    if B[i]<=B[i+1]:
        A.append(B[i])
    else:
        A.append(B[i+1])
A.append(B[-1])
print(sum(A))

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

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

print(ret)

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

A=[0]*N

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

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

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

a_l = [0] * n
a_l[0] = b_l[0]
a_l[-1] = b_l[-1]
for i in range(1, n-1):
    a_l[i] = min(b_l[i],b_l[i-1])
print(sum(a_l))

Solution (Python):









import os
import sys




def main():
    n = int(input())
    b = list(map(int, input().split()))
    if n == 1:
        print(b[0]*2)
        return
    a = [-float('inf')]*n
    a[0] = b[0]
    a[1] = b[0]
    for i in range(1, n-1):
        if a[i] > b[i]:
            a[i] = b[i]
        a[i+1] = b[i]
    print(sum(a))



if __name__ == "__main__":
    main()

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

s = B[0]

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

s += B[-1]

print(s)

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

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

if n==2:
  print(sum(l)*2)
else:
  ans=[]
  ans.append(l[0])
  ans.append(l[len(l)-1])

  for i in range(len(l)-1): 
    num=min(l[i],l[i+1])
    ans.append(num)
  
  print(sum(ans))

Solution (Python):
def main():
    n = int(input())
    b_list = list(map(int, input().split()))
    ans = b_list[0] + b_list[n - 2]

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys


def main():
    input = sys.stdin.buffer.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 - 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(1,n-1):
  a[i]=min(b[i],b[i-1])
print(sum(a)+b[n-2])

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):
def main():
    N = int(input())
    B = list(map(int, input().split()))
    A = [B[0]]
    for i in range(N - 1):
        a = max([A[-1], B[i]])
        if i != N - 2 and a > B[i + 1]:
            a = B[i + 1]
        A.append(a)
    print(sum(A))


if __name__ == '__main__':
    main()

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

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

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

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

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

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

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


if __name__ == "__main__":
    solve()

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

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

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

Solution (Python):
n=int(input())
sum=0
a=[0]*n

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    B=LI()
    A=[0]*N
    A[0]=B[0]
    A[-1]=B[-1]
    for i in range(N-2):
        A[i+1]=min(B[i],B[i+1])
        
    print(sum(A))

main()

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

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

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

B = list(map(int, input().split()))
A = [B[0]]


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

ans = 0

for j in range(N):
  ans += A[j]
  
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[-1]
print(ans)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    B_list = list(map(int, input().split()))

    if n == 2:
        sum_a0_a1 = B_list[0]*2
        print(sum_a0_a1)
        return

    first_a = B_list[0]
    last_a = B_list[n-2]
    sum_other_a = 0

    for i in reversed(range(0,n-2)):
        min_b = min(B_list[i+1],B_list[i])
        sum_other_a += min_b

    print(first_a + last_a + sum_other_a)


if __name__ == '__main__':
    main()

Solution (Python):


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

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

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

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

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])
for j in range(n):
  ans += a[j]

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):
def mapt(fn, *args):
    return tuple(map(fn, *args))

def Input():
    return mapt(int, input().split(" "))

def main():
    n = int(input())
    b = Input()
    data = 0
    for i in range(n-1):
        if i == 0:
            data += b[i]
            continue
        data += min(b[i], b[i-1])
    data += b[-1]
    print(data)
main()

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

ans = sum(A)

print(ans)

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


def solve(acc, xs):
    head, *tail = xs
    if not acc:
        acc.append(head)
    if not tail:
        acc.append(head)
        return acc

    peek, *_ = tail
    acc.append(min(head, peek))
    return solve(acc, tail)


arr = solve([], Bs)
print(sum(arr))

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

a[1] = b[1]
a[-1] = b[-1]

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

print(sum(a))

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

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy







mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
bl = inpl()
ans = bl[0]
for i in range(0, n):
    if(i == n - 2):
        ans += bl[n - 2]
        break
    ans += min(bl[i], bl[i + 1])
print(ans)

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

a=[0]*n

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

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

print(sum(a))

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    f_inf = float("inf")
    b = [f_inf] + LI() + [f_inf]

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

main()

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

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