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

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

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

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

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

myans += list_B[-1]
 
print(myans)

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

aL = []
bL.reverse()
if len(bL) == 1:
    aL.append(bL[0]*2)
else:
    aL.append(bL[0])
    for i in range(len(bL)):
        if i == len(bL) - 1:
            aL.append(bL[i])
        else:
            aL.append(min(bL[i],bL[i+1]))
print(sum(aL))

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

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

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

lstA = []

for i in range(N):
    if i == 0:
        lstA.append( lstB[i] )
    elif i == N-1:
        lstA.append( lstB[i-1] )
    else:
        lstA.append( min(lstB[i],lstB[i-1]))
        
print(sum(lstA))

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

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

print(S)

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.append(b[i-1])
    else:
        a.append(b[i])
a.append(b[len(b)-1])
print(sum(a))

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

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

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

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

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

Solution (Python):
INF = 10 ** 6

N = int(input())
B = [INF] + [int(i) for i in input().split()] + [INF]
print(sum(min(B[i], B[i + 1]) for i in range(len(B) - 1)))

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

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

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

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

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

count+=int(b[n-2])
print(count)

Solution (Python):
N=int(input())
B_list=[int(thing) for thing in input().split(" ")]
a_sum=0
for i in range(N):
    if i==0:
        a_sum=a_sum+B_list[0]
    else:
        if i==N-1:
            a_sum=a_sum+B_list[N-2]
        else:
            a_sum=a_sum+min(B_list[i],B_list[i-1])
print(a_sum)

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

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

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



print(sum(a))

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

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

    elif 1 <= i and i < n-1:
            if b[i-1]>b[i]:
                a.append(b[i])
            elif b[i-1] <= b[i]:
                a.append(b[i-1])

print(sum(a))

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

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

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

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

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

print(sum(a))

Solution (Python):

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

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


print(cnt)

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

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

print(sum(l))

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

n = N-1
aSum = 0

for i in range(n):

	if i == 0:
		aSum = B[i]
	elif i == n:
		break
	else:
		aSum = min(B[i],B[i-1])+aSum
aSum = B[n-1]+aSum



print(aSum)

Solution (Python):


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

A = []

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

    A.append(B[i])
    if A[i] >= A[i + 1]:
        A[i] = B[i]


print(sum(A))

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

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

print(sum(res))

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

A = [0]*N


A[0] = B[0]

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

print(sum(A))

Solution (Python):

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

    if Atmp > B[i + 1]:
        ans += B[i + 1]
    else:
        ans += Atmp

print(ans)

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

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

    print(ans)

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

Solution (Python):
N=int(input())
B= [int(s) for s in 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]
  else:
    A[i]=B[i-1]


print(sum(A))

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


count=0
n=N-1
A=[int(0) for _ in range(N)]
for i in range(0,n):
    A[i]=B[i]

for i in range(0,n):
    if A[i+1]>B[i]:
        A[i+1]=B[i]
        
for i in range(0,n):
    count+=A[i]
    
count+=B[n-1]
print(count)

Solution (Python):


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

max_A =[B[0]]
B.append(B[N-2])

for i in range(N-1):
    max_A.append(min(B[i],B[i+1]))

print(sum(max_A))

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

Solution (Python):

"""
A:長さNの要素不明の正数列
B:要素bi(1<=i<=N-1)でbiはbi>=max(ai,ai+1)を満たす
Aの要素の総和の最大値を求めよ
要素ai(i>2)はbi-1,biから(両方を超えないように)制約を受ける.その中で最大となるaiを選ぼうと思えば、bi,bi-1の最小値に等しくなる
i==0とi==Nのときは特殊
"""
N=int(input())
B=list(map(int,input().split()))

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

print(sum_ai)

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

A = 0
ans = 0

ans = B[0]

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

ans += B[N-2]

print(ans)

Solution (Python):

import sys


def solve(N: int, B: "List[int]"):

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

            
    
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    B = [ int(next(tokens)) for _ in range(N-1) ]  
    solve(N, B)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
result = a[0] + a[n-2]

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

print(result)

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

Solution (Python):
N = int(input())
B = [int(x) for x in input().split()]
A = [10**5] * N
for i, b in enumerate(B):
    A[i] = min(A[i], b)
    A[i+1] = min(A[i+1], b)
print(sum(A))

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

B.append(B[-1])
B.reverse()

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

A.append(B[-1])
ans = sum(A)

print(ans)

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

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

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

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

Solution (Python):
from itertools import tee


def pairwise(iterable):
    x, y = tee(iterable)
    next(y, None)
    return zip(x, y)


n = int(input())
b = tuple(map(int, input().split(" ")))

if len(b) == 1:
    print(2 * b[0])
else:
    s = b[0] + sum(min((i, j)) for i, j in pairwise(b)) + b[-1]
    print(s)

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

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

A = [0] * N
sub= [0] * N
ans = 0

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


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

A[0] = B[0]
A[-1] = B[-1] 
A[N-2] = min(B[N-2], B[N-3])

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

print(ans)

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

