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())) 
A = []
for i in range(len(B)):
    if i == 0:
        A.append(B[i])
        A.append(B[i])
    elif 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()))

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

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

print(count)

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

Submission status: Wrong Answer

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


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

    result = b[n - 2]
    target = b[n - 2]
    for i in range(1, n - 1):
        index = (n - 2) - i

        if b[index] <= b[index+1]:
            target = b[index]
        else:
            target = b[index+1]

        result += target

    result += target
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

result = 0

for index in range(N-1):
    if index == 0:
        if len(A) == 1:
            result += A[0]*2
        else:
            result += min(A[index], A[index+1])
    elif index == len(A)-1:
        result += min(A[index-1], A[index])
    else:
        result += min(A[index-1], A[index], A[index+1])
if len(A) != 1:
    result += A[len(A)-1]

print(result)

Submission status: Wrong Answer

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

arr1=[0]*(n)
arr1[-1]=arr[-1]
prev=arr1[-1]
for i in range(n-3,-1,-1):
	if(arr[i]<prev):
		arr1[i+1]=arr[i]
		prev=arr[i]
	else:
		arr1[i+1]=prev
	#print(*arr1)
arr1[0]=arr[0]
print(sum(arr1))

Submission status: Wrong Answer

Solution code:


def main():


   A = int(input())
   bList = list(map(int,input().split()))
   ansList = []
   flag = False



   for i in range(A-1):
      if i == A-2:
         if bList[i-1] <= bList[i]:
            ansList.append(bList[i-1])
            ansList.append(bList[i])
         else:
            ansList.append(bList[i])
            ansList.append(bList[i])
         break

      if flag:
         ansList.append(bList[i-1])
         flag = False
         continue



      if bList[i] <= bList[i+1]:
         ansList.append(bList[i])
         flag =True
      else:
         ansList.append(bList[i])

   print(sum(ansList))









if __name__== "__main__":
    main()

Submission status: Wrong Answer

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

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

print(D)

Submission status: Wrong Answer

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

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


A.append(A[-1])

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

s=[]

if(N==2):
    s.append(B[0])
    s.append(B[0])
else:
    for i in range(N-1-1):
        value=B[i]
        if(i==0):
            s.append(value)
            if(N==3):
                s.append(value)
        elif(value>B[i+1]):
            #s.append(B[i+1])
            s.append(B[i+1])
        else:
            #s.append(value)
            s.append(value)
    s.append(B[-1])

print(sum(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = [b[0], b[0]]

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

a.append(b[n-2])

print(sum(a))

Submission status: Wrong Answer

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

res = []

if len(dishs)==1:
    res.append(dishs[0])
    res.append(dishs[0])
    print(sum(res))
else:
    for i in range(0,len(dishs)-1):
        if i == 0 or i == 1:
            res.append(dishs[0])
        else:
            res.append(min(dishs[i],dishs[i+1]))
    res.append(min(dishs[-2],dishs[-1]))
    res.append(dishs[-1])

    print(sum(res))

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_b = list(map(int, sys.stdin.readline().split()))
list_a = [0]*N
list_a[N-1] = list_b[N-2]

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

sum = 0

for i in range(N):
    sum += list_a[i]

# print(list_a)

print(sum)

Submission status: Wrong Answer

Solution code:
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, = gi()
b = gi()
a = [b[0]]
for k in range(1, n - 1):
	if b[k] > b[k - 1]:
		a.append(a[k - 1])
	else:
		a.append(b[k])
a.append(b[-1])
print(sum(a))

Submission status: Wrong Answer

Solution code:
def solve():
  import sys
  import math

  sys.setrecursionlimit(10**7)
  readline=sys.stdin.readline

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


if __name__ == '__main__':
  solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a = [a[0],a[0]] + a + [a[-1]]
C = 0
for (i,j,k) in zip(a[:-2],a[1:-1],a[2:]):
    C += max([i,j]) if max([i,j]) < k else k
print(C)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
A = []
A.append(B[N-2])
for i in reversed(range(1, len(B))):
    if B[i]>=B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, B: "List[int]"):

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

            
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [ int(next(tokens)) for _ in range(N-1) ]  # type: "List[int]"
    solve(N, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
B.insert(0, 10000)
## 最後以外
ans = 0

if N >= 3:
  for n in range(1,N-1):
    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[-1],B[-2])
  ans += B[-1]

else:
  ans = B[1] * 2

  
print(ans)

Submission status: Wrong Answer

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

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

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

ans = sum + wkv

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
B = list(map(int, input().split(" ")))
A = B[0]
An = B[0]
C = B[0]
for i in range(len(B)):
  if An <= B[i]:
    C += An
  else:
    C+= B[i]
  An = B[i]

C += An
print(C)

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-1):
    if B[i]<tmp:
        tmp = B[i]
    sum += tmp
