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 = [10 ** 5 for _ in range(n)]  
a[-1] = b[-1]

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

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

A=[0]*N

MIN = float('inf')
for i in reversed(range(N)):
    if (i == N-1):
        A[i] = B[N-2]
    elif (i == 0):
        A[i] = B[0]
    else:
        A[i] = min(B[i], B[i-1])

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())
B = list(map(int, input().split()))
print(sum([min(B[x], B[x+1]) for x in range(len(B)-1)]) + B[0] + B[-1])

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

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

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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


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


if __name__ == '__main__':
    main()

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

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

import sys














def main():
    n, *b = [int(x) for x in sys.stdin.read().split()]
    a = [None for _ in range(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])

    ans = sum(a)
    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
n=int(input())
b=list(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))

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

B.append(B[-1])

max = B[0]
for i in range(1, N):
    max += np.minimum(B[i-1], B[i])
print(max)

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

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

Solution (Python):
n=int(input())
a=[None]*n
b=list(map(int,input().split()))
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]
    else:
        a[i]=b[i]
print(sum(a))

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

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

A=[1000000]*N

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

print(sum(A))

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

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

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

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

A.append(B[-1])

print(sum(A))

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

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

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

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

Solution (Python):
N = int(input())
BS = list(map(int, input().split()))
AS = [float('inf') for i in range(N)]

for i in range(N-1):
    AS[i] = min(AS[i], BS[i])
    AS[i+1] = max(AS[i], BS[i])

print(sum(AS))

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

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

print(total)

Solution (Python):
def solve():
    N = int(input())
    B = list(map(int , input().split()))
    max_candidate = B[0]
    ret = B[0]
    for i in range(1, N-1):
        if max_candidate < B[i]:
            ret += max_candidate
        else:
            ret += B[i]
        max_candidate = B[i]
        
    ret += max_candidate
    print(ret)
    
solve()

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


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

ans += Blist[0]+Blist[n-2]
print(ans)

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

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

print(sum(A))

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

print(sum(A))

Solution (Python):
n = int(input())
A = [None for i in range(n)]
B = list(map(int, input().split()))
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())
a = [int(x) for x in input().split()]

b = a[0]
bef = 0

for i in a:
  
  if i >= bef:
    b = b + i
    
  else:
    b = b - bef + i + i
    
  bef = i
  

print(b)

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



total=0

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

Solution (Python):
def main():
    N = int(input())
    B = list(int(x) for x in input().split())
    A = [0]*N

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

if __name__ == '__main__':
    main()

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

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

print(sum(a))

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

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

Solution (Python):
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]



def A():
    N = I()
    print(pow(N, 3))
    return



def B():
    N = I()
    A = LI()
    B = LI()
    C = LI()
    a_p = -1
    ans = 0
    for a in A:
        if (a - a_p == 1):
            ans += B[a - 1] + C[a - 2]
        else:
            ans += B[a - 1]
        a_p = a
    print(ans)
    return



def C():
    N = I()
    B = LI()
    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))
    return



def D():
    return



def E():
    return



def F():
    return



def resolve():
    C()
    return



if __name__ == "__main__":
    C()

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

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

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

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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
def print_ans(N,B):
    """Test Case
    >>> print_ans(3,"2 5")
    9
    >>> print_ans(2,"3")
    6
    >>> print_ans(6,"0 153 10 10 23")
    53
    """
    B_arr = list(map(int,B.split()))
    A_arr = [0] * N
    for i in range(N - 1):
        A_arr[i + 1] = B_arr[i]
        if i == 0:
            A_arr[i] = B_arr[i]
        else:
            A_arr[i] = min(A_arr[i],B_arr[i])
    print(sum(A_arr))
if __name__ == '__main__':
    N = int(input().rstrip())
    B = input().rstrip()
    print_ans(N,B)

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

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

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

A_list = [0] * N
A_list[0] = B_list[0]

if len(B_list) >=1:
    for i in range(N-2):
        A_list[i+1] = min(B_list[i], B_list[i+1])

    A_list[N-1] = B_list[N-2]
else:
    A_list[1] = B_list[0]

print(sum(A_list))

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

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

print(sum(a))

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

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

Solution (Python):

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

A = []

A.append(B[0])

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

A.append(B[N-2])
answer = sum(A)  
print(answer)

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

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

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

