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

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

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

answer = sum(A)

print(answer)

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

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

sum = 0

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

print(sum)

Solution (Python):
def myAnswer(N:int,B:list) -> int:
   total = B[0]+B[-1]
   pre = B.pop(0)
   for b in B:
      total += min(pre,b)
      pre = b
   return total

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   B = list(map(int,input().split()))

   print(myAnswer(N,B[:]))

if __name__ == '__main__':
   main()

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

print(max)

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

Solution (Python):
n=int(input())
def lima():
    return list(map(int,input().split()))


b=lima()
sum=b[0]+b[-1]
if len(b)==1:
    print(sum)
else:
    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()))
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])

total = sum(a)

print(total)

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

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    B = LI()

    sm = 0
    for i in range(n):
        j = i - 1
        
        if j < 0:
            a = B[i]
        elif i == n-1:
            a = B[j]
        else:
            a = min(B[i], B[j])
        sm = sm + a
    print(sm)



if __name__ == '__main__':
    solve()

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 = [int(i) for i in input().split()]

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

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

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

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

a = [0 for i in range(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, *b = map(int, open(0).read().split())
a = [0]*n
b.append(float("inf"))
for i in range(n):
  a[i] = min(b[i-1], b[i])
print(sum(a))

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

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

Solution (Python):
n = int(input())
B = list(map(int,input().split()))
ans = 0
p = 10**9
for b in B:
    ans += min(p,b)
    p = b
ans+= b
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):
    now_b = b[i]
    a[i] = min(b[i-1], now_b)
    a.append(now_b)

print(sum(a))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    B=[int(_) for _ in input().split()]
    ans=B[0]+B[-1]
    for i in range(n-2):
        ans+=min(B[i],B[i+1])
    print(ans)
if __name__=='__main__':
    main()

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

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

a_li = [[] for i in range(n)]

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

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):
import sys
N=input()
B=map(int, sys.stdin.readline().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-1], B[i])
print(ans)

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

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

A[-1] = B[-1]

print(sum(A))

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

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

Solution (Python):
import math

length = int(input())
array = str(input()).split(" ")
for index in range(len(array)):
    array[index] = int(array[index])
narray = []
narray.append(array[0])
for index in range(1, len(array)):
    narray.append(min(array[index-1],array[index]))
narray.append(array[-1])
sum = 0
for element in narray:
    sum += element
print(sum)

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

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

print(s)

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

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

Solution (Python):
def main():
    n = int(input())
    B = input()
    B = B.split()
    B = [int(i) for i in B]
    s = 0
    for i in range(0, n-1):
        if i == 0:
            s += B[0]
        else:
            s += min(B[i - 1], B[i])
    s += B[-1]
    return s

print(main())

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

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

print(sum(a))

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

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

print(sum(a))

Solution (Python):


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

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

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

print(sum(A))

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

Solution (Python):
def q3():
    N = int(input())
    B = [int(i) for i in input().split()]
    A = [10**5]*N
    for i in range(N-1):
        if A[i] > B[i]:
            A[i] = B[i]
        if A[i+1] > B[i]:
            A[i+1] = B[i]
    print(sum(A))

if __name__ == '__main__':
    q3()

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

ans = sum(A)
print(ans)

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

ans = sum(A)
print(ans)

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
blis = [float('inf')] + b + [float('inf')]
alis = []
for i in range(n):
    alis.append(min(blis[i], blis[i+1]))
print(sum(alis))

Solution (Python):
import math

length = int(input())
array = str(input()).split(" ")
for index in range(len(array)):
    array[index] = int(array[index])
narray = []
narray.append(array[0])
for index in range(1, len(array)):
    narray.append(min(array[index-1],array[index]))
narray.append(array[-1])
sum = 0
for element in narray:
    sum += element
print(sum)

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

print(ans)

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

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

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

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

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

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

Solution (Python):
n = int(input())
B = [int(x) for x in input().split()]
res = 0
for i in range(n):
  if i == 0:
    res += B[i]
  elif i < n - 1:
    res += min(B[i-1], B[i])
  else:
    res += B[i-1]
print(res)

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

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

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

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
B=nl()
ans=[0]*N
ans[0]=B[0]
for i in range(1,N-1):
    ans[i]=min(B[i-1],B[i])

ans[N-1]=B[N-2]
print(sum(ans))

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

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

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

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

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

print( ret )

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect



import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  b = list(map(int, readline().split()))
  a = [0]*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))
  
  
  
  
  