cnt = 0 
ss = 0
for i in range(n-1) :
    if(c[i] > b[i]) :
        c[i] = b[i]
    c[i+1] = b[i]

print(sum(c))

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

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

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

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

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

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

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

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

for n in reversed(range(0, len(B))):
  A[n] = B[n]
  A[n+1] = B[n] if B[n] < A[n+1] else A[n+1]  

print(sum(A))

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


A_seq=[]

for i in range(0,num-1):
    A_seq.append(B_seq[i])


A_seq.insert(0,B_seq[0])

cnt = 0
for j in range(num-1):
    if max(A_seq[j],A_seq[j+1])<=B_seq[j]:
        pass
    else:
        A_seq[j]=A_seq[j+1]

cnt=0
for x in range(num):
    cnt = cnt+A_seq[x]
print(cnt)

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

for i in range(n-1):
    a[i+1] = max(a[i],b[i])
    if(i == n-2):
        break
    if(b[i+1]<=b[i]):
        a[i+1] = b[i+1]
print(sum(a))

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

B = [int(n) for n in input().rstrip().split(' ')]
A = []

A.append(B[0])

for i in range(0, N-2):
  if i == 0:
    prev = B[-1]
  else:
    prev = B[0]
  
  next = B[i+1]
  b = B[i]
  
  max_b = (max(prev, b))
  min_b = (min(next, b))
  
  A.append(min_b)

if N > 2:
  A.append(B[-1])
else:
  A.append(B[-1])

print(sum(A))

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

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

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

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

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

A =[]
if N == 2:
    print(N*B[0])
    sys.exit()
else:
    if B[1] >= B[0]:
      A.append(B[0])
      A.append(B[0])
    else:
      A.append(B[0])
      A.append(B[1])
    for i in range(1,len(B)-1):
        if B[i+1] >= B[i]:
          A.append(B[i])
        else:
          A.append(B[i+1])
 
x = 0
for y in A:
  x = x + y
print(x+B[-1])

Solution (Python):
while True:
    try:
        num = int(input())
        lst = list(map(int, input().split()))
        ans = 0
        ans += lst[-1] + lst[0]
        if num == 2:
            print(ans)
            continue
        for i in range(1, num-1):
            ans += min(lst[i], lst[i-1])
        print(ans)
    except:
        break

Solution (Python):




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


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

sum = sum + b[n-2]


print(sum)

Solution (Python):

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


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

if(a[-1]>=b[-1]):
    a.append(a[-1])
else:
    a.append(b[-1])

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

print(sum)

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

print(sum(A))

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

if n == 2:
    print(b[0]*2)
elif n==3:
    print(b[1]+min(b[0],b[1])*2)
else:
    co = [min(x , y) for (x, y) in zip(b[0:-1], b[1:])]
    print(sum(co)+b[-1]+b[0])

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


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


print(sum(A))

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

S = B[0]
pre_b = -1

for i in range(len(B)):
  val = max(pre_b, B[i])
  if i < N - 2:
    if B[i] > B[i + 1]:
      val = B[i + 1]

  S += val
  pre_b = val
  
print(S)

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

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

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

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

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

print(ans)

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

count = 0
for i in range(0, n-1):
    if count == 0:
        a.append(b[i])
        a.append(b[i])
        count = count +1
    elif b[i] > b[i-1]:
        a.append(b[i])
    elif b[i] < b[i-1]:
        del a[i]
        a.append(b[i])
        a.append(b[i])
    elif b[i] == b[i-1]:
        a.append(b[i])
print(sum(a))

Solution (Python):
import sys
sys.setrecursionlimit(int(1e6))

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()))
S=0
for i,b in enumerate(B[:-1]):
    if b<B[i+1]:
        S+=b
    else:
        S+=B[i+1]
S += (B[0]+B[-1])
print(S)

Solution (Python):


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

s = b[0]+b[-1]
p = b[0]


if n > 2:
    for i in range(1,n-1):
        s += min(b[i],p)
        p = b[i]

print(s)

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

a[0] = b[0]
if n >= 4:
    a[n-1] = b[n-2]
    for i in range(1,n-2):
        if b[i-1] <= b[i] <= b[i+1]:
            a[i] = b[i-1]
            a[i+1] = b[i]
        elif b[i-1] >= b[i] >= b[i+1]:
            a[i] = b[i]
            a[i+1] = b[i+1]
        elif b[i-1] < b[i] > b[i+1]:
            a[i] = b[i-1]
            a[i+1] = b[i+1]
        else:
            a[i] = b[i]
            a[i+1] = b[i]
elif n == 3:
    a[0] = b[0]
    a[1] = min(b[0], b[1])
    a[2] = b[1]
elif n == 2:
    a[0] = b[0]
    a[1] = b[0]

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

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
b.append(1000000) 
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()))
amt = b[0] + b[n-2]
for i in range(n-1):
    if i != n-2 and b[i] <= b[i+1]:
        amt += b[i]
    elif i != n-2 and b[i] > b[i+1]:
        amt += b[i+1]
print(amt)

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

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

