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

Solution (Python):
N = int(input())
Bi = [pow(10,6)] + list(map(int,input().split())) + [pow(10,6)]
Asum = 0
for i in range(1,N+1):Asum = Asum + min(Bi[i-1], Bi[i])
print(Asum)

Solution (Python):
import sys

n=int(sys.stdin.readline())
B=list(map(int,sys.stdin.readline().split()))
a=0
first=1
for b in B:
    if first==1:
        a=b
        pre=b
        first=0
    else:
        a+=min(b,pre)
        pre=b
        
a+=pre
print(a)

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

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

if n==2:
    print(b[0]*2)
    exit()

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

print(sum(a))

Solution (Python):












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

arrA = [0 for _ in range(n)]

for i in range(len(arrB)):
    if i == 0:
        arrA[i] = arrB[i]
        arrA[i+1] = arrB[i]
    else:
        if arrB[i] <= arrA[i]:
            arrA[i] = arrB[i]
            arrA[i+1] = arrB[i]
        else:
            arrA[i+1] = arrB[i]

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

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

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

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

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

Solution (Python):
N = int(input())
B = list(map(int,input().split()))
B = B[:1] + B + B[-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=[None for _ 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):

"""
C - Maximal Value
https://atcoder.jp/contests/abc140/tasks/abc140_c

"""
import sys


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


def main(args):
    N = int(input())
    B = [int(b) for b in input().split()]
    ans = solve(N, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

print(ans)

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

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

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

print(res)

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

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


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

Solution (Python):








def resolve():

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

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

resolve()

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

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

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

print(sum(A))

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

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

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

print(sum)

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

Solution (Python):
import sys


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

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

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

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

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

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

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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

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

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

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

print(sum(A))

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

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

print(sum(A))

Solution (Python):

def submit():
    n = int(input())
    blist = list(map(int, input().split()))

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

    print(ans)


if __name__ == "__main__":
    submit()

Solution (Python):
def solve():
    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[-1]
    
    return ans

print(solve())

Solution (Python):

n = int(input())

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

B.insert(0, 2 ** 32)
B.append(2 ** 32)

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

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

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

v = B[-1]
pb = 10 ** 5
for b in B:
  v += min(b, pb)
  pb = b

print(v)

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] = min(B[i],B[i-1])
  elif i == N-1:
    A[i] = B[i-1]

print(sum(A))

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

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

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

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

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

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

print(wrk)

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

a = [b[0]]

for i in b:
    if a[-1] > i: a[-1] = i
    a.append(i)
print(sum(a))

Solution (Python):
import math 
import bisect
import heapq
from collections import deque

n = int(input())
b = list(map(int,input().split())) + [0]
b[n-1] = 100000 
a = [0] * n
a[0] = b[0]
for i in range(1,n):
    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
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(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()))
A = [-1] * N
B_sort = sorted(B)
for i in range(N - 1):
    index = B.index(B_sort[i])
    if A[index] == -1:
        A[index] = B[index]
    else:
        A[index] = min(A[index], B[index])
    if A[index + 1] == -1:
        A[index + 1] = B[index]
    else:
        A[index + 1] = min(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 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())
b = list(map(int,input().split()))
ans = b[0] + b[-1]
for i in range(1,n-1):
    ans += min(b[i-1],b[i])
print(ans)

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

res = 0
was = 99999999
for b in B:
    res += min(b, was)
    was = b

print(res + B[-1])

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

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

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

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

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

Solution (Python):
N = int(input())
B = [int(i) for i in input().split(" ")]
B.append(10**5+1)
Sum = B[0]

for i in range(N-1):
    Sum += B[i]
    if B[i+1]<B[i]:
        Sum = Sum -B[i] + B[i+1]
print(Sum)

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 = input()
n = int(n)
a_list = [0 for i in range(n)]
line = input()
b_list = line.split(" ")
b_list = [int(b) for b in b_list]

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

Solution (Python):
n = int(input())
b = [int(e) for e in input().split()]
div = [min(x,y) for x,y in zip(b,b[1:]+[100000])]
a = [b[0]] + div
print(sum(a))

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

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

Solution (Python):

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

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

Solution (Python):

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

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

print(ans)

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

b_list.append(b_list[num-2])
ans_list = []
ans_list.append(b_list[0])

for i in range(1, num, 1):
    ans_list.append(min(b_list[i-1], b_list[i]))

print(sum(ans_list))

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

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

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

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

print(sum(A))

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

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

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
b = [int(x) for x in stdin.readline().rstrip().split()]

a = [b[0]]

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

print(sum(a))

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

Solution (Python):
def resolve():
    N = int(input())
    B_list = list(map(int, input().split()))
 
    sum_point = B_list[-1]
    before_b = B_list[0]

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

if __name__ == "__main__":
    resolve()

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

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

print(asum)

Solution (Python):


