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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    b = list(map(int, input().rstrip('\n').split()))
    a = [10 ** 6] * n
    for i in range(len(b)):
        a[i] = min(a[i], b[i])
        a[i+1] = min(a[i+1], b[i])
    print(sum(a))


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
# ABC140C - Maximal Value
def main():
    N, *B = map(int, open(0).read().split())
    ans = sum(min(i, j) for i, j in zip(B, B[1:])) + B[0] + B[-1]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

A = [0] * N
B.append(100000000)

A[0] = B[0]

for i in range(1, N):
    A[i] = 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
b.append(1000000)
 
a[0] = b[0]
for i in range(1,n):
    a[i] = 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
b.append(1000000)

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

print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
list_B = list(map(int, input().split()))
list_A = [0]*(len(list_B) + 1)

for i in reversed(range(len(list_B))):

    #書き換えるかどうかの判断
    if list_B[i] < list_A[i + 1]:
        list_A[i + 1] = list_B[i]

    list_A[i] = list_B[i]

#右端の処理
list_A[-1] = list_B[-1]

print(sum(list_A))

Submission status: Accepted

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

a = [0]*n
b.append(1000000)

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

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc140c

n=int(raw_input())
b=map(int,raw_input().split())
res=b[0]+b[-1]
for i in xrange(n-2):
 res+=min(b[i],b[i+1])
print res

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
b=[int(i) for i in 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))

Submission status: Accepted

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

Submission status: Accepted

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

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

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()))
A = []
for i in range(N):
    if not i == 0 and not i == N - 1:
        A.append(min(B[i - 1], B[i]))
    elif i == 0:
        A.append(B[i])
    else:
        A.append(B[i - 1])
print(sum(A))

Submission status: Accepted

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

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

    A.append(B[-1])
    print(sum(A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline
# from collections import defaultdict
# import bisect

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

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

A = [1e10] * N

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

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

print(sum(A))

Submission status: Accepted

Solution code:
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):
    ai_1 = min(b[i],b[i+1])
    a[i+1] = ai_1

print(sum(a))

Submission status: Accepted

Solution code:
import numpy as np 

listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

sum=listA[1][0]+listA[1][-1]
for i in range(len(listA[1])-1):
  if listA[1][i+1]>listA[1][i]:
    sum+=listA[1][i]
  else:
    sum+=listA[1][i+1]
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:
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

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

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

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

    print(sum(A))

sol()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def acinput():
    return list(map(int,input().split(" ")))



N=int(input())
B=acinput()

dp=[-1]*(N)

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

Submission status: Accepted

Solution code:
n=int(input())
b=[int(i) for i in 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:
a=int(input())
lis=list(map(int,input().split()))
anlis=[0]
for i in range(a-1):
  if lis[i]<anlis[i] or i==0:
    anlis[i]=lis[i]
  anlis.append(lis[i])
print(sum(anlis))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
b = list(map(int, input().split()))
a = [b[0]]

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

Submission status: Accepted

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

for i in range(1, n-1):
    a.append(b[i])
    if b[i] < b[i-1]:
        a[i] = b[i]

print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

data = []
data.append(b[0])
data.append(b[-1])
for i in range(1,N-1):
  tmp = min(b[i-1], b[i])
  data.append(tmp)

print(sum(data))

Submission status: Accepted

Solution code:
n=int(input())
b=[int(x) for x in input().split()]
a=[0]*n
for i in range(n-1):
	if(i==0):
		a[0]=b[0]
		a[1]=b[0]
	else:	
		if(b[i]>=b[i-1]):
			a[i+1]=b[i]
		if(b[i]<b[i-1]):		
			a[i]=b[i]
			a[i+1]=b[i]
print(sum(a))

Submission status: Accepted

Solution code:
n = int(input()) 
data = [100001] + [int(i) for i in input().split()] + [100001]

p = 0
for i in range(n):
    p += min(data[i:i+2])

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

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

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(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(0,N-2):
    if i>=1 & i < 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 = [int(i) for i in input().split()]
A = [10**6]*N 

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

print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
B = input().split(' ')
A = []
A.append(int(B[0]))
A.append(int(B[0]))
SUM_MAX = A[0]

for i in range(N - 2):
  if A[i + 1] > int(B[i + 1]):
    A[i + 1] = int(B[i + 1])
  A.append(int(B[i + 1]))
  SUM_MAX = SUM_MAX + A[i + 1]
  
SUM_MAX = SUM_MAX + A[N - 1]
print(SUM_MAX)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
for n in range(N):
  if n == 0:
    A.append(B[n])
  else:
    if A[n] > B[n]:
      A[n] = B[n]

  A.append(B[n])
  sum += A[n]

  if n == N-2:
    sum += A[n+1]
    break

      
print(sum)

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

Submission status: Accepted

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


A0 = B[0]
An = B[-1]
A = []
A.append(A0)
for i in range(n - 2):
    a = min(B[i], B[i + 1])
    A.append(a)
A.append(An)

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

a = []

for _ in range(n):
    a.append(list())

for index, value in enumerate(b):
    a[index].append(value)
    a[index + 1].append(value)

min_sum = sum([min(collection) for collection in a])

print(min_sum)

Submission status: Accepted

Solution code:
n = int(input())

MAXVAL = 10**5
a = [MAXVAL] * 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))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    bl = list(map(int, input().split()))
    al = [0] * n

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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[N - 2]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    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[N-2]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def c_maximal_value(INF=float('inf')):
    N = int(input())
    B = [INF] + [int(i) for i in input().split()] + [INF]
    return sum([min(B[i], B[i + 1]) for i in range(N)])

print(c_maximal_value())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(x) for x in input().split()]
B.insert(0,B[0])
B.append(B[-1])
ans = 0
for ind,i in enumerate(B[:-1]):
    ans += min(i,B[ind+1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(x) for x in 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]
print(sum(A))

Submission status: Accepted

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

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()))
k=b[n-2]
if n>2:
    for i in range(0,n-2):
        if b[n-i-3]<b[n-i-2]:
            k+=b[n-i-3]
        else:
            k+=b[n-i-2]
