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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
B = IL()[::-1]

A = [max(B) for i in range(N+1)]
A[0] == A[1] == B[0]

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

P(sum(A))

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
B = IL()[::-1]

A = [B[0]]

for b in B[1:]:
  if b > A[-1]:
    A.append(A[-1])
  else:
    A.append(b)
A.append(A[-1])
P(sum(A))

Submission status: Wrong Answer

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

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

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

if N != 2:
    A.append(B[N-2])
print(sum(A))

Submission status: Wrong Answer

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

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

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

if N != 2:
    A.append(B[N-2])
print(sum(A))

Submission status: Wrong Answer

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

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

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

if N != 2:
    A.append(B[N-2])
print(sum(A))

Submission status: Wrong Answer

Solution code:
input()
bs = input()
b_list = [int(n) for n in bs.strip().split()]

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

Submission status: Wrong Answer

Solution code:
# ABC140C

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

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

Submission status: Wrong Answer

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

a = 0 + b_s[n-2]
for i in range(n-2, 1, -1):
  b_i, a_i = b_s[i], b_s[i-1]
  a += (b_i if b_i <= a_i else a_i)
a += b_s[0]
print(a)

Submission status: Wrong Answer

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

a = 0
if n > 3:
  for i in range(0, n-2):
    b_i, a_i = b_s[i], b_s[i+1]
    a += (b_i if b_i <= a_i else a_i)
elif n == 3:
  a += b_s[1] + b_s[0] * 2
elif n == 2:
  a += b_s[0] * 2
print(a + b_s[n-2])

Submission status: Wrong Answer

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

a = 0
for i in range(0, n-2):
  b_i, a_i = b_s[i], b_s[i+1]
  a += (b_i if b_i <= a_i else a_i)
print(a + b_s[n-2])

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = int(input())
    B = list(map(int, input().split()))
    for i in range(N-2):
        ans += min(B[i], B[i+1])
    ans += B[-1]
    if N != 2:
        ans += min(B[0], B[1])
    else:
        ans += B[0]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    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[-1]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# check
A = []
append = A.append
for i, b in enumerate(B):
    while len(A[i:]) < 2:
        if i < len(B) - 1 and b >= B[i + 1]:
            append(B[i + 1])
        else:
            append(b)

print(sum(A))

Submission status: Wrong Answer

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

# check
A = []
append = A.append
for i, b in enumerate(B):
    while len(A[i:]) < 2:
        append(b)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

num = [b[0]]

for i in range(1, n - 1):
  if(b[i] <  b[i - 1]):
    num[-1] = b[i]
    num.append(b[i])
  else:
    num.append(b[i])

num.append(b[0])

print(num)
print(sum(num))

Submission status: Wrong Answer

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

res = 0

for i in range(n - 1):
    # print('＝＝＝＝＝＝＝＝＝＝')
    if i + 1 < n - 1:
        if b[i] > b[i + 1]:
            if i == 0:
                res = b[i + 1] + b[i + 1]
                # print('b[0] = ', b[0])
                # print('b[0] = ', b[0])
            else:
                res += b[i + 1]
                # print('b[i + 1] = ', b[i + 1])
        else:
            if i == 0:
                res = b[0] + b[0]
                # print('b[0] = ', b[0])
                # print('b[0] = ', b[0])
            else:
                res += b[i]
                # print('b[i] = ', b[i])
    elif i == 0:
        res = b[0] + b[0]
        # print('b[0] = ', b[0])
        # print('b[0] = ', b[0])
    else:
        res += b[i]
        # print('b[i] = ', b[i])
print(res)

Submission status: Wrong Answer

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

res = 0

for i in range(n - 1):
    # print('＝＝＝＝＝＝＝＝＝＝')
    if i + 1 < n - 1:
        if b[i] > b[i + 1]:
            if i == 0:
                res = b[0] + b[0]
                # print('b[0] = ', b[0])
                # print('b[0] = ', b[0])
            else:
                res += b[i + 1]
                # print('b[i + 1] = ', b[i + 1])
        else:
            if i == 0:
                res = b[0] + b[0]
                # print('b[0] = ', b[0])
                # print('b[0] = ', b[0])
            else:
                res += b[i]
                # print('b[i] = ', b[i])
    elif i == 0:
        res = b[0] + b[0]
        # print('b[0] = ', b[0])
        # print('b[0] = ', b[0])
    else:
        res += b[i]
        # print('b[i] = ', b[i])
