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: Wrong Answer

Solution code:
n = int(input())
bn = [int(num) for num in input().split()]

an = [0]*n
an[0] = bn[0]
an[n-1] = bn[n-2]
for i in range(1,n-1):
    s = min(bn[i],bn[i-1])
    an.append(s)
    
print(sum(an))
print(an)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

# 双対考える
# A1<=B1, A2<= min(B1,B2), A3<=min(B2,B3) ...
A = [B[0]]

for i in range(N-1):
    if i+1 != len(B):
        A.extend([min(B[i],B[i+1])])
    else:
        A.extend([max(B[i-1],B[i])])


print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
b.reverse()
ans=b[0]
num=b[0]
for i in range(1,len(b)):
    if b[i]<num:
        num=b[i]
    ans+=num
print(ans+num)

Submission status: Wrong Answer

Solution code:
print(input().split())

Submission status: Wrong Answer

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

# A_1 <= B_1
# A_2 <= min(B_1, B_2)
# A_3 <= min(B_2, B_3)
# A_(N-1) <= min(B_(N-2), B_(N-1))
# A_N <= B_(N-1)
# ans = B_1 + min(B_1, B_2) + ... + min(B__(N-2), B_(N-1)) + B_(N-1)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
prev = b[0]
cnt = 0
for i in b:
    if i >= prev:
        cnt += prev
        prev = i
    else:
        cnt += i
        prev = i
