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):
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''

gi = lambda : list(map(int,input().split()))
n, = gi()
b = gi()
a = [1e9] * n
k = 0
while k < n - 1:
	a[k] = min(a[k], b[k])
	a[k + 1] = min(a[k + 1], b[k])
	k += 1
print(sum(a))

Solution (Python):
N = int(input())
B = [int(_) for _ in input().split()]
ans = [0] * N
ans[0] = B[0]
ans[N - 1] = B[len(B) - 1]

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

print(sum(ans))

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

A = 0
for idx, b in enumerate(B):
  if idx == 0:
    A += b
  else:
    A += min(B[idx], B[idx-1])
A +=  B[-1]
print(A)

Solution (Python):
n = int(input())
b_list = list(map(lambda x: int(x), input().split()))
a_list = [0] * n

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

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

if N ==  2:
  print(B[0]*2)

else:
  for i,v in enumerate(B):
    if i != N-2:
      if B[i] <= B[i+1]:
        if A[i] == 'a':
          A[i] = B[i]
        if A[i+1] == 'a':
          A[i+1] = B[i]
      else:
        if A[i] == 'a':
          A[i] = B[i]
    else:
      if A[i] == 'a':
        A[i] = B[i]
      if A[i+1] == 'a':
        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):
    if B[i]>=B[i-1]:
        A[i+1]=B[i]
    else:
        A[i]=B[i]
        A[i+1]=B[i]

print(sum(A))

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

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

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

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

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

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

print(m)

Solution (Python):


import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = int(lines[0])
    b = [int(e) for e in lines[1].split(" ")]

    return (n, b)


def solve(n, b):

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

    a.append(b[n-2])

    return sum(a)


def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)


if __name__ == '__main__':

    main()

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

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

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

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

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

    Ans+=B[N-2]

    print(Ans)

main()

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

for i in range(n-1):
  a_1 = a[i]
  a_2 = b[i]
  if b[i] >= max(a_1,a_2):
    a.append(b[i])
  else:
    a.append(b[i])
    a[i] = b[i]

print(sum(a))

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

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

print(s)

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

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

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

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

Solution (Python):

n = int(input())

blist =list(map(int,input().split()))
a = blist[0]+blist[-1]

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

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

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

Solution (Python):

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

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

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

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

print(score)

Solution (Python):

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

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

print(maxA)

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

Solution (Python):
'use strict'
N = int(input())
B = list(map(int, input().split()))
A = [0 for i in range(N)]

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

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

print(sum(A))

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

print(ans)

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

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

print(sum(a))

Solution (Python):
n = int(input())
B = list(map(int, input().split(" ")))
A = B[0]
An = B[0]
C = B[0]
for i in range(1,n-1):
  if An <= B[i]:
    C += An
  else:
    C+= B[i]
  An = B[i]

C += An
print(C)

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

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





def sum(list):
    lsum = 0
    for i in range(len(list)):
        lsum = lsum+list[i]

    return lsum

print(sum(a))

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

Solution (Python):
import numpy as np


N = int(input())
B = np.array(input().split(), np.int32)
A = np.zeros_like(np.arange(N, dtype='int'))

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

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

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

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

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

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

print(ans)

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

Solution (Python):
import numpy as np

n = int(input())
b = np.array(list(map(int,input().split())))
b = b[::-1]
a = np.array([])

a = np.append(a,b[0])

for index in range(len(b)-1):
  if b[index+1]<b[index]:
    a = np.append(a,b[index+1])
  else:
    a = np.append(a,b[index])

a = np.append(a,b[n-2])

print(int(np.sum(a)))

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


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

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

a = []
buf = -1
for i in b :
    a.append(max(buf, i))
    if buf == -1 :
        a.append(i)
    buf = i

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

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

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

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

print(count)

Solution (Python):


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

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

print(sum(A))

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

a = list()

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

import numpy as np

A = np.zeros(N)
A[N-1] = B[N-2] 

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

print(int(np.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()))
A = []
A.append(B[N-2])
for i in reversed(range(1, len(B))):
    if B[i]>=B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])

A.append(B[0])

print(sum(A))

Solution (Python):
n = int(input())
B = list(map(int, input().split()))
A = []*n
ans = B[0]
curosr = B[0]
for b in B[1:]:
  if curosr < b:
    ans += curosr
  else:
    ans += b
  curosr = b