if __name__ == '__main__':
  main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
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
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
b = LIST()
a = [0 for _ in range(n)]
for i in range(n - 1):
    if i > 0:
        if b[i - 1] >= b[i]:
            a[i] = b[i]
        else:
            a[i] = b[i - 1]
    else:
        a[i] = b[i]
a[-1] = b[-1]
print(sum(a))

Solution (Python):

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

ans = b[0]
for i in range(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=[]

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

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

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


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())
seqB = [int(x) for x in input().split()]

ai = aj = seqB[0]
seqA = [ai,aj]
for i in range(1, len(seqB)):
  aj = max(aj, seqB[i])
  if aj > seqB[i]: 
    aj = seqA[i] = seqB[i]
  seqA.append(aj)

print(sum(seqA))

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

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

a = [b[0]]
for num, i in enumerate(b[1:]):
  a.append(min(i, b[num]))
a.append(b[-1])
print(sum(a))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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

if __name__ == '__main__':
    main()

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

ans = b[0]

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

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

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




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


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

print(score)

Solution (Python):
N = int(input())
Bi = list(map(int, input().split()))
listA = [0 for i in range(N)]
listA[N-1] = Bi[N-2]
gokei = 0
listA[0] = Bi[0]
for j in range(N-2, 0, -1):
    listA[j] = min(Bi[j], Bi[j-1])

for k in listA:
    gokei += k
print(gokei)

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

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

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

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

for i in range(N-2):
    if max(A[i],A[i+1]) > B[i]:
        A[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 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())
blist=list(map(int,input().split()))
alist=[]

alist.append(blist[0])
for i in range(1,n-1):
    alist.append(min(blist[i-1],blist[i]))
alist.append(blist[n-2])
print(sum(alist))

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

print(sum(A_max))

Solution (Python):













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

maxB        = max(Blist) 
Bit1        = iter([maxB] + Blist)  
Bit2        = iter(Blist + [maxB])  
pairBit     = zip(Bit1,Bit2)        

maxAsum     = sum(map(min,pairBit)) 

print(maxAsum)

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

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

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

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

else:
    ans = b[0] + b[-1]

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

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

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

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

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

print(sum(a))

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

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

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

print(ret)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N = int(input())
    B = input_nums()
    B = B[::-1]
    A = [B[0], B[0]]
    for b in B[1:]:
        if A[-1] > b:
            A.pop()
            A.append(b)
            A.append(b)
        else:
            A.append(b)
    print(sum(A))

if __name__ == '__main__':
    main()

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

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

resolve()

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

Solution (Python):
import sys
N=int(input())
B=list(map(int,input().split()))
if(N==2):
    print(B[0]*2)
    sys.exit()
before=B.pop(0)
ans=before
for b in B:
    ans+=min(before,b)
    before=b
ans+=B[-1]
print(ans)

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

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

ans = 0
limit = 10**10
for i in range(n-1):
    if limit>b[i]:
        ans += b[i]
    else:
        ans += limit
    limit = b[i]
ans += limit
print(ans)

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

ans = 0
limit = 10**10
for i in range(n-1):
    if limit>b[i]:
        ans += b[i]
    else:
        ans += limit
    limit = b[i]
ans += limit
print(ans)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
B = np.array(lr() + [10 ** 6])
answer = B[0] + np.minimum(B[:-1], B[1:]).sum()
print(answer)

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 ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    lb = rli()
    ans = lb[0]+lb[-1]
    for i in range(1,n-1):
        ans += min(lb[i-1],lb[i])
    print(ans)


if __name__ == '__main__':
    main()

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

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


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

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

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):
    if a[i]>b[i]:
        a[i]=b[i]
        a[i+1]=b[i]
    else:
        a[i+1]=b[i]

print(sum(a))

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

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


if __name__ == "__main__":
    main()

Solution (Python):

"""
Created on Wed Mar 25 10:07:17 2020

@author: Kanaru Sato
"""

N = int(input())
B = list(map(int, input().split()))
count = B[0]+B[-1]

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

print(count)

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

A = [float('Inf')] * 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):
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s


n = load()
B = load_list()


r = [B[0]]

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

r.append(B[-1])

print(sum(r))

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

Solution (Python):
n = int(input())
B = list(map(int, input().split()))
ans = B[0] + B[-1]
for b1, b2 in zip(B,B[1:]):
    if b1 < b2:
        ans += b1
    else:
        ans += b2
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):
import sys
input = sys.stdin.readline

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

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    B = [int(x) for x in 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)


if __name__ == '__main__':
    main()

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

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

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

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

print(sum(Alist))