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()))
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]
        elif temp > B[N-i-2]:
            temp = B[N-i-2]

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

print(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n - 1):
    if i == 0 and (n - 2) != 0:
        if b[i] > b[i + 1]:
            ans.append(b[i + 1])
        if b[i] < b[i + 1]:
            ans.append(b[i])
    if i == (n - 2):
        ans.append(b[i])
        if len(ans) != n:
            ans.append(b[i])
        continue

    if b[i] == b[i + 1]:
        ans.append(b[i])
    elif b[i] > b[i + 1]:
        ans.append(b[i+1])
    elif b[i] < b[i + 1]:
        ans.append(b[i])

print(sum(ans))

Submission status: Wrong Answer

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

max_no = [b[0]]
before = 0
for n in b:
  m = n if before < n else before
  max_no.append(m)

print(sum(max_no))

Submission status: Wrong Answer

Solution code:
List=[list(map(int,input().split())) for i in range(2)]

c=[0]*(len(List[1])-1)

if len(List[1])==1:
  print(List[0][0]*List[1][0])
else:
  for i in range(len(List[1])-1):
    c[i]=min(List[1][i],List[1][i+1])
  d=sum(c)+List[1][-1]+min(List[1][0],List[1][1])
  print(d)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n = int(input())
b = list(map(int, input().split()))
 
a = []
a.append(b[0])
 
for i in range(0, n-1):
    if i == n-2:
        if b[n-2] > b[n-3]:
            a.append(b[n-2])
        else:
            a.append(b[n-3])
    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())
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]
        elif temp > B[N-i-2]:
            temp = B[N-i-2]

if N >2:
    if B[0] > B[1]:
        S = S + B[0] - temp  

print(S)

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

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

Submission status: Wrong Answer

Solution code:
#Maximal Value

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

sum = B[0] + B[N-2]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n > 3:
    for i in range(n-2): 
        if   b[i] < b[i+1]:
            tmp += b[i]
        elif b[i+1] < b[i]:
            tmp += b[i+1]
        else:
            tmp += b[i]
    tmp += b[n-2]
else:
    tmp = sum(b) + min(b)

print(tmp)

Submission status: Wrong Answer

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

arr = [float('inf')]
for i in range(len(b)):
    arr.append(min(b[i], arr[i]))
arr.append(arr[-1])
print(sum(arr[1:]))

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]) )
        break
    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:
a=0
n = int(input())
b = list(map(int, input().split()))

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
kind = int(input())
atLIST=[int(i) for i in input().split()]
atLIST.reverse()
num_max = atLIST[0]
sum_list = []
sumA = 0
for i in range(kind):
		if i == 0:
				sumA = sumA + atLIST[0]
				continue
		if i == (kind-1):
				sumA = sumA + atLIST[i-1]
				continue
		if atLIST[i-1] > atLIST[i]:
				sumA = sumA + atLIST[i]

		else:
				sumA = sumA + atLIST[i-1]


print(sum(sum_list))

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

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

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

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

Submission status: Wrong Answer

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

print(sum(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
List=[list(map(int,input().split())) for i in range(2)]

c=[0]*(len(List[1])-1)

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

d=sum(c)+List[1][-1]

print(d)

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]
        elif temp > B[N-i-2]:
            temp = B[N-i-2]

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

print(S)

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 += mem
        b_rev[i+1] = b_rev[i]
        #l.append(mem)
ans += b_rev[-1]*2
print(ans)

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]
        elif (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:
n=int(input())
b=list(map(int,input().split()))
for j in range(n-2):
    if b[j]>min(b[j+1:]):
        b[j]=min(b[j+1:])

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

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
    print(temp)
    if N-i-3 >=0:
        if B[N-i-3] < B[N-i-2]:
            temp = B[N-i-3]
        elif temp > B[N-i-2]:
            temp = B[N-i-2]

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

print(S)

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]
        elif (list_b[i] <= list_b[i-1]) and (list_b[i] <= list_b[i+1]):
            ans += list_b[i]
        elif(list_b[i-1] < list_b[i+1]):
            ans += list_b[i+1]
        elif(list_b[i-1] > list_b[i+1]):
            ans += list_b[i-1]
    else:
        ans += list_b[i]  

