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


import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq





def solve(f):
    n = f.read_int()
    b = f.read_int_list()

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

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

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case 
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Solution (Python):


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

A = []
for n in range(N):
    A.append(min(B[n], B[n+1]))

print(sum(A))

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

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

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

arr = []

arr.append(barr[0])

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

print(sum(arr))

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

print(sum(a))

Solution (Python):
import numpy as np
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

ret = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1

ret += B[-1]
print(ret)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


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


def B():
    n = II()
    a = LI()
    b = LI()
    c = LI()
    ans = 0
    for i in range(n):
        ans += b[a[i] - 1] + (c[a[i] - 1] if i != n - 1 and a[i] + 1 == a[i + 1] else 0)
    print(ans)
    return


def C():
    n = II()
    b = LI()
    ans = b[0]
    for i in range(n-2):
        if b[i] >= b[i + 1]:
            ans += b[i + 1]
        else:
            ans += b[i]
    print(ans+b[-1])
    return


def D():
    n, k = LI()
    s = S()
    a = []
    for i in range(n):
        if i == n - 1:
            a.append(s[i])
        elif s[i] != s[i + 1]:
            a.append(s[i])
    print(min(n - 1, n - len(a) + 2 * k))
    return


def E():
    return


def F():
    return



if __name__ == '__main__':
    C()

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
ans = 0
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()))







if 3<=n:
    ans=b[0]+b[-1]
    for i in range(n-2):
        ans+=min(b[i],b[i+1])
else:
    print(b[0]*2)
    exit()
print(ans)

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
ans = [min(x,y) for x,y in zip(b[:-1],b[1:])]

if n>2:
    ans.insert(0,b[0])
    ans.insert(n-1,b[n-2])
    print(sum(ans))
else:
    ans.insert(0,b[0])
    ans.insert(n-2,b[0])
    print(sum(ans))

Solution (Python):
input()
vs = list(map(int, input().split()))
print(vs[0] + sum(min(x, y) for x, y in zip(vs[:-1], vs[1:])) + vs[-1])

Solution (Python):
n = int(input())
b_list = list(map(int, input().split()))
a_list = [0 for _ in range(n)]

i = 0
while i < n-1:
    if i == 0:
        a_list[i] = b_list[i]
    a_list[i+1] = b_list[i]
    if a_list[i] > b_list[i]:
        a_list[i] = b_list[i]
    i += 1

print(sum(a_list))

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

a = []

a.append(b_list[0])

for b, b_next in zip(b_list[:-1], b_list[1:]):
    a.append(min(b, b_next))

a.append(b_list[-1])

print(sum(a))

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

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

Solution (Python):
def main():
    N = int(input())
    lst_B = [float("INF")] + list(map(int, input().split())) + [float("INF")] 

    ans = sum(min(lst_B[i - 1], lst_B[i]) for i in range(1, len(lst_B)))

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    lst_B = list(map(int, input().split()))
    
    ans = 0
    for i in range(N):
        if i == 0:
            ans += lst_B[0]
        elif i == N - 1:
            ans += lst_B[-1]
        else:
            ans += min(lst_B[i - 1], lst_B[i])

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

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

a_sum = B[0] + B[-1]
for i, b in enumerate(B[1:]):
    a_sum += min(B[i], b)
print(a_sum)

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

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

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

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

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

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

Solution (Python):




 
from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul,itemgetter
from bisect import* 
from heapq import* 
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)

 
def main():
    n=int(input())
    *a,=map(int,input().split())
    b=[a[0]]*2
    for i in a[1:]:
        b[-1]=min(i,b[-1])
        b.append(i)
    print(sum(b))
if __name__ == '__main__':
    main()

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

tmp_list = []
tmp_list.append(input_list[n-2])
tmp_list.extend(input_list[::-1])

output_list = [ min(tmp_list[i:i+2]) for i in range(len(tmp_list) - 1) ]
output_list.append(input_list[0])

print(sum(output_list))

Solution (Python):
n = int(input())
b_list = list(map(int,input().split()))
b_list.append(b_list[-1])
a_list = b_list[:]

for count in range(1, n):
    if a_list[count] > b_list[count - 1]:
        a_list[count] = b_list[count - 1]

print(sum(a_list))

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

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

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

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

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

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

print(ans)

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

A = [B[0]] + [0] * (N-2) + [B[-1]]
for i, (prv, nxt) in enumerate(zip(B[:-1], B[1:]), 1):
    A[i] = min(prv, nxt)
print(sum(A))

Solution (Python):
from __future__ import print_function


import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )



import random


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

if __name__ == '__main__':
    main()

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

l = [B[0]]
for i in range(1,N-1):
    l.append(min(B[i-1], B[i]))
l.append(B[-1])

print(sum(l))

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

sum =b[0]

if len(b) >= 2:
    for i in range(1,len(b)):
        if b[i-1]<b[i]:
            sum+=b[i-1]
        else:
            sum+=b[i]
        
