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:
import sys
input = sys.stdin.readline

def main():
    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))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

a = l()

co = []

co.append(a[0])

for i in range(n-1):
    if i == n-2:
        co.append(a[i])
    else:
        co.append(min(a[i],a[i+1]))
print(sum(co))

Submission status: Accepted

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

ans=blist[0]
for idx in range(n-2):
    if blist[idx]<=blist[idx+1]:
        ans+=blist[idx]
    else:
        ans+=blist[idx+1]
ans+=blist[-1]
print(ans)

Submission status: Accepted

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

cnt = B[0]*2
p = B[0]
for i in range(1, N-1):
    if B[i]>=p:
        cnt += B[i]
    else:
        cnt -= p
        cnt += B[i]*2
    p = B[i]

print(cnt)

Submission status: Accepted

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

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

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:
n = int(input())
b = [int(v) for v in input().split()]

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

Submission status: Accepted

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

ans = [0] * N

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

print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

before = 10**6
s = 0
for i in b:
    if i < before:
        s += i
    else:
        s+= before
    before = i
s += b[-1]
print(s)

Submission status: Accepted

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

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

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

Submission status: Accepted

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


A = [B[-1]]

for b in reversed(B):
    if A[-1] > b:
        A[-1] = b
    A.append(b)
print(sum(A))

Submission status: Accepted

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

for i,v in enumerate(b):
    if i == 0: # when i = 0 : first
        a[i] = b[i]
    else:
        a[i] = min(b[i],b[i-1])
a[n-1] = b[n-2] # when i = n-1: last

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

a_sum = 0

a_sum += b[0]

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

print(a_sum)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main(n, b):
    total = b[0] + b[-1]

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

    return total


if __name__ == "__main__":
    n = int(input())
    b = list(map(int, input().split()))
    print(main(n, b))

Submission status: Accepted

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

total = Bs[-1] + Bs[0]
Bs = Bs[::-1]

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

print(total)

Submission status: Accepted

Solution code:
N=int(input())
B=[int(x) for x in input().split()]
A=[-1 for x in range(N)]
ans=0
bef=0
A[0]=B[0]
for i in range(N-1):
    if B[i]>=A[i]:
        A[i+1]=B[i]
    else:
        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):
    if i == 0:
        A[i] = B[i]
        A[i+1] = B[i]
    else:
        A[i] = min(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_list = [10**18]*N
for i, b in enumerate(B):
    a_list[i] = min(a_list[i], b)
    a_list[i+1] = min(a_list[i+1], b)

print(sum(a_list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(item) for item in input().split()]
ans = b[0] + b[-1]
for p, q in zip(b, b[1:]):
    ans += min(p, q)
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    b_s = list(map(int, input().split(' ')))
    b_pre = 10**5 + 1
    a_s = []
    
    for b in b_s:
        a_s.append(min(b_pre, b))
        b_pre = b
    a_s.append(b)

    print(sum(a_s))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

print(ans+B[0])

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


ans = B[0]

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

ans += B[-1]

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans += B[0]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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:
from sys import stdin

N = int(stdin.readline().rstrip())
B = [int(x) for x in stdin.readline().rstrip().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()))
A = N*[0]

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
b_max = max(B)
A = [b_max for _ in range(N)]

def solve():
    for i, b in enumerate(B):
        A[i] = min(A[i], b)
        A[i+1] = min(A[i+1], b)
    print(sum(A))

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n1 = int(input())

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

r1 = 0

for i1 in range(n1):
    if i1 == 0:
        r1 += n2[0]
    elif i1 == n1 - 1:
        r1 += n2[n1 - 2]
    else:
        r1 += min(n2[i1 - 1],n2[i1])

print(r1)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
b_list = []
for i in range (n-1):
  b_list.append([b[i],i])
b_list.sort()

a_list = []
for i in range(n):
  a_list.append("Yet")

for i in range(n-1):
  idx = b_list[i][1]
  if a_list[idx]=="Yet":
    a_list[idx]=b_list[i][0]
  if a_list[idx+1]=="Yet":
    a_list[idx+1]=b_list[i][0]

print(sum(a_list))

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int, input().split()))
r = li[0] + li[-1]
for i, j in enumerate(li):
    if i != len(li)-1:
        r += min(j, li[i + 1])
print(r)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from heapq import heappush, heappop, heapify
from bisect import bisect_left

class Solution:
    def main(self):
        N = int(input())
        B = [float('inf')] + list(map(lambda x: int(x), input().split())) + [float('inf')]

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

        print(res)


if __name__ == '__main__':
    Solution().main()

Submission status: Accepted

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

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

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(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]]
for i in range(n-1):
    a.append(b[i])
    if max(a[-1], a[-2]) > b[i]:
        a[-2] = b[i]

print(sum(a))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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(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().strip())
B = list(map(int, input().strip().split(' ')))
A = [float('inf')]*N

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

print(sum(A))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
Arr=get_array()
new_Arr=[0]*n
new_Arr[-1]=Arr[-1]
new_Arr[-2]=Arr[-1]
for i in range(n-3,-1,-1):
    if Arr[i]>=Arr[i+1]:
        new_Arr[i]=Arr[i]
    elif Arr[i]<Arr[i+1]:
        new_Arr[i]=Arr[i]
        new_Arr[i+1]=Arr[i]
print(sum(new_Arr))

Submission status: Accepted