print(ans)

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

Submission status: Wrong Answer

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

#print(N,B)

A=[0]*N

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

for i in range(2,N-1):
  if B[i]<B[i-1]:
    A[i]=B[i]
  else:
    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()))
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:
# -*- coding: utf-8 -*-

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

max_A =[B[0]]
B.append(B[N-2])

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

print(sum(max_A))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

res = []
res.append(B[0])
res.append(B[0])
for i in range(1, len(B)):
    res[i - 1] = min(res[i - 1], B[i])
    res.append(B[i])

print(sum(res))

Submission status: Wrong Answer

Solution code:
kind = int(input())
atLIST=[int(i) for i in input().split()]
atLIST.reverse()
num_max = atLIST[0]
sum_list = []
for i in range(kind):
		if i == 0:
				sum_list.append(atLIST[0])
				continue
		if i == (kind-1):
				sum_list.append(sum_list[i-1])
				continue
		if atLIST[i-1] > atLIST[i]:
				sum_list.append(atLIST[i])
		else:
				sum_list.append(atLIST[i-1])

print(sum(sum_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i, b in enumerate(B):
  if N == 2 and i == 0: 
    A.append(B[i])
    A.append(B[i])
    break
  if i == 0:
    if B[i] <= B[i + 1]:
      A.append(B[i])
      A.append(B[i])
    else:
      A.append(B[i + 1])
      A.append(B[i + 1])
  elif i == len(B) - 1:
    if B[i] > B[i - 1]:
      A.append(B[i])
    else:
      A.append(B[i - 1])
  else:
    if B[i] <= B[i + 1]:
      A.append(B[i])
    else:
      A.append(B[i + 1])
#print(A)
print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
b_list = [int(i) for i in input().split()]
a_list = [0] * n
before_val = 0
for i in range(n-1):
    target = b_list[i]
    if a_list[i] == before_val:
        a_list[i], a_list[i+1] = b_list[i], b_list[i]
    else:
        a_list[i+1] = b_list[i]
print(sum(a_list))

Submission status: Wrong Answer

Solution code:
#Maximal Value

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N =	 int(input())
L1 = list(map(int,input().split()))
#L2 = list(map(int,input().split()))
#L3 = list(map(int,input().split()))
 
L1.append(L1[-1])
L1.reverse()
#print(L1)

C= []
for n in range(N):
  if L1[n-1] >= L1[n]:
    C.append(L1[n])
  else:
    C.append(L1[n-1])
    

print(sum(C))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

if len(list_B) != 1:
    myans += list_B[-1]

print(myans)

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]=b[j+1]
if b[-1]!=max(b):
    print(b[0]*n)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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 += mem
        b_rev[i+1] = b_rev[i]
        #l.append(mem)
ans += b_rev[-1]*2
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
num = int(input())

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

a=[arr[0]]
for i in range(1,num-1):
    a0 = min(arr[i],arr[i-1])
    print(a0)
    a.append(a0)
a.append(arr[-1])

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]
        elif (list_b[i] < list_b[i-1]) and (list_b[i] < list_b[i+1]):
            ans += list_b[i]
        elif (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:
N = int(input())
B =  [int(i) for i in input().split()]

A = [0] * N
sub= [0] * N
ans = 0

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

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

A[0] = B[0]
A[-1] = B[-1] 
A[N-2] = min(B[N-2], B[N-3])

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i, b in enumerate(B):
  if N == 2 and i == 0: 
    A.append(B[i])
    A.append(B[i])
    break

  if i == 0:
    if B[i] < B[i + 1]:
      A.append(B[i])
      A.append(B[i])
    else:
      A.append(B[i + 1])
      A.append(B[i + 1])
  elif i == len(B) - 1:
    A.append(B[i])
  else:
    if B[i] < B[i + 1]:
      A.append(B[i])
    else:
      A.append(B[i + 1])
#print(A)
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)
    exit()

an=(b[0]*2)+b[-1]

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

