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

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

count = B_i[0] + B_i[N - 2]

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

print(count)

Solution (Python):
n = int(input())
b = [int(i) for i in input().split()]
dp = [0] * n
dp[0] = b[0]
for i in range(n):
    targets = []
    if i < n - 1:
        targets.append(b[i])
    if i - 1 >= 0:
        targets.append(b[i - 1])
    dp[i] = min(targets)
print(sum(dp))

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

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

ans = B[0]

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

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

s += array_b[n-2]
print(s)

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

B = list(map(int, input().split()))
B.append(max(B[0], B[-1]))

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

print(ans)

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

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

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

print(ans)

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

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
B=[INTMAX] + LI() + [INTMAX]

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

Solution (Python):
import sys


N = int(input())
B = [inp for inp in map(int, input().split())]

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

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

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

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(B[i])
    if A[i]>B[i-1]:
        A[i] = B[i-1]
A.append(B[-1])
print(sum(A))

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

Solution (Python):


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

Al = []
Al.append(Bl[0])
for bi in range(N-1):
    try:
        Al.append(min(Bl[bi], Bl[bi+1]))
    except IndexError:
        pass

Al.append(Bl[-1])
print(sum(Al))

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

Solution (Python):
import sys

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

print(sum(a))

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

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

print(ans)

Solution (Python):
input();B = list(map(int, input().split()))
print(sum([min(x, y) for x, y in zip(B + [10**5 + 1], [B[0]] + B)]))

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

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

ans=sum(c)
print(ans)

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

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().strip())
B = list(map(int, input().strip().split()))

A = []

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

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

print(ans)

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


A = []

A.append(B[0])

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

print(sum(A))

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

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

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

print(sum(a))

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

as_ = [0] * n

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

print(sum(as_))

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

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(ans + B[-1] + B[0])

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

ls_a = [0] * n

ls_a[n - 1] = ls_b[n - 2]
ls_a[0] = ls_b[0]

for i in reversed(range(1, n - 1)):
    ls_a[i] = min(ls_b[i], ls_b[i - 1])

print(sum(ls_a))

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

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

A = [0] * N

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

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

print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=0
l=len(a)
s+=a[0]+a[l-1]
i=1
while(i<l):
    s+=min(a[i],a[i-1])
    i+=1

print(s)

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

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

print(result + b[-1])

Solution (Python):

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

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

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

print(sum(a))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    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)
resolve()

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

A = [0]*N

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

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

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

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

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

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import math
import numpy as np

def main():
    N= int(input())
    Bs = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        if i == 0:
            A_max = Bs[0]
        elif i == N-1:
            A_max = Bs[-1]
        else:
            A_max = min(Bs[i-1], Bs[i])

        ans += A_max

    print(ans)

if __name__ == '__main__':
    main()

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

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

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

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

ans = 0
pbi = 0

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    B = LI()
    ans = B[0] + B[-1]
    for i in range(1, N-1):
        ans += min(B[i], B[i-1]) 
    print(ans)
main()

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

    previous = 10 ** 5

    for b in b_list:
      a = min(previous, b)
      a_list.append(a)
      previous = b
      
    a_list.append(b_list[-1])
    print(sum(a_list))
    

if __name__ == '__main__':
    main()

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    b = list(map(int, readline().split()))
    a = [0] * n
    for i in range(n):
        if i == 0:
            a[i] = b[i]
        elif i == n - 1:
            a[i] = b[i-1]
        else:
            a[i] = min(b[i], b[i-1])
    print(sum(a))


if __name__ == '__main__':
    solve()

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

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

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

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

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

Solution (Python):

import numpy as np
def main():
    n = int(input())
    b = list(map(int, input().split()))
    
    ans_list = []
    ans_list.append(b[0])
    for i in range(n-2):
        if i == n-1:
            ans_list.append(b[i])
            break
        ans_list.append(np.min([b[i], b[i+1]]))
        
    ans_list.append(b[n-2])
    print(np.sum(ans_list))


    
if __name__ == '__main__':
    main()

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

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

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

ans += bs[-1]

print(ans)

Solution (Python):

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

max_A = [None] * N

max_A[0] = B[0]
max_A[-1] = B[-1]

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

print(sum(max_A))

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

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


if __name__ == '__main__':
    main()

Solution (Python):
n,*a=map(int,open(0).read().split());print(sum(min(a[i],a[i+1])for i in range(n-2))+a[0]+a[-1])

Solution (Python):

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

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

    ans = sum(a)
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

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

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

Solution (Python):
num = int(input())
b = [int(i) for i in input().split()]
ans = b[0] + b[-1]

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

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

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

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

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

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

Solution (Python):

import sys



def solve(N: int, B: "List[int]"):
    lists = []
    C = B[::-1]
    for i in range(N):
        if i == 0:
            lists.append(C[i])
        elif i == N-1:
            lists.append(C[-1])
        else:
            lists.append(min(C[i], C[i-1]))

    sum = 0
    for n in lists:
        sum += n
    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())
b=list(map(int,input().split()))

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

result=0
for j in a:
    result+=j
print(result)

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

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())
b = list(map(int,input().split()))
a = [0] * n
a[0] = b[0]
a[-1] = b[-1]
for i,v in enumerate(zip(b,b[1::])):
    a[i+1] = min(v)
