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

A = []

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

print(sum(A))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

#最適なAの値を求めていく
A = []

A.append(B[0])

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

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

print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = [-1]*n
for i in range(n):
    if i == 0:
        a[i] = b[i]
    elif i < n-1:
        a[i] = min(b[i],b[i-1])
    else:
        a[i] = b[i-1]

print(sum(a))

Submission status: Accepted

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

as_ = [0] * n

for i in range(n):
    if i == 0:
        as_[i] = bs[i]
    elif i < n - 1:
        as_[i] = min(bs[i - 1], bs[i])
    else:
        as_[i] = bs[i - 1]

print(sum(as_))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

ls_a = [0] * n

ls_a[n - 1] = ls_b[n - 2]
ls_a[0] = ls_b[0]

for i in reversed(range(1, n - 1)):
    ls_a[i] = min(ls_b[i], ls_b[i - 1])

print(sum(ls_a))

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

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

ans = 0
for i in range(N):
    ans += A[i]

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=0
l=len(a)
s+=a[0]+a[l-1]
i=1
while(i<l):
    s+=min(a[i],a[i-1])
    i+=1

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

print(result + b[-1])

Submission status: Accepted

Solution code:
# 0:50 事前にスマホで問題読んでる
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],b[i-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]
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:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    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)
resolve()

Submission status: Accepted

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

A = [0]*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],B[i-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]
a[1]=b[0]
for i in range(1,n-1):
    x=b[i]
    a[i+1]=x
    if a[i]>x:
        a[i]=x
print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import numpy as np

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

        ans += A_max

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if N == 2:
        print(B[0] * 2)
        exit()

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

Submission status: Accepted

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

ans = 0
pbi = 0

for i in range(n-1):
    ans += 2 * b[i]
    if i > 0:
    	ans -= max(b[i], pbi)
    pbi = b[i]
    
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-2):
    left=b[i]
    right=b[i+1]
    a.append(min(left,right))
a.append(b[-1])
print(sum(a))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    B = LI()
    ans = B[0] + B[-1]
    for i in range(1, N-1):
        ans += min(B[i], B[i-1]) # a[i]
    print(ans)
main()

Submission status: Accepted

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

    previous = 10 ** 5

    for b in b_list:
      a = min(previous, b)
      a_list.append(a)
      previous = b
      
    a_list.append(b_list[-1])
    print(sum(a_list))
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    b = list(map(int, readline().split()))
    a = [0] * 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], b[i-1])
    print(sum(a))


if __name__ == '__main__':
    solve()

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

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

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

Submission status: Accepted

Solution code:

import numpy as np
def main():
    n = int(input())
    b = list(map(int, input().split()))
    
    ans_list = []
    ans_list.append(b[0])
    for i in range(n-2):
        if i == n-1:
            ans_list.append(b[i])
            break
        ans_list.append(np.min([b[i], b[i+1]]))
        
    ans_list.append(b[n-2])
    print(np.sum(ans_list))


    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

ans += bs[-1]

print(ans)

Submission status: Accepted

Solution code:
#ABC-140-C
N = int(input())
B = list(map(int, input().split()))

max_A = [None] * N

max_A[0] = B[0]
max_A[-1] = B[-1]

for i in range(1, N-1):
    #例:max_A[1] = min(B[0], B[1])
    max_A[i] = min(B[i-1], B[i])

print(sum(max_A))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split());print(sum(min(a[i],a[i+1])for i in range(n-2))+a[0]+a[-1])

Submission status: Accepted

Solution code:

def main():
    buf = input()
    n = int(buf)
    buf = input()
    buflist = buf.split()
    b = list(map(int, buflist))

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

    ans = sum(a)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
a = [0]*n
a[0] = b[0]
a[-1] = b[-1]
if n==2:
  print(sum(a))
  exit()
i=1
while i<n-1:
  a[i]=min(b[i-1],b[i])
  i+=1
print(sum(a))

Submission status: Accepted

Solution code:
num = int(input())
b = [int(i) for i in input().split()]
ans = b[0] + b[-1]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

