qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
B = list(map(int, input().split()))

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

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

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

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

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

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


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

print(sum(a))
Buggy code:
N = int(input())
B = []
B = list(map(int, input().split()))

A = 0

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

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

A = 0

for i in range(N):
    if i == 0:
        A += B[0]
    elif i < len(B):
#         print(i, B[i-1], B[i])
        A += min(B[i-1], B[i])
    elif i == N-1:
        A += B[i-1]
        
print(A)
Buggy 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)

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

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


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

ans = B[-1]

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

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

Fixed code:
n=int(input())
B=list(map(int,input().split()))
c=B[0]+B[-1]
if n>=3:
    for i in range(n-2):
        c+=min(B[i],B[i+1])
print(c)
Buggy 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))


Fixed 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))
Buggy 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)

Fixed 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)
Buggy 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))

Fixed code:
N = int(input())
A = [0] * N
B = list(map(int, input().split()))
for i in range(1, N-1):
  A[i] = min(B[i-1],B[i])
A[0] = B[0]
A[-1] = B[-1]
print(sum(A))
Buggy code:
n = int(input())
b = list(map(int,input().split()))
sum = 0
for i in range(n-1):
    if i == 0:
        sum += b[0]
        pass
    sum += min(b[i-1],b[i])
sum += b[-1]
print(sum)

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

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

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

Fixed code:
N = int(input())
B = [int(i) for i in 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[N - 1] = B[N-2]

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

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

B = [int(i) for i in input()split()]

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

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

Fixed code:
N = int(input())

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

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

for i in range(1,N-1):
    ans+=min(B[i],B[i-1])
    
print(ans)
Buggy code:
N=int(input())
B=list(map(int,input().split()))
A=[B[0]]
preb=B[0]
for b in B[1:]:
  A.append(min(preb,b))
  preb=b
print(sum(A))

Fixed code:
N=int(input())
B=list(map(int,input().split()))
A=[B[0]]
preb=B[0]
for b in B[1:]:
  A.append(min(preb,b))
  preb=b
A.append(B[-1])
print(sum(A))
Buggy 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[1])
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)

Fixed 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[1])
    exit()
for i in range(N-2):
    total+=min(B[i],B[i+1])
    
#if N%2==0:
total+=B[-1]
print(total)
Buggy 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)

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

ans += b[-1]
print(ans)
Buggy code:
N = int(input())
B_LIST = list(map(int, input().split(' ')))
ans = 0
for i in range(N):
  if i == 0:
    ans += B_LIST[i]
  else:
    ans += B_LIST[i - 1]
print(ans)

Fixed code:
N = int(input())
B_LIST = list(map(int, input().split(' ')))
ans = 0
for i in range(N):
  if i == 0:
    ans += B_LIST[i]
  else:
    if i == N - 1:
        ans += B_LIST[i - 1]
    else:
        if B_LIST[i - 1] > B_LIST[i]:
            ans += B_LIST[i]
        else:
            ans += B_LIST[i - 1]
print(ans)
Buggy code:
n = int(input())
c = input().split()
b = [int(n) for n in c]
if n == 2:
    N = b * 2
else:
    a = [b[0]]
    for i in range(1,n-1):
        x = min(b[i-1],b[i])
        a.extend(str(x))
    a.extend(str(b[n-2]))
    N = 0
    for i in range(n):
        N = N + int(a[i])

print(N)

Fixed code:
n = int(input())
c = input().split()
b = [int(n) for n in c]
if n == 2:
    N = b[0] * 2
else:
    a = [n]
    a[0] = b[0]
    for i in range(1,n-1):
        x = min(b[i-1],b[i])
        a.append(x)
    a.append(str(b[n-2]))
    N = 0
    for i in range(n):
        N = N + int(a[i])
print(N)
Buggy 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)
  
  

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

Fixed code:
n=int(input())
if n!=2:
    blist=list(map(int,input().split()))
    alist=[blist[0]]
    for i in range(1,n-1):
        alist.append(min(blist[i],blist[i-1]))
    alist.append(blist[n-2])
    gokei=sum(alist)
    print(gokei)
else:
    b=int(input())
    print(int(b*2))
Buggy code:
N=int(input())
B = [int(i) for i in input().split()] 
A=[0]*N
A[0]=B[0]
for i in range(N-2):
    A[i+1]=B[i]
    if B[i+1]>=B[i]:
        A[i+2]=B[i+1]
    else:
        A[i+1]=B[i+1]