print(res)

Submission status: Wrong Answer

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

res = 0

for i in range(n - 1):
    # print('＝＝＝＝＝＝＝＝＝＝')
    if i + 1 < n - 1:
        if i == 0:
            res = b[0] + b[0]
            # print('b[0] = ', b[0])
            # print('b[0] = ', b[0])
        elif b[i] > b[i + 1]:
            res += b[i + 1]
            # print('b[i + 1] = ', b[i + 1])
        else:
            res += b[i]
            # print('b[i] = ', b[i])
    elif i == 0:
        res = b[0] + b[0]
        # print('b[0] = ', b[0])
        # print('b[0] = ', b[0])
    else:
        res += b[i]
        # print('b[i] = ', b[i])
print(res)

Submission status: Wrong Answer

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

res = 0

for i in range(n - 1):
    # print("＝＝＝＝＝＝＝＝＝＝")
    if i == 0:
        res = b[0] + b[0]
        # print('b[0] = ', b[0])
        # print('b[0] = ', b[0])
    else:
        if i + 1 < n - 1:
            if b[i] >= b[i + 1]:
                res += b[i + 1]
                # print('b[i + 1] = ', b[i + 1])
            else:
                res += b[i]
                # print('b[i] = ', b[i])
        else:
            res += b[i]
            # print('b[i] = ', b[i])
print(res)

Submission status: Wrong Answer

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

res = 0

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

Submission status: Wrong Answer

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

a = [b.pop()]
for b_i in b[::-1]:
  a.append(min(a[-1],b_i))
a.append(a[-1])
print(sum(a))

Submission status: Wrong Answer

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

a = [b.pop()]
for b_i in b[::-1]:
  a.append(min(a[-1],b_i))
  
print(sum(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a =[0]*n
a[0] = b[0]

if n == 2:
    a[1] =b[0]
    print(sum(a))

else:

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

        else:
            a[i+1] = b[i+1]

    print(sum(a))

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    B = list(map(int, input().split()))
    A = []
    A.append(min(B[0:2]))
    A.append(min(B[0:2]))

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

    print(sum(A))

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = [B[0]] + B

print(sum(ans))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
b=list(map(int,input().split()))

a=[b[0] for _ in range(n)]
a[n-1]=b[n-2]
for i in range(n-1):
  if i!=0 or i!=n-1:
    if b[i-1] <= b[i]:
      a[i]=b[i-1]
    else:
      a[i]=b[i]

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

print(sum)

Submission status: Wrong Answer

Solution code:
# C - Maximal Value

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

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = b[0] + max(b[n-2],b[n-3])
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 = list(map(int,input().split()))
print((min(B_list))+sum(B_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=input()
b=input().split()
sum=0
for i in range(len(b)-1) :
  sum+=min(int(b[i]),int(b[i+1]))
sum+=int(b[-1])

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(s) for s in input().split(' ')]
def doit(bb):
    bb = list(bb)
    A = []
    for b in bb:
        if len(A) == 0:
            A.append(b)
            continue
        A.append(min(A[-1], b))
    A.append(min(bb[-1], A[-1]))
    return sum(A)

print(max(doit(B), doit(reversed(B))))

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(s) for s in input().split(' ')]
def doit(bb):
    bb = list(bb)
    A = []
    for b in bb:
        if len(A) == 0:
            A.append(b)
            continue
        A.append(min(A[-1], b))
    A.append(max(bb[-1], A[-1]))
    return sum(A)

print(max(doit(B), doit(reversed(B))))

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(s) for s in input().split(' ')]
def doit(bb):
    bb = list(bb)
    A = []
    for b in bb:
        if len(A) == 0:
            A.append(b)
            continue
        A.append(min(A[-1], b))
    A.append(bb[-1])
    return sum(A)

print(max(doit(B), doit(reversed(B))))

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(s) for s in input().split(' ')]
def doit(bb):
    A = []
    for b in bb:
        if len(A) == 0:
            A.append(b)
            continue
        A.append(min(A[-1], b))
    A.append(A[-1])
    return sum(A)

