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: Runtime Error

Solution code:
import numpy as np
N=int(input())
B=list(map(int,input.split()))
A=np.zeros(N,dtype="int64")

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
N,K,Q=map(int,input().split())
a = [int(input()) for i in range(Q)]
for i in range(N):
  if a.count(i+1)>=Q-K+1:
    print("Yes")
  else:
    print("No")

Submission status: Runtime Error

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

ans += b[-1]
print(ans)

Submission status: Runtime Error

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

A = 0

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

Submission status: Runtime Error

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

    total = B[0]
    for i in range(N):
        total += B[i]
    print(total)

check()

Submission status: Runtime Error

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

B = [100] + B [100]
s = 0
for i in range(len(B) - 1):
    s += min(B[i], B[i + 1])
print(s)

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python
N = int(input())
B = list(map(int, input().split()))

B = [100, *B, 100]
s = 0
for i in range(len(B) - 1):
    s += min(B[i], B[i + 1])
print(s)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
b = list(map(int, input().split()))
sum = 0
for i in range(N):
    if i==0:
        sum += b[0]
    elif i==N-1:
        sum += b[N-1]
    else:
        sum += min(b[i], b[i+1])
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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])
  elif b[i] <= b[i+1]:
    a.append(b[i+1])
a.append(b[-1])
print(sum(a))

Submission status: Runtime Error

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

b.append(100010)
a = []
a.append(b[0])

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

Submission status: Runtime Error

Solution code:
n =  int(raw_input())
B = map(int, raw_input().split())
print sum(B) - sum([abs(B[i] - B[i-1]) for i in xrange(1, n)])

Submission status: Runtime Error

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



for i in range(len(B)):

    if i == 0:
        if len(B)==1 or B[i]<=B[i+1]:

            A.extend(B[:1]*2)

        elif B[i]>B[i+1]:

            A.extend(B[1:2]*2)

            
    if 0 < i < len(B):

        if B[i]<B[i+1]:


            A.append(B[i])

        elif B[i]>=B[i+1]:

            A.append(B[i+1])

    if i!=0 and i==len(B)-1:

        A.append(B[i])
            
        
from functools import reduce

print(reduce(lambda x,y : x+y,A))

Submission status: Runtime Error

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

for i in range(len(B)):

    if i==0:
        if B[i]<B[i+1] or B[i]==B[i+1]:

            A.extend(B[:1]*2)

        elif B[i]>B[i+1]:

            A.extend(B[1:2]*2)
            
        

    elif i<len(B)-1 and B[i]>B[i+1]:

        A.append(B[i+1])

    else:

        A.append(B[i])
            
        

    
from functools import reduce

print(reduce(lambda x,y : x+y,A))

Submission status: Runtime Error

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

list_A = [0]*n

list_A[0] = B[0]
list_A[i-1] = B[i-2]
for i in range(1:n-2):
    list_A[i] = max(B[i],B[i+1])

print(sum(list_A))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
b_arr = list(map(lambda b: int(b), input().split()))
a_arr = list(range(N))

for n in range(N-1, -1, -1):
    if (n == N-1) or (n == N-2):
        a_arr[N-1] = b_arr[N-2]
        a_arr[N-2] = b_arr[N-2]
    elif b_arr[n+1] >= b_arr[n]:
        a_arr[n+1] = b_arr[n]
        a_arr[n] = b_arr[n]
    else:
        a_arr[n] = b_arr[n]

print(sum(a_arr)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int,input().split())
s = 0
for i in range(n-2):
  s+=min(a[n-2-i],a[n-i-3])
print(s+a[n-2])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def maximal():
    query = input().split('\n')
    B = query[1]
    B = B.split()
    B = [int(i) for i in B]
    # length of values is N
    # any number more or equals than 0
    result = []
 
    result.append(B[0])
 
    for i in range(0, len(B) - 1):
        # if value is same put in first one
        compared = B[i]
        if B[i + 1] <= compared:
            result.append(B[i + 1])
        else:
            result.append(B[i])
 
    result.append(B[len(B) - 1])
    return sum(result)
 
 
