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 = [b[0]]

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

    while b[i] < max(a[i], a[i+1]):
        a[i+1] += 1

print(sum(a))

Solution (Python):
N = int(input())
B = [100000] + [int(e) for e in input().split(" ")] + [100000]
ans = 0
for i in range(N):
    ans += min(B[i], B[i+1])

print(ans)

Solution (Python):
N = int(input())
B = [100000] + [int(e) for e in input().split(" ")] + [100000, 100000]
ans = 0
for i in range(N):
    ans += min(B[i], B[i+1])

print(ans)

Solution (Python):
N = int(input())
B = input().split()
Ap = [0 for i in range(N)]
for i in range(N-1):
    B[i] = int(B[i])
for i in range(N):
    if i != 0 and i != N-1:
        Ap[i] = min({B[i-1],B[i]})
    elif i == 0:
        Ap[i] = B[i]
    elif i == N-1:
        Ap[i] = B[N-2]

S = sum(Ap)
print(S)

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

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

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

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

print(s)

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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    b = list(map(int, input().rstrip('\n').split()))
    a = [10 ** 10] * n
    for i in range(n-1):
        a[i] = min(b[i], a[i])
        a[i+1] = min(b[i], a[i+1])
    print(sum(a))


if __name__ == '__main__':
    slove()

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    B = [inf] + LIST() + [inf]
    sumv = 0
    for i in range(N):
        sumv += min(B[i], B[i+1])
    print(sumv)

if __name__ == '__main__':
    main()

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

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

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

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

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

print(S)

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
i=0
ans=0
while i!=n:
    if i==0:
        ans+=b[i]
    elif i==(n-1):
        ans+=b[i-1]
    else:
        c=[b[i],b[i-1]]
        ans+=min(c)
    i+=1

print(ans)

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

maximum_sum = 0

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

print maximum_sum

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


A = []
A.append(B[0])
i = 1
while i < (N -1):
	A.append(min(B[i], B[i-1]))
	i += 1
A.append(B[-1])
print(sum(A))

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

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

	else:
		a+=B[i+1]

print(a+B[0]+B[-1])

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

A = 0

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

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

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

print(total)

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

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

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

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

print(result)

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int,ins()))
def lin(): return list(input())
def iin(): return map(int,ins())

n = ii()
b = iil()
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())
bs = list(map(int, input().split(' ')))

ret = bs[0]
for i in range(len(bs) - 1):
    ret += min(bs[i: i+2])
ret += bs[-1]

print(ret)

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

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

print(sum(A))

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

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

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

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

list.append(B[N-2])

print(sum(list))

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):
num = int(input())
int_row = list(map(lambda x: int(x), input().split(" ")))
ans = 0
for i in range(num):
    if i == 0:
        ans += int_row[0]
    elif i == num - 1:
        ans += int_row[-1]
    else:
        ans += min(int_row[i - 1], int_row[i])
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 = []

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

sum = b[0]

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

sum += b[n-2]

print(sum)

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

output = sum(a)
print(output)

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

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

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

print(sum(a))

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

print(sum(A))

Solution (Python):
import sys

sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline

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):
import numpy as np
N = input()
N = int(N)
B = np.hstack([int(a) for a in input().split()])

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

Solution (Python):
num = int(input())
comp = [int(s) for s in input().split()]
answer = comp[0]
for i in range(num -2):
  if comp[i] >= comp[i + 1]:
  	answer+=comp[i + 1]
  else:
    answer += comp[i]
answer += comp[-1]
print(answer)

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

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

print(sum(A))

Solution (Python):
from sys import stdin
from math import factorial
n = int(stdin.readline().rstrip())
b = list(map(int,stdin.readline().rstrip().split()))
point = 0
point += b[0]
for i in range(n-2):
    point += min(b[i],b[i+1])
point += b[n-2]
print(point)

Solution (Python):



import sys

N = int(sys.stdin.readline())

a = []
b = list(map(int, sys.stdin.readline().rstrip().split()))



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


print(sum(a))

Solution (Python):
N=int(input())
B=[int(b) for b in input().split()]
A=[int(a) for a in range(N)]



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

print(sum(A))

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

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

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

Solution (Python):
import sys
import math

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def pro(k, l, n):
    if l < n:
        if k == 0:
            return(n - l)
        return (n - l + 2)
    if l == n:
        if k == 0:
            return 0
        elif k == 1:
            return 1
        return 3
    else:
        l -= n - 1
        if l == k:
            return 1
        elif l > k:
            return 0
        if l < k - 1:
            return 2
        else:
            return 3
            

def rt(k, l , n):
    if k < n:
        if l == 0:
            return (k * 2 + n)
        return (n + k * 2 - 1)
    elif k == n:
        if l == 1:
            return (k * 3 - 2)
        elif l == 0:
            return (k * 3)
        return (k * 3 - 3)
    else:
        k -= n - 1
        if k == l:
            return (n * 3 - 2)
        elif k > l:
            return (n * 3)
        if k < l - 1:
            return ((n - 1) * 3 - 1)
        else:
            return ((n - 1) * 3)



def main():
    n = iinput()
    a = rlinput()
    res = a[0] + a[-1]
    for i in range(n - 2):
        if a[i] > a[i + 1]:
            res += a[i + 1]
        else:
            res += a[i]
    print(res)
    
    
    
    
    


main()

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

cnt = B[0]

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

cnt += B[N-2]

print(cnt)

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

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

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

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

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

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

  if i == n - 1 - 1:
    a[i + 1] = b[i]
  else:
    a[i + 1] = min(b[i], b[i + 1])