if B[N-2]<B[N-3]:
    A[N-1]=B[N-2]
ans=sum(A)
print(ans)

Fixed code:
N=int(input())
B = [int(i) for i in input().split()] 
A=[0]*N
A[0]=B[0]
for i in range(N-2):
    A[i+1]=B[i]
    if B[i+1]>=B[i]:
        A[i+2]=B[i+1]
    else:
        A[i+1]=B[i+1]
if B[N-2]<=B[N-3]:
    A[N-1]=B[N-2]
ans=sum(A)
print(ans)
Buggy code:
N = int(input())
B = list(map(int, input().split()))
A = []
A.append(B[N-2])
for i in reversed(range(1, len(B))):
    if B[i]>=B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])

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


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

A.append(B[0])

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


Fixed code:
N = int ( input() )
c = list( map( int, input().split() ) )
ans_list = [ c[0] ]
for i in range( N - 2 ):
    ans_list.append( min(c[i], c[i+1]) )
ans_list.append( c[N-2] )
print( sum( ans_list ) )
Buggy code:
n = int(input())
b = list(map(int,input().split()))
ans = [b[0],b[-1]]
b = [float('inf')] + b + [float('inf')]
for i in range(2,n-1):
    ans.append(min(b[i],b[i+1]))
print(sum(ans))

Fixed code:
n = int(input())
b = list(map(int,input().split()))
ans = [b[0],b[-1]]
b = [float('inf')] + b + [float('inf')]
for i in range(1,n-1):
    ans.append(min(b[i],b[i+1]))
print(sum(ans))
Buggy code:
n=int(input())
b=list(map(int,input().split()))
ans=0
a=[]
a.append(b[0])
for i in range(1,n):
  a.append(min(b[i-1],b[i]))
  
for i in range(n):
  ans+=a[i]
  
print(ans)

Fixed code:
n = int(input())
b = list(map(int,input().split()))
ans = 0
ans += b[0] + b[-1]

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

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

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

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

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

for i in range(n-2) :
  a.append(min(b[i], b[i+1]))
  
print(sum(a))
Buggy code:
N = int(input())
B = list(map(int,input().split()))
A = [0 for _ in range(N)]
ans = 0
for i in range(N-2):
    if B[i] < B[i+1]:
        A[i]=B[i]
        A[i+1]= B[i]
    elif B[i] > B[i+1]:
        A[i+1]=B[i+1]
    else:
        A[i]=B[i]
        A[i+1]= B[i]
ans = sum(A)
ans += B[N-2]
print(ans)

Fixed code:
N = int(input())
B = list(map(int,input().split()))
A = [0 for _ in range(N)]
ans = B[0]
for i in range(N-2):
    if B[i] < B[i+1]:
        A[i+1]= B[i]
    elif B[i] > B[i+1]:
        A[i+1]=B[i+1]
    else:
        A[i+1]= B[i]
ans += sum(A)
ans += B[N-2]
print(ans)
Buggy code:
n = int(input())

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

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

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

    alis = [blis[0], blis[0]]
    for i in range(2, n):
        alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()


Fixed code:
def main():
    n = int(input())
    blis = list(map(int, input().split()))

    alis = [blis[0], blis[0]]
    if n > 2 and alis[1] > blis[1]:
        alis[1] = blis[1]
    if n > 2:
        for i in range(3, n):
            alis.append(min(blis[i-2], blis[i-1]))
    if n > 2:
        alis.append(blis[n-2])
    print(sum(alis))


    


if __name__ == "__main__":
    main()
Buggy 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))

Fixed 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(sum(a))
Buggy code:
N = int(input())
b = [10**9] + list(map(int,input().split())) + [10**9]
a = []
a.append(b[1])
for i in range(1,N-1):
  a.append(min(b[i-1],b[i]))
  
a.append(b[N-1])
print(sum(a))

Fixed code:
N = int(input())
b = [10**9] + list(map(int,input().split())) + [10**9]
a = []

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

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

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





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

Fixed code:
N = int(input())
B =list(map(int,input().split()))
ans = 0
A = [0]*N
A[0] = B[0]
for i in range(1,N-1):
    if B[i] < B[i-1]:
        A[i] = B[i]
    else:
        if B[i] == A[i]:
            A[i] = A[i-1]
        else:
            A[i] = B[i-1]