print(sum(a))

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

B_index = np.argsort(B)


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

Solution (Python):
from itertools import *
from math import *

INF = int(1e18)
N = int(input())
B = list(map(int, input().split()))
B = [INF] + B + [INF]

C = [INF]
for i in range(1, N + 1):
    C.append(min(B[i - 1], B[i]))
print(sum(C[1:]))

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

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

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

ans = 0

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

print(ans+arr[-1]+arr[0])

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:
        if B[i-1] < B[i]:
            sum += B[i-1]
        else:
            sum += B[i]
print(sum)

Solution (Python):

import numpy as np
N = int(input())
B = list(map(int, input().split()))
A = [0]*N
if N>2:
    A[0]=B[0]
    for i in range(1,N-1):
        A[i]=min(B[i],B[i-1])
    A[N-1]=B[N-2]
    print(np.sum(A))
else:
    print(B[0]*2)

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

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

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

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


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

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

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

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

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

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

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

b.append(max(b)+1)

result=b[0]

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

print(result)

Solution (Python):
import numpy as np
N=int(input())
B=list(map(int,input().split()))
A=np.zeros(N)
A[0]=B[0]
i=0
while i<=len(B)-1:
    if i==len(B)-1:
        A[i+1]=B[i]
        i+=1
    else:
        if B[i]<=B[i+1]:
            A[i+1]=B[i]
            i+=1
        else:
            A[i+1]=B[i+1]
            i+=1
print(int(sum(A)))

Solution (Python):
import numpy as np

INF = 1e+9
N = int(input())
B = list(map(int, input().split()))

A = B.copy() + [INF]

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

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
B = MAP()



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

for idx,b in enumerate(B):
	A[idx+1] = b

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

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


print(sum(A))

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

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

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

print(sum(A))

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

b.insert(0, float("inf"))
b.insert(len(b), float("inf"))

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

print(ans)

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

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

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

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

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

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

print(sum(A))

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

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

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

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

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

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

A = [None]*N

A[0] = B[0]

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

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

print(sum(A))

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

ans = []
for n in range(N):
    if n == 0:
        ans.append(blist[0])
    elif n>0 and n<N-1:
        mina = min(blist[n-1],blist[n]) 
        ans.append(mina)
    else:
        ans.append(blist[n-1])    

ansnum = sum(ans)
print(ansnum)

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):
import numpy as np

N = int(input())
A = [-1] * N

B = np.array(list(map(int, input().split())))
indices = np.argsort(B)

for i in indices:
    if A[i] == -1 and A[i + 1] == -1:
        A[i] = A[i + 1] = B[i]
    elif A[i] == -1:
        A[i] = B[i]
    elif A[i + 1] == -1:
        A[i + 1] = B[i]

print(sum(A))

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

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

Solution (Python):
import numpy as np
N = input()
B = np.array(input().split()).astype(int)
B_left = np.insert(B, 0, B[0])
B_right = np.insert(B, len(B)-1, B[-1])
print(np.min(np.array([B_left, B_right]).T, axis=1).sum())

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

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

b.insert(0, float("inf"))
b.insert(len(b), float("inf"))

a = []

for i in range(len(b)-1, 0, -1):
    a.insert(0, min(b[i-1], b[i]))

print(sum(a))

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

print(ans)

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

a_list = []

a_list.append(b[0])

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

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

a = [b[0]]

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

print(ans)

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

Solution (Python):

import math
import heapq
import bisect

MOD = 10**9+7

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

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

Solution (Python):
if __name__ == "__main__":
	N = int(input())
	B = list(map(int,input().split()))
	A = []
	A.append(B[0])
	for i in range(1,int(len(B))):
		
		A_left = B[i-1]
		A_right = B[i]
		A.append(min(A_left,A_right))

	A.append(B[-1])
	ans = 0
	for i in range(0,len(A)):
		ans += A[i]

	print(ans)

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

Solution (Python):
n = int(input())
b = list(map(int, input().split()))
a = [10 ** 9 for _ in range(n)]
for i, bi in enumerate(b):
    a[i] = min(a[i], bi)
    a[i + 1] = bi
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[i]
  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=[int(i) for i in input().split()]
ans=b[0]+b[n-2]
for i in range(n-2):
  ans+=min(b[i],b[i+1])
print(ans)

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

while sum(B) != -1*(N-1):
    max_val = max(B)
    index = B.index(max_val)
    if A[index] > B[index]:
        A[index] = B[index]
    if A[index+1] > B[index]:
        A[index+1] = B[index]
    B[index] = -1
        
print(sum(A))

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

A = [B[0]]

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

A.append(B[-1])

print(sum(A))

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

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

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

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

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

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

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

A.append(B[0])

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

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):
def minValue(a,b):
    return b if a > b else a

def getSum(arr):
    return sum(list(arr))

def calculate(arr,n):

    ret = []

    for i in range(n):
        if i == 0:
            ret.append(arr[0])
        elif i == len(arr):
            ret.append(arr[i-1])
        else:
            ret.append(minValue(arr[i],arr[i-1]))

    return ret


N = int(input())
S = input().split()

arr = list(map(int, list(S)))
result = calculate(arr,N)
ret = getSum(list(result))
print(ret)

Solution (Python):

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

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

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