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 = [int(i) for i in input().split(' ')]
A = [0]*(N)
for i,a in enumerate(B):
    if i == 0: 
        A[i] = a
        A[i+1] = a
    else:
        if B[i-1] < B[i]:
            A[i+1] = a
        else:
            A[i] = a
            A[i+1] = a

print(sum(A))

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 = list(map(int, input().split()))
B = [10**5] + B + [10**5]
print(sum(min(B[i], B[i+1]) for i in range(N)))

Solution (Python):
N = int(input())
B = [float("inf")] + [int(i) for i in input().split()] + [float("inf")]
A = 0
for i in range(N):
    A += min(B[i], B[i+1])
print(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()))
A=[B[0]]*n
for i in range(n-1):
    A[i+1]=B[i]
    A[i]=min(A[i],B[i])
print(sum(A))

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

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

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

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

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

Solution (Python):







__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


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(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 = [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().strip().split()))

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

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

a=[0]*n
if n>2:
  
  for x in range(1,n-1):
    c=min(b[x-1],b[x])
    a[x]+=c
  
  a[0]+=b[0]
  a[n-1]+=b[n-2]

  ans=0

  for y in range(len(a)):
    ans+=a[y]
  print(ans)

else:
  print(b[0]*2)

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

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

A = list()
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):
def main():
    n = int(input())
    blis = list(map(int, input().split()))

    alis = [blis[0], blis[0]]
    if n > 2 and alis[1] > blis[1]:
        alis[1] = blis[1]
    if n > 2:
        for i in range(3, n):
            alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()

Solution (Python):
n,*bb = map(int, open(0).read().split())

ans = bb[0] + bb[-1]

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

print(ans)

Solution (Python):
def resolve():
    N = int(input())
    B = list(map(int, input().split()))
    array = [0 for _ in range(N)]
    prev = B[0]
    array[0] = B[0]
    for i in range(N-1):
        if prev <= B[i]:
            array[i+1] = B[i]
        else:
            array[i] = B[i]
            array[i+1] = B[i]
        prev = B[i]
    print(sum(array))

    
if '__main__' == __name__:
    resolve()

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

ans = [b[0]]

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

print(sum(ans))

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

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

Solution (Python):
N = int(input())
B = [int(x) for x in input().split()]
A = [0 for y 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):
MAX_B = 10**5
N = int(input())
B = [MAX_B] + list(map(int, input().split())) + [MAX_B]
res = 0
for i in range(N):
    res += min(B[i], B[i + 1])
print(res)

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

Solution (Python):
n = int(input())
lb = [int(w) for w in input().split()]

ans = 0

if n - 1 == 1:
    ans = lb[0]*2
else:
    ans += lb[0]
    for i in range(n - 2):
        ans += min(lb[i:i + 2])
    ans += lb[n - 2]

print(ans)

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

Solution (Python):
from sys import stdin,stdout


if __name__=="__main__":

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

    s=b[0]

    for i in range(n-1):
        if b[i]>b[i+1]:
            s+=b[i+1]
        else:
            s+=b[i]
    stdout.write(str(s)+"\n")

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

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

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

ans = b[n-2]


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

print(ans+b[0])

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

Solution (Python):

def solve():
    A = [0]*N


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


    print(sum(A))

if __name__ == "__main__":
    N = int(input())
    B = list(map(int, input().split()))
    solve()

Solution (Python):

def solve():
    A = [0]*N
    A[-1] = 10**6
    A[0] = 10**6
    for i in range(N-2,0,-1):
        A[i] = min(B[i], B[i-1])

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

    print(sum(A))

if __name__ == "__main__":
    N = int(input())
    B = list(map(int, input().split()))
    solve()

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

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

Solution (Python):









import sys
input = sys.stdin.readline

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

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

print(ans)

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

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

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

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

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

for i in range(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[n-2]]

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

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

ans = 0
for b1,b2 in zip(bl[:-1],bl[1:]):
    ans += min(b1,b2)

print(ans)

Solution (Python):
import os
from math import*
import sys
input=sys.stdin.buffer.readline

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

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

Solution (Python):

n, *b = map(int, open(0).read().split())
b = [b[0]] + b + [b[-1]]

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

Solution (Python):
N, *B = map(int, open(0).read().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]
for i in range(len(A)-2):
    A[i+1] = min(B[i],B[i+1])
    
A[-1] = B[-1]  

print(sum(A))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)





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


def main():
    N = int(input())
    B = list(map(int,input().split()))
    B.append(10**6)
    A =[]
    A.append(B[0])
    for i in range(N-1):
        a =min(B[i],B[i+1])
        A.append(a)
    print(sum(A))




if __name__ == "__main__":
    main()

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

ans.append(b[len(b)-1])

print(sum(ans))

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

dp = [10**8]*n

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

print(sum(dp))

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

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

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