cnt += max(b[0], b[-1])
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = B[0]
for i in B:
    ans += i
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    B_list = list(map(int, input().split()))

    sum_a0_a1 = B_list[0]*2
    if n == 2:
        print(sum_a0_a1)
        return  
    last_a = B_list[n-2]
    sum_other_a = 0

    for i in reversed(range(1,n-2)):
        min_b = min(B_list[i+1],B_list[i])
        sum_other_a += min_b

    print(sum_a0_a1+ last_a + sum_other_a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
bl = inpl()
ansl = []
for i in range(0, n + 1):
    ansl.append(mod)
for i in reversed(range(0, n)):
    ansl[i] = min(bl[i - 1], ansl[i + 1])
ansl[n] = 0
ansl[0] = bl[0]
print(sum(ansl))

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
bl = inpl()
ansl = []
for i in range(0, n + 1):
    ansl.append(mod)
for i in reversed(range(0, n)):
    ansl[i] = min(bl[i - 1], ansl[i + 1])
ansl[n] = 0
print(sum(ansl))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()
B = LI()

A = [0]*N

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
B = inintl()[::-1]

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

prev = B[0]
ans = prev + 2*B[n-2]

for i in range(1,n-2):
    if B[i] <= prev:
        ans += B[i]
    else:
        ans += prev
    prev = B[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
B = inintl()[::-1]

prev = B[0]
ans = prev

if n == 3:
    for i in range(1,n-2):
        if B[i] <= prev:
            ans += B[i]
        else:
            ans += prev
        prev = B[i]
else:
    for i in range(1,n-2):
        if B[i] <= prev:
            ans += B[i]
        else:
            ans += prev
        prev = B[i]

ans += B[n-2]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
a = []
m = 0
if N == 2:
    print(B[0] * 2)
elif N == 3:
    print(B[0] + B[1] + min(B[0],B[1]))
else:

    for i in range(N - 1):
        if i == 0:
            a.append(B[i])
        elif i == N - 2:
            a.append(max(a[i - 1],B[i]))
        else:
            if max(B[i],B[i - 1]) <= B[i + 1]:
                a.append(B[i])
            else:
                a.append(B[i + 1])
    

for i in range(len(a)):
    m += a[i]
print(m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#52 1日かかった
N = int(input())
b = list(map(int,input().split()))
a = [0 for i in range(N)]

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

a[-1] = b[-1]
            
        
    

print(sum(a))

Submission status: Wrong Answer

Solution code:
#52 1日かかった
N = int(input())
b = list(map(int,input().split()))
a = [0 for i in range(N)]

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

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

Submission status: Wrong Answer

Solution code:
#52 1日かかった
N = int(input())
b = list(map(int,input().split()))
a = [min(b) for i in range(N)]

for i in range(N-1):
    while b[i] > max(a[i],a[i+1]): 
        a[i+1] += 1
    while b[i] < max(a[i],a[i+1]):
        a[i] -= 1
    if i <= N-3:
        if b[i] == b[i+1]:
            a[i+2] = a[i+1] = a[i]
            

print(sum(a))

Submission status: Wrong Answer

Solution code:

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

    a = [0]*n

    for i,e in enumerate(b):
        if i == 0:
            a[0] = b[0]
        else:
            a[i] = min(b[i-1], b[i])

    a[-1] = b[-1]
            # if a[i] >= a[i+1] and e <= b[i-1]:
            #     a[i] = e
            # else:
            #     a[i+1] = e

    print(a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    blis = list(map(int, input().split()))

    alis = [blis[0], blis[0]]
    if n > 2:
        for i in range(3, n):
            alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    blis = list(map(int, input().split()))

    alis = [blis[0], blis[0]]
    if n > 3:
        for i in range(2, n):
            alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    blis = list(map(int, input().split()))

    alis = [blis[0], blis[0]]
    for i in range(2, n):
        alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
lb = [int(w) for w in input().split()]

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

for i in range(len(b)):
    a.append(b[i])

print(sum(a))

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout


if __name__=="__main__":

    n=int(stdin.readline())
    b=[int(x) for x in stdin.readline().split()]
    b.append(1000000)

    s=b[0]

    for i in range(n-1):
        if b[i]>b[i+1]:
            s+=b[i+1]
        else:
            s+=b[i]
    stdout.write(str(s)+"\0")

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout


if __name__=="__main__":

    n=int(stdin.readline())
    n-=1
    b=[int(x) for x in stdin.readline().split()]

    s=b[0]

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

    stdout.write(str(s)+"\0")

Submission status: Wrong Answer

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

A = list()
A.append(B[N-2])
for i in range(N-1):
    if B[N-2-i]>=B[N-3-i]:
        A.append(B[N-3-i])
    else:
        A.append(B[N-2-i])

for t in range(1,len(A)-1):
    if A[t-1]<A[t]:
        A[t] = A[t-1]

print(sum(A))

Submission status: Wrong Answer

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

A = list()
A.append(B[N-2])
for i in range(N-1):
    if B[N-2-i]>=B[N-3-i]:
        A.append(B[N-3-i])
    else:
        A.append(B[N-2-i])
print(sum(A))

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout


if __name__=="__main__":

    n=int(stdin.readline())
    n-=1
    b=[int(x) for x in stdin.readline().split()]

    s=b[0]

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

    stdout.write(str(s)+"\0")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

def solve():
    A = [0]*N
    A[-1] = 10**6
    A[0] = 10**6
    for i in range(N-2,0,-1):
        A[i] = min(A[i+1], B[i-1])
#        print(i)
    A[-1] = B[-1]
    A[0] = B[0]
#    print(A)
    print(sum(A))

if __name__ == "__main__":
    N = int(input())
    B = list(map(int, input().split()))
    solve()

Submission status: Wrong Answer

Solution code:

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

if __name__ == "__main__":
    N = int(input())
    B = list(map(int, input().split()))
    solve()

Submission status: Wrong Answer

Solution code:

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

if __name__ == "__main__":
    N = int(input())
    B = list(map(int, input().split()))
    solve()

Submission status: Wrong Answer

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

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

print(sum(a))

Submission status: Wrong Answer

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

for i in range(n-1):
    if len(B) == 1:
        print(2*B[i])
        exit()
    elif B[i] <= B[i-1]: 
        A[i] = B[i]
        A[i+1] = B[i]
    else:
        A[i+1] = B[i]
print(sum(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 9)


# map(int, sys.stdin.read().split())


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    B = list(map(int,input().split()))
    B.append(1000)
    A =[]
    A.append(B[0])
    for i in range(N-1):
        a =min(B[i],B[i+1])
        A.append(a)
    print(sum(A))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = [b[0]]

for i in range(n-2):
    if b[i] <= b[i+1]:
        ans.append(b[i])
    else:
        ans.append(b[i+1])

ans.append(b[len(b)-1])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main(N, X):
    def calc_cost(p):
        return sum((x-p)**2 for x in X)

    return min(map(calc_cost, range(max(X) + 1)))


if __name__ == "__main__":
    N = int(input())
    X = list(map(int, input().split()))
    ans = main(N, X)
    print(ans)

Submission status: Wrong Answer

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
import copy

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

As = [copy.copy(Bs[0])]
As.extend(copy.copy(Bs))

#print(Bs)
#print(As)

for index, B in enumerate(Bs):
    print(Bs)
    print(As)
    if B < As[index]:
        As[index] = B

#print(As)
print(sum(As))

Submission status: Wrong Answer

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

As = [Bs[0]]
As.extend(Bs)

#print(Bs)
#print(As)

for index, B in enumerate(Bs[1:]):
    if B < As[index]:
        As[index] = B

print(sum(As))

Submission status: Wrong Answer

Solution code:

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

result = B[0]
for i in range(len(B)):
    if i == 0:
        result += B[0]
    elif i == len(B) - 1:
        result += B[i]
    elif(B[i] >= B[i+1]):
        result += B[i+1]
    else:
        result += B[i]

print(result)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

B.append(float('inf'))

mins = [min(B[0], B[1])]

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

print(sum(mins))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

alis = [0]*n

alis[0] = blis[0]

for i in range(n-1):
    alis[i+1] = blis[i]
    
print(sum(alis))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
ans = [-1] * n
ans[-1]=b[-1]
for i,B in enumerate(reversed(b)):
#    print('r=',ans[n-i-1], 'l=', ans[n-i-2])
    if ans[n-i-1]>B:
       ans[n-i-1]=B
    ans[n-i-2]=min(B,ans[n-i-1])
print(sum(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(x) for x in input().split()]
sum=0
n=len(l)
for i in range(0,n):
    if(i==0):
        sum=sum+(l[i]*2)
    elif(i==n-1):
        sum=sum+l[i]
    else:
        if(l[i]<=l[i+1]):
            sum=sum+l[i]
        else:
            sum=sum+l[i+1]
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = b[0] + b[-1]
for i in range(len(b)-2):
    c = [b[i+1],b[i+2]]
    result += min(c)
if n == 3:
    result = b[0]*2 + b[1]

print(result)

Submission status: Wrong Answer

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

print(sum)

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int,input().split()))
A=[B[0],B[-1]]
if N==3:
  A.append(min(B))

for i in range(N-3):
  
  if max(B[i],B[i+1])<=B[i+2]:
    A.append(max(B[i],B[i+1]))
  else:
    A.append(B[i+2])
print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
B = IL()[::-1]

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

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

P(sum(A))

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
B = IL()[::-1]

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

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