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

#output
A = [0] * N
A[0] = B[0]
A[N-1] = B[N-2]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = []

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

    A.append(A[0])
    A.append(B[N-2])


if N==2:
    A.append(B[0])
    A.append(B[0])


print(A)

Submission status: Wrong Answer

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

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

print(sum(A))

Submission status: Wrong Answer

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

A = [0] * N
for i in range(1, N-1):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i+1] = B[i]
A.insert(0, A[0])

print(sum(A))

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

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

print(sum(A))

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

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

print(sum(A))

Submission status: Wrong Answer

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

A = []
a = 99999
for b in reversed(B):
    if b < a:
        A.insert(0, b)
        a = b
    else:
        A.insert(0, a)
A.insert(0, A[0])

sum = 0
for a in A:
    sum += a

print(sum)

Submission status: Wrong Answer

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

A = []
a = 99999
for b in reversed(B):
    if b < a:
        A.insert(0, b)
        a = b
    else:
        A.insert(0, a)
A.insert(0, A[0])

sum = 0
for a in A:
    sum += 0

print(sum)

Submission status: Wrong Answer

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

print(sum(a))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

B_lst = list(map(int,input().split()))
A_lst = [0] * n

for i in range(n-2):
    if B_lst[i+1] > B_lst[i]:
        A_lst[i] = B_lst[i]
    else:
        A_lst[i] = B_lst[i+1]

if B_lst[n-3] > B_lst[n-2]:
    A_lst[n-2] = B_lst[n-2]
else:
    A_lst[n-2] = B_lst[n-3]

A_lst[n-1] = B_lst[n-2]
print(sum(A_lst))

Submission status: Wrong Answer

Solution code:
n = int(input())

B_lst = list(map(int,input().split()))
A_lst = [0] * n

for i in range(n-2):
    if B_lst[i+1] > B_lst[i]:
        A_lst[i] = B_lst[i]
    else:
        A_lst[i] = B_lst[i+1]

if B_lst[n-3] > B_lst[n-2]:
    A_lst[n-2] = B_lst[n-2]
else:
    A_lst[n-2] = B_lst[n-3]

A_lst[n-1] = B_lst[n-2]
print(A_lst)
print(sum(A_lst))

Submission status: Wrong Answer

Solution code:
n = int(input())

B_lst = list(map(int,input().split()))
A_lst = [0] * n

for i in range(n-1):
    if B_lst[i] > B_lst[i-1]:
        A_lst[i] = B_lst[i-1]
    else:
        A_lst[i] = B_lst[i]

    if i == n-2:
        A_lst[i+1] = B_lst[i]
        break

print(sum(A_lst))

Submission status: Wrong Answer

Solution code:
n = int(input())

B_lst = list(map(int,input().split()))
A_lst = [0] * n

for i in range(n-1):
    if B_lst[i] > B_lst[i-1]:
        A_lst[i] = str(B_lst[i-1])
    else:
        A_lst[i] = str(B_lst[i])

    if i == n-2:
        A_lst[i+1] = str(B_lst[i])
        break

list = ' '.join(A_lst)
print(list)

Submission status: Wrong Answer

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

result = B[0]

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

print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    B = inputList()
    
    ans = 0
    for i,val in enumerate(B):
        ans += val
            
    ans += B[0]
    print(ans)
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))  # len = n-1
b_prime = [101] + b + [101]  # len = n+1

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def solve():
    N, *bl = map(int, open(0).read().split())
    al = [0] * N
    al[0], al[-1] = bl[0], bl[-1]
    max_num = bl[-1]
    
    for i in range(1, N-1):
        al[i] = min(bl[i-1], bl[i], max_num)
    
    print(sum(al))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
MAX_N = 10000


