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_L = list(map(int, input().split()))
A_L=[]

for num in range(N-1):
    if num==0:
        A_L.append(B_L[num])
    A_L.append(B_L[num-1])

print(sum(A_L))

Submission status: Wrong Answer

Solution code:
N = input()
B = list(map(int, input().split()))
B_last = int(len(B))
A = B[0] + B[B_last - 1]
i = 1
old_b = B[0]
for i in range(B_last):
  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:
# -*- 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 and N >= 4:
            ans += min(B[i-1],B[i],B[i+1])
        else:
            ans += min(B[i-1],B[i])
    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()))

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] = A[i-1]
for a in A:
  sum += a
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

for i in range(1, N-2):
  prev = B[-1]
  next = B[i+1]
  b = B[i]
  
  max_b = (max(prev, b))
  min_b = (min(next, b))
  
  A.append(min_b)

if N > 2:
  A.append(B[-1])
  
print(sum(A))

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

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

Submission status: Wrong Answer

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

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

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

j = max(b[n-2],b[n-3])
a.append(j)

for i in range(n):
  ans += a[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
    print(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:
n = int(input())
b = [int(x) for x in input().split(' ')]

b.sort()
b.reverse()


cnt = 0 
ss = 0
for i in range(n-1) :
    cnt += b[i]
    ss = b[i]

print(cnt + ss)

Submission status: Wrong Answer

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

if n == 2:
  print(b[0] * 2)
  exit()
  
a.append(b[0])
for i in range(1,n-1):
  if b[i] > b[i-1]:
    c = b[i-1]
  else:
    c = b[i]
  a.append(c)
  if b[i] == b[len(b)-1]:
    a.append(b[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([0,0])

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

    a.append(max(b[j], b[j+1]))
    if b[j+1] <= a[i]:
        a[i-1]=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())
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 and len(A) != N:
    A.append(B[i])
  else:
    if B[i] <= B[i + 1]:
      A.append(B[i])
    else:
      A.append(B[i + 1])
print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
B = list(map(int, input().split()))
a = []
num = B[0]
if n == 2:
    print(B[0]*2)
    exit()
for i in range(n-1):
    if i == n-2:
        a.append(a[-1])
        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:
#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-1] < B[i] and B[i] > B[i+1]:
        cnt += max(B[i-1],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=[]

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 0
 
if N >= 3:
  for n in range(1,N-2):
    b = B[n]
    b_before = B[n-1]
    b_after = B[n+1]
    tmp = min(b,b_before)
    tmp = min(tmp,b_after)
    ans += tmp
    
  ans += min(B[0],B[1])
  ans += min(B[-2],B[-1])  
  ans += B[-1]
 
else:
  ans = B[0] * 2
 
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = input().split()
A = {}


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

print(sum(list(A.values())))

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)
elif 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-1):
        a[i]=min(b[i-1], b[i])
        print(i)
    ans =sum(a)
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
if n!=2:
    blist=list(map(int,input().split()))
    alist=[]
    for i in range(n-2):
        alist.append(min(blist[i],blist[i+1]))
    alist.append(blist[n-2])
    gokei=sum(alist)
    print(gokei)
else:
    b=int(input())
    print(int(b*2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 0
for ind in range(len(B)):
  hoge = min(B[ind:][0],B[ind+1:][0] if B[ind+1:] else 101)
  result += hoge
  if ind+2 == N[0]:
    break
    
for i in B:
  result += i
  
print (result)

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

print(sum(lstA))

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(n) for n in input().split()]
A=[]
if len(B)==1:
    print(B[0]*2)
else:
    A.append(B[0]*2)
    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:
hoge = input()
nums = list(map(int, input().split(' ')))[::-1]
current = nums[0]
ans = 0
for n in nums:
    current = min(current, n)
    ans += current
    current = n  # !
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

for i in range(1, N-2):
  prev = B[-1]
  next = B[i+1]
  b = B[i]
  
  max_b = (max(prev, b))
  min_b = (min(next, b))
  
  A.append(min_b)

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

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

Submission status: Wrong Answer

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

for i in range(len(B)):
    A.append(B[i])
    
A.append(B[0])
print(sum(A))

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)
    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())
B = list(map(int, input().split()))
A = []

for i, b in enumerate(B):
  if i == 0 and i == len(B) - 1: 
    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 and len(A) != N:
    A.append(B[i])
  else:
    if B[i] <= B[i + 1]:
      A.append(B[i])
    else:
      A.append(B[i + 1])
print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())

B = list(map(int, input().split()))
b = len(B)
A = []

A.append(B[0])
A.append(B[0])
if len(B) > 1:
    for i in range(1,b-1):
        if B[i] <= B[i +1]:
            A.append(B[i])
        else:
            A.append(B[i+1])
    A.append(B[b-1])
print(sum(A))

Submission status: Wrong Answer

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

#print(N,B)


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
B = [int(i) for i in input().split()] 
A=[0]*N
A[0]=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]
if B[N-2]<B[N-3]:
    A[N-1]=B[N-2]
