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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
for j in range(n-2):
    if b[j]>b[j+1]:
        b[j]=int(b[j+1])

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

s=[0]*N

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

s[-1]=B[-1]

print(sum(s))

Submission status: Wrong Answer

Solution code:
N=int(input())
B=[int(i) for i in input().split()]
for j in range(N-2):
    if(B[j]>B[j+1]):
        B[j]=B[j+1]

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

Submission status: Wrong Answer

Solution code:
N = int(input())

list_B = list(map(int, input().split()))
myans = 0


for i in range(len(list_B)-1):
    myans += min(list_B[i], list_B[i+1])
    print(i, myans)
myans += list_B[-1]
        
        
if len(list_B) <= 2:
    myans += list_B[0]


    


print(myans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum = 0
flag = 0
last = 0
for i in range(n-2, -1, -1):
  if i == 0:
    sum += (li[i] * 2)
    break
  if flag == 1:
    sum += min(li) *(i+1)
    break
    
  if li[i] >= li[i-1]:
    sum += li[i]
  else:
    sum += (li[i] * 2)
    flag = 1
    
    
print(sum)

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int, input().split()))  #複数数値入力

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

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

  A.append( B[-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])  

print(ans+b[-1]+min(b))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

s=[0]*N

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

s[-1]=B[-1]

print(sum(s))

Submission status: Wrong Answer

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


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


s=sum(a)
print(s)

Submission status: Wrong Answer

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

a = []

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

#print(a)
print(sum(a))

Submission status: Wrong Answer

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

ans = 0
ans += list_b[0]
for i in range(N-1):
    if (i != 0) and (i != N-2):
        if (list_b[i] >= list_b[i-1]) and (list_b[i] <= list_b[i+1]):
            ans += list_b[i]
        else:
            ans += list_b[i+1]
    else:
        ans += list_b[i]  

print(ans)

Submission status: Wrong Answer

Solution code:
#code
n=int(input())
b=input()

b=b.split()

b=list(map(int,b))
a=list()
a.append(b[0])
a.append(b[0])
for i in range(1,len(b)-1):
    
    
    a.append(min(b[i],b[i+1]))
if(n>2):
    a.append(max(b[len(b)-1],a[len(a)-1]))
sum=0 
for i in range(len(a)):
    sum+=a[i]
print(sum)

Submission status: Wrong Answer

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

if N == 1:
    ans = B[0]*2
else:
    ans += min(B[0], B[1])

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

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
# スペース区切りの整数の入力
a = map(int, input().split())
alist = list(a)

tmp = []

for i in range(n-1):

    if i == 0:
        tmp.append(alist[i])
        tmp.append(alist[i])
    else:
        if i+2 < n and alist[i] > alist[i+1]:
            tmp.append(alist[i+1])
        else:
            tmp.append(alist[i])


sum = 0
for i in tmp:
    sum += int(i)

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A=[0 for i in range(N)] 
A[0]=B[0]
if N > 2:
  A[N-2]=min(B[N-2],B[N-3])
  A[N-1]=B[N-2]
  for i in range(1,N-2):
    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
if N>2:
    for i in range(N-1):
        if i==0 and B[0]!=0:
            A[0] = B[0]
        else:
            A[0] = 0
        if i!=0:
            A[i] = min(B[i-1],B[i])
    if B[-1]!=0:
        A[-1] = max(B[-1],B[-2])
    else:
        A[-1] = 0
    print(sum(A))