print(sum(a))

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

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

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

for i in range(len(B)):
    A[i] = B[i]
    A[i+1] = B[i]

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

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

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

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

print(ans)

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

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

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

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

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

print(hoge)

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

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

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

print(sum(a))

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

init1 = a[0]
last1 = a[n-2]
retval = init1+last1
for i in range(n-2):
  retval += min(a[i],a[i+1])
print(retval)

Solution (Python):
def solve(n, b):
    ans = 0
    for i in range(n):
        if i == 0:
            ans += b[0]
        elif i == n-1:
            ans += b[-1]
        else:
            ans += min(b[i-1], b[i])
    return ans

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

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

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
C = B[:]
C.pop(0)
C.append(1e5)

maximum = B[0] + sum([min(b, c) for b, c in zip(B, C)])
print(maximum)

Solution (Python):

n = int(input())
B = [int(i) for i in input().split()]
A = [B[0]]+[min(B[k],B[k+1]) for k in range(n-2)]+[B[-1]]
print(sum(A))

Solution (Python):



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

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

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

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

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[N-2]
    else:
        sum += min([b[i-1], b[i]])
print(sum)

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

print(s)

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

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

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

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

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

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

print(sum(a))

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

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

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

c =[]

c.append(b[0])

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

c.append(b[n-2])

print(sum(c))

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

a_sum += b[0]

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

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

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

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

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

print(res)

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

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

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

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

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

print(score)

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

ans = 0

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

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

a = [b[0],b[0]]

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

print(sum(a))

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

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

numbers = [int(i) for i in input().split()]
res = 0

for i in range(n):
    res += min(numbers[max(i-1, 0)], numbers[min(i, n-2)])

print(res)

Solution (Python):

N = int(input())
list_A = []
list_B = list(map(int, input().split()))











temp_A = list_B[0]
ans = temp_A

for i in range(1,N-1):
    
    if temp_A > list_B[i]:
        temp_A = list_B[i]
        ans += temp_A
    else: 
        ans += temp_A
        temp_A = list_B[i]

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

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

print(sum(A))

Solution (Python):

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

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

print(num)

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

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

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

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, B: "List[int]"):
    ret = 0
    for i in range(N - 2):
        ret += min(B[i], B[i + 1])
    ret += B[0] + B[N - 2]
    print(ret)
    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())
B = list(map(int, input().split()))
A = [0 for _ in range(n)]
A[0] = B[0]
A[n-1] = B[n-2]
for i in range(n-2):
  A[i+1] = min(B[i], B[i+1])
print(sum(A[j]for j in range(n)))

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

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


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

    
    if i >= 1:
        if A[i] > B[i-1]:
            A[i] = B[i-1]

print(sum(A))

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

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

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

ans=A[0]+A[N-2]
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()))

ans = 0
tmp_b = 0

tmp_b = B[0]
for b in B:
    max_a = min(tmp_b,b)
    ans += max_a 
    tmp_b = b

max_a = B[-1]
ans += max_a

print(ans)

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

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

print(a)

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

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

print(a)

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

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

print(max_val)

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

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

Solution (Python):
n =  int(raw_input())
B = map(int, raw_input().split())
B = [1000000] + B + [1000000]
print sum(min(B[i-1], B[i]) for i in range(1, n+1))

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

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

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

a.append(b[-1])

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

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

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

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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

B.append(float('inf'))
A.append(B[0])

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

print(sum(A))

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

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










As = [0] * N
As[0] = Bs[0]
As[N-1] = Bs[N-2] 

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

print(sum(As))

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

mx = 0

for i in range(len(B)):

    if i==0 :

        if len(B)==1 :

            mx += B[0]*2

        else:

            if B[i] > B[i+1]:

                mx += B[i]+B[i+1]

            else:

                mx += B[i]*2

    elif i>0 :

        if i != len(B)-1:

            if B[i] < B[i+1]:

                mx += B[i]

            elif B[i] >= B[i+1]:

                mx += B[i+1]

        elif i == len(B)-1:

            mx += B[i]

print(mx)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
B_array = list(map(int, input().split()))
A_array = [0] * N
A_array[0] = B_array[0]
for i in range(N-1):
    A_array[i+1] = B_array[i]
    if B_array[i] <= A_array[i]:
        A_array[i] = B_array[i]
print(sum(A_array))

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

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

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

print(sum(ans))

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

b.append(b[n-2])
b.append(0)
s = 0

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

s += b[0]
print(s)

Solution (Python):



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

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

    print(result)


if __name__ == "__main__":
    main()

Solution (Python):



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

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

    print(result)


if __name__ == "__main__":
    main()

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

ans+=B[N-2]

print(ans)

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

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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    B = LI()
    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)
if __name__ == '__main__':
    main()

Solution (Python):



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

Solution (Python):



n = int(input())
b = list(map(int, input().split()))
a = [b[0], b[0]]
for i in range(1, n-1):
    if b[i] > b[i-1]:
        a.append(b[i])
    else:
        a.append(b[i])
        a[i] = b[i]
print("{}".format(sum(a)))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()
INF = 100000000000
nums = [INF] + getList() + [INF]
ans = 0
for i, j in zip(nums, nums[1:]):
    ans += min(i, j)

print(ans)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
B = [int(_) for _ in stdin.readline().rstrip().split()]
A = [0 for i in range(N)]
A[0] = B[0]
A[-1] = B[-1]
for i in range(1, N-1):
    A[i] = min(B[i], B[i-1])
print(sum(A))

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

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

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

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

list_A = [0]*n

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

print(sum(list_A))