Solution code:
import collections as c
ip = lambda : map(int, input().split())
# ##############
N = int(input())
B = list(ip())
B.insert(0,B[0])
B.append(B[-1])

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

Submission status: Accepted

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

n = int(input())
b = MAP()

a = [0]*n
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())
b = list(map(int, input().split()))
a = [None]*n
a[0] = b[0]
ans = a[0]

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

Submission status: Accepted

Solution code:
# coding=utf-8

if __name__ == "__main__":
    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]))
    else:
        A.append(B[-1])
    print(sum(A))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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

Submission status: Accepted

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

ans = b[0]
for i in range(len(b)-1):
    ans += min(b[i], b[i+1])
ans += b[-1]
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())
Bs= [10**10] + list(map(int,input().split(" ")))  + [10**10]

As = []
for b1,b2 in zip(Bs[0:N],Bs[1:N+1]):
    As.append(min(b1,b2))

print(sum( As))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc(N, B):
    B = [10 ** 6] + B + [10 ** 6]
    r = 0
    for i in range(N):
        r += min(B[i], B[i + 1])
    return r


N = int(input())
B = [int(s) for s in input().split()]
print(calc(N, B))

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

Solution code:
n = int(input())
A = [10**6]*n
B = [int(b) for b in input().split()]
for i in range(n-1):
    A[i] = min(A[i], B[i])
    A[i+1] = B[i]
    
print(sum(A))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC140
import sys
#sys.setrecursionlimit(100000)


n=int(input())
tmp = input().split()
b = list(map(lambda a: int(a), tmp))

a=[]

#print(n)

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

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

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()))
ans = 0
for i in range(n):
    if i == 0:
        ans += b[0]
    elif i < n - 1:
        ans += min(b[i-1],b[i])
    else:
        ans += b[-1]
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC140 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

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

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

ans += b[len(b)-1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
N = int(input())
A, B = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(M)]
A = list(map(int,input().split()))
"""

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]))
else:
  A.append(B[-1])
  
print(sum(A))

Submission status: Accepted

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


ct=0
bt=10**6
for b in B:
    if bt>=b:
        ct+=b
    else:
        ct+=bt
    bt=b
ct+=B[-1]
print(ct)

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

Submission status: Accepted

Solution code:
import sys

def main():
    _ = int(sys.stdin.readline())
    *B, = map(int, sys.stdin.readline().split())

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

    for b1,b2 in zip(B[:-1],B[1:]):
        sumA += min(b1,b2)

    print(sumA)

if __name__=='__main__':
    main()

Submission status: Accepted

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

a_list = []

for i in range(N):
    if i == 0:
        a = b_list[0]
        a_list.append(a)
        continue
    if i == N - 1:
        a = b_list[i-1]
        a_list.append(a)
        continue

    # BiとBi-1以下である必要がある
    a = min(b_list[i-1], b_list[i])
    a_list.append(a)

ans = sum(a_list)
print(ans)

Submission status: Accepted

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


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

Submission status: Accepted

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

cnt = B[0] + B[N-2]
for i in range(N-2):
    if B[i] > B[i+1]:
        cnt += B[i+1]
    else:
        cnt += B[i]
       
        
print(cnt)

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[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]]
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[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()))
ans = 0;
ans += b[0]
for i in range(len(b)-1):
    ans += min(b[i], b[i+1])
ans += b[-1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# @author 

import sys

class CMaximalValue:
    def solve(self):
        n = int(input())
        b = [int(_) for _ in input().split()] + [float('inf')]
        ans = 0
        for i in range(n):
            ans += min(b[i], b[i - 1])
        
        print(ans)

solver = CMaximalValue()
input = sys.stdin.readline

solver.solve()

Submission status: Accepted

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

Submission status: Accepted

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

dp = [10**8] * n

for i in range(n-1):
    if dp[i] > b_list[i]:
        dp[i] = b_list[i]
    if dp[i+1] > b_list[i]:
        dp[i+1] = b_list[i]
        
print(sum(dp))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
def LILI(n): return [LI() for _ in range(n)]
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()
    B = LI()

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

main()

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()))
print(sum(min(i,j) for i,j in zip([b[0]]+b,b+[b[-1]])))

Submission status: Accepted

Solution code:
_,b=open(0);*b,=map(int,b.split());print(b[0]+b[-1]+sum(min(i,j)for i,j in zip(b,b[1:])))

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
B = LIST()

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

Submission status: Accepted

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

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

print(sum(As))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())  
B = np.array(input().split(), dtype=np.int64)

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

for i in np.arange(N-2):
    ans += np.min(np.array([B[i], B[i+1]]))
    
print(int(ans))

Submission status: Accepted

Solution code:

N = int(input())
B = list(map(int,input().split()))
C = [10**6]
for b in B:
    C.append(b)
B.append(10**6)
sm = 0
# print(B)
# print(C)
for n in range(N):
    sm+=min(B[n],C[n])
print(sm)

Submission status: Accepted

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

ans = 0
last = 10**5
for i in range(N - 1):
    b = B[i]
    ans += min(last, b)
    last = b
    if i == N - 2:
        ans += b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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



resolve()

Submission status: Accepted

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

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

print(ans)

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

Submission status: Accepted

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

a_list = []
a_list.append(b_list[0])

for i in range(len(b_list)-1):
    a_list.append(min(b_list[i],b_list[i+1]))

a_list.append(b_list[-1])

print(sum(a_list))

Submission status: Accepted

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