ans=sum(A)
print(ans)

Submission status: Wrong Answer

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

S = B[0]
pre_b = -1

for b in B:
  S += max(pre_b, b)
  pre_b = b
  
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:])]
    print(sum(co)+b[-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i, b in enumerate(B):
  print(A)
  if i == 0 and i == len(B) - 1: 
    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 and len(A) != N:
    A.append(B[i])
  else:
    if B[i] <= B[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(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]


        
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 = []
num = B[0]
if n == 2:
    print(B[0]*2)
    exit()
for i in range(n-1):
    if i == n-2:
        a.append(a[-1])
        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(lambda x: int(x), input().split()))
ans = []

for i in range(n - 1):
    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:
# n = int(input())
# a=list(map(int,input().split()))
# b=list(map(int,input().split()))
# c=list(map(int,input().split()))
# c.sort()
# # s = 0
# # j=0
# # for i in range(n):
# #   s+=b[a[i]-1]
# #   # print(a[i])
# #   try:
# #     if (a[i+1]-a[i])==1 and (i)<(n-1):
# #       s+=c[j]
# #       j+=1
# #         # print(c[j],a[i],a[i-1])
# #   except:
# #     pass
# # print(s)
# ss=sum(b)+sum(c)
# print(ss)
n = int(input())
b = list(map(int,input().split()))
print(sum(b)+min(b))

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

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])
        else:
            ans += min(B[i-1],B[i])
    ans += B[N-2]
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

A = []
A.append(B[0])
for i in range(N-1):
  if i == 0:
    A.append(B[i])
  elif i < N-2:
    if B[i] >= B[i+1]:
      A.append(B[i+1])
    else:
      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 - 1):
    if i == 0:
      l = B[i]
      A.append(l)
    elif i == N - 2:
      if B[i - 1] < B[i]:
      	l = B[i]
      else:
        l = B[i - 1]
    else:
      if B[i] < B[i + 1]:
        l = B[i]
      else:
        l = B[i + 1]
    A.append(l)
    print
print(sum(A))

Submission status: Wrong Answer

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


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

    for i in range(len(b) - 1):
        if b[i] < b[i+1]:
            b[i + 1] = b[i]

    result = sum(b) + b[n - 2]
    print(result)


if __name__ == "__main__":
    main()

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]
    
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()))
ans = 0
bef = B[-1]
for n in reversed(B):
    tmp = min([n, bef])
    ans += tmp
    bef = tmp
ans += bef
print(ans)

Submission status: Wrong Answer

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

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

print(sum(A))

Submission status: Wrong Answer

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


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

    for i in range(len(b) - 1):
        if b[i] < b[i+1]:
            b[i + 1] = b[i]
        print(b)

    result = sum(b) + b[n - 2]
    print(result)


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)
    exit()
l = [B[0],B[0]]
for i in range(N-3):
    # print(l)
    # print("i=====",i)
    # print("B[i]",B[i])
    last = l[i+1]
    if B[i+1] > B[i+2]:
        l.append(B[i+2])
    else:
        l.append(B[i+1])
l.append(B[N-2])
# print(l)
print(sum(l))

Submission status: Wrong Answer

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

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

if A[0] == 0:
    A[0] = A[1]

print(sum(A))

Submission status: Wrong Answer

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

for i in range(n):
    index = (n-1)-i
    if index >= 1:
        c = b[index-1]
    else:
        c = b[0]
    if c < max:
        max = c
    s += max
print(s)

Submission status: Wrong Answer

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

sum = 0
if N==2:
    sum += B[0]+B[0]
    print(B[0]+B[0])
else:
    sum += B[0]
    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())
B = list(map(int, input().split()))
sum = B[0]
 
for i in range(1,N-1):
  sum += max(B[i-1], B[i])
print(sum)

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] * 2)
    break
  if flag == 1:
    sum += min(li) *(i+1)
    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] * 2)
    flag = 1
    
    
print(sum)

Submission status: Wrong Answer

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

ans = 0
a = 10**6

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

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+1<n-1:
    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())
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()))
# B.reverse()

sum = 0
# tmp = B[0]

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())
b=input().split()

a=[0]*n
a[0]=b[0]
a[n-1]=b[n-2]
ans=0

for i in range(n-2):
  if b[n-i-2]>=b[n-i-3]:
    a[n-i-2]=b[n-i-3]
  elif b[n-i-2]<b[n-i-3]:
    a[n-i-2]=b[n-i-2]

for j in range(n):
  ans+=int(a[j])

print(ans)

Submission status: Wrong Answer

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

sum = b[0]*2
if n >= 5:
    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:
hoge = input()
nums = list(map(int, input().split(' ')))[::-1]
current = nums[0]
ans = 0
for n in nums:
    current = min(current, n)
    ans += current
print(ans)

Submission status: Wrong Answer

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