print(max(doit(B), doit(reversed(B))))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = [int(s) for s in input().split(' ')]
for b in reversed(B):
    if len(A) == 0:
        A.append(b)
        continue
    A.append(min(A[-1], b))
A.append(A[-1])
print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
b = [int(i) for i in input().split()]
b = [b[0]] + b
low = 1000000
ret = 0
for i in reversed(b):
	low = min(low, i)
	ret += low
print (ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
# a = x 3 3  -> aaa[i] は右と左下のmin?
# b = 3 3
# bi = max(ai, ai+1)
aaa = {}
bbb = list(map(int, input().split(' ')))
aaa[n-1] = bbb[n-2]
for i in range(n-2, -1, -1):
    aaa[i] = min(aaa[i+1], bbb[i-1])
print(sum([aaa[i] for i in range(n)]))

Submission status: Wrong Answer

Solution code:
n=int(input())

l1=list(map(int,input().split()))
l2=[l1[0]]
l=l2+l1
l.append(l1[-1])
print(l)

res=[]

for i in range(1,n+1):
    res.append(min(l[i],l[i-1]))

print(sum(res))

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    B = il()
    ret = B[len(B) - 1]
    for n in range(N - 1):
        ret += min(B[n], B[n - 1])
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 初期入力
N = int(input())
B = list(map(int, input().split()))

#
A =[0]*(N)
A[0]=B[0]
for i in range(N-1):
    A[i+1] =B[i]
    A[i] =min(B[i],B[i-1])
    #if 0<i:
     #   A[i] =min(A[i-1],b) 

print(sum(A))

Submission status: Wrong Answer

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

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

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[0]=A[1]
a=sum(A)+B[N-2]
print(a)

Submission status: Wrong Answer

Solution code:
N=int(input())
B=[int(x) for x in input().rstrip().split()]
A=[B[0]]
for i in range(1,N-1):
  if i+1<N-1:
    A.append(min(B[i-1],B[i],B[i+1]))
  else:
    A.append(min(B[i],B[i-1]))
A.append(B[N-2])

print(sum(A))

Submission status: Wrong Answer

Solution code:
print("test")
print("test")
print("test")
print("test")
print("test")
print("test")
print("test")
print("test")
print("test")
print("test")

Submission status: Wrong Answer

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

res = 0

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

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
x = 1
result = 0
count = 1

for a in B[:N-2]:
    if a < B[x]:
        result += a * count
        if x < N - 2:
            x += 1
    else:
        count += 1
        if x < N - 2:
            x += 1
        continue
Z = 0
for i in range(N-2):
    if B[i] < B[i + 1]:
        Z = B[i]
        break

print(result + B[N-2] + Z)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int, input().split()))
x = 1
result = 0
count = 1

for a in B[:N-2]:
    if a < B[x]:
        result += a * count
        if x < N - 2:
            x += 1
    else:
        count += 1
        if x < N - 2:
            x += 1
        continue
print(result + B[N-2])

Submission status: Wrong Answer

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

# a1 a2 a3 a4 a5
# b1 b2 b3 b4

# b1 b2 b3 b4 b4

A = (B + [B[-1]]).copy()
for i in range(0, N - 1):
    a1 = A[i]
    a2 = A[i + 1]
    if (a1 < a2 and a1 == B[i]):
        A[i + 1] = a1
A[-1] = B[-1]

print(sum(A))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    B = input()
    B = B.split()
    B = [int(i) for i in B]
    s = 0
    for i in range(0, n-1):
        if i == 0:
            s += B[0]
        else:
            s += min(B[i - 1], B[i])
    s += B[-1]
    return s

main()

Submission status: Wrong Answer

Solution code:
def maximalValue():
    n = int(input())
    B = input()
    B = B.split()
    B = [int(i) for i in B]
    s = 0
    for i in range(0, n-1):
        if i == 0:
            s += B[0]
        else:
            s += min(B[i - 1], B[i])
    s += B[-1]
    return s

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = [0 for _ in range(n)]

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

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

Submission status: Wrong Answer

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

A = [0] * N

B.append(B[-1])

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
B=nl()
ans=[B[0]]+B[:]
print(sum(ans))

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

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = [b[0]]
for num, i in enumerate(b):
  if num == 0:
    a.append(i)
  elif num == n-2:
    a.append(i)
  elif i <= b[num + 1]:
    a.append(i)
  elif i > b[num + 1]:
    a.append(b[num + 1])
