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

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

print(ans)

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

AX = [0 for _ in range(N)]
AX[N-1] = BX[N-2]
AX[N-2] = BX[N-2]
for i in reversed(range(N - 2)):
    if BX[i] < BX[i+1]:
        AX[i+1] = BX[i]
    AX[i] = BX[i]
    
print(sum(AX))

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

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

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

A[-1] = B[-1]

print(sum(A))

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

if n == 2:
    ans = b[0] * 2
else:
    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()))

exB = [B[0]]
exB.extend(B)
exB.extend([B[-1]])

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



print(sum(A))

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

print(sum(ans))

Solution (Python):


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

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

Solution (Python):
import numpy as np

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

a  = np.zeros(n)

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

print(int(sum(a)))

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

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

print(c_maximal_value())

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

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

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


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

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

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

print(ans)

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

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

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

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

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

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

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

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

a.append(b[0])

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

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):
    if 0 < i < n-1:
        if b[i-1] < b[i]:
            s += b[i-1]
        else:
            s += b[i]
    elif i == 0:
        s += b[i]
    else:
        s += b[i-1]
print(s)

Solution (Python):

import sys;
import string;
sys.setrecursionlimit(20000) 

import copy
import math
import itertools

from functools import lru_cache


PPP = 1000000007






n = int(input())
























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














import re
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def ton(n, k, x):
  s = ""
  while n > 0:
    s = str(n%k) + s
    n //= k
  return s





def getEnergy():
  for y in b:
    yield y

def doit():
  total = b[0] + b[n-2]
  prev = None
  for x in b:
    if not prev == None:
      total += min(prev, x)
    prev = x
  return total

def yn():
  if doit():
    return "Yes"
  else:
    return "No"




try:
  
  print(doit())
  
except Exception as e:
  print("e", e, file=sys.stderr)

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



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

ans=sum(a)
print(ans)

Solution (Python):


N = int(input())

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

A = [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()))

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

print(ans)

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

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

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

for i in range(n-1) :
	b[i] = int(b[i]);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

print(sum(A))

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

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

Solution (Python):
while True:
    try:
        N = int(input())
        B = list(map(int, input().split()))
        A = [2**31] * 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))
    except:
        break

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

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

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

print(ans)

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

a = [0]*n
a[-1] = b[-1]
tmp1 = b.pop()
for i in range(n-2,-1,-1):
  if i == 0:
    a[i] = tmp1
  else:
    tmp2 = b.pop()
    a[i] = min(tmp1, tmp2)
    tmp1 = tmp2
print(sum(a))

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

A = [0] * N
for _ in range(N - 1):
    idx = B.index(max(B))
    A[idx] = A[idx + 1] = B[idx]
    B[idx] = -1
print(sum(A))

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

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

a.append(b[-1])

print(sum(a))

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

print(sum(an))

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])
ans+=b[n-2]
print(ans)

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

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

sum_ = 0

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

print(sum_)

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

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

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

buff.append(B[-1])
ans += B[-1]
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):
    if i!=len(b):
        a[i] = min(b[i-1],b[i])
    else:
        a[i] = b[i-1]
print(sum(a))

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

ans = b[0]
for i in range(0, 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 = []
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 = list(map(int, input().split()))

a = [0]*n




a[0] = b[0]

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

print(sum(a))

Solution (Python):


import sys

n=int(sys.stdin.readline())
b=[ int(x) for x in sys.stdin.readline().split() ]
b= [b[0]] + b + [b[-1]]
c=0
for i in range(1,n+1):
    c+= min(b[i-1],b[i])
print( c )

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

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

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

answer = 0

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

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

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

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

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

ans=[B[0]]
for i in range(n-1):
  if ans[-1]>B[i]:
    ans[-1]=B[i]
  ans.append(B[i])
print(sum(ans))

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

A[0] = B[0]
for bi in range(len(B)):
  A[bi+1] = B[bi]
  A[bi] = min(B[bi], A[bi])

print(sum(A))

Solution (Python):
N=int(input())
l_b=list(map(int,input().split()))
l_a=[l_b[-1]]
for i in range(N-2):
  l_a.append(min(l_b[N-2-i],l_b[N-3-i]))
l_a.append(l_b[0])
print(sum(l_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()))
A = [0] * N

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

print(sum(A))

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


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

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

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

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

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

    print(sum(A))





if __name__ == "__main__":
    main()

Solution (Python):

import numpy as np
import sys


def main():
    N = int(input())
    A = np.zeros(N)
    B = np.array(input().split(), dtype='int64')


    for i in range(N):
        if i == 0:
            A[0] = B[0]
        elif i == N-1:
            A[-1] = B[-1]
        else:
            if B[i-1] < B[i]:
                A[i] = B[i-1]
            else:
                A[i] = B[i]
    ans = int(np.sum(A))
    print(ans)








if __name__ =='__main__':
    main()

Solution (Python):
import math
input = raw_input

N = int(input())
A = list(map(int, input().split(" ")))

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

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

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

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


if __name__ == '__main__':
    main()

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

Solution (Python):

import numpy as np

if __name__ == '__main__':
    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(np.sum(A))

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

Solution (Python):
n = int(input())
b_list = list(map(int, input().split()))
temp = 10**5
max_sum = 0
for b in b_list:
    max_sum += min(b, temp)
    temp = b
print(max_sum+temp)

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

Solution (Python):
def solve():
    data = read()
    result = think(data)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n - 1)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    result = []
    result.append(data[0])
    for i in range(len(data) - 1):
        result.append(min(data[i], data[i + 1]))
    result.append(data[-1])
    return sum(result)