sum+=b[-1]
        
print(sum)

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

Solution (Python):

def solve():
    n = int(input())
    b = list(map(int, input().split()))
    b.insert(0, 100000000)
    b.append(100000000)

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

    print(sum)

solve()

Solution (Python):

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

a = [0] * n

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

print(sum(a))

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


if __name__ == '__main__':
  main()

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

arrayA = [arrayB[0]]

for k in range(1,n-1):

    if arrayB[k] < arrayB[k-1]:
        arrayA.append(arrayB[k])

    else:
        arrayA.append(arrayB[k-1])

arrayA.append(arrayB[n-2])

print(sum(arrayA))

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

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

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

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

for i in range(n):
  sum += a[i]
  
print(sum)

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

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

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

ans = sum(A)

print(ans)

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

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):
inf = 1e+10
n = int(input())
b  = [inf] + list(map(int, input().split())) + [inf]
c = []
for i in range(len(b)-1):
    c.append(min(b[i], b[i+1]))
print(sum(c))

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

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

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

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

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

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

a = [0] * n

for i in range(len(a)):
  if i == 0:
    a[i] = b[i]
  elif i == len(a) -1:
    a[i] = b[i - 1]
  else:
    a[i] = min((b[i], b[i - 1]))

print(sum(a))

Solution (Python):
N = int(input())
B_list = [int(i) for i in input().split()]
total = B_list[-1]
prev_b = B_list[0]
for b in B_list:
    total += min(b, prev_b)
    prev_b = b
print(total)

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

a = []
pb = 10**6
for x in b[::-1]:
    tmp = min(x, pb)
    a.append(tmp)
    pb = x
a.append(pb)
print(sum(a))

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

cnt = 0
for a,b in zip(A[:-1],B):
    
    if a > b:
        cnt += b
    else:
        cnt += a
cnt += A[-1]
print(cnt)

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

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

print(sum(A))

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


if n==2:
    print(lists[0]*2)
else:
    nums=lists[0]+lists[-1]
    for j in range(n-2):
        nums+=min(lists[j],lists[j+1])
    print(nums)

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

for i, bi in enumerate(b_list):
    if i == 0:
        a_list.append(bi)
    elif b_list[i] > b_list[i-1]:
        a_list.append(b_list[i-1])
    else:
        a_list.append(b_list[i])

a_list.append(b_list[-1])

print(sum(a_list))

Solution (Python):
n = int(input())
b_list = list(map(int, input().split()))
sum = 0
min = b_list[0]
for i in range(n-1):
    if b_list[i] < min:
        min = b_list[i]
        sum+=min
    else:
        sum+=min
        min = b_list[i]

sum+=b_list[-1]
print(sum)

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

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

print(sum(a))

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

B = list(map(lambda x:int(x), input().split()))

ans = B[0]

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

  
if len(B) != 1:
  ans += B[-1]
else:
  ans += B[0]
print(ans)

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


if len(B) == 1:
    B.append(0)

for i in range(n-1):
    if i == 0:
        ans = ans + B[0]

    else:
        ans = ans + min(B[i-1],B[i])




print(ans+B[n-2])

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

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

ans = 0
for a1, a2 in zip(A, A[1:]):
    if a1 >= a2:
        ans += a2
    else:
        ans += a1
ans += A[-1]
ans += A[0]
print(ans)

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

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

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

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

score = 0
score +=numberlist[0]

for i in range(n-1):
  if i == n-2:
    score +=numberlist[i]
  else:
    score +=numberlist[i] if numberlist[i] < numberlist[i+1] else numberlist[i+1]
print(score)

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

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

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

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

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

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

A=[int(i) for i in input().split()]
al=[0 for i in range(n)]

al[0]=A[0]
al[-1]=A[-1]
for i in range(1,n-1):
    al[i]=min(A[i-1],A[i])

print(sum(al))

Solution (Python):


import math
import os
import sys


DEBUG = 'DEBUG' in os.environ


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


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, B):
    A = [-1] * 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])
    return sum(A)


def main():
    N = int(inp())
    B = [int(e) for e in inp().split()]
    print(solve(N, B))


if __name__ == '__main__':
    main()