ans +=B[-1]
print(ans)

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

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

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

sum = B[0]+B[N-2]

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

print(sum)

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

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()))+[100001]

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

for i in range(1,n):
    bi=b[i]
    a[i]=min(bi,bi1)
    bi1=bi
s=sum(a)
print(s)

Solution (Python):
def solve():
  import sys
  import math

  sys.setrecursionlimit(10**7)
  readline=sys.stdin.readline

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

  print(a)


if __name__ == '__main__':
  solve()

Solution (Python):
input()
b = list(map(int, input().split()))
print(sum(map(min, [b[0]] + b, b + [b[-1]])))

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

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

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

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

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

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

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    BS = list(map(int, input().split()))
    ans = 0
    prev = float('inf')
    for i in range(N-2,-1,-1):
        if BS[i] <= prev:
            ans += BS[i]
        else:
            ans += prev
        prev = BS[i]
    ans += BS[0]
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
N = int(input())
B = list(map(int, input().split()))

sum_ = 0
B.insert(0, B[0])
for b1, b2 in zip(B[1:], B[:-1]):
  sum_ += min(b1, b2)

print(sum_ + B[-1])

Solution (Python):
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy




def main():
    N = int(input())
    B = list(map(int,input().split()))
    A = [B[0]]
    ans = B[0]
    for i in range(1,N-1):
        tmp = min(B[i-1],B[i])
        ans += tmp
        A.append(tmp)
    tmp = max(A[-1],B[-1])
    A.append(tmp)
    ans += tmp
    
    print(ans)

if __name__ == '__main__':
    main()

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

B = [int(i) for i 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()))
sum = 0

for i in range(len(B)+1):   
  if i == 0:
    sum += B[0]
  elif i > 0 and i < N-1:
    sum += min(B[i-1],B[i])
  else:
    sum += B[N-2]
print(sum)

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

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

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

ans.append(B[len(B) - 1])

print(sum(ans))

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

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

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

print(sum(A))

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

Solution (Python):
from copy import deepcopy as dp
N = int(input())
B = [int(i) for i in input().split()]
ans = dp(B)
ans.insert(0,B[0])
cnt = 0
while cnt < len(B):
    for i in range(len(B)):
        if max(ans[i],ans[i+1]) <= B[i]:
            cnt+=1
        else:
            cnt = 0
            if ans[i] < B[i]:
                ans[i+1] = B[i]
            else:
                ans[i] = B[i] 
print(sum(ans))

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

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

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

print(cnt + B[N-2])

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

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

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

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

Solution (Python):



from math import *
import os
import sys


import numpy as np



if __name__ == "__main__":
    Input = [input() for i in range(2)]
    N = int(Input[0])
    B = list(map(int,Input[1].split()))
    B.reverse()

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

Solution (Python):
from sys import stdin

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

    maxb = max(B)
    ans = [maxb] * N
    for i, b in enumerate(B):
        ans[i] = min(ans[i], b)
        ans[i+1] = min(ans[i+1], b)
    print(sum(ans))

input = lambda: stdin.readline()[:-1]
main()

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

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

print(ans)

Solution (Python):


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

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

Solution (Python):
import sys
stdin = sys.stdin
mod = 10**9 + 7

import numpy as np

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
b = na()
ans = b[0] + b[-1]
bpre = b[0]
for bi in b[1:]:

        if bpre < bi:
                ans += bpre
        else:
                ans += bi
        bpre = bi
print(ans)

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

nA = [ 0 for i in range(N)]
nB = [ 0 for i in range(N)]

Tmp = []
Tmp = input().rstrip().split(' ')

for i in range(N-1):
  nB[i] = int(Tmp[i])

Ans = nB[0]
Ans += nB[N-2]

for i in range(N-2):
  B1 = nB[i]
  B2 = nB[i+1]
  Tmp = min(B1, B2)
  Ans += Tmp

print(Ans)

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

l = [b[0]]
if n>=3:
  for i in range(0, len(b)-1):
      test =  b[i+1] - b[i]
      if test>=0:
          l.append(b[i])
      else:
          l.append(b[i+1])
  l.append(b[-1])
  print(sum(l))
else:
  print(b[0]*2)

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

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

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