def write(result):
    print(result)


if __name__ == '__main__':
    
    
    
    
    solve()

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

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

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

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

for i in range(len(b)):
    if (i == 0) or (c[i] > b[i]):
        c[i] = b[i]
    c[i+1] = b[i]

print(sum(c))

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

Solution (Python):
def f_c():
    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[-1]
    print(s)

if __name__ == "__main__":
    f_c()

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

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

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

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
A = []
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])
    else:
      A.append(B[i-1])
print(sum(A))

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

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

B.sort()

for i in range(N-1):
    index = B[i][1]
    b = B[i][0]
    
    if A[index] == -1:
        A[index] = b
    if A[index+1] == -1:
        A[index+1] = b   

print(sum(A))

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

A = [max(B)] * N

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

Solution (Python):


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

A.append(B[0])

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

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

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

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

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

a = [0]*n

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

ans = sum(a)

print(ans)

Solution (Python):
def main():
    N = input()
    B_l = [int(i) for i in input().split()]
    A_l = []
    for i in range(len(B_l)):
        if i == 0:
            A_l.append(B_l[i])
        elif i < len(B_l):
            A_l.append(min(B_l[i - 1], B_l[i]))

    A_l.append(B_l[-1])
    print(sum(A_l))


if __name__ == "__main__":
    main()

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

sum=0

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

print(sum)

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

Solution (Python):
from collections import deque

def main():
    _ = int(input())
    B = deque([int(x) for x in input().split()])
    
    old = B[0]
    B.append(B[-1])
    ans = 0
    while B:
        now = B.popleft()
        ans += min(old, now)
        old = now
    print(ans)

if __name__ == "__main__":
    main()

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

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

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

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

for i in range(n-1):
    if a[i] is None or a[i] > b[i]:
        a[i] = b[i]
    a[i+1] = b[i]

res = sum(a)

print(res)

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

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

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

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

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

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

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

print(s)

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

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

As = [0] * N

ans = Bs[0]
mae = Bs[0]


for b in Bs[1:]:
    if mae < b:
        ans += mae
    else:
        ans += b
    mae = b

    
ans += Bs[-1]

print(ans)

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])
print(ans+B[N-2])

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


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



print(sum(A))

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

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

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

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


temp=a[0]
result=0
for item in a[1:]:
  result+=min(temp,item)
  temp=item

result+=a[0]
result+=a[-1]

print(result)

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

Solution (Python):
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
    
    
n=int(input())
l=list(map(int,input().split()))

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

cnt=0

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

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

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

if N == 2:
    print(sum(b_list) * 2)
    exit()
a_list.append(b_list[0])
for i in range(N-2):
    b = b_list[i]
    b2 = b_list[i+1]
    a_list.append(min(b, b2))

a_list.append(b_list[-1])
print(sum(a_list))

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

B = list(map(int, input().split()))
B.append(10**6)

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

print(ans)

Solution (Python):


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

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



if __name__ == '__main__':
    main()

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

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

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

Solution (Python):

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

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

print(count)

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

max_a.append(B[N-2])
print(sum(max_a))

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

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

print(total)

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

Solution (Python):
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


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

    ans = [10**5 + 1] * n

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

        if v < ans[i]:
            ans[i] = v
        if v < ans[i+1]:
            ans[i + 1] = v

    print(sum(ans))


if __name__ == '__main__':
    main()

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

b = list(map(int, input().split())) + [10**5+1]

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

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