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:
while True:
    try:
        N = int(input())
        B = list(map(int, input().split()))
        A = [2**31] * N
        
        if N == 2:
            print(B[0]*2)
            continue
        
        A[N-1] = B.pop()
        for i in range(N-2, 0, -1):
            _ = B.pop()
            A[i] = min(A[i+1], _)
        A[0] = _
            
        #print(A)
        print(sum(A))
    except:
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
l_b=list(map(int,input().split()))
l_a=[l_b[-1]]
for i in range(N-1):
  l_a.append(min(l_b[N-2-i],l_b[N-3-i]))
print(sum(l_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, = map(int, input().split())
  
  a=[]
  for i in range(1,n-1):
    a+=[min(b[i],b[i-1])]
  a+=[b[-1]]
    
  print(sum(a))


if __name__ == '__main__':
  solve()

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
# from itertools import accumulate
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())
L =  list(map(int, sys.stdin.readline().split()))

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

X = accumulate(L)
print(list(X)[-1] + L[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
k=[int(i) for i in input().split()]
l=[]
for i in range(n-1):
    if i==0:
        l+=[k[-1]]
        continue
    if k[-i]<k[-i-1]:l+=[k[-i]]
    else:l+=[k[-i-1]]
print(sum(l)+l[-1])

Submission status: Wrong Answer

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

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

ans=[b[0]]*2
for i in range(N):
	if b[i] != max(ans[i], ans[i+1]):
		ans[i]=ans[i+1]
	ans.append(b[i+1])
	if len(ans)==N:
		break
print(sum(ans))

Submission status: Wrong Answer

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

a=[0]*n
a[0]=bs[0]
a[n-1]=bs[n-2]

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

print(a)
print(sum(a))

Submission status: Wrong Answer

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

result = 0

pre = float("inf")
for i in range(n-1)[::-1]:
    this_num = pre
    if bi[i] <= pre:
        this_num = bi[i]
        pre = bi[i]
    result += this_num

result += pre

print(result)

Submission status: Wrong Answer

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

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


if __name__ == '__main__':
  solve()

Submission status: Wrong Answer

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


def solve(N, B):
    ans = 0
    last_b = 999
    for b in B:
        ans += min(b, last_b)
        last_b = b
    ans += B[-1]
    return ans


if __name__ == '__main__':

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

    ans = solve(N, B)

    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


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

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


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])
A.append(B[0])

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

  else:
    A.pop(i - 1)
    A.append(B[i])
    A.append(B[i])

print(sum(A))

Submission status: Wrong Answer

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

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

    A.append(max(A[N-2],B[N-2]))
print(sum(A))

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

# print(A)
print(sum(A))

Submission status: Wrong Answer

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

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

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):
    if B[i] < B[i-1]:
        A.append(B[i])
    else:
        A.append(B[i-1])

A.append(A[-1])

print(sum(A))

Submission status: Wrong Answer

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

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

print(c_maximal_value())

Submission status: Wrong Answer

Solution code:
a=int(input())
li = list(map(int,input().split()))
li.reverse()
ans=0
ans+=li[0]
for i in range(len(li)-1):
	ans+=min(li[i],li[i+1])
print(ans)

Submission status: Wrong Answer

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

total = 0
prev = None
for B in Bs[::-1]:
  if not prev:
    prev = B
  
  if B > prev:
    total = total + prev
  else:
    total = total + B
    prev = B

print(total + prev)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, B):
    B = B + [sys.maxsize, sys.maxsize]
    ans = 0
    for i in range(N):
        ans += min(B[i-1], B[i], B[i+1])
    return ans



def main():
    N = read_int()
    B = read_int_n()
    print(slv(N, B))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

minV=10**5+1
result=0
for item in a:
  minV=min(minV,item)
  result+=minV
result+=minV

print(result)

Submission status: Wrong Answer

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

count = 0
m = 100000
for i in b[::-1]:
    m = min(m, i)
    count += m
count += m

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
b_array = [int(x) for x in input().split()]
a_array = [b_array[-1]]
now = b_array[-1]
for b in reversed(b_array[:-1]):
    now = min(b, now)
    a_array.append(now)
print(sum(a_array)+b_array[0])

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def calc(N, B):
    B = [101] + B + [101]
    r = 0
    for i in range(N):
        r += min(B[i], B[i + 1])
    return r


N = int(input())
B = [int(s) for s in input().split()]
print(calc(N, B))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
N = int(input())
B = inpl()
INF = 10*6
ans = 0
prev_b = INF
for b in B:
    ans += min(prev_b, b)
    prev_b = b
ans += prev_b
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
r = li[0] + li[-1]
for i, j in enumerate(li):
    if j != li[-1]:
        r += min(j, li[i + 1])