sum += tmp

print(sum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

arr1=[0]*(n)
arr1[-1]=arr[-1]
prev=arr1[-1]
for i in range(n-3,-1,-1):
	if(arr[i]<prev):
		arr1[i+1]=arr[i]
		prev=arr[i]
	else:
		arr1[i+1]=prev
	#print(*arr1)

arr1[0]=arr1[1]
print(sum(arr1))

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [float('inf')] + [int(x) for x in input().split()] + [float('inf')]
total = sum(min(b[i: i + 3]) for i in range(n - 1)) + b[-2]
print(total)

Submission status: Wrong Answer

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

ans = B[-1]
pre = B[-1]
for i in reversed(range(0,N-2)):
  now = B[i]
  if now <= pre:
    ans += now
  else:
    ans += pre  
  pre = now
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

l = [b[0], b[0]]
if n>=3:
  for i in range(1, len(b)-1):
      test =  b[i+1] - b[i]
      if test>=0:
          l.append(b[i])
      else:
          l.append(b[i+1])
  l.append(b[-1])
  print(sum(l))
else:
  print(b[0]*2)

Submission status: Wrong Answer

Solution code:
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))
sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    B = LIST()

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

an = []

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

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

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


print(sum(an))

Submission status: Wrong Answer

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

ans = B[0]
for i in range(N-2):
  ans += max([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()))
ans = 0
m = max(B)
for n in reversed(B):
    if m<n:
        ans += m
    else:
        ans += n
        m = n
if m<n:
    ans += m
else:
    ans += n
    m = n
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a = a + [a[-1]]
C = 0
for (i,j,k) in zip(a[:-2],a[1:-1],a[2:]):
    C += max([i,j]) if max([i,j]) < k else k
print(C)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
a = [b[0]]
for i in range(n-2):
    c = min(b[i], b[i+1])
    a.append(c)
try:
    a.append(max(b[-2],b[-1]))
except:
    a.append(b[0])
print(sum(a))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a = []
a.append(b[-1])
for i in range(1,N-1):
    a.append(min(a[i-1], b[-(i+1)], b[-i]))
a.append(b[0])

print(sum(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(x) for x in input().split()]
ans = [0]*(N)
if N==2:
  print(int(B[0])*2)
  exit()
for i in range(1,N-2):
  ans[i] = min(B[i-1],B[i])
ans[0] = min(B[0],B[1])
ans[N-2] =  min(B[N-3],B[N-2])
ans[N-1] = B[N-2]
print(sum(ans))

Submission status: Wrong Answer

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

def main():
    N = int(input())
    B = list(map(int,input().split()))
    B.append(B[-1])
    S = Ap = B[0]
    for i in range(N-1):
        Bmin = min(B[i],B[i+1])
        A = max(Ap,Bmin)
        S += A
        Ap = A
    print(S)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
B = list(map(int,input().split()))
sum = 0

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

print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())

b = list(map(int,input().split()))
ans = 0
b_max = b[-1]
for i in b[::-1]:
    b_max = min(i, b_max)
    ans += b_max
ans += b_max
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
B_l = list(map(int,input().split()))[::-1]
if(N == 2):
    ans = B_l[0]
else:
    ans = max([B_l[0],B_l[1]])
for i in range(N-2):
    ans += min([B_l[i],B_l[i+1]])
ans += min(B_l[N-3],B_l[N-2])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
B = [int(i) for i in input().split()]
if n == 2:
    print(B[0]*2)
    exit()

ans = []
ans.append(min(B[0],B[1]))
for i in range(n-2):
    ans.append(min(B[i],B[i+1]))
