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()))
src = []
for ni in range(n):
    if ni == 0:
        src.append(b[0])
    elif ni == n-1:
        src.append(b[ni-1])
    else:
        src.append(min(b[ni],b[ni-1]))
print(sum(src))

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):
    if i == 0 or i == (N-1):
        pass
    else:
        A[i] = min(B[i-1], B[i])

print (sum(A))

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

sum=b[0]
last=0
for i in range(1,n):
  if i==n-2:
    sum=sum+min(b[i],b[i-1])
    last=b[i]
  elif i==n-1:
    sum=sum+max(last,b[i-1])
  else:
    sum=sum+min(b[i],b[i-1])
    
print(sum)

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

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


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

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

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

Solution (Python):

"""
Created on Sat Sep  7 21:12:15 2019

@author: doppe
"""

N = int(input())

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

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

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

B = list(map(int, input().split()))
A = []
for index, b in enumerate(B):
    if(index == 0):
        A.append(b)

    if(index+1 < N-1):
        if(B[index+1] > B[index]):
            A.append(B[index])
        else:
            A.append(B[index+1])
    else:
        A.append(B[index])

print(sum(A))

Solution (Python):

import numpy as np


def main():
    n = int(input())
    b = np.array(input().split(), dtype='int')
    a = np.zeros(n, dtype='int')

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

    print(ans)

main()

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

for bi in b:
    if bi >= ai:
        ans += ai
    else:
        ans += bi
    ai = bi
ans += c[-1]
print(ans)

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

b = b[::-1]
ans = b[0]
for i in range(len(b) - 1):
    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], b[i]))
a.append(b[-1])
print(sum(a))

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

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

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

b.append(10 ** 9 + 1)
b.insert(0, 10 ** 9 + 1)
ans = 0

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

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

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



ans_array = [array[0]]
for i in range(N - 1):
    
    
    if i == N - 2:
        ans_array.append(array[-1])
    else:
        ans_array.append(min([array[i], array[i + 1]]))
print(sum(ans_array))

Solution (Python):
import copy

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

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

print(ans)

Solution (Python):
N = int(input().strip())
B = [int(str) for str in input().strip().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()))
A = [0] * N
for k in range(N):
    A[0] = B[0]
    if k == N-1:
        A[k] = B[k-1]
    else:
        A[k] = min([B[k-1], B[k]])
print(sum(A))

Solution (Python):
n = int(input())
B = [int(i) for i in input().split()]
if n == 2:
    print(B[0]*2)
    exit()

ans = []
ans.append(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()))

right = [b[0]]+b
left  = b + [b[-1]]
count=0

for i in range(n):
  count+=min(right[i],left[i])
print(count)

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

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

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

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

Solution (Python):
s = input().split()
N=int(s[0])
s = input().split()
count=[]
count.append(int(s[0]))
for i in range(1,N-1):
        if int(s[i])<int(s[i-1]):
                count.append(int(s[i]))
        else:
                count.append(int(s[i-1]))
count.append(int(s[N-2]))
print(sum(count))

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

last = 10 ** 6
sum = 0
for i in range(0, n - 1):
    if b[i] < last:
        sum += b[i]
    else:
        sum += last
    last = b[i]

sum += b[n-2]

print(sum)

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

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

print(count)

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


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

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

print(sum(a))

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

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


if __name__ == "__main__":
    resolve()

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

A=[]

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

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


al = [bl[0]] * 2
for b in bl[1:]:
    if al[-1] > b:
        al[-1] = b
    al.append(b)

print(sum(al))

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

ans=b[0]

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

ans=ans+b[n-2]

print(ans)

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

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

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

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

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:
        if B[i-1]>=B[i]:
            ans += B[i]
        else:
            ans +=B[i-1]

print(ans)

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

result = B[-1]
s = B[-1]

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

print(result)

Solution (Python):


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

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

t += b[n - 2]

print(t)

Solution (Python):

import sys


def solve(N: int, B: "List[int]"):
    A = [0] * (N)
    A[0] = B[0]
    A[1] = B[0]
    for i in range(1,N-1):
        A[i] = min(A[i], B[i])
        A[i+1] = B[i]

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

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

print(sum(a))

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

ans = 0
c = 0
for i, b in enumerate(li):
  if i == 0:
    ans += b
  else:
    ans += min(c, b)
  c = b
ans += b

print(ans)

Solution (Python):


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

exit(0)

Solution (Python):
def get_list(str):
    str_list = str.split(" ")
    result_list = []
    for str in str_list:
        result_list.append(int(str))
    return result_list

n = int(input())
b_str = input()
b_list = get_list(b_str)

result = 0
pre_num = pow(10, 5)
for b in b_list:
    if b >= pre_num:
        result += pre_num
    else:
        result += b
    pre_num = b
result += b_list[-1]

print(result)

Solution (Python):
import sys
n = int(sys.stdin.readline())
B = list(map(int, input().split()))

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

print(sum(A))

Solution (Python):


n = int(input())

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

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

print(sum(a))

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

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

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

print(maximal)

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

ans = sum(B)*2

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


print(ans)

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

a = [0]*n

tmp = 0

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


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

ans = sum(a)

print(ans)

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

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

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

result = sum(A)

print(result)

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

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):
def A():
    print(int(input())**3)

def B():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    points = B[A[0]-1]
    previous = A[0]-1
    
    for i in range(1, N):
        points += B[A[i]-1]
        if A[i]-1 == previous+1:
            points += C[previous]
        
        previous = A[i]-1
    
    print(points)

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

    s = B[0]
    temp = B[0]
    for i in range(1, len(B)):
        if B[i] > temp:
            s += temp
        else:
            s += B[i]
        
        temp = B[i]
    
    s += temp

    print(s)