else:
    print(sum(B)*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
B=list(map(int, input().split()))
S=0
for x in reversed(range(0,N)):
    if x==N-1:
        S=S+B[N-2]
        AA=B[N-2]
    if x!=N-1 and x!=0:
        if AA>=B[x-1]:
            S=S+B[x-1]
            AA=B[x-1]
        if AA<B[x-1]:
            S=S+AA
            AA=AA
    if x==0:
        if AA>=B[0]:
            S=S+B[0]
        if AA<B[0]:
            S=S+AA
print(S)

Submission status: Wrong Answer

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

SUM = 0
A = [0]*N

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

    if i < N-2:
        if B[i] > B[i+1]:
            A[i+1] = B[i+1]
        else:
            A[i+1] = B[i]

    else:
        A[i+1] = B[i]


print(sum(A))

Submission status: Wrong Answer

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

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


#0 153 10 160 23
#?,0,  153,10,160,23
#?,0,  10, 10,160,23
#0,0,  10, 10,10 ,23

Submission status: Wrong Answer

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

    if N <= 2:
        print(B[0] * 2)
        return
    sum = B[0] * 2
    for i in range(2, N):
        if i == N-1:
            sum += B[N-2]
            break
        sum += min(B[i], B[i-1])

    print(sum)


if __name__ == '__main__':
    c()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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


A.append(A[-1])

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(0,len(b)):
    if b[i] < max(a[i],a[i+1]):
        a[i] = b[i]
        a[i+1] = b[i]
    
print(sum(a))

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin.readline
na = lambda: map(int, stdin().split())
ns = lambda: stdin().rstrip()
ni = lambda: int(ns())
def main():
  n = ni()
  b = list(na()) + [0]
  
  if n == 2:
    print(b[0]*2)
  else:
    a = []
    for i in range(n-1):
      if i == n-2:
        break
      if b[i] <= b[i+1]:
        a.append(b[i])
      else:
        a.append(b[i-1])
        a.append(b[i+1])
    print(sum(a)+b[-2])
main()

Submission status: Wrong Answer

Solution code:
N = int(input())

list_B = list(map(int, input().split()))
myans = list_B[0]*2



if len(list_B) >= 3:
    for i in range(1,len(list_B)-1):
        myans += min(list_B[i], list_B[i+1])
        #print(i, myans)
    myans += list_B[-1]
        
        
        
elif len(list_B) == 2:
    myans += list_B[1]

    


print(myans)

Submission status: Wrong Answer

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

A = [0] * n

if n == 2:
  A[0] = A[1] = B[0]
elif n == 3:
  A[0] = B[0]
  A[1] = min(B[0], B[1])
  A[-1] = B[-1]
elif n > 3:
  A[0] = B[0]
  A[-1] = B[-1]
  
  for i in range(1, n-1):
    A[i] = min(B[i-1], B[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
S = 0
temp = B[N-2]
for i in range(N):
    S += temp
    if N-i-3 >=0:
        if B[N-i-3] < temp:
            temp = B[N-i-3]

print(S)

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

if n == 2:
    print(min(b)*2)
else:
    print(ans+b[-1]+min(b))

Submission status: Wrong Answer

Solution code:
N = int(input()) # 長さNの整数列

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

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

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

print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
N = int(input())

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

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

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

	if i != 0:
		A[i - 1] = B[i - 1]


print(sum(A))

Submission status: Wrong Answer

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

list_a[0] = list_b[0]
list_a[1] = list_b[0]
for i in range(1, n-1):
  if list_b[i] < list_a[i]:
    list_a[i] = list_b[i]
    list_a[i+1] = list_b[i]
  else:
    list_a[i+1] = list_b[i]

print(list_a)
print(sum(list_a))

Submission status: Wrong Answer

Solution code:
from functools import reduce
N = int(input())

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


A = [B[0], B[0]]

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

ans = reduce(lambda x, y: x+y, A)
print(ans)

Submission status: Wrong Answer

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

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys
import copy


def main():
    N = int(input())
    B = [int(i) for i in input().split()]
    b = copy.deepcopy(B)

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

    for i in range(N-2):
        if b[i] < b[i+1]:
            b[i+1] = b[i]
    ans1 = sum(B)+B[0]
    ans2 = sum(b)+b[len(b)-1]
    print(ans1 if ans1 >= ans2 else ans2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 2019/09/07
# AtCoder Beginner Contest 140 - B

# Input
n = int(input())
b = list(map(int,input().split()))

# Calc
sum = 0
wkv = 999999
for i in range(n-2, -1, -1):
    if wkv > b[i]:
        wkv = b[i]
    sum = sum + wkv

if n == 2:
    ans = sum + b[0]
else:
    ans = sum + min(b[0], b[1])

# Output
print(ans)

Submission status: Wrong Answer

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

sum = 0
tmp = 10**5

for i in range(N-1):
    if B[i]<tmp:
        tmp = B[i]
    sum += tmp
sum += tmp

print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
b.sort()
if n > 3:
  print(sum(b[:-1])+sum(b[:2]))
elif n == 3:
  print(b[0]*2+b[1])
else:
  print(b[0]*2)

Submission status: Wrong Answer

Solution code:
N = int(input()) 
B = list(map(int, input().split())) 
A = [0] * (len(B)+1)
A[0] = B[0]
A[1] = B[0]
n = 1
for b in B[1:]:
  if n <= len(B)-2:
    if b <= B[1+n]:
      A[1+n] = b
    elif b > B[1+n]:
      A[1+n] = B[1+n]
  n += 1
A[-1] = B[-1]
print(sum(A))

Submission status: Wrong Answer

Solution code:
# C - Maximal Value
N = int(input())
B = list(map(int,input().split()))
A = [10**6]*N

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

print(A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(sum)

Submission status: Wrong Answer

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

ans = 0

for i in range(n):
  if n % 2 == 0:
    ans += a[i-1]
  
print(ans)

Submission status: Wrong Answer

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

b = sorted(b)
for i in b:
    if i==0:
        continue
    else:
        mini=i
        break
ans = sum(b)+mini-b[-1]
print(ans)

Submission status: Wrong Answer

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

arr = []
for i in range(len(b)):
    if i == 0:
        arr.append(b[i])
    elif b[i] <= b[i-1]:
        arr.append(b[i])
    else:
        arr.append(b[i-1])

    
arr.append(arr[-1])
print(sum(arr))

Submission status: Wrong Answer

Solution code:
N = int(input())

B = [int(n) for n in input().rstrip().split(' ')]
A = []

A.append(B[0])

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

  A.append(min(next, b))

if N > 2:
  A.append(max(B[-1], B[-2]))
else:
  A.append(max(B[0], B[0]))

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = 0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
Bs = list(map(int, input().split()))
As = []
As.append(Bs[0])
ai = Bs[0]
for i in range(N-1):
    if i==0:
        As.append(Bs[i])
    else:
        As.append(max(Bs[i], Bs[i-1]))
        
for i in range(N-1):
    if max(As[i], As[i+1])>Bs[i]:
        As[i] = Bs[i]
print(sum(As))

Submission status: Wrong Answer

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


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


s=sum(a)
print(s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
N = int(input())

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

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

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


print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    Bs = list(map(int, input().split()))
 
    A = np.zeros(N)
    ans = 0
    for i in range(N-1):
        b_c = Bs[i]
        if i == N-2:  # 最終
          A[i+1] = b_c
        elif i != N-2:  # 最終以外
            b_n = Bs[i+1]
            if b_c < b_n:
                A[i] = b_c
                A[i+1] = b_c
            elif b_c >= b_n:
                if i == 0:
                    A[i] = b_c
                A[i + 1] = b_n
 
    ans = np.int64(np.sum(A))
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

solution = [0]*n
for i in range(n):
    if i == 0:
        solution[i] = arr[i]
    if i == n-1:
        solution[i] = arr[i-1]
    else:
        solution[i] = min(arr[i-1], arr[i])

print(sum(solution))

Submission status: Wrong Answer

Solution code:
from functools import reduce
N = int(input())

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


A = [B[0], B[0]]

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

ans = reduce(lambda x, y: x+y, A)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
S = 0
temp = B[N-2]
for i in range(N):
    S += temp
    if N-i-3 >=0:
        if B[N-i-3] < B[N-i-2]:
            temp = B[N-i-3]

print(S)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    Bs = list(map(int, input().split()))
 
    A = np.zeros(N)
    ans = 0
    for i in range(N-1):
        b_c = Bs[i]
        if i == N-2:  # 最終
          A[i+1] = b_c
        elif i != N-2:  # 最終以外
            b_n = Bs[i+1]
            if b_c < b_n:
                A[i] = b_c
                A[i+1] = b_c
            elif b_c >= b_n:
                if i == 0:
                    A[i] = b_c
                A[i + 1] = b_n

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-1):
    a.append(min(b[i:n-1]))
print(sum(a))

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

Submission status: Wrong Answer

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

A = [0] * n

if n == 2:
  A[0] = A[1] = B[0]
elif n == 3:
  A[0] = A[1] = B[0]
  A[-1] = B[-1]
elif n > 3:
  A[0] = A[1] = B[0]
  A[-1] = B[-1]
  
  for i in range(2, n-1):
    A[i] = min(B[i-1], B[i])

print(sum(A))

Submission status: Wrong Answer

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

sum = 0
first = 0
for i in range(n-2, -1, -1):
  if i == 0:
    sum += li[i]*2
    break
  if li[i] >= li[i-1]:
    sum += li[i]
  else:
    sum += li[i] * 2
    break
print(sum)

Submission status: Wrong Answer

Solution code:
def main(): 
    
    N = int(input())
    A = []
    B = list(map(int, input().split()))
    B.insert(0, 100)
    B.append(100)

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
ans = 0
m = B[-1]
for n in reversed(B):
    if m<n:
        ans += m
    else:
        ans += n
        m = n
if m<n:
    ans += m
else:
    ans += n
    m = n
print(ans)

Submission status: Wrong Answer

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


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

a.append(b[0])
s=sum(a)
print(s)

Submission status: Wrong Answer

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

ans = B[0] + B[-1]
a = B[0]

for b in B[1:]:
    a = min(a, b)
    ans += a
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    a = ([min(b[0],b[1])] if n != 2 else [b[0]])
    for i in range(1,n-1):
        a.append(min(b[i-1],b[i]))
    a.append(b[-1])
    print(sum(a))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
tmp = B[-1]
i = 0
output = 0

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

elif N == 3:
    for i in range(N - 2):
        output += min(B[i], B[i + 1]) * 2

    print(output + tmp)

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

    print(output + tmp)

Submission status: Wrong Answer

Solution code:
while True:
    try:
        num = int(input())
        lst = list(map(int, input().split()))
        point = lst[-1]
        ans = 0
        for n in lst[-1::-1]:
            point = min(point, n)
            ans += point
        ans += point
        print(ans)
    except:
        break

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    Bs = list(map(int, input().split()))

    A = np.zeros(N)
    ans = 0
    for i in range(N-1):
        b_c = Bs[i]
        if i == N-2:  # 最終
          A[i+1] = b_c
        elif i != N-2:  # 最終以外
            b_n = Bs[i+1]
            if b_c < b_n:
                A[i] = b_c
                A[i+1] = b_c
            elif b_c >= b_n:
                A[i + 1] = b_n

    ans = np.int64(np.sum(A))
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# そのまま入力文字列の入力
n = int(input())
bn = list(map(int, input().split()))

an = []

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

for i in range(0, n - 1 - 1):
    b = bn[i]
    if i == 0:
        an.append(min(bn[0], bn[1]))
    an.append(min(bn[i], bn[i+1]))

an.append(max(an[-1], bn[-1]))

print(sum(an))

Submission status: Wrong Answer

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

def main():
    N = int(input())
    B = list(map(int,input().split()))
    B.reverse()
    Ap = B[0]
    S = 0
    for Bi in B:
        A = min(Bi,Ap)
        S += A
        Ap = A
    S += Ap
    print(S)
          

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

As = [ None for _ in range(N) ]

for i in range(N-1):
  i = N - i - 2
  if not As[i+1] or As[i+1] > Bs[i]:
    As[i+1] = Bs[i]
  
  As[i] = Bs[i]

print(sum(As))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

As = [ None for _ in range(N) ]

for i in range(N-1):
  i = N - i - 2
  if not As[i+1] or As[i+1] > Bs[i]:
    As[i+1] = Bs[i]
  
  As[i] = Bs[i]
  print(Bs)
  print(As)


print(sum(As))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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