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



Sample input:
3
2 5


Sample output:
9

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int,input().split()))
 
def A(N,B):
   sum = B[0] + B[N-2]
   for i in range(N-2):
       sum += min(B[i],B[i+1])
   print(sum)
 
if __name__=='__main__':
   A(N,B)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
b.reverse()
score = 0
prev = 10 ** 9
for i in range(n - 1):
    score += min(b[i], prev)
    prev = b[i]
score += b[n - 2]
print(score)

Submission status: Accepted

Solution code:
# ABC140 C - Maximal Value

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

A = []

A.append(B[0])

for i in range(N):
    if i > 0 and i <= N-2:
        A.append(min(B[i-1], B[i]))
    
A.append(B[N-2])

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

if __name__ == '__main__':

	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)

Submission status: Accepted

Solution code:
def func(N, B_i):
    sum = B_i[N-2]
    for i in reversed(range(N-1)):
        if i >= 1:
            sum += min(B_i[i], B_i[i-1])
        else:
            sum += B_i[i]
    return sum

N = int(input())
B_i = list(map(int, input().split(" ")))
print(func(N, B_i))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8


def solve():
    N, *bl = map(int, open(0).read().split())
    al = [0] * N
    al[0], al[-1] = bl[0], bl[-1]
    
    for i in range(N-2, 0, -1):
        al[i] = min(bl[i], bl[i-1])
    
    print(sum(al))


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, *B = map(int, open(0).read().split())
    print(B[0] + B[-1] + sum(min(b1, b2) for b1, b2 in zip(B[:-1], B[1:])))
    return


main()

Submission status: Accepted

Solution code:
# 入力を受け取る
B_MAX = 100000
N = int(input().strip())
B = input().strip().split()

# B_MAX + 1を入れておくことで 必ずmin(B[0], B[1]) = B[1], min(B[N-1], B[N]) = B[N-1]となる
B = [B_MAX + 1] + [int(b) for b in B] + [B_MAX + 1] # 整数に変換

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

print(sum)

Submission status: Accepted

Solution code:
MAX_N = 100000


def main():
    N, *B = map(int, open(0).read().split())
    B.insert(0, MAX_N)
    B.insert(N, MAX_N)
    print(sum(min(b1, b2) for b1, b2 in zip(B[:-1], B[1:])))
    return


main()

Submission status: Accepted

Solution code:
MAX_N = 100000


def main():
    N, *B = map(int, open(0).read().split())
    B.insert(0, MAX_N)
    B.insert(N, MAX_N)
    print(sum(min(B[i - 1], B[i]) for i in range(1, N + 1)))
    return


main()

Submission status: Accepted

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

Submission status: Accepted

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

sums=0
cnt=N-2

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 26 12:13:54 2019

@author: hiros
"""

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

ans = B[0]
i = 1

while (i < N-1):
    if (B[i-1] <= B[i]):
        ans += B[i-1]
    else:
        ans += B[i]
    i += 1
    #print(ans,i)

ans += B[-1]

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
b = list(map(int, input().split()))
a = [int(0) for i in range(n)]
a[0] = b[0]
a[n-1] = b[n-2]
b.append(b[n-2])
for i in range(1,n-1):
    a[i] = min(b[i-1], b[i])
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(n) for n in input().split()]

A = [0]*N
A[0] = B[0]
for x in range(len(B)):
	if A[x] > B[x]:
		A[x] = B[x]
	A[x+1] = B[x]

print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = [0] * N
for i in range(N):
    first = B[i] if 0 <= i < len(B) else float('inf')
    second = B[i-1] if 0 <= i-1 < len(B) else float('inf')
    A[i] = min(first, second)
print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())

B = [int(i) for i in 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))

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
n = int(input())
li_b = list(map(int, input().split()))
li_a = [9999999] * n

for idx, b in enumerate(li_b):
    li_a[idx] = min(li_a[idx], b)
    li_a[idx + 1] = min(li_a[idx + 1], b)

print(sum(li_a))

Submission status: Accepted

Solution code:
n = int(input())
li_b = list(map(int, input().split()))
li_a = [9999999] * n

for idx, b in enumerate(li_b):
    if idx == 0:
        li_a[0] == b
    if idx == n - 1:
        li_a[-1] == b
    else:
        li_a[idx] = min(li_a[idx], b)
        li_a[idx + 1] = min(li_a[idx + 1], b)
print(sum(li_a))

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

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 #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

Solution code:
#coding:utf-8

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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')

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

#B
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

#C
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

#D
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

#E
def E():
    return

#F
def F():
    return


#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n,m=map(int,input().split())
#p_3,p_4=map(int,input().split())
n=int(input())
#a=int(input())
#b=int(input())
#S=input()
#T=input()
#recipe=[list(input().split())for _ in range(n)]
#m=int(input())
#have=[list(input().split())for _ in range(m)]
#s=[list(input())for _ in range(n)]
b=list(map(int,input().split()))
#b=list(map(int,input().split()))
#c=list(map(int,input().split()))
#c=list(map(float,input().split()))
#n=int(input())
#s=[list(map(int,input().split()))for _ in range(n)]
#s=[list(input().split())for _ in range(n)]
#s=[input()for _ in range(n)]
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
# coding: utf-8
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#はじめて解答例とか参考にせずに解けた問題かもしれん

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
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 )
# from itertools import accumulate
# from collections import deque

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
# C - Maximal Value
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))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(a)
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
B = list(map(int,input().split()))
ans = 0
#list = []

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

for i in range(n-1):
    if i == 0:
        ans = ans + B[0]
#        list.append(B[0])
    else:
        ans = ans + min(B[i-1],B[i])
#        list.append(min(B[i-1],B[i]))

#list.append(B[n-2])
#print(list)
print(ans+B[n-2])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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