print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = list(map(int, input().split(" ")))
cnt = c[-1]
for i in range(N-1):
  cnt += min(c[N-i-2],c[N-i-3])
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = [max(B)] * N

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

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
r = li[0] + li[-1]
for i, j in enumerate(li):
    if j != li[-1]:
        r += min(j, li[i + 1])
        print(j, li[i + 1])
print(r)

Submission status: Wrong Answer

Solution code:
import sys,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n = onem()

a = l()

co = []

co.append(a[0])

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

b = [1000] + b + [1000]

score = 0
for i in range(len(b)-1):
    temp = min(b[i],b[i+1])
    score += temp

print(score)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

for i in range(N-2):
  if B[N-2-i] < B[N-2-i-1]:
    B[N-2-i-1] = B[N-2-i]

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

Submission status: Wrong Answer

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

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

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

print(ans + B[-1] + min(B[0], B[1]))

Submission status: Wrong Answer

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

inf = 10**10
B = [inf] + B + [inf]
ans = 0
for i in range(N):
    ans += min(B[i], B[i+1])

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
r = li[-1]
for i, j in enumerate(li):
    if j != li[-1]:
        r += min(j, li[i + 1])
print(r)

Submission status: Wrong Answer

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

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

Submission status: Time Limit Exceeded

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

a = [0 for k in range(n)]
a[0] = b[0]
a[n-1] = b[n-2]

for i in range(1, n-1):
  j=0
  while not j == min(b[i], b[i-1]):
    j += 1
  a[i]=j
  
ans = 0
for x in range(n):
  ans += a[x]

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
bl = list(map(int, input().split()))
al = [0]*n
al[0] = bl[0]
al[-1] = bl[-1]

for i in range(n-2):
    al[i+1] = min(bl[i], bl[i+1])

print(sum(al))

Submission status: Accepted