A[N-1] = B[N-2]
ans = sum(A)
print(ans)
Buggy code:
n = int(input())
b = list(map(int,input().split()))

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

Fixed code:
n=int(input())
b=list(map(int,input().split()))
ct=b[0]+b[n-2]
for i in range(n-2):
  ct+=min(b[i],b[i+1])
print(ct)
Buggy 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))

Fixed 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-1):  
  As[i] = min(Bs[i-1], Bs[i])

As[-1] = Bs[-1]

print(sum(As))
Buggy 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)

Fixed 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))
Buggy code:
n = int(input())
b = list(map(int, input().split()))
ans = 0
a = [0]*n
a[0]=b[0]
for i in range(1,n-1):
  a[i] = min(b[i],b[i-1])
a[n-1]=b[n-2]
ans=sum(a) 
print(ans,a)

Fixed code:
n = int(input())
b = list(map(int,input().split()))
a = [0] * n
a[0] = b[0]
a[n-1] = b[n-2]
sum = a[0] + a[n-1]
for i in range(1,n-1):
    a[i] = min(b[i-1],b[i])
    sum += a[i]
print(sum)
Buggy 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))

Fixed 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:
            pass
            #a[0] = min(b[0],b[1])
        else:
            a[i] = min(b[i-1],b[i])
    print(sum(a))
Buggy 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])

Fixed code:
N = int(input())
B = list(map(int, input().split()))
s = 0
for i in range(N-1):
  if i == 0:
    s += B[0]
  else:
    s += min(B[i-1], B[i])
print(s + B[N-2])
Buggy code:
n=int(input())  
B=list(map(int, input().split())) 
A = []
for i in range(len(B)):
    if i == 0:
        A.append(B[i])
        A.append(B[i])
    elif B[i] > B[i-1]:
        A.append(B[i])
    else:
        A.append(B[i-1])

print(sum(A))

Fixed code:
n=int(input())  
B=list(map(int, input().split())) 
A = []
for i in range(len(B)):
    if i == 0:
        A.append(B[i])
    elif B[i] > B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])
    #print(B[i], B[i-1])
A.append(B[i])

print(sum(A))
Buggy 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))

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

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

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

	ans += min(B[i-1], B[i])

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

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

import numpy as np
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

et = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1
print(ret)

Fixed code:
import numpy as np
N = int(input())
B = np.array(input().split(), dtype=int)[::-1]

ret = 0

ret += B[0]

i = 0
while i < N-2:
    ret += B[i] if B[i] < B[i+1] else B[i+1]
    i+=1

ret += B[-1]
print(ret)
Buggy code:
n = int(input())
B = list(map(int, input().split()))

A = [0] * n

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


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

A = [0] * n

if n == 2:
  A[0] = A[1] = B[0]
elif n == 3:
  A[0] = B[0]
  A[1] = min(B[0], B[1])
  A[-1] = B[-1]
elif n > 3:
  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))
Buggy code:
N = int(input())
B = list(map(int, input().split()))

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

print(sum)

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

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

cnt = B[0] + B[-1]

for i in range(0, n-2)
    cnt += min(B[i], B[i+1])

print(cnt)


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

cnt = B[0] + B[-1]

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

print(cnt)
Buggy code:
n=int(input())

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

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

print(sum(a))


Fixed code:
n=int(input())

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

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

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


Fixed 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(a[-1]>=b[-1]):
    a.append(a[-1])
else:
    a.append(b[-1])

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

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

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

print(res)


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

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

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

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


Fixed 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])
print(max_value)
Buggy 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))

Fixed code:
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-1):
    A[i] = B[i]
  for i in range(N-2):
    if A[i+1] > B[i]:
      A[i+1] = B[i]

  A[-1] = B[-1]

  print(sum(A))
Buggy code:
hoge = input()
nums = list(map(int, input().split(' ')))[::-1]
current = nums[0]
ans = 0
for n in nums:
    current = min(current, n)
    ans += current
print(ans)


Fixed code:
hoge = input()
nums = list(map(int, input().split(' ')))[::-1]
current = nums[0]
ans = 0
for n in nums:
    current = min(current, n)
    ans += current
    current = n  # !
print(ans + current)  # !!
Buggy code:
n = int(input())
B = list(map(int,input().split()))[::-1]

ans = B[0]

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

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