def main():
    N, *B = map(int, open(0).read().split())
    B.insert(0, MAX_N)
    B.insert(N, MAX_N)
    print(sum(min(B[i - 1], B[i]) for i in range(1, N + 1)))
    return


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(sum(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
li_b = list(map(int, input().split()))
li_a = [99999] * n

for idx, b in enumerate(li_b):
    if idx == 0:
        li_a[0] == b
    if idx == n - 1:
        li_a[-1] == b
    else:
        li_a[idx] = min(li_a[idx], b)
        li_a[idx + 1] = min(li_a[idx + 1], b)
print(sum(li_a))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(6)
B = np.array('0 153 10 10 23'.split(), dtype=int)[::-1]

ret = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1

ret += B[-1]
print(ret)

Submission status: Wrong Answer

Solution code:

import numpy as np
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

ret = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

ret = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = [int(item) for item in input().split()]

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

print(ans)

Submission status: Wrong Answer

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

l = [B[0]]
for i in range(1,N-1):
    print(i)
    l.append(min(B[i-1], B[i]))
l.append(B[-1])

print(sum(l))

Submission status: Wrong Answer

Solution code:

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

B.reverse()
bmin = B[0]
for i in range(len(B)):
    if B[i] > bmin:
        B[i] = bmin
    elif B[i] < bmin:
        bmin = B[i]

B.reverse()

print(B[0] + sum(B))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

list2 = []
list2.append(list1[0])
for i in range(n-1):
    list2.append(min(list1[(n-2)-i:]))
print(sum(list2))

Submission status: Wrong Answer

Solution code:
# C - Maximal Value
n = (int)(input())
b = list(map(int, input().split()))

a = [0] * n

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

print(sum(a))

Submission status: Wrong Answer

Solution code:
# C - Maximal Value
n = (int)(input())
b = list(map(int, input().split()))

a = [0] * n

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

print(sum(a))

Submission status: Wrong Answer

Solution code:
# C - Maximal Value
n = (int)(input())
b = list(map(int, input().split()))

a = [0] * n

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

print(sum(a))

Submission status: Wrong Answer

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

arrayA = [arrayB[0]]

for k in range(0,n-2):

    if arrayB[k] < arrayB[k-1]:
        arrayA.append(arrayB[k])

    else:
        arrayA.append(arrayB[k-1])

arrayA.append(arrayB[n-2])

print(sum(arrayA))

Submission status: Wrong Answer

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

a = [0]*n

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
Bi = list(map(int, input().split()))
#想定される最大値を受け取る配列の準備
AiMaxs = []
for i in range(N):
    AiMaxs.append(0) 
    
for i in range(N-2):
    if i+1 <=N-2 and Bi[i] <= Bi[i+1]:
        AiMaxs[i] = Bi[i]
        AiMaxs[i+1] = Bi[i]
    if i+1 <= N-2 and Bi[i] > Bi[i+1]:
        AiMaxs[i] = Bi[i]
        
print(sum(AiMaxs))

Submission status: Wrong Answer

Solution code:
N = int(input())

B = list(map(lambda x:int(x), input().split()))

ans = B[0]

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

  
if len(B) != 1:
  ans += B[-2]
else:
  ans += B[0]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

B = list(map(lambda x:int(x), input().split()))

ans = B[0]

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

  
if len(B) != 1:
  ans += max(B[-1], B[-2])
else:
  ans += B[0]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = [b[0],b[-1]]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(1, N):
    if S[i] > S[i-1]:
        S[i] = S[i-1]

print(sum(S))

Submission status: Wrong Answer

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

cnt = S[0]
for i in range(1, N):
    if S[i] <= S[i-1]:
        cnt += S[i]
    else:
        cnt += S[i-1]
        S[i] = S[i-1]

print(cnt)

Submission status: Wrong Answer

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

cnt = S[0]
for i in range(1, N):
    if S[i] <= S[i-1]:
        cnt += S[i]
    else:
        cnt += S[i-1]
        S[i] = S[i-1]
        print(S)

print(cnt)

Submission status: Wrong Answer

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

cnt = S[0]
for i in range(1, N-1):
    if S[i] <= S[i-1]:
        cnt += S[i]
    else:
        cnt += S[i-1]
        S[i] = S[i-1]

print(cnt+S[-1])

Submission status: Wrong Answer

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

cnt = S[0]
for i in range(1, N-1):
    if S[i] <= S[i-1]:
        cnt += S[i]
    else:
        cnt += S[i-1]
        S[i] = S[i-1]
print(cnt)

Submission status: Wrong Answer

Solution code:

a= int(input())
l = list(map(int,input().split()))
l = l[::-1]
s = 0 
for n,(x,y) in enumerate(zip(l,l[1:])):
    s+= min(x,y)
print(s+l[0])

Submission status: Wrong Answer

Solution code:
a= int(input())
l = list(map(int,input().split()))
l = l[::-1]
t = l[0]
s = t
for n , x in enumerate(l[1:-1]):
    if x < t:  t = x
    s+=t
    # print(t)
print(s+l[-1])

Submission status: Wrong Answer

Solution code:
a= int(input())
l = list(map(int,input().split()))
l = l[::-1]
t = l[0]
s = t
for n , x in enumerate(l[1:]):
    if x < t:  t = x
    s+=t
    # print(t)
print(s+l[-1])

Submission status: Wrong Answer

Solution code:
a= int(input())
l = list(map(int,input().split()))
l = l[::-1]
t = l[0]
s = t
for n , x in enumerate(l[1:]):
    if x < t:  t = x
    s+=t
    # print(t)
print(s+t)

Submission status: Wrong Answer

Solution code:

a= int(input())
l = list(map(int,input().split()))
l = l[::-1]
t = 100000000
s = 0
for n , x in enumerate(l):
    if x < t:  t = x
    s+=t
print(s+t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
s = B[N-2]
for i in range(N-1):
    if B[N-2-i] >= B[N-3-i]:
        s+=B[N-3-i]
    else:
        s+=B[N-2-i]

print(s)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    array = list(map(int, input().split()))
    sum_value = array[-1]
    for i in reversed(range(n-1)):
        if array[i - 1] <= array[i]:
            sum_value += array[i - 1]
        else:
            array[i - 1] = array[i]
            sum_value += array[i - 1]
    print(sum_value)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
Bn = list(map(int, input().split()))
Bn = [999] + Bn + [999]

Astar = [
  min(Bn[i], Bn[i+1])
  for i in range(N)
]
print(sum(Astar))

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(elem) for elem in input().split()]
a = [b[n - 2]]

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

print(sum(a))

Submission status: Wrong Answer

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

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

A[N - 1] = B[N - 2]
print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
B = list(map(int, input().split())) 
A=np.zeros([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])

int(A.sum())

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
B = list(map(int, input().split())) 
import numpy as np
A=np.zeros([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])

int(A.sum())

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split())) 
sum(A)+min(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [100000] + [int(e) for e in input().split(" ")] + [100000, 100000]
ans = 0
for i in range(N):
    ans += min(B[i], B[i+1], B[i+2])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input()) -1

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