k+=b[0]
print(k)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

n = int(raw_input())
b = map(int, raw_input().split())

res = 0

for i in xrange(n):
    if i == 0:
        res += b[i]
    elif i == n-1:
        res += b[i-1]
    else:
        tmp = min(b[i],b[i-1])
        res += tmp

print res

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
ans=[]
for j in range(n-2):
    ans.append(min(b[j],b[j+1]))

print(sum(ans)+b[0]+b[-1])

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = b[-1]

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

ans += b[0]

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Bs = list(map(int, input().split()))
 
As = [ None for _ in range(N) ]

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

As[-1] = Bs[-1]

print(sum(As))

Submission status: Accepted

Solution code:
n=int(input())
b_list=list(map(int,input().split()))
ans=int()
b_list.append(10**5+1)
for i in range(0,n-1):
    if b_list[i]  <= b_list[i+1]:
        ans+=b_list[i]
    else:
        ans+=b_list[i+1]
print(ans+b_list[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
b=input().split()

a=[0]*n
a[0]=b[0]
a[n-1]=b[n-2]
ans=0

for i in range(n-2):
  if int(b[i+1])>=int(b[i]):
    a[i+1]=b[i]
  else:
    a[i+1]=b[i+1]

for j in range(n):
  ans+=int(a[j])

print(ans)

Submission status: Accepted

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

sum = 0
for i in range(N):
    if i == 0:
        sum += list_B[i]
#         print('i == 0')
#         print('i=', i, 'sum=', sum)
    elif i == N-1:
        sum += list_B[i-1]
#         print('i == N-1')
#         print(list_B[i-1])
#         print('i=', i, 'sum=', sum)
    else:
        if (list_B[i] >= list_B[i-1]):
            sum += list_B[i-1]
        else:
            sum += list_B[i]
#         print('i=', i, 'sum=', sum)
print(sum)

Submission status: Accepted

Solution code:
def find(B):
    A=[B[0]]
    for i in range(len(B)-1):
        A+=[min(B[i],B[i+1])]
    A+=[B[-1]]
    return sum(A)

input()
B=list(map(int,input().strip().split(" ")))
print(find(B))

Submission status: Accepted

Solution code:
#coding:utf-8
#解き直し
n = int(input())
b = list(map(int, input().split()))

a = []
# 最初は強制的にbの最初の値が入る
a.append(b[0])

# 2番目からn-1番目まではb[i], b[i-1]の最小値が入る
for i in range(1, n-1):
    a.append(min(b[i], b[i-1]))

# 最後はbの最後の要素が入る
a.append(b[n-2])
#print(a)
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
c = input().split()
b = [int(n) for n in c]
if n == 2:
    N = b[0] * 2
else:
    a = [n]
    a[0] = 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:
#Maximal Value

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

sum = B[0]

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

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

Submission status: Accepted

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

tot = b[0]  #A[0]

#A[1] ~ A[-2]
for i in range(N-2):
  if b[i + 1] >= b[i]:
    tot += b[i]
  else:
    tot += b[i + 1]

#A[-1]
tot += b[-1]

print(tot)

Submission status: Accepted

Solution code:
n = int(input())
b_list = [int(i) for i in input().split()]
a_list = [0] * n
before_val = 0
for i in range(n-1):
    target = b_list[i]
    if i == 0:
        a_list[i], a_list[i+1] = target, target
    elif before_val >= target:
        a_list[i], a_list[i+1] = target, target
    else:
        a_list[i], a_list[i+1] = before_val, target
    before_val = target
print(sum(a_list))

Submission status: Accepted

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

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())
s1= input()
ss1 = list(map(lambda x:int(x), s1.split()))

sum = 0

ss1 = [ss1[0]] + ss1 +[ss1[-1]]

for i in range(1,n+1):

    sum += min(ss1[i-1],ss1[i])
print(sum)

Submission status: Accepted

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

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

arr.append(b[n-2])
print(sum(arr))

Submission status: Accepted

Solution code:
n = int(input())
Bs = list(map(int,input().split()))
ans = 0

if n==2:
    ans = Bs[0]*2

elif n==3:
    ans += sum(Bs)
    ans += min(Bs)
else:
    ans += Bs[0]
    ans += Bs[-1]
    for i in range(len(Bs)-1):
        ans += min(Bs[i],Bs[i+1])
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

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

A[-1] = B[-1]
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(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())
 
list_B = list(map(int, input().split()))
myans = list_B[0]
 
for i in range(len(list_B)-1):
    myans += min(list_B[i], list_B[i+1])

myans += list_B[-1]
 
print(myans)

Submission status: Accepted

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

aL = []
bL.reverse()
if len(bL) == 1:
    aL.append(bL[0]*2)
else:
    aL.append(bL[0])
    for i in range(len(bL)):
        if i == len(bL) - 1:
            aL.append(bL[i])
        else:
            aL.append(min(bL[i],bL[i+1]))
print(sum(aL))

Submission status: Accepted

Solution code:
N = int(input())
lstB = list(map(int,input().split()))
 
lstA = []
 
for i in range(N):
    if i == 0:
        lstA.append( lstB[i] )
    elif i == N-1:
        lstA.append( lstB[i-1] )
    else:
        lstA.append( min(lstB[i],lstB[i-1]))
        
print(sum(lstA))

Submission status: Accepted

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

Submission status: Accepted

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

lstA = []

for i in range(N):
    if i == 0:
        lstA.append( lstB[i] )
    elif i == N-1:
        lstA.append( lstB[i-1] )
    else:
        lstA.append( min(lstB[i],lstB[i-1]))
        
print(sum(lstA))

Submission status: Accepted

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

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

print(S)

Submission status: Accepted

Solution code:
N = int(input())
b = list(map(int, input().split()))
a = [b[0]]
for i in range(1,N-1):
    if b[i-1] < b[i]:
        a.append(b[i-1])
    else:
        a.append(b[i])
a.append(b[len(b)-1])
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

A = []
A.append(B[0])

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

A.append(B[N-2])

#print(N)
#print(B)

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INF = 10 ** 6

N = int(input())
B = [INF] + [int(i) for i in input().split()] + [INF]
print(sum(min(B[i], B[i + 1]) for i in range(len(B) - 1)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
b=list(input().split())

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

count+=int(b[n-2])
print(count)

Submission status: Accepted

Solution code:
N=int(input())
B_list=[int(thing) for thing in input().split(" ")]
a_sum=0
for i in range(N):
    if i==0:
        a_sum=a_sum+B_list[0]
    else:
        if i==N-1:
            a_sum=a_sum+B_list[N-2]
        else:
            a_sum=a_sum+min(B_list[i],B_list[i-1])
print(a_sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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



print(sum(a))

Submission status: Accepted

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

a=[]
ans=0
for i in range(n):
    if i ==0:
        a.append(b[i])
        
    elif i == n-1:
        a.append(b[n-2])

    elif 1 <= i and i < n-1:
            if b[i-1]>b[i]:
                a.append(b[i])
            elif b[i-1] <= b[i]:
                a.append(b[i-1])

print(sum(a))

Submission status: Accepted

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

if n==2:
    print(b[0]*2)
elif n==3:
    a=[]
    a.append(b[0])
    a.append(min(b[0],b[1]))
    a.append(b[1])
    print(sum(a))
else:
    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:
k = int(input())
b = list(map(int, input().split()))
a = [b[0]]+b
for i in range(len(b)):
	if (a[i]<=b[i]):
		pass
	else:
		a[i] = b[i]
print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
b = [ int(_) for _ 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[n-2])

print(sum(a))

Submission status: Accepted

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

cnt += B[N-2]+B[0]


print(cnt)

Submission status: Accepted

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

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

print(sum(l))

Submission status: Accepted

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

n = N-1
aSum = 0

for i in range(n):

	if i == 0:
		aSum = B[i]
	elif i == n:
		break
	else:
		aSum = min(B[i],B[i-1])+aSum
aSum = B[n-1]+aSum



print(aSum)