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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n = I()
    print(n**3)
    return


def B():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    ans = sum(b)
    for i in range(n-1):
        x = a[i]
        y = a[i+1]
        if y == x+1:
            ans += c[x-1]
    print(ans)
    return


def C():
    n = I()
    b = LI()
    b.append(float("inf"))
    a = [min(b[i],b[i-1]) for i in range(n)]
    print(sum(a))
    return


def D():

    return


def E():

    return


def F():

    return


if __name__ == "__main__":
    C()

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

print(ret)

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

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()
b = na()

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

Solution (Python):


from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

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

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

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

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

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

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], L[i-1])
print(res)

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

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

print(c)

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

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

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




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





if __name__ == '__main__':
    main()

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

print(sum(ans))

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