sum = 0

for x in range(0, N -1, 1):
	
	y = N - x -1
	
	if x == 0:
		print(y)
		print(list1)
		sum += list1[y]

	elif (y > 0):
		if list1[y-1] > list1[y]:
			list1[y-1] = list1[y]
		sum += list1[y]

	else:
		sum += list1[x]
print(sum)

Submission status: Wrong Answer

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

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

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

print(S)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

B = [100] + B + [100]
s = 0
for i in range(len(B) - 1):
    s += min(B[i], B[i + 1])
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
B = [int(e) for e in input().split()]
A = [B[0]]
for i in range(n-2):
    A.append(min(B[i:i+2]))
A.append(max(B[-2:]))
print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = input()
N = int(N)
B = np.hstack([int(a) for a in input().split()])

A = np.zeros(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(np.sum(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
temp = input().split()
B = []
for i in range(N-1):
  B.append(int(temp[i]))

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

for i in range(N):
  total += A[i]
print(total)

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int,input().split()))
print(B)
A=[]
A.append(B[0])
A.append(B[N-2])

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

N = int(sys.stdin.readline())

a = []
b = list(map(int, sys.stdin.readline().rstrip().split()))

# print(b)
# aはbよりも1項多い
for i in range(N):
  print(i)
  
  if i == 0:
    a.append(b[i])
  elif i == N - 1:
    a.append(b[i-1])
  else:
    a.append(min(b[i-1], b[i]))


print(sum(a))

Submission status: Wrong Answer

Solution code:
N=int(input())
B=[int(b) for b in input().split()]
A=[int(a) for a in range(N)]



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

print(sum(A))
print(A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input()) #waiting_for_pudging
b = list(map(int, input().split())) #waiting_for_pudging
summ = 0 #waiting_for_pudging
for i in range(1, len(b) - 1): #pudging
    if b[i] > b[i - 1] and b[i] > b[i + 1]: #pudging
        b[i] = max(b[i - 1], b[i + 1]) #pudging
for i in range(1, len(b)): #pudging
    summ += b[i] #pudging
print(summ + 2 * b[0]) #pudging
#accepted

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in str(input()).split(" ")]
a = [0] * (n)

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

print(a)

Submission status: Wrong Answer

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

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

    answer = 0

    a_list = [0] * n

    a_list[n-1] = b_list[n-2]

    for i in reversed(range(n)):
        if(i == 0):
            break
        if(b_list[i-1] >= b_list[i-2]):
            a_list[i-1] = b_list[i-2]
        else:
            a_list[i-1] = b_list[i-1]

    for i in range(n):
        answer += a_list[i]

    print(answer)

if __name__ == "__main__":
    main()

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]
print(sum(B)+B[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N-1):
    if i==0:
        sum += b[0]
    elif i==N-2:
        sum += b[N-2]
    else:
        sum += min([b[i], b[i+1]])
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c =[]

c.append(b[0])

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

c.append(b[n-2])
print(c)
print(sum(c))

Submission status: Wrong Answer

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

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

for i in range(c-2):
    _tmp = b[i]
    while(b[i] < max(a[0], _tmp)):
        _tmp -= 1
    a.append(_tmp)

a.append(b[len(b)-1])
print(sum(a))

Submission status: Wrong Answer

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

a = [b[0],b[-1]]

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

Submission status: Wrong Answer

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans = 0
tmp_b = 0

tmp_b = 0
for b in B:
    max_a = min(tmp_b,b)
    ans += max_a 
    tmp_b = b

max_a = B[-1]
ans += max_a

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input()
list1 = list(map(int,a.split()))
list1.insert(0,list1[0])
maxint = list1[0]
for i in range(n):
    if maxint < list1[i]:
        for j in range(i):
            if list1[j] > list1[i]:
                list1[j] = list1[i]
cout = 0
for i in range(n):
    cout += list1[i]
print(cout)

Submission status: Wrong Answer

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

cout = 0
maxint,minint = 0,0
for i in range(n-1):
    if minint > list1[i]:
        for j in range(i):
            if list1[j] > list1[i]:
                list1[j] = list1[i]
    minint = list1[i]
maxint = 0
"""
for i in range(n-1):
    if list1[i] > maxint:
        maxint = list1[i]
        cout += maxint
    else:
        cout += maxint
"""
cout += list1[0]
for i in range(n-1):
    cout += list1[i]
print(cout)