n = int(input().rstrip())
b_list = list(map(int, input().rstrip().split(" ")))

a_list = list(range(n))

a_list[0] = b_list[0]
for i in range(1, n):
    if i >= len(b_list):
        a_list[i] = b_list[i - 1]
        break
    a_list[i] = min(b_list[i - 1], b_list[i])

print(sum(a_list))

Solution (Python):


n = int(input().rstrip())
b_list = list(map(int, input().rstrip().split(" ")))

a_list = list(range(n))

a_list[0] = b_list[0]
for i in range(1, n):
    if i >= len(b_list):
        a_list[i] = b_list[i - 1]
        break
    a_list[i] = min(b_list[i - 1], b_list[i])

print(sum(a_list))

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

ans = B[0] + B[-1]
for a,b in zip(B,B[1:]):
    ans += min(a,b)
print(ans)

Solution (Python):

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

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

print(sum)

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


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

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

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

A = [B[0]] + [-1]*(N-2) + [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(int,input().split()))
s = b[0] + b[-1]

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

Solution (Python):

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

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

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

print(ans)

Solution (Python):




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

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

    if len(B) == 1:
        pass
    else:
        for i in range(N - 2):
            result += min(B[i], B[i + 1])

    print(result)


if __name__ == "__main__":
    main()

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

s = b[0] + b[-1]
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()))
B+=[max(B)]
print(sum(min(B[i-1],B[i]) for i in range(N)))

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

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

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

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

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

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

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

Solution (Python):
import sys
import math
import bisect
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')

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):
import math
import collections
N=int(input())
B=list(map(int,input().split()))
cnt=0
for i in range(N):
 if i==0:
  cnt=cnt+B[0]
 elif  i==N-1:
  cnt=cnt+B[N-2]
 else:
  cnt=cnt+min(B[i-1],B[i])
print(cnt)

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

ans = B[0]

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

ans += B[N-2]

print(ans)

Solution (Python):
import collections


class Solution:
    def solve(self, N: int, B) -> int:

        answer = B[0]

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

        answer += B[N-2]

        return answer


if __name__ == '__main__':

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

    
    solution = Solution()
    answer = solution.solve(N, B)
    print(answer)

Solution (Python):


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

if __name__ == "__main__":
    main()

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

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

print(sum(a))

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

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

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

print(res)

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

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

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

print(res)

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

ans = b[0] + b[-1] + sum(min(x, y) for x, y in zip(b, b[1:]))
print(ans)

Solution (Python):

import sys



def solve(N: int, B: "List[int]"):
    a=[100001]*N
    for i in range(N-1):
        a[i]=min(a[i],B[i])
        a[i+1]=min(a[i+1],B[i])
    print(sum(a))
    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(i) for i in input().split()][0]
Bn = [int(i) for i in input().split()]

An = [Bn[0]]
for n in range(1, N-1):
  An.append(min(Bn[n], Bn[n-1]))
An.append(Bn[-1])
print(sum(An))

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

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

base_lis = []
ans_lis = []  

for i in B:
    base_lis.append(i)
    base_lis.append(i)

ans_lis.append(base_lis[0])
base_lis.pop(0)
ans_lis.append(base_lis[-1])
base_lis.pop(-1)

for i in range(0,len(base_lis),2):
    ans_lis.append(min(base_lis[i],base_lis[i+1]))

print(sum(ans_lis))

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

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

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

a[0] = b[0]

print(sum(a))

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

Solution (Python):



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

if __name__=='__main__':
  main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

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

if __name__ == '__main__':
	main()

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

Solution (Python):
import sys

inf = float('inf')

n, *b = map(int, sys.stdin.read().split())

def main():
    a = [inf] * n
    for i in range(n-1):
        a[i] = min(a[i], b[i])
        a[i+1] = min(a[i+1], b[i])
    return sum(a)

if __name__ == '__main__':
    ans = main()
    print(ans)

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

ans = sum(A)

print(ans)

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

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

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

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

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

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

Solution (Python):
N = input()
B = [int(x) for x in input().split()]
B.append(int(10e5+1))
ans = B[0]
for i in range(1, len(B)):
    ans += min(B[i], B[i-1])
print(ans)

Solution (Python):

INF = int(1e9)
def main():
    n = int(input())
    b = [int(i) for i in input().split()]
    b.insert(0, INF)
    b.append(INF)
    ans = 0
    for i in range(len(b)-1):
        ans += min(b[i], b[i+1])
    print(ans)
main()

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

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

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

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

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

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

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

print(a_sum)

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

ans.append(h[-1])


print(sum(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):
    a[i] = 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 = []
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=[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())
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):

def pin(type=int):
    return map(type,input().split())

"""
愚直に操作を実装する
"""

N=int(input())
B=list(pin())

A=[B[0]]+[0]*(N-2)+[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 = [int(x) for x in input().split()]

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

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