print(maximal())

Submission status: Runtime Error

Solution code:
def maximal():
    query = input().split()
    B = query[1]
    B = B.split()
    B = [int(i) for i in B]
    # length of values is N
    # any number more or equals than 0
    result = []

    result.append(B[0])

    for i in range(0, len(B) - 1):
        # if value is same put in first one
        compared = B[i]
        if B[i + 1] <= compared:
            result.append(B[i + 1])
        else:
            result.append(B[i])

    result.append(B[len(B) - 1])
    return sum(result)


print(maximal())

Submission status: Runtime Error

Solution code:
_,b=open(0);a,*b,c=map(int,b.split());print(a+sum(map(min,zip([a]+b,b+[c])))+c)

Submission status: Runtime Error

Solution code:
N = int(input())
B = list(map(int,input().split()))
A = []
for i in range(N):
  A.append(0)

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

Submission status: Runtime Error

Solution code:
N = int(input())
B = list(map(int,input().split()))
A = []
for i in range(N):
  A.append(0)

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

print(A)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# get a integer
N = int(input())

b = list(map(int, input().split()))
a = b[0]

# calc
for i in range(N-1):
  a = a + b[i]

# output
print(str(a))


print(str(point));

Submission status: Runtime Error

Solution code:
n=int(input())
b = list(map(int,input().split()))
score=b[n-2]
for i in range(b):
  if(n-i<2):
    break
  score+=min(b[n-2-i],b[n-3-i])
score+=b[0]
print(score)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# get a integer
N = int(input())

b = list(map(int, input().split()))
point = 0
temp_a = 0
temp_c = 0

# calc
for i in range(N):
  a[i] = b[i]
  #print(str(len(c)))
a[i] = b[i-1]  

# output
print(str(a))
#print(str(b))
#print(str(c))
#print(str(N))

print(str(point));

Submission status: Runtime Error

Solution code:
N = int(input())
B_list = list(map(int,input().split()))
A_list = [0 for i in range(N)]

A_list[0] = B_list[0]

for i in range(1,N-1):
    A_list[i] = min(B_list[i],B_list[i-1])