A=[-1 for x in range(N)]
i=0
j=0
for a in B:
  j=i+1
  if A[i]==-1:
    A[i]=a
    A[j]=a
  else:
    if A[i]>a:
      A[i]=a
    A[j]=a
  i=i+1
  
total = 0
for num in A:
  total = total + num
print(total)

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

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

a+=b[-1]

print(a)

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
b = intl()

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

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

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

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

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

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

Solution (Python):
N = int(input())
a = [1e10]*N
b = list(map(int,input().split()))

for i,num in enumerate(b):
    if a[i] > num:
        a[i] = num
    a[i+1] = num
print(sum(a))

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

Solution (Python):
n = int(input())
a = [1e10]
b = list(map(int, input().split()))
for i, num in enumerate(b):
    if a[i] > num:
        a[i] = num
    a.append(num)
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()))

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

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

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

print(A_sum)

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

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

ans = bn[0] + bn[-1]

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

print(ans)

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

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

if __name__ == '__main__':
    main()

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

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

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

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

total += b[n-2]

print(total)

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

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()))
S = B[0] + B[N-2]
i = 0
while i <= N-3:
    if B[i] > B[i+1]:
        S += B[i+1]
    else:
        S += B[i]
    i += 1
print(S)

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

B_=[inf]
B_.extend(B)
B_.append(inf)
A=[]

for n in range(1,N+1):
    A.append(min(B_[n-1],B_[n]))
    
print(sum(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):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *B = map(int, read().split())

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

    print(ans)
    return


if __name__ == '__main__':
    main()

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

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

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

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

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

print(sum(a))

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

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

ans = B[0] + B[-1]
for i in range(len(B) - 1):
  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[-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 = [-1] * n

for i, b in enumerate(B):
    if a[i] > B[i]:
        a[i] = b
        a[i+1] = b
    elif a[i] != -1:
        a[i+1] = b
    elif a[i] == -1:
        a[i] = b
        a[i+1] = b

print(sum(a))

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

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


if __name__ == '__main__':
    main()

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

al = [-1]*N
al[0] = bl[0]
for i in range(1,N-1):
    al[i] = min(bl[i],bl[i-1])
al[N-1] = bl[N-2]
print(sum(al))

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]







n = I()
b = RI()

a = []
for i in range(n):
    if i==0:
        a.append(b[i])
    elif i>0 and i<(n-1):
        a.append(min(b[i-1],b[i]))
    elif i==(n-1):
        a.append(b[i-1])
    else:
        print("E")
ans = sum(a)
print(ans)

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

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

Solution (Python):
import sys
from collections import defaultdict, deque
import math








input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7

def divide(k):
    return pow(k, MOD-2, MOD)


def make_nck(n):
    ret = [1]
    for i in range(1, n+1):
        ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)

    
    return ret

def make_nigojyo(n):
    ret = [1]

    for i in range(1, n+1):
        ret.append((ret[-1] * 25) % MOD)

    
    return ret


def solve():
    n = getN()
    a = getList()
    ans = 0
    for i, j in zip(a, a[1:]):
        ans += min(i, j)
    ans += a[0] + a[-1]

    print(ans)



def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

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

print(sum(a))

Solution (Python):
n,*l=map(int,open(0).read().split())
s,p=0,l[0]
for i in l: s+=min(p,i); p=i
print(s+p)

Solution (Python):
n,*l=map(int,open(0).read().split())
s,p=0,l[0]
for i in l:
  s+=min(p,i)
  p=i
print(s+p)

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

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):
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
l=list(mi())
ans=l[0]
for i in range(a-2):
  ans+=min(l[i],l[i+1])
print(ans+l[-1])

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

if __name__ == '__main__':
    main()

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

wa = 0

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

print(wa)

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

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

Solution (Python):
def main():
    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[-1] = B[-1]
    print(sum(A))
main()

Solution (Python):

 

 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 

 







 
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(max(B[N-2],A[N-2]))

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[0])
    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
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline




n = int(input())
b = [1000000] + list(map(int, input().split())) + [1000000]

res = []

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

print(sum(res))

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

ans=B[0]+B[-1]
i=0
while i+1<N-1:
    ans+=min(B[i],B[i+1])
    i+=1

print(ans)

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

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

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

print(sum(a))

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

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

print(sum(a))

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

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

print(sum(A))

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

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

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

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

print(sum(A))

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

Solution (Python):
n=int(input())
b=list(map(int,input().split()))
a=[float('Inf')]*n
for i,num in enumerate(b):
	if n>i:
		a[i]=min(a[i],num)
		a[i+1]=num
print(sum(a))

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

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

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

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

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

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

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

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

Solution (Python):






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





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

Solution (Python):
def resolve():
    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))

resolve()

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

Solution (Python):
def resolve():
    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))
resolve()

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

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

print(ans)