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())
nums = list(map(int,input().split(" ")))
s = 0
s += nums[0]
for i in range(len(nums)-1):
    s += min(nums[i],nums[i+1])
s += nums[-1]
print(s)

Submission status: Accepted

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

ans = nums[0]
nums.append(10**10)
for i in range(1, n):
    ans += min(nums[i-1], nums[i])
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0

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

print(ans)

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    B = list(map(int, input().split()))
    ans = [0] * N
    ans[0] = B[0]

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

    print(sum(ans))


main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sumA)

Submission status: Accepted

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

ans=b[0]

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

Submission status: Accepted

Solution code:
_ = input()
B = (10 ** 5,) + tuple(map(int, input().split())) + (10 ** 5,)
print(sum(min(b) for b in zip(B, B[1:])))

Submission status: Accepted

Solution code:
def func(n,b,ans):
    for i in range((n-1)):
        if i+1 < (n-1) and b[i]<=b[i+1]:
            ans.append(b[i])
        elif i+1 < (n-1) and b[i]>b[i+1]:
            ans.append(b[i+1])
        else:
            ans.append(b[i])
    return ans

if __name__=='__main__':
    n=int(input())
    b=list(map(int,input().split()))
    ans=[]
    ans=func(n,b,ans)
    print(sum(ans)+b[0])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