for i in range(1,n-1):
  if i == n-2:
    ans1 += b[i]
    break
  if b[i] >= max([ans[i],ans[i+1]]):
    ans[i+1] = min([b[i],b[i+1]])

print(sum(ans) + ans1)

Submission status: Wrong Answer

Solution code:
n = int(input())

B = list(map(int, input().split()))
b = len(B)
A = []

A.append(B[0])
A.append(B[0])
if len(B) > 1:
    for i in range(1,b-1):
        if B[i] <= B[i +1]:
            A.append(B[i])
        else:
            A.append(B[i+1])
    if B[b-1] >= A[b-1]:
        A.append(B[b-1])
    else:
        A.append(A[b-1])
print(sum(A))

Submission status: Wrong Answer

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

a = B[0]
ans  = a

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


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

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

count = a[0]

for i in range(0,n-2):
#  print(i)
#  print(min(a[i],a[i+1]))
  count += min(a[i],a[i+1])
count += min(a[n-3],a[n-2])
print(count)

Submission status: Wrong Answer

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

sum = b[0]*2
if n >= 4:
    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()))
B.reverse()

ans = 0
for i in range(N-1):
 if(i == 0): 
  tmp = B[i]
 else:
  if(tmp>=B[i]):
   tmp = B[i]
  else:
   B[i] = tmp

ans +=B[-1]
ans += sum(B)
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(arr[i-1])

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

Submission status: Wrong Answer

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

a[n-1]=b[n-2]

for i in range(n-2,0,-1):
    #print("i="+str(i))
    a[i]=min(b[i-1],a[i+1])
    #print(a[i])
    
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 = [0] * (len(B)+1)
A[0] = B[0]
A[1] = B[0]

for i in range(2,len(B)):
  if B[i] <= B[i-1]:
    A[i] = B[i]
  elif B[i] > B[i-1]:
    A[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()))
ans = 0
b_max = b[-1]
tmp = b[-1]
for i in b[::-1]:
    b_max = min(i, b_max) if tmp != i else i
    tmp = i
    ans += b_max
ans += b_max
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])

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

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:
  print(sum(b[:-1])+sum(b[:2]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=list(map(int, input().split()))

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

print (np.sum(C))

Submission status: Wrong Answer

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

sum = 0
if N==2:
    sum += B[0]+B[0]
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())
B_list = list(map(int, input().split()))

A_list = []
for i, B in enumerate(B_list):
    if not A_list:
        A_list.append(B)
        A_list.append(B)
    elif i < len(B_list)-1:
        if B > B_list[i+1]:
            A_list.append(B_list[i+1])
        else:
            A_list.append(B)
    else:
        A_list.append(B)
print(sum(A_list))

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-1]=B[N-2]
if N > 2:
  A[N-2]=min(B[N-2],B[N-3])
  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:
#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:
            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())
a=input().split()
if len(a)>1:
	ans=min(int(a[0]),int(a[1]))
else:
  ans=int(a[0])
for b in range(len(a)):
  if b+1<len(a):
    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())
B_list = list(map(int, input().split()))

A_list = []
for i, B in enumerate(B_list):
    if not A_list:
        A_list.append(B)
        A_list.append(B)
        print(B, B)
    elif i < len(B_list)-1:
        if B > B_list[i+1]:
            A_list.append(B_list[i+1])
        else:
            A_list.append(B)
    else:
        A_list.append(B)
    print(A_list)
print(sum(A_list))

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

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)
elif 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:
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)
    for i in range(N-1):
        b_c = Bs[i]
        if i == 0:
            A[i] = b_c
            A[i+1] = b_c
        elif i == N-2:  # 最終
            A[i+1] = b_c
        elif i != N-2:  # 最終以外
            b_n = Bs[i+1]
            if b_c < b_n:
                if A[i] < b_c:
                    pass
                else:
                    A[i] = b_c
                A[i+1] = b_c
            elif b_c >= b_n:
                A[i] = b_c
                A[i + 1] = b_n
    #print(A)
    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 = [0]*N
if N>2:
    for i in range(N-1):
        if i==0:
            if B[0]==0:
                A[0] = 0
                continue
            else:
                A[0] = B[0]
                continue
        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:
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)
    for i in range(N-1):
        b_c = Bs[i]
        if i == 0:
            A[i] = b_c
            A[i+1] = b_c
        elif i == N-2:  # 最終
            A[i+1] = b_c
        elif i != N-2:  # 最終以外
            b_n = Bs[i+1]
            if b_c < b_n:
                if A[i] < b_c:
                    pass
                else:
                    A[i] = b_c
                A[i+1] = b_c
            elif b_c >= b_n:
                A[i] = b_c
                A[i + 1] = b_n
    print(A)
    ans = np.int64(np.sum(A))
    print(ans)
if __name__ == '__main__':
    main()

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-1):
    aa = min(a[i-1],a[i])
    aaa.append(aa)
  aaa.append(a[n-2])
  print(sum(aaa))