ans.append(B[-1])
#print(ans)
print(sum(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#C
#len(A) = n
#len(b) = n-1
#b[i] >= max(a[i],a[i+1])
#b[1] = max(a[1], a[2])
#b[i] = max(a[i],a[i+1])
#b[i+1] = max(a[i+1], a[i+2])
n = int(input())
b = list(map(int, input().split()))
a = [b[0]] + b

for i in range(1,n-1):
    if a[i] > a[i-1] and a[i+1] < a[i]:
        a[i] = max(a[i-1], a[i+1])
print(sum(a))


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

Submission status: Wrong Answer

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

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

for i in range(1, len(B)):
    if res[-1] < B[i]:
        res.append(res[-1])
    else:
        res.append(B[i])

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

Submission status: Wrong Answer

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

B.append(10**6)

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

A.append(A[-1])

print(sum(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def solve():
  import sys
  import math

  sys.setrecursionlimit(10**7)
  readline=sys.stdin.readline

  n = int(input())
  *b, = map(int, input().split())
  
  a = b[0]
  for i in range(1,n-1):
    a += min(b[i],b[i-1])
  if n>2:
    a += b[-1]
    
  print(a)


if __name__ == '__main__':
  solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = []
a.append(b[-1])
for i in range(1,N-1):
    a.append(min(a[i-1], b[-(i+1)]))
a.append(b[0])

print(sum(a))

Submission status: Wrong Answer

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

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

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

print(sum(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

for i in range(1, len(B)):
    if res[-1] < B[i]:
        res.append(res[-1])
    else:
        res.append(B[i])
        
res.append(res[-1])
print(sum(res))

Submission status: Wrong Answer

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

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

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

print(sum(As))

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:

n = int(input())

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

an = [10*6]*n

for i in range(n-1):

    an[i] = min(an[i],bn[i])
    an[i+1] = min(an[i+1],bn[i])


#print(an)
print( sum(an) )

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
B.insert(0, 10000)
## 最後以外
ans = 0

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

else:
  ans = B[1] * 2

  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())

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

sum=0
for i in range(len(B)+1):
    if i==len(B)-1:
        sum+=B[i]
        break

    if B[i]<B[i+1]:
        sum+= B[i]
    else:
        sum+=B[i+1]

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a = [a[0]] + a + [a[-1],a[-1]]
C = 0
for (i,j,k) in zip(a[:-2],a[1:-1],a[2:]):
    C += min([i,j,k])
print(C)

Submission status: Wrong Answer

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

ans = 0


def mini(x, y):
    if x > y:
        return y
    else:
        return x


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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = B[-1]

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

if N == 2:
    ans += B[0]


print(ans)

Submission status: Wrong Answer

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

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

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

    print(output + B[-1])

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

    print(output + B[-1] + min(B[-2], B[-3]))

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 += b[i]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int,input().split()))
ans=sum(b)+b[0]

Submission status: Wrong Answer

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

out=B[N-2]

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

print(out)

Submission status: Wrong Answer

Solution code:
n = int(input())
B = list(map(int, input().split()))
min_ele = B[-1]
total = 0

for i in range(n-2, -1, -1):
	if B[i] <= min_ele:
		min_ele = B[i]
	total += min_ele
total += min_ele
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
B.insert(0, 10000)
## 最後以外
ans = 0

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

else:
  ans = B[1] * 2

  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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[i+1]>=b[i]:
    a[i+1]=b[i]
  else:
    a[i+1]=b[i+1]

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    B = list(map(int,input().split()))
    A = [B[0]]
    ans = B[0]
    for i in range(1,N-1):
        tmp = min(A[i-1], B[i])
        ans += tmp
        A.append(tmp)
    ans += max(A[-1],B[-1])
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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


print(sum)

Submission status: Wrong Answer

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

A = [B[-1]]

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

A.append(A[-1])

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

# print(A)
# print(A2)
print(max(sum(A), sum(A2)))

Submission status: Wrong Answer

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

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

ans = []
for i in range(n-2):
    ans.append(min(B[i],B[i+1]))
    if i == 0: ans.append(min(B[i],B[i+1]))
ans.append(B[-1])
print(sum(ans))

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	b = list(map(int,input().split()))
	a = []
	a.append(b[0])
	for i in range(1,n-1):
		min_b = min(b[i],b[i-1])
		if(min_b < a[i-1]):
			a[i-1] = min_b
		a.append(min_b)
	a.append(b[-1])
	print(sum(a))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

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])
ans += b[n - 2]
if n == 2 or n == 3:
    ans += b[0]
print(ans)

Submission status: Wrong Answer

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

def solve():
    n = int(input())
    bl = [int(i) for i in input().split()]
    bl = [bl[0]] + bl
    ans, m = 0, bl[-1]
    for i in range(n - 1, -1, -1):
        if bl[i] < m:
            m = bl[i]
        ans += m
    print(ans)

if __name__=="__main__":
    solve()