# 6
# 0 153 10 10 23
def solve(N: int, B: "List[int]"):
    lists = []
    C = B[::-1]
    for i in range(N):
        if i == 0:
            lists.append(C[i])
        elif i == N-1:
            lists.append(C[-1])
        else:
            lists.append(min(C[i], C[i-1]))

    sum = 0
    for n in lists:
        sum += n
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

result=0
for j in a:
    result+=j
print(result)

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:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
b = list(map(int,input().split()))
a = [0] * n
a[0] = b[0]
a[-1] = b[-1]
for i,v in enumerate(zip(b,b[1::])):
    a[i+1] = min(v)
print(sum(a))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
B = np.array(list(map(int, input().split())))

B_index = np.argsort(B)
# print(B)
# print(B_index)
A = [-1] * (len(B)+1)
for i in B_index:
    if A[i] < 0:
        A[i] = B[i]
        if A[i+1] < 0:
            A[i+1] = B[i]
    else:
        if A[i+1] < 0:
            A[i+1] = B[i]
print(sum(A))

Submission status: Accepted

Solution code:
from itertools import *
from math import *

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

C = [INF]
for i in range(1, N + 1):
    C.append(min(B[i - 1], B[i]))
print(sum(C[1:]))

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[-1] = B[-1]
print(sum(A))

Submission status: Accepted

Solution code:
n = int(input())

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

ans = 0

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

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

Submission status: Accepted

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

sum = 0

for i in range(N):
    if i == 0:
        sum += B[0]
    elif i ==N-1:
        sum += B[-1]
    else:
        if B[i-1] < B[i]:
            sum += B[i-1]
        else:
            sum += B[i]
print(sum)

Submission status: Accepted

Solution code:
#c
import numpy as np
N = int(input())
B = list(map(int, input().split()))
A = [0]*N
if N>2:
    A[0]=B[0]
    for i in range(1,N-1):
        A[i]=min(B[i],B[i-1])
    A[N-1]=B[N-2]
    print(np.sum(A))
else:
    print(B[0]*2)

Submission status: Accepted

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

ans += b[N-2]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

# A の初期化
A = [0 for i in range(N)]

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

Submission status: Accepted

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

for i in range(1,n-1):
    L.append(min(b[i],b[i-1]))
L.append(b[-1])
    
print(sum(L))

Submission status: Accepted

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

b.append(max(b)+1)

result=b[0]

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

print(result)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
B=list(map(int,input().split()))
A=np.zeros(N)
A[0]=B[0]
i=0
while i<=len(B)-1:
    if i==len(B)-1:
        A[i+1]=B[i]
        i+=1
    else:
        if B[i]<=B[i+1]:
            A[i+1]=B[i]
            i+=1
        else:
            A[i+1]=B[i+1]
            i+=1
print(int(sum(A)))

Submission status: Accepted

Solution code:
import numpy as np

INF = 1e+9
N = int(input())
B = list(map(int, input().split()))

A = B.copy() + [INF]

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
B = MAP()

# always B[i] >= MAX(A[i],A[i+1])

A = [0] * (N)
A[0] = B[0]

for idx,b in enumerate(B):
	A[idx+1] = b

for i in range(N-1):
	#print(B[i], A[i], A[i+1], B[i]>=max(A[i],A[i+1]))
	if B[i]<max(A[i],A[i+1]):
		if A[i]>A[i+1]: A[i] = B[i]
		else : A[i+1] = B[i]

for i in range(N-1):
	#print(B[i], A[i], A[i+1], B[i]>=max(A[i],A[i+1]))
	if B[i]<max(A[i],A[i+1]):
		if A[i]>A[i+1]: A[i] = B[i]
		else : A[i+1] = B[i]

#print(A)
print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
INF = 1000000
B = [INF]*(N+1)
tmp = list(map(int, input().split()))
for i in range(1, N):
    B[i] = tmp[i-1]