C()

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

a = [[] for i in range(n)]

for i in range(len(b)):
  a[i].append(b[i])
  a[i+1].append(b[i])

ans = 0
for i in a:
  ans += min(i)

print(ans)

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

if __name__ == '__main__':
    main()

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

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

print(sum(a))

Solution (Python):
N = int(raw_input())
B = map(int, raw_input().split(' '))
A = [100000] * N

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

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

A=[ float("inf") for _ in range(N)]

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


print sum(A)

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

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

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

Solution (Python):


import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    A = [0] * N
    B = i2nn()
    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))
    return

main()

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

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

A_array.append(B_array[0])

for i in range(1, N-1):
    B_i = B_array[i]
    B_iminus1 = B_array[i-1]
    if B_i < B_iminus1:
        A_array.append(B_i)
    else:
        A_array.append(B_iminus1)

A_array.append(B_array[N-2])

counter = 0
for i, e in enumerate(A_array):
    counter += e

print(counter)

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

ans = 0


def mini(x, y):
    if x > y:
        return y
    else:
        return x


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

print(ans)

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

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

ans = b[0]

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

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

Solution (Python):

import sys


def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
B = ILI()
A = []
for i in range(N-1):
    if i == 0:
        A.append(B[i])
    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()))
ma = []
ma.append(b[0])
for i in range(len(b)-1):
    if b[i] <= b[i+1]:
        ma.append(b[i])
    else:
        ma.append(b[i+1])
"""
if b[-2] <= b[-1]:
    ma.append(b[-2])
else:
    ma.append(b[-1])
"""
ma.append(b[-1])
print(sum(ma))

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

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

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

sum_ = 0
prev = float("inf")
for i in range(n):
    if i < len(B):
        sum_ += min(prev, B[i])
        prev = B[i]
    else:
        sum_ += prev
print(sum_)

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

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
ins = 0
count = 0
for i in range(N-1):
  if i == 0:
    count += B[i]
  if i > 0 and B[i-1] > B[i]:
    count += B[i]
  elif i > 0 and B[i-1] <= B[i]:
    count += B[i-1]
count += B[i]
print(count)

Solution (Python):


def main(N,B):
    ans = 0
    for i in range(1,len(B)):
        ans += min(B[i-1], B[i])
    print(ans+B[0]+B[-1])    
    
if __name__ == '__main__':
    N = int(input())
    B = [int(b) for b in input().split()]
    main(N,B)

Solution (Python):
N=int(input())
B=list(map(int,input().split()))
ans=B[0]
for i,b in enumerate(B):
  if i>=len(B)-1:
    ans+=b
    break
  ans+=min(b,B[i+1])
print(ans)

Solution (Python):
import sys
from pprint import pprint

def solve(n, b):
    ans = 0

    for i, b_i in enumerate(b):
        if i == 0:
            ans += b_i
            continue
        ans += min(b_i, b[i-1])
    ans += b[i]

    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    b = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, b)

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

import sys

input = sys.stdin.readline


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



if __name__ == '__main__':
    AtCoder().main()

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

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


if __name__ == '__main__':
    main()

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

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

print(sum)

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

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

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

print(ans)

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

a_sum = 0
last_b = 10 ** 5 + 1
for b in b_list:
    i = b if b <= last_b else last_b 
    a_sum += i
    last_b = b
a_sum += b

print(a_sum)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

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

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

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

isum = b[0]

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
x.append(x[n-2])
res=[]
res.append(x[0])

for i in range(n-1):
	res.append(min(x[i],x[i+1]))


    
print(sum(res))

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

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

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

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

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

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

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N = int(input())
B = inpl()
INF = 10**6
ans = 0
prev_b = INF
for b in B:
    ans += min(prev_b, b)
    prev_b = b
ans += prev_b
print(ans)

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

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

print(tot)

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

ans = 0
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 = 0

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

print(ans)

Solution (Python):

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())


dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

add = 1 
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)


li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    


org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)




    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


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

    
def main(): 
    res = B[-1]
    for n in range(N-2):
        res += min(B[-(n+1)], B[-(n+2)])
    res += B[0]
    print(res)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

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

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

    A.append(max(A[N-2],B[N-2]))
print(sum(A))

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

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

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


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

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

alist = [-1 for i in range(n)]

alist[0] = blist[0]
alist[1] = blist[0]

for i in range(1,n):
    if alist[i-1] <= blist[i-1]:
        alist[i] = blist[i-1]
    else:
        alist[i-1] = blist[i-1]
        alist[i] = blist[i-1]

print(sum(alist))

Solution (Python):

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

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

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

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

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

Solution (Python):
n = int(input())
ListB = [int(val) for val in input().split()]
sumA = ListB[0]
count = 1
while(count < n - 1):
	if (ListB[count - 1] < ListB[count]):
		sumA += ListB[count - 1]
	else:
		sumA += ListB[count]
	count += 1
sumA += ListB[n - 2]
print(sumA)

Solution (Python):



N = int(input())
A = [0 for _ in range(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())
B = list(map(int, input().split()))
A = [0]*N
for i in range(N):
  if i != 0 and i != (N-1):
  	A[i] = min(B[i-1], B[i])
  elif i == 0:
    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_sum = B[0] + B[-1]

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

print(a_sum)

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

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

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

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

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

total = 0

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

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

als = []
for i in range(n-2):
  als.append(min(bls[i], bls[i+1]))

print(sum(als)+bls[0]+bls[n-2])

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