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 = list(map(int, input().split(' ')))
ans = 0
for i in range(N):
  if i == 0:
    ans += B_LIST[i]
  else:
    if i == N - 1:
        ans += B_LIST[i - 1]
    else:
        if B_LIST[i - 1] > B_LIST[i]:
            ans += B_LIST[i]
        else:
            ans += B_LIST[i - 1]
print(ans)

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

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

print(sum(A))

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()
B = III()

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):
import sys
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()))
INF = 10**8
n = INT()
B = LIST()
B.append(INF)
ans = B[0]
for i in range(n-1):
  ans += min(B[i], B[i+1])
 
print(ans)

Solution (Python):
if __name__ == "__main__":
 
    n = int(input())
    b_list = [int(b) for b in input().split()]
    a_list = []

    for i, b in enumerate(b_list):
        if i != 0:
            a_list.append(min(b_list[i], b_list[i - 1]))
            
    a_list.insert(0, b_list[0])
    a_list.append(b_list[len(b_list) - 1])
    print('{0}'.format(sum(a_list)))

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

s = bn[0] + bn[-1]
b0 = bn[0]
for bi in bn[1:]:
  s += min(b0, bi)
  b0 = bi
print(s)

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):
import sys
from collections import deque
sys.setrecursionlimit(200000)
input = sys.stdin.readline

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

A = [B[0]] + [v for v in B]

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

print(sum(A))

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))
N = int(input())
B = LI()

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

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

MX = 100001

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

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

B = list(map(int,B))
total = 0


A[0] = B[0]

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

A[int(N)-1] = B[int(N)-2]

for i in range(int(N)):
    total = A[int(i)] + total

print(total)

Solution (Python):
N = int(input())
B = [int(i) for i in input().split()]
B.append(10**5)

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

print(ans)

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



if n == 2:
    ans = 2*b_list[0]

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

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

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

for i in range(N-2):
    if b[i] > b[i+1]:
        a_list.append(b[i+1])
    
    else:
        a_list.append(b[i])

a_list.append(b[-1])

print(sum(a_list))

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

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

Solution (Python):



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

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

a_list = [b_list[0]]
for i, b in enumerate(b_list):
    if a_list[i] > b:
        a_list[i] = b
    a_list.append(b)

print(sum(a_list))

Solution (Python):


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

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

print(sum(a))

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

A = [10 ** 6] * 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))

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

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

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

ans = 0

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

print(ans)

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

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

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

Solution (Python):
n=int(input())
a=[0 for i in range(n)]
b=list(map(int,input().split()))

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

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

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

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

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

  A[-1] = B[-1]

  print(sum(A))

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

Solution (Python):
n=input()  
a=list(map(int,input().split()))
cnt=a[0]+a[len(a)-1]
for i,_ in enumerate(a):
  if i > 0:
    cnt+=min(a[i],a[i-1])
print(cnt)

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

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()))
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=[b[0]]+b+[b[-1]]
ans=0

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

Solution (Python):
import numpy as np
input()
a = np.array(list(map(int,input().split())))
print(np.minimum(a[1:],a[:-1]).sum()+a[0]+a[-1])

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

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

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

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

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

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

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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    b = list(map(int, input().rstrip('\n').split()))
    a = [10 ** 6] * n
    for i in range(len(b)):
        a[i] = min(a[i], b[i])
        a[i+1] = min(a[i+1], b[i])
    print(sum(a))


if __name__ == '__main__':
    slove()

Solution (Python):

def main():
    N, *B = map(int, open(0).read().split())
    ans = sum(min(i, j) for i, j in zip(B, B[1:])) + B[0] + B[-1]
    print(ans)


if __name__ == "__main__":
    main()

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

A = [0] * N
B.append(100000000)

A[0] = B[0]

for i in range(1, N):
    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
b.append(1000000)
 
a[0] = b[0]
for i in range(1,n):
    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
b.append(1000000)

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

print(sum(a))

Solution (Python):
n = int(input())
list_B = list(map(int, input().split()))
list_A = [0]*(len(list_B) + 1)

for i in reversed(range(len(list_B))):

    
    if list_B[i] < list_A[i + 1]:
        list_A[i + 1] = list_B[i]

    list_A[i] = list_B[i]


list_A[-1] = list_B[-1]

print(sum(list_A))

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

a = [0]*n
b.append(1000000)

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

print(sum(a))

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

Solution (Python):


n=int(raw_input())
b=map(int,raw_input().split())
res=b[0]+b[-1]
for i in xrange(n-2):
 res+=min(b[i],b[i+1])
print res

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

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

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

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

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

print(sum(A))

Solution (Python):


from collections import Counter,deque


from sys import stdin,setrecursionlimit


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

n=int(input().rstrip())
b=[int(i) for i in 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[-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()))

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

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(N):
    if not i == 0 and not i == N - 1:
        A.append(min(B[i - 1], B[i]))
    elif i == 0:
        A.append(B[i])
    else:
        A.append(B[i - 1])
print(sum(A))

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

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

    A.append(B[-1])
    print(sum(A))


if __name__ == '__main__':
    main()

Solution (Python):


import sys
import copy

sys.setrecursionlimit(1000000)







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

A = [1e10] * 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 for _ in range(n)]

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

print(sum(a))

Solution (Python):
import numpy as np 

listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

sum=listA[1][0]+listA[1][-1]
for i in range(len(listA[1])-1):
  if listA[1][i+1]>listA[1][i]:
    sum+=listA[1][i]
  else:
    sum+=listA[1][i+1]
