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

cout = 0
maxint,minint = 0,0
cout += list1[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)

Submission status: Wrong Answer

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

cout = 0
maxint,minint = 0,0
cout += list1[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
cout += list1[0]
for i in range(n-1):
    if list1[i] > maxint:
        maxint = list1[i]
        cout += maxint
    else:
        cout += maxint

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
cout += list1[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

print(cout)

Submission status: Wrong Answer

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

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

print(max_val)

Submission status: Wrong Answer

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

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

print(max_val)

Submission status: Wrong Answer

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

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

print(max_val)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n =  int(raw_input())
B = map(int, raw_input().split())
B = [1000000] + B
print sum(min(B[i-1], B[i]) for i in range(1, n))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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



for i in range(len(B)):

    if i == 0:
        if len(B)==1 or B[i]<=B[i+1]:

            A.extend(B[:1]*2)

        elif B[i]>B[i+1]:

            A.extend(B[1:2]*2)

            
    if 0 < i < len(B)-1:

        if B[i]<B[i+1]:


            A.append(B[i])

        elif B[i]>=B[i+1]:

            A.append(B[i+1])

    if i!=0 and i==len(B)-1:

        A.append(B[i])
            
        
from functools import reduce

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

Submission status: Wrong Answer

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

    for n in range(N-2):
        A[n+1] = min(B[n+1],B[n])
    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 n in range(N-1):
    A[n] = min(B[n-1],B[n])
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 n in range(N):
    if n != N-1:
        A[n] = min(B[n-1],B[n])
    else:
        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[0],B[0]]

for i in range(1,len(B)):

    if i<len(B)-1 and B[i]>B[i+1]:

        A.append(B[i+1])

    else:

        A.append(B[i])
            
        

    
from functools import reduce

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

Submission status: Wrong Answer

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


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

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

    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

list_A = [0]*n

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

print(list_A)
print(sum(list_A))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    a = int(input())
    li_1 = list(map(int, input().split()))
    res = []
    for x in range(0, a - 1):
        if x == 0:
            res.append(li_1[x])
        else:
            res.append(min(li_1[x], li_1[x - 1]))
res.append(li_1[-1])
result = 0
for x in res:
    result += x

Submission status: Wrong Answer

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

list_A = [0]*n

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

print(list_A)
print(sum(list_A))

Submission status: Wrong Answer

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


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

else:
    A=[]
    for i in range(N-1):
        A.append(min(B[i-2],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()))


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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
B = list(map(int,input().split()))
A=[]
for i in range(len(B)-1):
  if B[i]<B[i+1]:
    heapq.heappush(A,B[i])
    heapq.heappush(A,B[i])
  if B[i]==B[i+1]:
      heapq.heappush(A,B[i])
if N == 2:
  heapq.heappush(A,B[0])
heapq.heappush(A,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-1):
    if i == 0:
        sum += b[0]
        pass
    sum += min(b[i-1],b[i])
sum += b[-1]
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

B.reverse()
result = [B[0]]
for i, e in enumerate(B):
    if i < len(B) - 1:
        result.append(min(B[i], B[i+1]))
    else:
        result.append(B[i])
print(result, sum(result))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
B_list = list(map(int,input().split()))
ans = 0

if N == 2:
  ans += B_list[0] * 2
  print(ans)
  sys.exit()
elif B_list[0] <= B_list[1]:
  ans += B_list[0] * 2
else:
  ans += B_list[1] * 2


for i in range(1,N-2):
  if B_list[i] <= B_list[i+1]:
    ans += B_list[i]
  else:
    ans += B_list[i+1]

ans += B_list[N-2]

print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    ans = b[0]
    for i in range(n-2):
      if b[i] > b[i+1]:
        b[i] = b[i+1]
    ans += b[-1]
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += min(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    for i in range(n-2):
      if b[i] > b[i+1]:
        b[i] = b[i+1]
    ans = b[0]+b[-1]
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += min(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    ans = b[0]+b[-1]
    for i in range(n-2):
      if b[i] > b[i+1]:
        b[i] = b[i+1]
    
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += min(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    ans = b[0]*2
    for i in range(n-2):
      if b[i] > b[i+1]:
        b[i] = b[i+1]
    
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += max(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    for i in range(n-2):
      if b[i] > b[i+1]:
        b[i] = b[i+1]
    
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += max(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
bl = [int(i) for i in input().split()]
al = []
memo = 0
for idx,i in enumerate(bl[::-1]):
    if idx in (0,n-1):
        al.append(i)
    else:
        al.append(min(i,al[idx-1]))
    memo = i
    
al.append(bl[0])
print(sum(al))

Submission status: Wrong Answer

Solution code:
n = int(input())

bl = [int(i) for i in input().split()]
al = []
memo = 0
for idx,i in enumerate(bl[::-1]):
    if idx == 0 or memo >= i:
        al.append(i)
    else:
        al.append(bl[idx-1])
    memo = i
    
al.append(bl[0])
print(sum(al))

Submission status: Wrong Answer

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

for i in range(n-1):
    if i == 0:
        ans_list.append(b_list[i])
        ans_list.append(b_list[i])
    elif b_list[i] < ans_list[i-1]:
        ans_list[i-1] = b_list[i]
        ans_list.append(b_list[i])
    else:
        ans_list.append(b_list[i])

print(sum(ans_list))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

output=0

for i in range(N):
   print("i",i)
   if (i==0):
      A[i]=B[i]
   elif(i==N-1):
      print("last",B[i-1])
      A[i]=B[i-1]
   else:
      if(B[i-1]<=B[i]):
         A[i]=B[i-1]
      else:
         A[i]=B[i]


# print("A:",A,"B:",B)
print(sum(A))

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]
cnt = 0
for i, x in enumerate(B):
    if i != 0:
        A[i + 1] = B[i]
        A[i] = min(A[i], B[i])
        cnt += A[i]
cnt += A[-1]
# print(A)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
b = list(map(int,input().split()))
score=b[n-2]
for i in range(n-1):
  if(n-i<2):
    break
  score+=min(b[n-2-i],b[n-3-i])

print(score)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
B_list = list(map(int,input().split()))
A_list = [0 for i in range(N)]

sum_aaa =0

sum_aaa = B_list[0]

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

sum_aaa += B_list[-1]
print(sum_aaa)

Submission status: Wrong Answer

Solution code:
N = int(input())
B_list = list(map(int,input().split()))
A_list = [0 for i in range(N)]

A_list[0] = B_list[0]

for i in range(N-1):
    A_list[i] = min(B_list[i],B_list[i-1])

A_list[-1] = B_list[-1]
print(sum(A_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


ans = []
c = list(reversed(a))
for i, name in enumerate(c):
    if i == 0:
        ans.append(name)
    else:
        b = min(name, c[i-1])
        ans.append(b)

print(sum(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

sum_A = B[0]

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

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  restrictionArray = list(map(int,input().split()))
  resultArray = [0] * (n+1)
  restrictionArray.append(1000)
  
  for i in range(n):
    resultArray[i] = min(restrictionArray[i],restrictionArray[i-1])
   
  resultSum = sum(resultArray)
  
  print(resultSum)
  
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
n = INT()
B = LIST()

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

Submission status: Wrong Answer

Solution code:
N=int(input())
B=[int(x) for x in input().split()]
bmax=max(B)
b2=[bmax]*(N+2)
b2[1:-2]=B
A=[0]*N
for i in range(N):
  A[i]=min(b2[i:i+3])
A[0]=B[0]
print(sum(A))

Submission status: Wrong Answer

Solution code:
N = input()
B = input().split(" ")
A = [0]*int(N)

B = list(map(int,B))
total = 0


A[0] = B[0]

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

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

print(total)

Submission status: Wrong Answer

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

A = [10 ** 6] * N

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

print(A)

Submission status: Wrong Answer

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

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

print(sum(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

  A[-1] = B[-1]

  print(sum(A))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy
input()
a = list(map(int,input().split()))
print(numpy.minimum(a[1:],a[:-1]).sum()+a[0]+a[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = [0] * N
B.append(10000)

A[0] = B[0]

for i in range(1, 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()))
A = [0] * N


B.append(10000)
# Aを決定していく いや決定の仕方がわからん

A[0] = B[0]


for i in range(1, 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()))
A = [0] * N


B.append(10000)
# Aを決定していく いや決定の仕方がわからん

A[0] = B[0]


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


B.append(10000)
# Aを決定していく いや決定の仕方がわからん

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

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_B = list(map(int, input().split()))
list_A = [0]*(len(list_B) + 1)

for i in reversed(range(len(list_B))):
    list_A[i + 1] = list_B[i]
    list_A[i] = list_B[i]

print(sum(list_A))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_B = list(map(int, input().split()))
list_A = [0]*(len(list_B) + 1)

for i in reversed(range(len(list_B))):
    list_A[i + 1] = list_B[i]
    list_A[i] = list_B[i]

print(list_A)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = []
for i in range(N):
    if not i == -1 and not i == N - 1:
        A.append(min(B[i - 1], B[i]))
    elif 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 = [int(x) for x in input().split()]

print((sum(b)+b[0]+b[-1])//2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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[1]=B[0]
A[n-1]=B[n-2]
for i in range(1,n-2):
    if B[i]<B[i+1]:
        A[i+1]=B[i]
    else:
        A[i+1]=B[i+1]

print(sum(A))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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

print(sum(a))

Submission status: Wrong Answer

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

A = [0] * N

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

Submission status: Wrong Answer

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

print(sum(ans)+min(b[:2])+b[-1])

Submission status: Wrong Answer

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

A = [0] * N


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

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

print(A)

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


for i in range(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()))

ans = b[-1]

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

print(ans)

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 Bs[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=[int(x) for x in input().split()]
bmax=max(B)
b2=[bmax]*(N+2)
b2[1:-2]=B
A=[0]*N
for i in range(N):
  A[i]=min(b2[i:i+3])
print(sum(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(sum(As))

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(n) for n in input().split()]
B.insert(0, 10**7)
B.append(10**7)
C = []
C.append(B[1])
for i in range(2, N-1):
    C.append(min(B[i-1], B[i]))
C.append(B[N-1])
print(sum(C))

Submission status: Wrong Answer

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

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

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

A += B[N-2]
print(A)

Submission status: Wrong Answer

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

a[0] = b[0]
if n >= 4:
    a[n-1] = b[n-2]
    for i in range(1,n-2,2):
        if b[i-1] <= b[i] <= b[i+1]:
            a[i] = b[i-1]
            a[i+1] = b[i]
        elif b[i-1] >= b[i] >= b[i+1]:
            a[i] = b[i]
            a[i+1] = b[i+1]
        elif b[i-1] < b[i] > b[i+1]:
            a[i] = b[i-1]
            a[i+1] = b[i+1]
        else:
            a[i] = b[i]
            a[i+1] = b[i]
elif n == 3:
    a[0] = b[0]
    a[1] = min(b[0], b[1])
    a[2] = b[1]
elif n == 2:
    a[0] = b[0]
    a[1] = b[0]

sum = 0
for i in range(n):
    sum += a[i]
print(sum)

Submission status: Wrong Answer

Solution code:
#Maximal Value

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

sum = B[0]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
c = input().split()
b = [int(n) for n in c]
if n == 2:
    N = b * 2
else:
    a = [b[0]]
    for i in range(1,n-1):
        x = min(b[i-1],b[i])
        a.extend(str(x))
    a.extend(str(b[n-2]))
    N = 0
    for i in range(n):
        N = N + int(a[i])

print(N)

Submission status: Wrong Answer

Solution code:

N = int(input())
b = list(map(int,input().split()))
ans = 0
if len(b)== 1:
    print(b[0]*2)
    exit()
for i in range(N-2):
    if i == 0:
        ans += 2*min(b[0],b[1])
        continue
    else:
        ans += min(b[i],b[i+1])
ans += b[-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
B=[int(_) for _ in input().split()]
ans=0
ans+=B[0]
ans+=B[0]
for i in range(1,len(B)):
  ans+=B[i]
 
  
print(ans)

Submission status: Wrong Answer

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

print(sum(a))

Submission status: Wrong Answer

Solution code:
#Maximal Value

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

if N > 2:
    sum = B[0] + B[N-2]

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

Submission status: Wrong Answer

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

lstA = []

if N == 2:
    print(lstB[0]+ lstB[0])
    exit(0)

for i in range(N-1):
    if i == 0:
        lstA.append( min(lstB[i],lstB[i+1]) )
    elif i == N-2:
        lstA.append( min(lstB[i-1],lstB[i]) )
    else:
        if (lstB[i-1] < lstB[i]):
            lstA.append( min(lstB[i],lstB[i+1]))
        else:
            lstA.append( min(lstB[i-1],lstB[i],lstB[i+1]))
            
        

lstA.append(lstB[N-2])
#lstA.append(lstB[N-2] if lstB[N-2] > lstB[N-3] else lstB[N-3])
print(sum(lstA))

Submission status: Wrong Answer

Solution code:
n = int(input())
Bs = list(map(int,input().split()))
ans = 0

if n==2:
    ans = Bs[0]*2

elif n==3:
    ans += sum(Bs)
    ans += min(Bs)

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    B = list(map(int,input().split()))
    ans = 0
    if N == 2:
        print(B[0]*2)
        return
    for i in range(N-1):
        if  i == 0:
            ans += min(B[0],B[1])
        elif i == N-2:
            ans += min(B[N-3],B[N-2])
        else:
            ans += min(B[i-1],B[i],B[i+1])
    ans += B[N-2]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
b_rev = b[::-1]
ans = 0
mem = 0
#l = []
for i in range(n-2):
    if b_rev[i] >= b_rev[i+1]:
        #print(b_rev[i])
        ans += b_rev[i]
        #mem = b_rev[i]
        #l.append(b_rev[i])
    else:
        ans += b_rev[i]
        b_rev[i+1] = b_rev[i]
        #l.append(mem)
ans += b_rev[-1]*2
print(int(ans))

Submission status: Wrong Answer

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

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

print(sum(a))

Submission status: Wrong Answer

Solution code:
from functools import reduce
n=int(input())
b=list(map(int, input().split()))
b.extend([b[n-2],b[n-2]])

a=[]
j=0
for i in range(n):
    if i < 2:
        a.append(b[j])
        continue

    a.append(max(b[j], b[j+1]))
    print(a)
    if b[j+1] <= a[i]:
        a[i-1]=min(b[j], b[j+1])
        a[i]=min(b[j], b[j+1])
    j+=1

print(reduce(lambda x,y: x+y, a))

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int,input().split()))
count = 0
for i in range (len(arr)):
  if i < len(arr)-1 and i !=len(arr)-1:
    if arr[i] > arr[i+1]:
      count =count + arr[i+1]
    else:
      count =count+arr[i]
  elif i ==len(arr)-1:
    count =count+arr[i]
print(count)