a=[arr[0]]
for i in range(1,num-1):
    a0 = min(arr[i],arr[i-1])

    a.append(a0)
a.append(arr[-1])

print(sum(a))

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

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


print(sum(a))

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
b = na()

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

print(ans)

Solution (Python):
N = int(input())
B_LIST = input().split(" ")
A = []
B = []
for i in B_LIST:
    B.append(int(i))

A.append(B[0])

for i in range(1, N - 1):
    if i == N - 1:
        a = B[N - 1]
        print(N, 555)
    else:
        if B[i] > B[i -1]:
            a = B[i -1]
        else:
            a = B[i]
    A.append(a)
    
A.append(B[N-2])

s = 0
for i in A:
    s += i
    
print(s)

Solution (Python):

N = int(input())

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

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

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

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
a=[0]*n
ans=0
if n == 2:
    print(b[0]*2)
elif n==3:
    print(min(b)*2 + max(b))
else:
    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]
    ans =sum(a)
    print(ans)

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

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

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

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

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

a = [b[0]]

if len(b) == 2:
    if b[0]<=b[1]:
        print(sum(b)+b[0])
    elif b[0] >b[1]:
        print(sum(b)+b[1])
elif len(b)==1:
    print(b[0]*2)
elif len(b)>=3:
    b.append(0)

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

        elif b[i]>b[i+1]:
            a.append(b[i+1])

    a.append(b[-2])
    print(sum(a))

Solution (Python):
_ = input().strip()
b = input().strip().split(" ")

pre_b = int(b[0])
t = 0
for _b in b:
    _b = int(_b)
    t += min(_b, pre_b)
    pre_b = _b
t += _b
print(t)

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

solution = [0]*n
for i in range(n):
    if i == 0:
        solution[i] = arr[i]
    elif i == n-1:
        solution[i] = arr[i-1]
    else:
        solution[i] = min(arr[i-1], arr[i])

print(sum(solution))

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

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

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

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

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

print(sum(A))

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

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

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

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


result = result + B[0]

print(result)

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

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

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

print(ans)

Solution (Python):
N, *B = map(int, open(0).read().split())
result = B[0] + B[len(B) - 1]
for i in range(N - 2):
    result += min(B[i], B[i + 1])

print(result)

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

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

print(Sum + B[0] + B[N-2])

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

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

print(sum(a))

Solution (Python):



import sys

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

for idx in range(len(B)):
    current_val = B[idx]
    if idx + 1 == len(B):
        next_val = sys.maxsize
    else:
        next_val = B[idx + 1]

    A.append(min(current_val, next_val))

print(sum(A))

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

b.insert(n, b[n-2])
b.insert(0, b[0])

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

ans = B[0]

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

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

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

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


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

Solution (Python):
n = int(input())
b_s = [int(h) for h in input().split()]

ans = 0
left = b_s[0]
right = left
ans += left

for i in range(1, n - 1):
  right = b_s[i]
  a_i = min(left, right)
  
  ans += a_i
  left = right
ans += right

print(ans)

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

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

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

print(sum(l))

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

Solution (Python):
hoge = input()
nums = list(map(int, input().split(' ')))[::-1]
current = nums[0]
ans = 0
for n in nums:
    current = min(current, n)
    ans += current
    current = n  
print(ans + current)

Solution (Python):
N=int(input())
B = [int(i) for i in input().split()] 
A=[0]*N
A[0]=B[0]
for i in range(N-2):
    A[i+1]=B[i]
    if B[i+1]>=B[i]:
        A[i+2]=B[i+1]
    else:
        A[i+1]=B[i+1]
if B[N-2]<=B[N-3]:
    A[N-1]=B[N-2]
ans=sum(A)
print(ans)

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

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

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

A = []

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

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

  else:
    A.pop(i)
    A.append(B[i])
    A.append(B[i])

print(sum(A))

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

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

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

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

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

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

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



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

Solution (Python):
N = int(input())
b = list(map(int, input().split()))
a = [ set() for _ in range(N)]
a = [-1]*N
pre = -1
for x in range(N):
    if x==0:
        a[x] = b[x]

    elif x==N-1:
        a[x] = b[x-1]

    else:
        a[x] = min(b[x-1], b[x])

print(sum(a))

Solution (Python):
n = int(input())
b = [int(x) for x in input().split()]
a = [0] * n
a[0], a[-1] = b[0], 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())

a = map(int, input().split())
alist = list(a)

tmp = []

for i in range(n-1):

    if i == 0:
        tmp.append(alist[i])
        tmp.append(alist[i])
    else:
        tmp.append(alist[i])
        if alist[i] < max(tmp[i], tmp[i+1]):
            tmp[i] = alist[i]


sum = 0
for i in tmp:
    sum += int(i)

print(sum)

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

Solution (Python):

N = int(input())
B = list(map(int, input().split()))
l = [0] * N
l[0] = B[0]
l[-1] = B[-1]
for i, b1, b2 in zip(range(1, N), B, B[1:]):
        if b1 > b2:
                l[i] = b2
        else:
                l[i] = b1

print(sum(l))

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

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

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