print(an)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = [0] * N
sub= [0] * N
ans = 0

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

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

A[0] = B[0]
A[-1] = B[-1] 
A[N-2] = min(B[N-2], B[N-3])

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

print(ans)

Submission status: Wrong Answer

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

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 += lst[0]
        print(ans)
    except:
        break

Submission status: Wrong Answer

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

if bb == b or bb == sorted(bb, reverse=True):
  print(sum(b)+sum(b[:1]))
else:
  if bb[0] >= bb[1]:
    for i in range(n-2):
      if bb[i] < bb[i+1]:
        m = i+1
  else:
    for i in range(n-2):
      if bb[i] > bb[i+1]:
        m = i
  print(sum(b)+sum(b[:2])-bb[m])

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]
            
if N >2:
    if B[0] > B[1]:
        S = S + B[0] - B[1]   

print(S)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
b = na()

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

print(ans)

Submission status: Wrong Answer

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

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

else:
  a[0]=b[-1]
print(sum(a))

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]
            
if N >2:
    if B[0] > B[1]:
        S = S + B[0] - B[1]

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] > arr[i-1]:
        arr.append(arr[i-1])
    elif b[i] <= arr[i-1]:
        arr.append(b[i])
    else:
        arr.append(arr[i-1])

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

Submission status: Wrong Answer

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

if B[N-2] < B[N-3]:
    cnt += B[N-2]
    cnt -= (B[N-3]-B[N-2])
else:
    cnt += B[N-2]
cnt += B[0]

print(cnt)

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-1,1,-1):
    if(b[i] < b[i-1]):
        b[i-1] = b[i]
if(b[0]>b[1]):
    b[0] = b[1]

print(sum(b))

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[n-1]=b[n-2]   
a[0]=min(b[0],a[1])


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

Submission status: Wrong Answer

Solution code:
num = int(input())

arr = list(map(int,input().split()))
arr.append(arr[num-2])
a=[]
for i in range(1,num):
    a0 = min(arr[i],arr[i-1])

    a.append(a0)

a.append(a[-1])

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]
    elif i == n-1:
        solution[i] = arr[i-1]
    else:
        solution[i] = min(arr[i-1], arr[i])

print(solution)
print(sum(solution))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = [0] * N
sub= [0] * N
ans = 0

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

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

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

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

print(ans)

Submission status: Wrong Answer

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

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

    print(ans)

Submission status: Wrong Answer

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

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

s = b[0]+b[-1]
p = 0


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

print(s)

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( lstB[i] if lstB[i] < lstB[i+1] else lstB[i+1] )
    elif i == N-2:
        lstA.append( min(lstB[i-1],lstB[i]))
    else:
        lstA.append( min(lstB[i-1],lstB[i],lstB[i+1]))

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

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

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


result = result + B[0]

print(result)

Submission status: Wrong Answer

Solution code:
#C
N = int(input())
B = list(map(int,input().split()))
cnt = 0
for i in range(0,N-2):
    if i!=0 and B[i] > B[i+1]:
        cnt += B[i+1]
    else:
        cnt += B[i]

if B[N-2] < B[N-3]:
    cnt += B[N-2]
    cnt -= (B[N-3]-B[N-2])
else:
    cnt += B[N-2]
cnt += B[0]

print(cnt)

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(1,n-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]

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

Submission status: Wrong Answer

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

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

for i in range(2, N - 1):
    if i == N - 1:
        a = B[N - 1]
        print(N, 555)
    else:
        if B[i] > B[i -1]:
            a = B[i -1]
        else:
            a = B[i]
    A.append(a)
    
if N == 2:
    pass
else:
    A.append(B[N-2])

s = 0
for i in A:
    s += i
    
print(s)

Submission status: Wrong Answer

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

if n == 2:
    print(b[0]*2)
elif n==3:
    print(b[1]+min(b[0],b[1])*2)
else:
    co = [min(x , y) for (x, y) in zip(b[0:-1], b[1:])]
    if  b[-1]<b[-2]:
        print(sum(co)+b[-1]-b[-1]+b[-2])
    else:
        print(sum(co)+b[-1])