print(sum)

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):
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

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

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

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

    print(sum(A))

sol()

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

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 = [0 for i in range(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):

def main():
    N, *B = map(int, open(0).read().split())
    ans = sum(min(i, j) for i, j in zip(B, B[1:])) + B[0] + B[-1]
    print(ans)


if __name__ == "__main__":
    main()

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

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

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

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



N=int(input())
B=acinput()

dp=[-1]*(N)

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

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

Solution (Python):

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

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

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

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

print(sum(a))

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

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

data = []
data.append(b[0])
data.append(b[-1])
for i in range(1,N-1):
  tmp = min(b[i-1], b[i])
  data.append(tmp)

print(sum(data))

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

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

p = 0
for i in range(n):
    p += min(data[i:i+2])

print(p)

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

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

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

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

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

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

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

a=[0]*(n+1)
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 = 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=[]
A.append(B[0])
for i in range(0,N-2):
    if i>=1 & i < 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()]
A = [10**6]*N 

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

print(sum(A))

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

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

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

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

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

print(sum)

Solution (Python):
N = int(input())
B = input().split(' ')
A = []
A.append(int(B[0]))
A.append(int(B[0]))
SUM_MAX = A[0]

for i in range(N - 2):
  if A[i + 1] > int(B[i + 1]):
    A[i + 1] = int(B[i + 1])
  A.append(int(B[i + 1]))
  SUM_MAX = SUM_MAX + A[i + 1]
  
SUM_MAX = SUM_MAX + A[N - 1]
print(SUM_MAX)

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

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

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

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[-1])
print(sum(c))

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

sum = 0
for n in range(N):
  if n == 0:
    A.append(B[n])
  else:
    if A[n] > B[n]:
      A[n] = B[n]

  A.append(B[n])
  sum += A[n]

  if n == N-2:
    sum += A[n+1]
    break

      
print(sum)

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

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


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

print(sum(A))

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

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

a = []

for _ in range(n):
    a.append(list())

for index, value in enumerate(b):
    a[index].append(value)
    a[index + 1].append(value)

min_sum = sum([min(collection) for collection in a])

print(min_sum)

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

MAXVAL = 10**5
a = [MAXVAL] * n

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

Solution (Python):
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

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


if __name__ == '__main__':
    main()

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

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

def main():
    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)
if __name__ == '__main__':
    main()

Solution (Python):
def c_maximal_value(INF=float('inf')):
    N = int(input())
    B = [INF] + [int(i) for i in input().split()] + [INF]
    return sum([min(B[i], B[i + 1]) for i in range(N)])

print(c_maximal_value())

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

Solution (Python):
N = int(input())
B = [int(x) for x in input().split()]
B.insert(0,B[0])
B.append(B[-1])
ans = 0
for ind,i in enumerate(B[:-1]):
    ans += min(i,B[ind+1])
print(ans)

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

Solution (Python):

import sys

n = int(raw_input())
b = map(int, raw_input().split())

res = 0

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

print res

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

print(sum(ans)+b[0]+b[-1])

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

a = [0] * n
a[0] = b[0]

for i in range(n - 1):
    if a[i] > b[i]:
        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):
  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())
B = list(map(int,input().split()))

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

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

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

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

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

ans += b[0]

print(ans)

Solution (Python):
N = int(input())
Bs = list(map(int, input().split()))
 
As = [ None for _ in range(N) ]

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

As[-1] = Bs[-1]

print(sum(As))

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

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

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

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

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

for j in range(n):
  ans+=int(a[j])

print(ans)

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

sum = 0
for i in range(N):
    if i == 0:
        sum += list_B[i]


    elif i == N-1:
        sum += list_B[i-1]



    else:
        if (list_B[i] >= list_B[i-1]):
            sum += list_B[i-1]
        else:
            sum += list_B[i]

print(sum)

Solution (Python):
def find(B):
    A=[B[0]]
    for i in range(len(B)-1):
        A+=[min(B[i],B[i+1])]
    A+=[B[-1]]
    return sum(A)

input()
B=list(map(int,input().strip().split(" ")))
print(find(B))

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


a.append(b[n-2])

print(sum(a))

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

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

Solution (Python):


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

sum = B[0]

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

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

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

tot = b[0]  


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


tot += b[-1]

print(tot)

Solution (Python):
n = int(input())
b_list = [int(i) for i in input().split()]
a_list = [0] * n
before_val = 0
for i in range(n-1):
    target = b_list[i]
    if i == 0:
        a_list[i], a_list[i+1] = target, target
    elif before_val >= target:
        a_list[i], a_list[i+1] = target, target
    else:
        a_list[i], a_list[i+1] = before_val, target
    before_val = target
print(sum(a_list))

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

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())
s1= input()
ss1 = list(map(lambda x:int(x), s1.split()))

sum = 0

ss1 = [ss1[0]] + ss1 +[ss1[-1]]

for i in range(1,n+1):

    sum += min(ss1[i-1],ss1[i])
print(sum)

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

arr = [b[0]]
for i in range(1, len(b)):
    arr.append(min(b[i-1], b[i]))

arr.append(b[n-2])
print(sum(arr))

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

if n==2:
    ans = Bs[0]*2

elif n==3:
    ans += sum(Bs)
    ans += min(Bs)
else:
    ans += Bs[0]
    ans += Bs[-1]
    for i in range(len(Bs)-1):
        ans += min(Bs[i],Bs[i+1])
        
print(ans)

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