Problem:


Score : 300 points

Problem Statement

There is an integer sequence A of length N whose values are unknown.

Given is an integer sequence B of length N-1 which is known to satisfy the following:

 B_i \geq \max(A_i, A_{i+1}) 

Find the maximum possible sum of the elements of A.

Constraints

All values in input are integers.

2 \leq N \leq 100

0 \leq B_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
B_1 B_2 ... B_{N-1}

Output

Print the maximum possible sum of the elements of A.

Sample Input 1

3
2 5

Sample Output 1

9

A can be, for example, ( 2 , 1 , 5 ), ( -1 , -2 , -3 ), or ( 2 , 2 , 5 ). Among those candidates, A = ( 2 , 2 , 5 ) has the maximum possible sum.

Sample Input 2

2
3

Sample Output 2

6

Sample Input 3

6
0 153 10 10 23

Sample Output 3

53



Sample input:
3
2 5


Sample output:
9

Submission status: Accepted

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

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

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:
# 初期入力
N = int(input())
#B = list(map(int, input().split()))
B = [10**5] + list(map(int,input().split())) + [10**5]
#
A =[0]*(N+1)
A[0]=B[0]
for i in range(N):
    A[i+1] =B[i]
    A[i] =min(B[i],B[i-1])
    #if 0<i:
     #   A[i] =min(A[i-1],b) 

print(sum(A[1:]))

Submission status: Accepted

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

Submission status: Accepted

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


a = [b[0]]+ b 

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

Submission status: Accepted

Solution code:
n = int(input())

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

a_list = [0] * n
a_list[0] = b_list[0]
for i in range(1, n - 1):
    a_list[i] = min([b_list[i - 1], b_list[i]])
a_list[n - 1] = b_list[n - 2]

ans = sum(a_list)
print(ans)

Submission status: Accepted

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

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

A= []
A.append(B[0])
for i in range(1,N):
    if i >= N-1:
        #print(i, "S")
        A.append(B[i-1])
    else:
        #print(i)
        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()))
ans = b[0]

for i in range(1,n-1):
    if b[i-1] <= b[i]:
        ans += b[i-1]
    else:
        ans += b[i]
print(ans+b[-1])

Submission status: Accepted

Solution code:
n, *b = map(int, open(0).read().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()))

result = b[0]

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

print(result+b[n-2])

Submission status: Accepted

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


def solve(N: int, B: "List[int]"):
    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[-1]

    print(sum(A))
    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:
def main():
    N = int(input())
    B = [int(a) for a in input().split()]
    A = [0]*N
    A[0] = B[0]
    A[1] = B[0]
    for i in range(1, N-1):
        if A[i] < B[i]:
            A[i+1] = B[i]
        else:
            A[i] = B[i]
            A[i+1] = B[i]
    print(sum(A))
if __name__ == "__main__":
    main()

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(sum(a)+b[0]+b[n-2])

Submission status: Accepted

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

Submission status: Accepted

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

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

a[N-1]=b[N-2]
print(sum(a))

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
big = 10**18
bb = list(map(int, input().split()))
aa = np.zeros(n+1)
aa = np.minimum([big] + bb, bb + [big])
print(sum(aa))

Submission status: Accepted

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

result = B[0]

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

result += B[N - 2]

print(result)

Submission status: Accepted

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

result = B[0]

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

result += B[N - 2]

print(result)

Submission status: Accepted

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

inf = float('inf')
A = [inf] * N

for i in range(N-1):
    if A[i] > B[i]:
        A[i] = B[i]
    if A[i+1] > B[i]:
        A[i+1] = B[i]
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
B=[int(x) for x in input().rstrip().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
ans=0
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])
for i in A:
  ans+=i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    b = list(map(int, input().split()))
    a = []

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

    print(sum(a))


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]

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

print(sum(A))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
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], 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)

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:
# solution
import io
import math

data = int(input())
array=list(map(int, input().split()))
counter=0
for i in range(data-2):
  counter+=min(array[i],array[i+1])
print(counter+array[0]+array[data-2])

Submission status: Accepted

Solution code:
n=int(input())
B = list(map(int,input().split(' ')))
total = B[0] + B[-1]
i = 1
while i < len(B):
    total += min(B[i-1],B[i])
    i += 1
print(total)

Submission status: Accepted

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

ans += B[N-2]

print(ans)

Submission status: Accepted

Solution code:
import sys
inf = float('inf')

n, *b = map(int, sys.stdin.read().split())
b = [inf] + b + [inf]

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

if __name__ ==  '__main__':
    main()

Submission status: Accepted

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

res = 0
count = 0

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

if count == n:
  print(res)
else:
  while count < n:
     if b[0] >= b[1]:
      res += b[1]
      count += 1
     else:
       res += b[0]
       count += 1
  print(res)

Submission status: Accepted

Solution code:
import numpy as np

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

A = np.zeros(N,dtype=int)
A[0] = B[0]
A[-1] = B[-1]

if N == 2:
    print(A.sum())
    exit(0)

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

print(A.sum())

Submission status: Accepted

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

A = []
A.append(B[0])
for i in range(1,N):
  a = 10 ** 6
  a = min(a,B[i-1])
  a = a if N-1 <= i else min(a,B[i])
  A.append(a)
  
print(sum(A))

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    B = readInts()
    ans = B[0] + B[-1]
    for i in range(1,n-1):
        ans += min(B[i],B[i-1])
    print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())