Solution (Python):
N =  int(raw_input())
B = list(map(int, raw_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]
  else:
    A[i+1] = B[i]
  
print sum(A)

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

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

if len(b) >= 2:
  for i in range(n-2):
    sums += int(min([b[i], b[i+1]]))


print(sums)

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

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

Solution (Python):
def main():
    n = int(input())
    b = [i for i in map(int, input().split())]
    b.append(max(b)+1)
    a = []
    for j, num in enumerate(b):
        a.append(min(b[j-1], b[j]))

    print(sum(a))


if __name__ == "__main__":
    main()

Solution (Python):


N = int(input())-1
b=list(map(int,input().split()))
a=b[0]
for i in range(1,N,1):
    if b[i] >= b[i-1]:
        a+=b[i-1]
    else: a+=b[i]
a+=b[N-1]
print(a)

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

Solution (Python):
def read_input():
	N = int(raw_input())
	B = map(int, raw_input().split())
	return B





B = read_input()
s = B[0] + sum(min(b1, b2) for b1, b2 in zip(B, B[1:])) + B[-1]
print s

Solution (Python):


N = int(input())
B_list = list(map(int,input().split()))
A_list = []
A_list.append(B_list[0])

for i in range(len(B_list)-1):
     B_i = B_list[i]
     B_j = B_list[i+1]
     A_list.append(min(B_i, B_j))

A_list.append(B_list[N-2])

print(sum(A_list))

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

b = list(map(int, input().split()))
b.insert(0, 9999999)

ans = 0
for i in range(1, len(b)):
    if b[i] < b[i-1]:
        ans += b[i]
    else:
        ans += b[i-1]
ans += b[-1]
print(ans)

Solution (Python):
N = int(input())
S = list(map(int, input().split()))
S = [10**5+1] + S + [10**5+1]
ans = []
for i in range(1, N+1):
    ans.append(min(S[i-1], S[i]))
print(sum(ans))

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

M = 10 ** 5 + 1 
B = [M] + B + [M]

R = []

for i in range(1, N+1):
    R.append(min(B[i-1], B[i]))

print(sum(R))

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

a = [-float('inf') for i in range(n)]
a[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):
a= int(input())
l = list(map(int,input().split()))
l = l[::-1]
s = l[-1]
for n,(x,y) in enumerate(zip(l,l[1:])):
    s+= min(x,y)
print(s+l[0])

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

Solution (Python):
import copy
N = int(input())
b = list(map(int, input().split()))
a = copy.copy(b)
a.insert(0, b[0])

for i in range(N-1):
    if a[i] > b[i]:
        a[i] = b[i]
    if a[i+1] > b[i]:
        a[i + 1] = b[i]
    else:
        continue
        
print(sum(a))

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

print(s)

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

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

if __name__ == "__main__":
    main()

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

Solution (Python):
def main():
    N = int(input())
    B = [int(i) for i in input().split()]
    A_sum = 0
    A = []
    A.append(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])
    
    for i in range(N):
        A_sum += A[i]
    print(A_sum)
        
if __name__ == "__main__":
    main()

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

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

ans = 0
for i, b in enumerate(B):
    if i == 0:
        ans += b
    else:
        ans += min(b, prev)
    prev = b
ans += prev
print(ans)

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

Solution (Python):
L1 = input()
L2 = list(map(int,input().split(" ")))
LA = [0]*int(L1)

for i in range(len(LA)):
    if i == 0:
        LA[i] = L2[i]
    elif i == len(LA)-1:
        LA[i] = L2[i-1]
    else:
        LA[i] = min(L2[i-1],L2[i])
print(sum(LA))

Solution (Python):
import numpy as np
N=int(input())
B=list(map(int,input().split()))
A=np.zeros(N,dtype="int64")

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())) 
summ = b[0] 

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

Solution (Python):

import sys


def solve(N: int, B: "List[int]"):

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

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

    print(result)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  
    B = [int(next(tokens)) for _ in range(N - 1)]  
    solve(N, B)


if __name__ == "__main__":
    main()

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

Solution (Python):
n = int(input())
b = [int(elem) for elem in input().split()]
a = [b[n - 2]]

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

Solution (Python):
N = int(input())
Bn = list(map(int, input().split()))
Bn = [999999] + Bn + [999999]

Astar = [
  min(Bn[i], Bn[i+1])
  for i in range(N)
]
print(sum(Astar))

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

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

sum = 0

for ib, value in enumerate(B):
    if ib > 0:
        if value >= B[ib-1]:
            sum += B[ib-1]
        else:
            sum += value
    else:
        sum += value

sum += B[len(B) - 1]
print(sum)

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

sum = 0

for ib, value in enumerate(B):
    if ib > 0:
        if value >= B[ib-1]:
            sum += B[ib-1]
        else:
            sum += value
    else:
        sum += value

sum += B[len(B) - 1]
print(sum)

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

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

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

ans = sum(a)
print(ans)

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

Solution (Python):
import math

N = int(input())
B = list(map(int, input().split())) 
import numpy as np
A=np.zeros([N])
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(int(A.sum()))

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

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

i=1
while i < n:
    a[i] = min(b[i-1],b[i])
    i = i +1

print(sum(a))

Solution (Python):

import sys


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

    print(sum(A))





def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    B = [ int(next(tokens)) for _ in range(N-1) ]  
    solve(N, B)

if __name__ == '__main__':
    main()

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

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

ans += b[0]
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-1):
    if i < n-2:
        a.append(b[i] if b[i+1] >= b[i] else b[i+1])
    else:
        a.append(b[i])

print(sum(a))