print(res)

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

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

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

ans = sum(A_li)
print(ans)

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

for i in range(0,num-1):
    if b[i] >= max(a[i],a[i+1]):
        if a_fix[i] == -1: 
            a[i] = a[i+1] = b[i]
            a_fix[i] = a_fix[i+1] = 1 
        else:
            a[i+1] = b[i]
            a_fix[i+1] = 1
    else:
        a[i] = a[i+1] = b[i]
        a_fix[i] = a_fix[i+1] = 1

print(sum(a))

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

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

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

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

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

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














































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

ans = sum(a)
print(ans)

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

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

print(sum(a))

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

Solution (Python):
N = int(input())
B = list(map(int, input().strip().split()))
INF = float('inf')

B.insert(0, INF)
B.append(INF)

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

print(sum(A))

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

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

print(sum(a))

Solution (Python):
if __name__ == "__main__":
    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(min(b[i - 1], b[i]))

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

Solution (Python):

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

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

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

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

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

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

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

for i in range(0,n):
  if i == 0:
    m[i] = b[i]
    continue
  elif i == n-1 :
    m[n-1] = b[i-1]
    continue
  m[i] = min(b[i],b[i-1])

print(sum(m))

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

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

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

count = B[0]

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

count += B[N-2]

print(count)

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

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

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

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

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

i=1
while n-1>i:
  if b[i-1]<=b[i]:
    x+=b[i-1]
    i+=1
  else:
    x+=b[i]
    i+=1
    
print(x)

Solution (Python):
N = int(input())
B = map(int,input().split())
ans = next(B)
tmp = ans
for i in range(N-2):
    t = next(B)
    ans += min(tmp,t)
    tmp=t
ans += tmp
print(ans)

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

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

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

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

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

Solution (Python):
n = int(input())
a = []
a.append(10 ** 5)
b = input().split()
x = 0 

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

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

print(x)

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

Solution (Python):

n = int(input())
bl = list(map(int, input().split()))
al = [0]*n

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

print(sum(al))

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

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

print(result)

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

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

print(res)

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

print(sum(A))

Solution (Python):
import math

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




if __name__ == '__main__':
    main()

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

a_integers = [b_integers[0]]
for i in range(n-2):
    if b_integers[i] > b_integers[i+1]:
        a_integers.append(b_integers[i+1])
    else:
        a_integers.append(b_integers[i])
a_integers.append(b_integers[-1])
print(sum(a_integers))

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

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

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

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

print(sum(c))

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

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

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

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

print(a)

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

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

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

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

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

print(cnt)

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

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

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

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

print(cnt)

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

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

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

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

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

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

for i in range(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=[B[0]]
preb=B[0]
for b in B[1:]:
  A.append(min(preb,b))
  preb=b
A.append(B[-1])
print(sum(A))

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

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

Solution (Python):
def main():

    n = int(input())
    b = [i for i in 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)


if __name__ == '__main__':
    main()

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], B[i-1]))
A.append(B[N-2])

print(sum(A))

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

Solution (Python):
N=int(input())
B=[10**6]
B.extend([int(b) for b in input().split()])
B.append(10**6)


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

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

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

for i,b in enumerate(b_list):
    if i == 0:
        a_list[i] = b
        a_list[i+1] = b
    else:
        a_list[i] = min(a_list[i],b)
        a_list[i+1] = b

print(sum(a_list))

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

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

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

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

a = [0] * n

a[0] = b[0]
a[-1] = b[-1]
for i, (v1, v2) in enumerate(zip(b[:-1], b[1:]), 1):
    a[i] = min(v1, v2)

print(sum(a))

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

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

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

print(sum(ans))

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

a = [0] * n

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

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


print(sum(a))

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

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

point = 0

if n == 2:
  point = int(a[0])*2
else:
  for i in range(n):
    if i == 0:
      point += int(a[0])
    elif i == (n-1):
      point += int(a[i-1])
    else:
      point += min(int(a[i-1]),int(a[i]))
print(point)

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

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

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
def c(n, b):
    A = [0 for i in range(n)]
    for i in range(n):
        if(i == 0 or i == 1):
            A[i] = b[0]
        else:
            A[i] = b[i-1]
            if(b[i-1] < b[i-2]):
                A[i-1] = b[i-1]
    return sum(A)
print(c(N,B))

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

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

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