*b, = map(int, input().split())
a = [1001001001]*n
a[:-1] = [min(ai, bi) for ai, bi in zip(a, b)]
a[1:] = [min(ai1, bi) for ai1, bi in zip(a[1:], b)]
print(sum(a))

Submission status: Accepted

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

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = [None] * n
    b = lmi()
    b.reverse()
    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))

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

print(str(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 += min(B[i],B[i+1])
print(A)

Submission status: Accepted

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

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

print(sum(a))

Submission status: Accepted

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

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

answer = sum(A)

print(answer)

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

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[i]
    elif i == N - 1:
        sum += B[i - 1]
    else:
        if B[i] >= B[i - 1]:
            sum += B[i - 1]
        else:
            sum += B[i]

print(sum)

Submission status: Accepted

Solution code:
def myAnswer(N:int,B:list) -> int:
   total = B[0]+B[-1]
   pre = B.pop(0)
   for b in B:
      total += min(pre,b)
      pre = b
   return total

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   B = list(map(int,input().split()))

   print(myAnswer(N,B[:]))

if __name__ == '__main__':
   main()

Submission status: Accepted

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

print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
def lima():
    return list(map(int,input().split()))


b=lima()
sum=b[0]+b[-1]
if len(b)==1:
    print(sum)
else:
    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()))
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])

total = sum(a)

print(total)

Submission status: Accepted

Solution code:
N = int(input())
A = [10 ** 5 for _ in range(N)]
B = list(map(int, input().split()))
for i in range(N - 1):
    if B[i] < A[i]:
        A[i] = B[i]
    if B[i] < A[i + 1]:
        A[i + 1] = B[i]
print(sum(A))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    B = LI()

    sm = 0
    for i in range(n):
        j = i - 1
        # print(i, j)
        if j < 0:
            a = B[i]
        elif i == n-1:
            a = B[j]
        else:
            a = min(B[i], B[j])
        sm = sm + a
    print(sm)



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())
B = list(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))

Submission status: Accepted

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

print(b[0] + sum([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 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(int, input().split()))

B = B + [B[-1]]
B = B[::-1]
A = []
for i in range(0, N - 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 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, *b = map(int, open(0).read().split())
a = [0]*n
b.append(float("inf"))
for i in range(n):
  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(1,N-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()))

ans = b[0] + b[n - 2]
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()))
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 = 0
p = 10**9
for b in B:
    ans += min(p,b)
    p = b
ans+= b
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

a_li = [[] for i in range(n)]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

A[-1] = B[-1]

print(sum(A))

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

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

Submission status: Accepted

Solution code:
import math

length = int(input())
array = str(input()).split(" ")
for index in range(len(array)):
    array[index] = int(array[index])
narray = []
narray.append(array[0])
for index in range(1, len(array)):
    narray.append(min(array[index-1],array[index]))
narray.append(array[-1])
sum = 0
for element in narray:
    sum += element
print(sum)

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

a = []
a.append(b[0])
a.append(b[n-2])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    B = input()
    B = B.split()
    B = [int(i) for i in B]
    s = 0
    for i in range(0, n-1):
        if i == 0:
            s += B[0]
        else:
            s += min(B[i - 1], B[i])
    s += B[-1]
    return s

print(main())

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 = [0]*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:
#ai <= min(bi-1,bi) and a1 <= b1

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

Submission status: Accepted

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

ans = 0
ans += B[0]

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

Submission status: Accepted

Solution code:
def q3():
    N = int(input())
    B = [int(i) for i in input().split()]
    A = [10**5]*N
    for i in range(N-1):
        if A[i] > B[i]:
            A[i] = B[i]
        if A[i+1] > B[i]:
            A[i+1] = B[i]
    print(sum(A))

if __name__ == '__main__':
    q3()

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]
    elif i == N - 1:
        A[i] = B[i - 1]
    else:
        a = min(B[i - 1], B[i])
        A[i] = a

ans = sum(A)
print(ans)

Submission status: Accepted

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

A =[]

A.append(B[0])

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

A.append(B[n-2])

ans = sum(A)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int, input().split()))
blis = [float('inf')] + b + [float('inf')]
alis = []
for i in range(n):
    alis.append(min(blis[i], blis[i+1]))
print(sum(alis))

Submission status: Accepted

Solution code:
#C
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],b[i-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(1, N-1):
    ans += min(B[i-1], B[i])

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
n=I()
Bs=LI()
ans=Bs[0]+Bs[n-2]
for i in range(1,n-1):
    ans+=min(Bs[i],Bs[i-1])
print(ans)

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.append(min(B[i], B[i+1]))
A.append(B[N-2])
print(sum(A))

Submission status: Accepted

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

sum= B[0]+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 = [float('inf')] + list(map(int, input().split())) + [float('inf')]
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 = [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()]
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 = []
for i in range(len(b)):
    if i == 0:
        a.append(b[0])
    else:
        if b[i] >= b[i-1]:
            a.append(b[i-1])
        elif b[i] < b[i-1]:
            a.append(b[i])
a.append(b[-1])
print(sum(a))

Submission status: Accepted

Solution code:
n = int(input())
B = [int(x) for x in input().split()]
res = 0
for i in range(n):
  if i == 0:
    res += B[i]
  elif i < n - 1:
    res += min(B[i-1], B[i])
  else:
    res += B[i-1]
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
B=nl()
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[N-2]
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print( ret )