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

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):
N=int(input())
ls=[int(s) for s in input().split()]
sum=ls[0]+ls[N-2]
for i in range(N-2):
  sum+=min([ls[i],ls[i+1]])

print(sum)

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

Solution (Python):

import sys
def input():
	return sys.stdin.readline().strip()

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

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

print(total)

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

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

main()

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

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

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

print(ans)

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

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

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

Solution (Python):




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

An = [10**5 for _ in range(N)]
An[0] = Bn[0]
An[-1] = Bn[-1]
for i in range(1,N-1):
  An[i] = min(Bn[i],Bn[i-1])
print(sum(An))

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    b_list = LI()

    a_list = [0 for i in range(N)]
    for i in range(N):
        
        if i == 0:
            a_list[i] = b_list[i]
        elif i == N-1:
            a_list[i] = b_list[i-1]
        else:
            a_list[i] = min(b_list[i], b_list[i-1])

    print(sum(a_list))

solve()

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

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

print(a)

Solution (Python):
def main():
    n = int(input())
    B = list(map(int, input().split()))
    ans = B[0]
    for b1, b2 in zip(B, B[1:]):
        ans += min(b1, b2)
    ans += B[-1]
    print(ans)


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

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

print(ans)

Solution (Python):
N,*B=map(int,open(0).read().split());print(B[0]+sum(min(i,j)for i,j in zip(B,B[1:]))+B[-1])

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    b_s = LI()
    a_s = [0 for i in range(n)]
    for i in range(n-1):
        if i == 0:
            a_s[i] = b_s[i]
            a_s[i+1] = b_s[i]
        else:
            if b_s[i] < b_s[i-1]:
                a_s[i] = b_s[i]
            a_s[i + 1] = b_s[i]
    print(int(sum(a_s)))

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

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

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

pre = 10 ** 6
res = 0
for b in B:
    if b < pre:
        pre = b
    res += pre
    pre = b

res += pre
print(res)

Solution (Python):
n = int(input())
bs = list(map(int, input().split()))
res = bs[0]
for b0, b1 in zip(bs, bs[1:]):
    res += min(b0, b1)
res += bs[-1]
print(res)

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

print(sum(a))

Solution (Python):
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N = int(input())
    A = InputToInt()
    c = A[0]+A[N-2]
    for i in range(N-2):
        c += min(A[i], A[i+1])
    print(c)

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

b.reverse()

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

ans[-1] = b[-1]


print(sum(ans))

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

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

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

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

print(sum(A))

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

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

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

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

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

    p = b[0]
    for i in b[1:]:
        s += min(p, i)
        p = i

    print(s)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

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

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

a[0] = b[0]

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

a[n-1] = b[n-2]
print(sum(a))

Solution (Python):
inf = float('inf')

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

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

Solution (Python):
def getlist():
    return list(map(int, input().split()))

N = int(input())
B = getlist()

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

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

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

ans=0

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

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

print(ans)

Solution (Python):
n = int(input())
bbb = list(map(int, input().split()))
ans = bbb[0]
ans += sum(map(min, zip(bbb, bbb[1:])))
ans += bbb[-1]
print(ans)

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

kazu=0

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

print(kazu)

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

Solution (Python):
N = int(input())
Bs = list(map(int, input().split())) + [float('inf')]
ans = Bs[0]
for i in range(1, N):
  a, b = Bs[i-1], Bs[i]
  ans += a if a <= b else b
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])
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):

import sys
INF = float("inf")


def solve(N: int, B: "List[int]"):
    ans = B[-1]
    pre = 0
    for i in range(N-2, 0, -1):
        ans += min(B[i], B[i-1])
    ans += B[0]
    print(ans)
    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())
A = [0] * N
B = [int(x) for x in input().split()]
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()))
ans = b[0] + b[n - 2]
for i in range(1, n - 1):
	ans += min(b[i], b[i - 1])
print(ans)

Solution (Python):
INF = 10**6