A = []
for i in range(N):
    A.append(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 for i in range(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(lambda x: int(x), input().split()))

a =[]
a.append(b[0])

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

Submission status: Accepted

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

b.insert(0, float("inf"))
b.insert(len(b), float("inf"))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = [0 for _ in range(n)]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A = [None]*N

A[0] = B[0]

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

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

print(sum(A))

Submission status: Accepted

Solution code:
N = int(input())
blist = list(map(int, input().split()))
#print(blist)
ans = []
for n in range(N):
    if n == 0:
        ans.append(blist[0])
    elif n>0 and n<N-1:
        mina = min(blist[n-1],blist[n]) 
        ans.append(mina)
    else:
        ans.append(blist[n-1])    
#print(ans)
ansnum = sum(ans)
print(ansnum)

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:
import numpy as np

N = int(input())
A = [-1] * N

B = np.array(list(map(int, input().split())))
indices = np.argsort(B)

for i in indices:
    if A[i] == -1 and A[i + 1] == -1:
        A[i] = A[i + 1] = B[i]
    elif A[i] == -1:
        A[i] = B[i]
    elif A[i + 1] == -1:
        A[i + 1] = B[i]

print(sum(A))

Submission status: Accepted

Solution code:
n=int(input())
b=list(map(int,input().split()))
a=[1000000 for _ in range(n)]

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

Submission status: Accepted

Solution code:
import numpy as np
N = input()
B = np.array(input().split()).astype(int)
B_left = np.insert(B, 0, B[0])
B_right = np.insert(B, len(B)-1, B[-1])
print(np.min(np.array([B_left, B_right]).T, axis=1).sum())

Submission status: Accepted

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

Submission status: Accepted

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

b.insert(0, float("inf"))
b.insert(len(b), float("inf"))

a = []

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

print(sum(a))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

a_list = []

a_list.append(b[0])

for i in range(n-2):
    if b[i] > b[i+1]:
        a_list.append(b[i+1])
    elif b[i] == b[i+1]:
        a_list.append(a_list[-1])
    elif b[i] < b[i+1]:
        a_list.append(b[i])
a_list.append(b[-1])
print(sum(a_list))

Submission status: Accepted

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

a = [b[0]]

ta = 0 # temporal a
for i in range(n - 2):
    ta = min(b[i], b[i + 1])
    a.append(ta)
    
ans = sum(a) + b[n - 2]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

N = int(input())

# 複数個の数値を、intの配列として取得
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()))
S=0
for i in range(N-2):
  S+=min(B[i],B[i+1])

print(S+B[0]+B[N-2])

Submission status: Accepted

Solution code:
if __name__ == "__main__":
	N = int(input())
	B = list(map(int,input().split()))
	A = []
	A.append(B[0])
	for i in range(1,int(len(B))):
		# print(i)
		A_left = B[i-1]
		A_right = B[i]
		A.append(min(A_left,A_right))

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

	print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
a = [10 ** 9 for _ in range(n)]
for i, bi in enumerate(b):
    a[i] = min(a[i], bi)
    a[i + 1] = bi
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):
  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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(i) for i in input().split()]
A = [1e5+1] * N

while sum(B) != -1*(N-1):
    max_val = max(B)
    index = B.index(max_val)
    if A[index] > B[index]:
        A[index] = B[index]
    if A[index+1] > B[index]:
        A[index+1] = B[index]
    B[index] = -1
        
print(sum(A))

Submission status: Accepted

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

A = [B[0]]

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

A.append(B[-1])

print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

A.append(B[0])

for i in range(len(B)-1):
    if B[i] < B[i+1]:
        A.append(B[i])
    else:
        A.append(B[i+1])

A.append(B[-1])

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def minValue(a,b):
    return b if a > b else a

def getSum(arr):
    return sum(list(arr))

def calculate(arr,n):

    ret = []

    for i in range(n):
        if i == 0:
            ret.append(arr[0])
        elif i == len(arr):
            ret.append(arr[i-1])
        else:
            ret.append(minValue(arr[i],arr[i-1]))

    return ret


N = int(input())
S = input().split()

arr = list(map(int, list(S)))
result = calculate(arr,N)
ret = getSum(list(result))
print(ret)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 後ろからみていって最小値or0で更新
n = int(input())
b = list(map(int, input().split()))
a = [10 ** 5 for _ in range(n)]  # どうせ後で更新されるので
a[-1] = b[-1]

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

Submission status: Accepted

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

A=[0]*N

MIN = float('inf')
for i in reversed(range(N)):
    if (i == N-1):
        A[i] = B[N-2]
    elif (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())
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()))
print(sum([min(B[x], B[x+1]) for x in range(len(B)-1)]) + B[0] + B[-1])

Submission status: Accepted

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