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

Solution (Python):
N=int(input())
b=list(map(int,input().split()))
cnt=0
wa=0
while cnt<N-1:
    if cnt==0:
        wa+=b[0]
    
    
    else:
        wa+=min(b[cnt-1:cnt+1])
       
    cnt+=1
print(wa+b[N-2])

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

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

print(s)

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

print(sum(a))

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

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

print(a)

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

A = [B[0]]
for i in range(N-1):
    A.append(B[i])
    if A[i] > B[i]:
        A[i] = B[i]

print(sum(A))

Solution (Python):
n = int(input())
bl = list(map(int, input().split()))
al = [0] * n
al[0], al[-1] = bl[0], bl[-1]

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

print(sum(al))

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

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

a = [0] * (n + 1)
a[0] = b[0]

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

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

print(sum(a))

Solution (Python):
_ = input()
B = list(map(int, input().split()))
A = [B[0]] + B
for i in range(len(A)-1):
  if max(A[i],A[i+1]) > B[i]:
    if A[i] <= A[i+1]: A[i+1] = A[i]
    else : A[i] = A[i+1]
print(sum(A))

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

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

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

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

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

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):
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys




read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *B = map(int, read().split())
A = [B[0]]

for i, j in zip(B, B[1:]):
    if i <= j:
        A.append(i)
    else:
        A.append(j)
print(sum(A) + B[-1])

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

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

A[0] = B[0]
print(sum(A))

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

ans = b[0] + b[-1]
for i, j in zip(b[:-1], b[1:]):
    ans += min(i, j)
print(ans)

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
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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
B = LIST()

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

print(su + B[len(B) - 1])

Solution (Python):
def main():
  n,*b=map(int,open(0).read().split())
  c1,cn=b[0],b[-1]
  c=[min(i,j) for i,j in zip(b,b[1:])]
  print(c1+sum(c)+cn)
if __name__=="__main__":
  main()

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

Solution (Python):
n = int(input())
b_list = list(map(int, input().split()))
a_list = [0 for _ in range(n)]
a_list[0] = b_list[0]
a_list[1] = b_list[0]

for i in range(1, len(b_list)):
    if b_list[i] > b_list[i-1]:
        a_list[i+1] = b_list[i]
    else:
        a_list[i] = b_list[i]
        a_list[i+1] = b_list[i]

print(sum(a_list))

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

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

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

Solution (Python):
N = int(input())
INF = float('inf')
B = [INF] + list(map(int,input().split())) + [INF]
ans = sum(min(a,b) for a,b in zip(B,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==n-2:
        a.append(b[i])
    else:
        if b[i]<b[i+1]:
            a.append(b[i])
        else:
            a.append(b[i+1])

print(sum(a))

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

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

Solution (Python):
import sys

[N] = [int(x) for x in sys.stdin.readline().split(" ")]
Bs = [int(x) for x in sys.stdin.readline().split(" ")]
result = 0

prev_b = 999999
for i in range(N-1):
    b = Bs[i]
    result += min(prev_b, b)
    prev_b = b

result += prev_b

print(result)

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

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

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

Solution (Python):
N = int(input())
inf = 10**10
*a, = map(int ,input().split())
b = [inf]+a+[inf]
print(sum(min(b[i], b[i+1]) for i in range(N)))

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
ans = B[0] + B[-1]
if N >= 3:
  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 = [-1] * n
num = [i for i in range(n - 1)]
d = {}
for i, j in zip(b, num):
    d[j] = i
d = sorted(d.items(), key=lambda x: x[1])
for k, v in d:
    if a[k] == -1:
        a[k] = v
    if a[k + 1] == -1:
        a[k + 1] = v
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):
A=int(input())
B=list(map(int,input().split()))
ans=[0]*A
ans[0]=B[0]
if A>=3:
    for i in range(1,A-1):
        ans[i]=min(B[i],B[i-1])
        ans[i+1]=B[i]
elif A==2:
    ans[1]=B[0]
print(sum(ans))

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

A = [B[0]]

for i, b in enumerate(B):

    A += [b]
    if b < A[i]:
        A[i] = b

print(sum(A))

Solution (Python):
n = int(input())
b_list = list(map(int, input().split(' ')))
b_list.append(b_list[-1])

pre_b = 10**5+1  
a_list = []
for i in range(len(b_list)):
  a_list.append(min(pre_b, b_list[i]))
  pre_b = b_list[i]
print(sum(a_list))

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

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

ans = nums[0]
nums.append(10**10)
for i in range(1, n):
    ans += min(nums[i-1], nums[i])
print(ans)

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

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

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

sum = 0

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

print(ans)

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

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

print(sum(A))

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

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

def main():
    N = int(input())
    B = list(map(int, input().split()))
    ans = [0] * N
    ans[0] = B[0]

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

    print(sum(ans))


main()

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

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

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

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

print(ans)

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

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

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

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

print(sumA)

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

ans=b[0]

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

Solution (Python):
_ = input()
B = (10 ** 5,) + tuple(map(int, input().split())) + (10 ** 5,)
print(sum(min(b) for b in zip(B, B[1:])))

Solution (Python):
def func(n,b,ans):
    for i in range((n-1)):
        if i+1 < (n-1) and b[i]<=b[i+1]:
            ans.append(b[i])
        elif i+1 < (n-1) and b[i]>b[i+1]:
            ans.append(b[i+1])
        else:
            ans.append(b[i])
    return ans

if __name__=='__main__':
    n=int(input())
    b=list(map(int,input().split()))
    ans=[]
    ans=func(n,b,ans)
    print(sum(ans)+b[0])

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

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

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

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

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

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

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

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

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

print(sum(A))

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

Solution (Python):
def solve(inp):
    N = int(inp.readline().strip())
    B = list(map(int, inp.readline().strip().split(' ')))

    A = [0 for i in range(N)]

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

    return str(sum(A))


def test(s):
    from io import StringIO
    print(solve(StringIO(s)))


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    
    
    
    main()

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

max = 0
a = [0] * N

for n in range(N):
  if n == len(li):
    a[n] = li[n-1]
    break
  
  if n == 0:
    a[n] = li[n]
  else:
    if li[n] > li[n-1]:
      a[n] = li[n-1]
    else:
      a[n] = li[n]

print(sum(a))

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

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

print(total)

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    ans = 0
    for i in range(N - 2):
        ans += min(A[i],A[i + 1])
    ans += A[0]
    ans += A[N - 2]
    print(ans)
    return

if __name__ == "__main__":
    main()

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

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

print(total)

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

ans = 0

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

ans = ans + B[0] + B[N-2]
print(ans)

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

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

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

Solution (Python):
length = int(input())
Bs = list(map(int, input().split()))
total = Bs[0] + Bs[length-2]

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

print(total)

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

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

else:
    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, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    B = LIST()

    B.insert(0, INF)
    B.append(INF)
    A = []
    for i in range(1, N+1):
        A.append(min(B[i-1], B[i]))
    print(sum(A))
    

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    num_list = list(map(int, input().split()))
    
    ls = [num_list[0]]

    for i in range(n-1):
        if i != n - 2 and num_list[i+1] < num_list[i]:
            ls.append(num_list[i+1])
        else:
            ls.append(num_list[i])

    print(sum(ls))

if __name__ == '__main__':
    main()

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

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]