Solution (Python):
N = int(input())
B = [int(x) for x in input().split()]
ans = [0]*(N)
if N==2:
  print(int(B[0])*2)
  exit()
for i in range(1,N-1):
  ans[i] = min(B[i-1],B[i])
ans[0] = B[0]
ans[N-1] = B[N-2]
print(sum(ans))

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

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


al=[0 for i in range(n)]


al[0]=bl[0]
al[1]=bl[0]

for i in range(1,n-1):
  if bl[i] >= bl[i-1]:
    al[i]=bl[i-1]
    al[i+1]=bl[i]
  else :
    al[i]=bl[i]
    al[i+1]=bl[i]
print(sum(al))

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

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

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

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

Solution (Python):

n = int(input())

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


a = []
a.append(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):
import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
B = list(map(int, inputs[1].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()))

ans = [0]*n
ans[n-1] = b[-1]
for j in reversed(range(n-1)):
  b_ = b[j]
  if ans[j+1] > b_:
    ans[j+1] = b_
  ans[j] = b_

print(sum(ans))

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

Solution (Python):
N = int(input())
tmp = input()
B = [int(x.strip()) for x in tmp.split(' ')]
wa = B[0]
for i in range(0, N-2):
    wa += min(B[i], B[i+1])
wa += B[N-2]
print(wa)

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

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

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

ans = B[-1]

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

ans += B[0]
print(ans)

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

A = [B[0]]

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

print(sum(A))

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

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

result = 0

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

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

for ii in range(N-2):
    total += B[ii] if B[ii] < B[ii+1] else B[ii+1]

print(total)

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

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

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

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

Solution (Python):
number_count = int(input())
b_numbers = list(map(int, input().split()))
sum_max_a = 0
for x in range(number_count):
  if x == number_count - 1:
    sum_max_a += b_numbers[x - 1]
  elif x > 0:
    sum_max_a += min(b_numbers[x], b_numbers[x - 1])
  else:
    sum_max_a += b_numbers[x]
print(sum_max_a)

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

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

out = 0
prev_b = 10**5
for b in B_list:
    out += min(b, prev_b)
    prev_b = b
    
out += B_list[N-2]    
print(out)

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

a.append(b[len(b)-1])
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()

ans=[b[0]]*2
for i in range(N):
	if b[i] != max(ans[i], ans[i+1]):
		ans[i]=ans[i+1]
	ans.append(b[i+1])
	if len(ans)==N:
		if b[-1]!=max(ans[-1], ans[-2]):
			ans[-2]=ans[-1]
		break

print(sum(ans))

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

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

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

a = [10 ** 6 for i in range(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 = [int(x) for x in 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(int(sum(a)))

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

b.append(b[-1])

s = b[0]

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

print(s)

Solution (Python):

n = int(input())

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

an = [10**6]*n

for i in range(n-1):

    an[i]   = min(an[i], bn[i])
    an[i+1] = bn[i]




print( sum(an) )

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

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

    print(sum(a))

resolve()

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

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

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

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

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

ans = b[0]

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

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

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

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

Solution (Python):
num = int(input())
A = [int(i) for i in input().split()]
B = []
for i in range(0,num-1):
    if(i==0):
        B.append(A[i])
        B.append(A[i])
    else :
        if(A[i]>B[i]):
            B.append(A[i])
        else:
            B[i] = A[i]
            B.append(A[i])
sum = 0
for i in range(0,num):
    sum = sum + B[i]
print(sum)

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

Solution (Python):
N = int(input())
line = input().split()
B = [0] * (N-1)
for i in range(N-1):
    B[i] = int(line[i])

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

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

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

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

al.append(bl[0])
al.append(bl[len(bl)-1])
for i in range(len(bl)-1):
    if bl[i] <= bl[i+1]:
        al.append(bl[i])
    else:
        al.append(bl[i+1])
print(sum(al))

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

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

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

A = [0] * N

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

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

for i in range(n-1):

    if i == 0:
        dp_a[i] = b[i]
        dp_a[i+1] = b[i]
    else: 
        if b[i] <= b[i-1]:

            dp_a[i] = b[i]
            dp_a[i+1] = b[i]
        else:

            dp_a[i+1] = b[i]

print(sum(dp_a))

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

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