N = int(input())
Bs = [INF] + list(map(int, input().split())) + [INF]

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

print(ans)

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

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

print(ans)

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

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

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
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):
n = int(input())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if i == 0:
        ans += b[0]
    elif i == n - 1:
        ans += b[n-2]
    else:
        ans += min(b[i-1],b[i])
print(ans)

Solution (Python):

from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()
    b = li()
    b = [100000000]+b+[100000000]
    ans = 0

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

    print(ans)

main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)
from collections import *
from bisect import *
mod = 10**9+7

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

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

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

ans = B[0] + B[-1] + sum(min(b0,b1) for b0,b1 in zip(B[:-1],B[1:]))
print(ans)

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

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
b_list=list(map(int,input().split()))
ans=0
for i in range(n):
    if i==0:
        ans+=b_list[0]
    elif i==n-1:
        ans+=b_list[n-2]
    else:
        ans+=min(b_list[i-1],b_list[i])
print(ans)

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

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

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

print(ans)

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

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

Solution (Python):

import sys


def solve(N: int, B: "List[int]"):
    prev = B[0]
    res = 0
    for b in B:
        res += min(b, prev)
        prev = b
    res += prev
    print(res)
    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):
def main():
    N = int(input())
    B = list(map(int, input().split()))
    B.insert(0, B[0])
    B.append(B[-1])
    ret = 0
    for b, b1 in zip(B, B[1:]):
        ret += min(b, b1)
    print(ret)


main()

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

Solution (Python):
import sys
import collections
import copy
import math
def input(): return sys.stdin.readline().strip()
N = int(input())
B = [int(i) for i in input().split()]
ans = B[0]+B[N-2]
for i in range(N-2):
    ans += min(B[i],B[i+1])
print(ans)

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

A = [float('inf')]*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):

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

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

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

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

import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


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

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
INF = 10**9
b = [int(i) for i in input().split()]
b = [INF]+b+[INF]
ans = 0
for i in range(N):
  ans += min(b[i], b[i+1])
print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

answer = sum(A)
print(answer)

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

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

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

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

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

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

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

print(ans)

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

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

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

Solution (Python):
N = int(input())
B = [1<<100] + [int(a) for a in input().split()] + [1<<100]
print(sum([min(B[i], B[i+1]) for i in range(N)]))

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

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  ans=l[0]

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

  return ans


print(main())

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

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

print(sum(A) + B[-1])

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

print(score)

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    b = LI()
    a = [inf] * n
    for i in range(n-1):
        a[i+1] = b[i]
        if b[i] < a[i]:
            a[i] = b[i]

    return sum(a)


print(main())

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

print(ans)

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

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

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

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

stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

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

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

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

a = [0]*(n+1)

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

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

print(res)

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

from sys import stdin




def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()
b_list = _li()

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

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    b = [int(s) for s in input().split()]
    ans = b[-1] + b[0]
    for i, v in enumerate(b[1:]):
        ans += min(v, b[i])
    print(ans)

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

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

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


if __name__ == "__main__":
    main()

Solution (Python):

import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
import heapq
from functools import reduce
sys.setrecursionlimit(200000)





input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()



def main():
    N = ii()
    A = lmi()
    B = []
    for i in range(1, N - 1):
        B.append(min(A[i], A[i - 1]))
    print(sum(B) + A[0] + A[-1])
    return


if __name__ == '__main__':
    main()

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

Solution (Python):



def ri():
    return int(input())

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

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

def main():
    n = ri()
    lb = [1000000] + rli() + [1000000]
    ans = 0
    for i in range(n):
        ans += min(lb[i], lb[i+1])
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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

print(sum(A))

Solution (Python):


def main():
    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)
if __name__ == '__main__':
    main()

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

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

main()

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

N = inp()
BB = [INF] + inpl() + [INF]
ans = 0
for i in range(N):
    ans += min(BB[i],BB[i+1])

print(ans)

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

b = [10**9] + b + [10**9]

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

Solution (Python):

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