A_list[-1] = B_list[-1]
print(sum(A_list)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

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

sum_A = min(B[0], B[1])

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

Submission status: Runtime Error

Solution code:
#!/anaconda3/bin/python
n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
money=0
ab.sort(key=lambda tup:tup[0])
for a,b in ab:
    if m-b>0:
        money+=a*b
        m-=b        
    else:
        money+=a*m
        break
print(money)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return map(int, input().split())


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


if __name__ == "__main__":
    N = read()
    B = [math.inf]
    B.extend(readlist())
    B.append(math.inf)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = input()
B = list(map(int, input().split()))
B_last = int(len(B))
A = B[0] + B[B_last - 1]
i = 1
old_b = B[1]
for i in range(B_last):
  #print("A =",A, "B =",B[i])
  b = B[i]
  if b >= old_b:
    A += old_b
    #print("A =",A)
  else:
    A += b
    #print(A)
  old_b = B[i]
  #print("A =",A, "B =",B[i],"old_b =", old_b)
#print("A =",A)
print(A)

Submission status: Runtime Error

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

N = int(input())
A = [100001] * N
B = list(map(int, input().split()))

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

  A[-1] = B[-1]

  print(sum(A))

Submission status: Runtime Error

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

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

print(sum(B))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

A = B[1]

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
b=[int(x) for x in input().split()]
a=[0]*n
for i in range(n-1):
	if(i==0):
		a[0]=b[0]
		a[1]=b[1]
	elif(b[i]>=b[i-1]):
		a[i+1]=b[i]
	elif(b[i]<b[i-1]):		
		a[i]=b[i]
		a[i+1]=b[i]
print(sum(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

A = [0] * N


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

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

print(sum(A))

Submission status: Runtime Error

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

A = [0] * N


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

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

print(A)

print(sum(A))

Submission status: Runtime Error

Solution code:
N = int(input())
Bs = list(map(int, input().split()))
 
As = [ None for _ in range(N) ]

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

print(sum(As))

Submission status: Runtime Error

Solution code:
sum = 0
for i in range(N):
    if i == 0:
        sum += list_B[i]
#         print('i == 0')
#         print('i=', i, 'sum=', sum)
    elif i == N-1:
        sum += list_B[i-1]
        print('i == N-1')
#         print(list_B[i-1])
#         print('i=', i, 'sum=', sum)
    else:
        if (list_B[i] >= list_B[i-1]):
            sum += list_B[i-1]
        else:
            sum += list_B[i]
#         print('i=', i, 'sum=', sum)
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
b = list(map(int, input().split()))
b = b[::-1]
a = []
cont0 = False
a.append(b[0])
if len(b) == 1:
	print(2*b[0])
	quit() 
if b[0] > b[1]:
	a.append(b[1])
	a.append(b[1])
elif b[0] == b[1]:
	a.append(b[0])
	a.append(b[0])
elif b[0] < b[1]:
	a.append(b[0])
	a.append(b[1])
if len(b) == 2:
	print(sum(a))
	quit()
for i in range(2,n-1):
	if not cont0
		if b[i-2] > b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = b[i]
				a.append(b[i])
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
		elif b[i-2] == b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = b[i]
				a.append(b[i])
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
		elif b[i-2] < b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = 0
				a.append(0)
				cont0 = True
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
	else:
		if b[i-1] < b[i]:
			a.append(b[i])
		else:
			a.append(0)
		cont0 = False

print(sum(a))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if n==2:
    ans = Bs[0]*2

elif n==3:
    ans += sum(Bs)
    ans += min(Bs)

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

Submission status: Runtime Error

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

if n==2:
    ans = Bs[0]*2

elif n==3:
    ans += sum(Bs)
    ans += min(Bs)

else:
    ans += Bs[0]
    ans += Bs[-1]
    for i in range(len(Bs)-1,-1,-1):
        ans += min(Bs[i],Bs[i+1])
        
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int,input().split()))
count = 0
for i in range (len(arr)):
  if i < len(arr)-1 and i !=len(arr)-1:
    if arr[i] > arr[i+1]:
      count =count + arr[i+1]:
    else:
      count =count+arr[i]:
  elif i ==len(arr)-1:
    count =count+arr[i]
print(count)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from collections import deque

n = 0
a = []
b = []

n = int(input())
b = list(map(int, input().split()))
bs = sorted(list(set(b)))
# print(bs)
queue = deque(bs)
# print(queue)

a.append(queue[0])

q = 0
for i in range(n-1):
    # print("=== loop:", i)
    # print("a = ", a)

    if i == n-1:
        a[-1] = queue.popleft()
        break
    if b[i] == a[i]:
        a.append(a[i])
        q+=1
    else:
        a.append(queue[q])

# print(a)
print(sum(a))

Submission status: Runtime Error

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

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

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

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

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:

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


for i in range(n-1):
    if(i>0):
        if(b[i]>=b[i-1]):
            a.append(b[i-1])
        else:
            a.append(b[i])

if(b[-2]>=b[-1]):
    a.append(b[-2])
else:
    a.append(b[-1])

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

print(sum)

Submission status: Runtime Error

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

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

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

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

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

print(ans)

Submission status: Runtime Error

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


for i in range(n-1):
    if(i>0):
        if(b[i]>b[i-1]):
            a.append(b[i-1])
        else:
            a.append(b[i])

if(b[-2]>=b[-1]):
    a.append(b[-2])
else:
    a.append(b[-1])

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

print(sum)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
B=list(map(int,input().split()))
total=B[0]
if N==2:
    print(B[0]*2)
    exit()
    
if N==3:
    print(B[0]+min(B[1],B[0])+B[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: Runtime Error

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

Submission status: Runtime Error

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

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

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

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

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

print(ans)

Submission status: Runtime Error

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

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

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

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

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

print(res)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(sum(ans) + ans1)

Submission status: Runtime Error

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

if N == 2:
  print(N*B)
else:
  for i in B:
    if B[i] > B[i+1]:
      A[i] = B[i]
      A[i+1] = B[i]
    else:
      A[i] = B[i]
      A[i+1] = B[i+1]

x = 0
for x in A:
  x = x + A
print(x)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

SUM = 0
A = [0]*N

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


print(sum(A))

Submission status: Runtime Error

Solution code:
N=int(input())
B=list(map(int,input().split()))
A=[]
A.append(B[0])
A.append(B[0])
num=0
for i in B:
    if i==B[0]:
        num+=1
        continue
    elif A[num]<=B[num]:
        A.append(B[num])
        num+=1
    else:
        A[num]=B[num]
        A.append(B[num])
        num+=1

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(sum(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#code
n=int(input())
b=input()

b=b.split()

b=list(map(int,b))
a=list()
for i in range(len(b)-1):
    if(i==0):
        a.append(b[i])
        a.append(b[i])
    else:
        a.append(min(b[i],b[i+1]))
a.append(max(b[len(b)-1],a[len(a)-1]))
sum=0 
for i in range(len(a)):
    sum+=a[i]
print(sum)

Submission status: Runtime Error

Solution code:
N=int(input())
B=[]
for i in range(N-1):
    x=int(input())
    B.append(x)
for j in range(N-2):
    if(B[j]>B[j+1]):
        B[j]=B[j+1]

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

Submission status: Runtime Error

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)
    
a.append(max(b[-2],b[-1]))
print(sum(a))

Submission status: Runtime Error

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

print(sum(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(a) for a in input().split()]
for i in range (n-1):
  aa = min(a[i],a[i+1])
  aaa.append(aa)
print(aaa)

Submission status: Runtime Error

Solution code:
import copy
n = int(input())
b = list(map(int,input().split()))
ans = 0
ls = copy.copy(b)

for i in range(n-1):
    if b[i] == 0:
        ls.remove(0)
        if i+1 < n-1:
            ls.remove(b[i+1])  

if n == 2:
    print(min(b)*2)
else:
    print(sum(ls)+min(ls))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = []
sum_a = b[0] + b[-1]
for i,b_i in enumerate(b):
    
    if i+1 < n-1:
        if b[i+1] >= b[i]:
            a.append(b[i])
            sum_a += b[i]
        else:
            a.append(b[i+1])
            sum_a += b[i+1]
print(sum_a)

Submission status: Runtime Error

Solution code:
num = int(input())
array = map(int, input().split())
sum = 0
 
for (i = 0; i < num; i++):
	if i == 0:
      sum += array[i]
    else if i < (num-1):
      if array[i] > array[i-1]:
        sum += array[i-1]
      else:
        sum += array[i]
    else:
      sum += array[i-1]
        
print(sum)

Submission status: Runtime Error

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(b[-i], b[-(i+1)]))
a.append(max(b[0], b[1]))

print(sum(a))

Submission status: Runtime Error

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

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

else:
  for i,v in enumerate(B):
    if i != N-2:
      if B[i] <= B[i+1]:
        if A[i] == 'a':
          A[i] = B[i]
        if A[i+1] == 'a':
          A[i+1] = B[i]
      else:
        if A[i] == 'a':
          A[i] = B[i]
    else:
      if A[i+1] == 'a':
        A[i+1] = B[i]
  print(sum(A))

Submission status: Runtime Error

Solution code:
num = int(input())
array = map(int, input().split())
sum = 0
 
for i in range(num):
	if i == 0:
      sum += array[i]
    else if i < (num-1):
      if array[i] > array[i-1]:
        sum += array[i]
      else:
        sum += array[i-1]
    else:
      sum += array[i-1]
        
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

A = [0,0,0,0,0,0]
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))