Solution code:
N, *B = map(int, open(0).read().split())
ans = B[0] + B[-1]
for i in range(N - 2):
    ans += min(B[i], B[i + 1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tmp = B[0]
ans = 0
B.append(B[-1])
for b in B:
    ans += min(tmp, b)
    tmp = b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
B = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    if(i == 0):
        A.append(B[0])
        continue
    if(i == N-1):
        A.append(B[N-2])
        continue
    a = B[i-1]
    b = B[i]
    if(a < b):
        A.append(a)
    else:
        A.append(b)
for i in A:
    ans += i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

list_a= [bs[0]]

for i in range(1,len(bs)):
    a = min(bs[i-1],bs[i])
    list_a.append(a)
    
list_a.append(bs[len(bs)-1])

print(sum(list_a))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans+B[-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
bn = [int(num) for num in input().split()]
 
an = [0]*n
an[0] = bn[0]
an[n-1] = bn[n-2]
for i in range(1,n-1):
    s = min(bn[i],bn[i-1])
    an.append(s)
    
print(sum(an))

Submission status: Accepted

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(B[0]+ans+B[n-2])

Submission status: Accepted

Solution code:
N = int(input())
B = tuple(map(int, input().split()))
assert len(B) == N - 1

count = B[0] + B[-1]
for b1,b2 in zip(B, B[1:]):
  count += min(b1, b2)
print(count)

Submission status: Accepted

Solution code:
# ABC 140 C
N = int(input())
B = [int(i) for i in input().split()]
ans = B[0] + B[-1]
if N >= 3:
    for i in range(0, N-2):
        ans += min(B[i], B[i+1])

print(ans)

Submission status: Accepted

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

ans = 0
last_n = 0
for i in l:
    if i >= last_n:
        ans += i
        last_n = i
    else:
        ans -= last_n
        ans += i*2
        last_n = i
ans += l[0]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
b=[int(x) for x in input().split()]
a=[0]*n
a[0]=b[0]
a[n-1]=b[n-2]
for i in range(1,n-1):
    s=min(b[i],b[i-1])
    a.append(s)
    
print(sum(a))

Submission status: Accepted

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-1]
    else:
        ans+=min(B[i],B[i-1])
print(ans)

Submission status: Accepted

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

c=0

c+=b[0]+b[-1]

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
B = list(map(int, input().split()))
#flag = True
ans = B[0]
before = B[0]
for k in range(N-1):
  if before > B[k]:
    ans -= before
    ans += B[k]+B[k]
    before = B[k]
  else:
    ans += B[k]
    before = B[k]
print(ans)
#print('Yes')
#print('No')

Submission status: Accepted

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

Submission status: Accepted

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(b[0]+ans+b[-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
#a, b = map(int, input().split())
bl = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]

al = [0]*n
al[-1] = bl[-1]
for i in range(n-2, -1, -1):
    if bl[i] < al[i+1]:
        al[i+1] = bl[i]
    al[i] = bl[i]
print(sum(al))

Submission status: Accepted

Solution code:
N = int(input())
B = list((int(x) for x in input().split()))
A1 = B + [100001]
A2 = [100001] + B
A = [min(A1[i],A2[i]) for i in range(N)]
print(sum(A))

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    numbers=[]
    n = int(input())
    numbers= list(map(int,input().split()))
    dp=[0]*n

    dp[0]=numbers[0]
    dp[-1]=numbers[-1]

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

if __name__=="__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

A.append(B[-1])

print(sum(A))

Submission status: Accepted

Solution code:
# coding: utf-8


def main():
    N = int(input())
    ans = 0
    B = list(map(int, input().split()))
    ans += B[0] + B[-1]

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

a =[b[0]]

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

print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

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

if n >= 3:
    for i in range(1, n-1):
        A[i] = min(B[i], B[i-1])

print(sum(A))

Submission status: Accepted

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

# 双対考える
# A1<=B1, A2<= min(B1,B2), A3<=min(B2,B3) ...
A = [B[0]]

for i in range(N-1):
    if i+1 != len(B):
        A.extend([min(B[i],B[i+1])])
    else:
        A.extend([B[i]])


print(sum(A))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# import math
# import statistics
# import itertools
a=int(input())
# b=input()
# c=[]
# for i in a:
#     c.append(int(i))
# N,K= map(int,input().split())
f = list(map(int,input().split()))
# g = [int(input()) for _ in range(N)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen
ans=[f[0],f[-1]]
for i in range(a-2):
    ans.append(min(f[i],f[i+1]))

print(sum(ans))

Submission status: Accepted

Solution code:
def abc140c():
    n = int(input())
    b = list(map(int, input().split()))
    ans = 0
    for i in range(len(b)):
        if i == 0:
            ans += b[i]

        if i == n-2:
            ans += b[i]

        if 0 < i :
            ans += min(b[i-1], b[i])
    print(ans)
abc140c()

Submission status: Accepted

Solution code:
n = int(input())
alist=list(map(int,input().split()))
alist.insert(0,1e7)
alist.append(1e7)
core = 0
for i in range(n):
  core +=min(alist[i],alist[i+1])
print(core)

Submission status: Accepted

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

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

a.append(b[-1])
#print(a)
print(sum(a))

Submission status: Accepted

Solution code:
import math
import collections
import itertools

def resolve():

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

    cnt=B[0]
    for i in range(N-2):
        if(B[i]<=B[i+1]):
            cnt+=B[i]
        else:
            cnt+=B[i+1]
    cnt+=B[N-2]
    print(cnt)
    
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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])
    else:
        if B[i-1] < B[i]:
            A.append(B[i-1])
        else:
            A.append(B[i])
A.append(B[i])

ANS = 0

for i in range(len(A)):
    ANS = ANS + A[i]
print(ANS)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0

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

print(res + B[0] + B[-1])

Submission status: Accepted

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

A = [0] * N

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

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

    if A[i] > B[i]:
        A[i] = B[i]
    
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

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

a_list = [0]*n
a_list[0] = num_list[0]

for i in range(1, n, 1):
	if i != n-1:
		a_list[i] = min(num_list[i-1], num_list[i])
	else:
		a_list[i] = num_list[-1]

sum = 0
for j in a_list:
	sum += j

print(sum)

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int, input().split()))
rli = li[::-1]
rli.append(100001)
ans = [0] * N

ans[0] = rli[0]
for i in range(0, len(li)):
    ans[i+1] = min(rli[i], rli[i+1])

#print(ans)
print(sum(ans))

Submission status: Accepted

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

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

print(A)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
res = [0] * n
res[0] = a[0]
for i in range(1,n-1):
  res[i] = min(a[i],a[i-1])
res[n-1] = a[-1]
print(sum(res))

Submission status: Accepted

Solution code:
n = int(input())
b = list(map(int,input().split()))
b.insert(0,1e7)
b.append(1e7)
count = 0 
for i in range(n):
    count +=min(b[i],b[i+1])
print(count)

Submission status: Accepted

Solution code:
#nは数列Aの長さ　Bの長さはn-1
n = int(input())
bn = list(map(int,input().split()))

an =[bn[0]]


for x in range(n-2):
    if bn[x+1] >= bn[x] :
        an.append(bn[x])
    else:
        an.append(bn[x+1])

an.append(bn[-1])

print(sum(an))

Submission status: Accepted

Solution code:
# C

N = int(input())
B = [10**10] + list(map(int,input().split())) + [10**10]
ans = 0
for i in range(N):
  ans += min(B[i],B[i+1])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ls = [int(i) for i in input().split()]
if len(ls) == 1:
  print(ls[0]*2)
else:
  als = [ls[0]]
  for n in range(1, N-1):
    als.append(min(ls[n-1], ls[n]))
  als.append(ls[-1])
  print(sum(als))

Submission status: Accepted

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

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

print(sum(A))

Submission status: Accepted

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

print(ans)