B = [int(zz) for zz in 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 = list(map(int, input().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve(inp):
    N = int(inp.readline().strip())
    B = list(map(int, inp.readline().strip().split(' ')))

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

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

    return str(sum(A))


def test(s):
    from io import StringIO
    print(solve(StringIO(s)))


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    # test('3\n2 5')
    # test('2\n3')
    # test('6\n0 153 10 10 23')
    main()

Submission status: Accepted

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

max = 0
a = [0] * N

for n in range(N):
  if n == len(li):
    a[n] = li[n-1]
    break
  
  if n == 0:
    a[n] = li[n]
  else:
    if li[n] > li[n-1]:
      a[n] = li[n-1]
    else:
      a[n] = li[n]

print(sum(a))

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    A = cin.mapInt()
    ans = 0
    for i in range(N - 2):
        ans += min(A[i],A[i + 1])
    ans += A[0]
    ans += A[N - 2]
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(total)

Submission status: Accepted

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

ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
length = int(input())
Bs = list(map(int, input().split()))
total = Bs[0] + Bs[length-2]

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

print(total)

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

Submission status: Accepted

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

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

else:
    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:
# 要復習
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    B = LIST()

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    num_list = list(map(int, input().split()))
    
    ls = [num_list[0]]

    for i in range(n-1):
        if i != n - 2 and num_list[i+1] < num_list[i]:
            ls.append(num_list[i+1])
        else:
            ls.append(num_list[i])

    print(sum(ls))

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

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

    else:
        A += B[i]

print(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 += [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()))

inf = 10 ** 9
B = B + [inf]
A = [0] * N


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
l.append(100000) #100000はダミー
#print(n, l, len(l))
z = []
z.append(l[0]) # z[0]のみl[0]と決まる
for i in range(len(l)-1):
    #print(i)
    z.append(min(l[i],l[i+1]))

print(sum(z))

Submission status: Accepted

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
l.append(100000)
#print(n, l, len(l))
z = []
z.append(l[0])
for i in range(len(l)-1):
    #print(i)
    z.append(min(l[i],l[i+1]))
print(sum(z))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(result_sum)

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

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

print(sum)

Submission status: Accepted

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

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

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

for i in range(len(B)-1) : 
    sum += min(B[i], B[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(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()))

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

Submission status: Accepted

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

sum=int(a[0])
for i in range(n-2):
    if int(a[i])<int(a[i+1]):
        sum=sum+int(a[i])
    else:
        sum=sum+int(a[i+1])
sum=sum+int(a[n-2])
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[N - 2])
print(sum(A))

Submission status: Accepted

Solution code:
def LI():
  return [int(s) for s in input().split()]

N = int(input())

B_s = LI()

A_count = B_s[0]

for i in range(1,N):
  if i < (N-1):
  	A_count += min(B_s[i],B_s[i-1])
  else:
    A_count += B_s[i-1]
  
print(A_count)

Submission status: Accepted

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

ansList = [0] * A

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

print(sum(ansList))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
B = list(map(int, input().split()))

b = deque(B)
b.appendleft(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:
n = int(input())
b = list(map(int, input().split()))

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

print(sum(a))

Submission status: Accepted

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

a = [0]*(n)

for i in range(len(a)):
  if (i == 0):
    a[i] = b[i]
  elif i == len(a)-1:
    a[i] = b[i-1]
  else:
    a[i] = min(b[i-1], b[i])
    
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()))
B.append(10**5+1)
B.insert(0, 10**5+1)


max_sum = 0

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

max_sum += B[-2]

print(max_sum)

Submission status: Accepted

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

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

Submission status: Accepted

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

a_list = [None for _ in range(N)]
a_list[0] = bs[0]

bs_size = len(bs)

for i in range(bs_size):
    if i == bs_size - 1:
        a_list[N-1] = bs[i]
    else:
        a_list[i+1] = min(bs[i],bs[i+1])

print(sum(a_list))

Submission status: Accepted

Solution code:
n = int(input())
A = [0 for i in range(n)]
B = list(map(int, input().split()))
for i in range(len(A)):
    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 = 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:
import numpy as np

N = int(input())
b = [int(s) for s in input().split(' ')]

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

for i in range(len(b)):
    B[i] = b[i]

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

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

print(sum(A))

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

Submission status: Accepted

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

Submission status: Accepted

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

i=0
A=[B[i]]
for i in range(1,N-1):
  if B[i] <= B[i-1]:
    A.append(B[i])
  else: A.append(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 = [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 = [None]*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:
def main():
    N = int(input())
    B = list(map(int, input().split()))

    ans = [B[0]]

    for i in range(1, N-1):
        ans.append(min(B[i-1], B[i]))
    ans.append(B[N-2])
    print(sum(ans))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def main():
    N = int(input())

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


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

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

    A.append(B[N-2])

    print(sum(A))

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

answer = sum(A)
print(answer)

Submission status: Accepted

Solution code:
def main():
    A = int(input())
    B = list(map(int, input().split(" ")))
    result = B[0]
    if A > 3:
        for i in range(0, A - 2):
            result += min(B[i], B[i + 1])
    elif A == 3:
        result += B[0]
    result += B[-1]
    print(result)


if __name__ == '__main__':
    main()

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

    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()))
A=[0]*N

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

Submission status: Accepted

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

a = [None for i 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())
bi = list(map(int, input().split()))

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

ans += bi[n-2]
print(ans)

Submission status: Accepted

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

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[-1]=b[-1]
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[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()))
a=[b[0],b[n-2]]

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

print(sum(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(sum(a_max))

Submission status: Accepted

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

A = [0]*N

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

print(sum(A))

Submission status: Accepted

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

def main():
    Ans = [B[0]]*(N)
    for i in range(1,N-1):
        Ans[i] = min(B[i-1],B[i])
    Ans[N-1] = B[-1]
    print(sum(Ans))
    return
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

count = B_i[0] + B_i[N - 2]

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

ans = B[0]

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

Submission status: Accepted

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

s += array_b[n-2]
print(s)

Submission status: Accepted

Solution code:
N = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
B=[INTMAX] + LI() + [INTMAX]

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

Submission status: Accepted

Solution code:
import sys


N = int(input())
B = [inp for inp in map(int, input().split())]

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A = int(input())
B = list(map(int,input().split(" ")))
count = 0
list_count = B[0] 
for i in range(A - 2):
    list_count += min(B[count],B[count + 1])
    count += 1
list_count += B[-1]
print(str(list_count))

Submission status: Accepted

Solution code:


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

Al = []
Al.append(Bl[0])
for bi in range(N-1):
    try:
        Al.append(min(Bl[bi], Bl[bi+1]))
    except IndexError:
        pass

Al.append(Bl[-1])
print(sum(Al))

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):
    if B[i]>= B[i-1]:
        A[i] = B[i-1]
        A[i+1] = B[i]
    else:
        A[i] = B[i]
        A[i+1] = B[i]
print(sum(A))

Submission status: Accepted

Solution code:
import sys

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

print(sum(a))

Submission status: Accepted

Solution code:
import numpy as np
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+=np.min((b[i],b[i-1]))

print(ans)

Submission status: Accepted

Solution code:
input();B = list(map(int, input().split()))
print(sum([min(x, y) for x, y in zip(B + [10**5 + 1], [B[0]] + B)]))

Submission status: Accepted

Solution code:
a=int(input())
b=list(map(int,input().split()))
b.append(b[-1])
c=[b[0]]

for i in range(1,a):
    c.append(min(b[i],b[i-1]))

ans=sum(c)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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