print(A)

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

for i in range(n - 1):
    a += [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()))

inf = 10 ** 9
B = B + [inf]
A = [0] * N


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

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

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

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

z = []
z.append(l[0]) 
for i in range(len(l)-1):
    
    z.append(min(l[i],l[i+1]))

print(sum(z))

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

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

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

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

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

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

print(result_sum)

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

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

print(sum)

Solution (Python):



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

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

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

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

Solution (Python):
def LI():
  return [int(s) for s in input().split()]

N = int(input())

B_s = LI()

A_count = B_s[0]

for i in range(1,N):
  if i < (N-1):
  	A_count += min(B_s[i],B_s[i-1])
  else:
    A_count += B_s[i-1]
  
print(A_count)

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

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

ansList = [0] * A

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

print(sum(ansList))

Solution (Python):
a=[]
n,*b=map(int,open(0).read().split())
a.append(b[0])
a.append(b[0])
for i in range(1,n-1):
  if a[-1]>b[i]:
    a[-1]=b[i]
    a.append(b[i])
  else:
    a.append(b[i])
print(sum(a))

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

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):
from collections import deque
N = int(input())
B = list(map(int, input().split()))

b = deque(B)
b.appendleft(B[0])
b.append(B[-1])

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

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

print(sum(a))

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

a = [0]*(n)

for i in range(len(a)):
  if (i == 0):
    a[i] = b[i]
  elif i == len(a)-1:
    a[i] = b[i-1]
  else:
    a[i] = min(b[i-1], b[i])
    
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()))
B.append(10**5+1)
B.insert(0, 10**5+1)


max_sum = 0

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

max_sum += B[-2]

print(max_sum)

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

for i in range(N-2):
    C.append(min(B[i],B[i+1]))
C.append(B[-1])
print(sum(C))

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

a_list = [None for _ in range(N)]
a_list[0] = bs[0]

bs_size = len(bs)

for i in range(bs_size):
    if i == bs_size - 1:
        a_list[N-1] = bs[i]
    else:
        a_list[i+1] = min(bs[i],bs[i+1])

print(sum(a_list))

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

Solution (Python):
import numpy as np

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

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

for i in range(len(b)):
    B[i] = b[i]

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

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

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

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

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

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

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

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 = [None]*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 main():
    N = int(input())
    B = list(map(int, input().split()))

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

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

Solution (Python):
import sys

def main():
    N = int(input())

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


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

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

    A.append(B[N-2])

    print(sum(A))

main()

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

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

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

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

answer = sum(A)
print(answer)

Solution (Python):
def main():
    A = int(input())
    B = list(map(int, input().split(" ")))
    result = B[0]
    if A > 3:
        for i in range(0, A - 2):
            result += min(B[i], B[i + 1])
    elif A == 3:
        result += B[0]
    result += B[-1]
    print(result)


if __name__ == '__main__':
    main()

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]
        continue

    ans += min(b[i], b[i - 1])

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

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

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

a = [None for i 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())
bi = list(map(int, input().split()))

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

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

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

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

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

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

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

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[0] = b[0]
        a[1] = b[0]
    elif b[i] >= b[i-1]:
        a[i+1] = b[i]
    elif b[i] < b[i-1]:
        a[i+1] = b[i]
        a[i] = b[i]
print(sum(a))

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

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

print(sum(a_max))

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

A = [0]*N

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

def main():
    Ans = [B[0]]*(N)
    for i in range(1,N-1):
        Ans[i] = min(B[i-1],B[i])
    Ans[N-1] = B[-1]
    print(sum(Ans))
    return
if __name__ == "__main__":
    main()