print(sum(a))

Submission status: Wrong Answer

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

a = [b[0]]
for num, i in enumerate(b):
  if num == 0:
    a.append(i)
  elif num == n-2:
    a.append(i)
  elif i <= b[num + 1]:
    a.append(i)
  elif i > b[num + 1]:
    a.append(b[num + 1])
print(sum(a))
print(a)

Submission status: Wrong Answer

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

a = [b[0]]
for num, i in enumerate(b[0:]):
  if num == 0:
    a.append(i)
  elif num == n-2:
    a.append(i)
  elif i <= b[num + 1]:
    a.append(i)
  elif i > b[num + 1]:
    a.append(b[num + 1])
print(sum(a))

Submission status: Wrong Answer

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

a = [b[0]]
for num, i in enumerate(b[:-1]):
  if num == 0:
    a.append(i)
  elif num == n-2:
    a.append(i)
  elif i <= b[num + 1]:
    a.append(i)
  elif i > b[num + 1]:
    a.append(b[num + 1])
print(sum(a))

Submission status: Wrong Answer

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

a = [b[0]]
for num, i in enumerate(b[:]):
  if num == 0:
    a.append(i)
  elif num == n-2:
    a.append(i)
  elif i <= b[num + 1]:
    a.append(i)
  elif i > b[num + 1]:
    a.append(b[num + 1])
print(sum(a))

Submission status: Wrong Answer

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

a = [b[0]]
for num, i in enumerate(b[:]):
  if num == 0:
    a.append(i)
  elif num == n-2:
    a.append(i)
  elif i <= b[num + 1]:
    a.append(i)
  elif i > b[num + 1]:
    a.append(b[num + 1])
print(sum(a))
print(a)

Submission status: Wrong Answer

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

a = list()
for num, i in enumerate(b[:]):
  if num == 0:
    a.append(i)
    a.append(i)
  elif num == n-2:
    a.append(i)
  elif i > b[num + 1]:
    a.append(b[num + 1])
  elif i <= b[num + 1]:
    a.append(i)
print(sum(a))

Submission status: Wrong Answer

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

a = list()
for num, i in enumerate(b[:]):
  if num == 0:
    a.append(0)
    a.append(0)
  elif num == n-2:
    a.append(i)
  elif i > b[num + 1]:
    a.append(b[num + 1])
  elif i <= b[num + 1]:
    a.append(i)
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-2):
  ans = ans + min(b[i],b[i+1])

if b[n-2] >= b[n-3]:
  ans = ans + b[n-2]
elif b[n-2] < b[n-3]:
  ans = ans + b[n-3]
  
print(ans)

Submission status: Wrong Answer

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

ans = b[0]

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

Submission status: Wrong Answer

Solution code:
N = int(input())
Bi = list(map(int, input().split()))
listA = [0 for i in range(N)]
listA[N-1] = Bi[N-2]
gokei = 0
for j in reversed(range(N-1)):
    listA[j] = min(Bi[j], Bi[j-1])

for k in listA:
    gokei += k
print(gokei)

Submission status: Wrong Answer

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

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

    if B[i] > B[i + 1]:
        A[i] = min(B[i + 1], A[i])
        A[i + 1] = B[i + 1]
    else:
        A[i] = min(B[i], A[i])
        A[i + 1] = B[i]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(sum(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    B = list(map(int, input().split()))
    B = [10**3] + B + [10**3]
    curr_sum = 0
    for i in range(1, len(B)):
        curr_sum += min(B[i-1], B[i])
    print(curr_sum)

resolve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Wrong Answer

Solution code:
N = int(input()) # sを取得し、strに値を入れる
B = list(map(int, input().split()))
sum = B[0]
for i in range(0, N-1):
	sum += min(B[i],B[i-1])
sum += B[N-2]
print(sum)

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    b = list(map(int, input().split()))
    b = b[::-1]
    blist = [0]*n
    blist[0] = b[0]
    for i in range(1,n-1):
        if b[i] < blist[i-1]:
            blist[i] = b[i]
        else:
            blist[i] = blist[i-1]
    blist[n-1] = blist[n-2]
    print(sum(blist))
resolve()

Submission status: Wrong Answer

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

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

print(res)

Submission status: Wrong Answer

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

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

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