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

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

print(res)

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

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

print(res)
Buggy code:
n = int(input())
b = list(map(int, input().split()))
a = [0] * n
for i in range(0,n-1):
    a[i] = min(b[i-1],b[i])
#a[0] = a[1]
a[-1] = b[-1]
print(a)


Fixed 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] = b[0]
a[-1] = b[-1]
print(sum(a))
Buggy 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[-1] = b[-1]
print(sum(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]
for i in range(1,n-1):
	a[i]=min(b[i-1],b[i])
sum=0
for i in range(n):
	sum+=a[i]
print(sum)
Buggy code:
 = 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))


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

#print(n)
#print(b)

score = b[0]+b[n-2]
#print(b[0],b[n-2])

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

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

#print(n)
#print(b)

score = b[0]+b[n-2]
#print(b[0],b[n-2])

for i in range(0,n-2):
	score = score + min(b[i],b[i+1])
#	print(min(b[i],b[i+1]))
print(score)
Buggy code:
# C - Maximal Value
n = (int)(input())
b = list(map(int, input().split()))

a = [0] * n

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

print(sum(a))

Fixed code:
# C - Maximal Value
n = (int)(input())
b = list(map(int, input().split()))

a = [0] * n

for i in reversed(range(0, n)):
    if i == n - 1: a[i] = b[i-1]
    elif i == 0: a[i] = b[0]
    else: a[i] = min(b[i], b[i-1])

print(sum(a))
Buggy code:
if __name__ == '__main__':
    a = int(input())
    li_1 = list(map(int, input().split()))
    res = []
    for x in range(0, a - 1):
        if x == 0:
            res.append(li_1[x])
        else:
            res.append(min(li_1[x], li_1[x - 1]))
res.append(li_1[-1])
result = 0
for x in res:
    result += x


Fixed code:
if __name__ == '__main__':
    a = int(input())
    li_1 = list(map(int, input().split()))
    res = []
    for x in range(0, a - 1):
        if x == 0:
            res.append(li_1[x])
        else:
            res.append(min(li_1[x], li_1[x - 1]))
res.append(li_1[-1])
result = 0
for x in res:
    result += x

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

Fixed 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], a[N-2]))

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

Fixed 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(sum(ans))
Buggy code:
n = int(input())
b = list(map(int,input().split()))

ans = b[0]

for i in range(n-1):
  ans += b[i]
print(ans)
  

Fixed code:
n = int(input())
b = list(map(int, 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:
#code
n=int(input())
b=input()

b=b.split()

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

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


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

b=b.split()

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

for i in range(1,len(b)):
    
    
    a.append(min(b[i],b[i-1]))
if(n>2):
    a.append(b[len(b)-1])
if(n==2):
    a.append(b[0])
sum=0 
for i in range(len(a)):
    sum+=a[i]
print(sum)
Buggy code:
import numpy as np
N = input()
N = int(N)
B = np.hstack([int(a) for a in input().split()])

A = np.zeros(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(np.sum(A))

Fixed code:
import numpy as np
N = input()
N = int(N)
B = np.hstack([int(a) for a in input().split()])

A = np.zeros(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(int(np.sum(A)))
Buggy 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]))
    print(b[i])
a.append(b[len(b)-1])

print(sum(a))

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


Fixed 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-2]
    else:
        sum += min([b[i-1], b[i]])
print(sum)
Buggy 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))
print(an)

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

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

Fixed code:
n=int(input())
a=list(map(int,input().split()))
a=a+[10**18]
ans=a[0]
for i in range(n-1):
  ans+=min(a[i],a[i+1])
print(ans)
Buggy code:
n = int(input())
b = [int(i) for i in str(input()).split(" ")]
a = [0] * (n)

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

print(a)

Fixed code:
n = int(input())
b = [int(i) for i in str(input()).split(" ")]
a = [0] * (n)

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

  if i == n - 1 - 1:
    a[i + 1] = b[i]
  else:
    a[i + 1] = min(b[i], b[i + 1])

print(sum(a))
Buggy code:
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    for i in range(n-2):
      if b[i] > b[i+1]:
        b[i] = b[i+1]
    
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += max(first,nextvalue)
      first = nextvalue
  print(ans)
solve()

Fixed code:
def solve():
  n = int(input())
  b = list(int(i) for i in input().split())
  ans = 0
  
  if n == 2:
    ans = b[0]*2
  else:
    ans = b[0]
    ans += b[-1]
    first = b[0]
    for i in range(n-2):
      nextvalue = b[i+1]
      ans += min(first,nextvalue)
      first = nextvalue
  print(ans)
solve()
Buggy code:
N = int(input())
B_list = list(map(int, input().split()))

A_list = []
for i, B in enumerate(B_list):
    if not A_list:
        A_list.append(B)
        A_list.append(B)
        print(B, B)
    elif i < len(B_list)-1:
        if B > B_list[i+1]:
            A_list.append(B_list[i+1])
        else:
            A_list.append(B)
    else:
        A_list.append(B)
    print(A_list)
print(sum(A_list))

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

A_list = []
for i, B in enumerate(B_list):
    if not A_list:
        if len(B_list) > 1 and B > B_list[i+1]:
            A_list.append(B)
            A_list.append(B_list[i+1])
        else:
            A_list.append(B)
            A_list.append(B)
    elif i < len(B_list)-1:
        if B > B_list[i+1]:
            A_list.append(B_list[i+1])
        else:
            A_list.append(B)
    else:
        A_list.append(B)
print(sum(A_list))
Buggy code:
# C - Maximal Value
N = int(input())
B = list(map(int,input().split()))
A = [10**6]*N

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

print(A)


Fixed code:
# C - Maximal Value
N = int(input())
B = list(map(int,input().split()))
A = [10**6]*N

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

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

if __name__='__main__':
   A(N,B)

Fixed code:
N = int(input())
B = list(map(int,input().split()))
 
def A(N,B):
   sum = B[0] + B[N-2]
   for i in range(N-2):
       sum += min(B[i],B[i+1])
   print(sum)
 
if __name__=='__main__':
   A(N,B)
Buggy code:
N=int(input())
B_list=list(map(int,input().split()))

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

Fixed code:
N=int(input())
n=N-1
B_list=list(map(int,input().split()))

ans=0
if N==2:
    print(B_list[0]*2)
else:
    ans+=B_list[0]
    for i in range(n-1):
        ans+=min(B_list[i],B_list[i+1])
    ans+=B_list[n-1]
    print(ans)
Buggy 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))
   

Fixed code:
n=int(input())

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

res=[]

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

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

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

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

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

a = [0]*n
for i in range(n-1):
    if i == 0:
        a[0] = b[0]
        a[1] = b[0]
    elif b[i] >= b[i-1]:
        a[i+1] = b[i]
    elif b[i] < b[i-1]:
        a[i+1] = b[i]
        a[i] = b[i]
print(sum(a))
Buggy code:
N=int(input())
B=[10**6]
B.extend([int(b) for b in input().split()])
B.append(10**6)
print(N, B)

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

Fixed code:
N=int(input())
B=[10**6]
B.extend([int(b) for b in input().split()])
B.append(10**6)
#print(N, B)

A=[None]*N
for i in range(N):
  A[i] = min(B[i], B[i+1])
  
print(sum(A))
Buggy code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
b = na()

b = [0] + b + [10**6]
ans = 0
for i in range(1,n+1):
    ans += min(b[i-1],b[i])

print(ans)

Fixed code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
b = na()

b = [10**6] + b + [10**6]
ans = 0
for i in range(1,n+1):
    ans += min(b[i-1],b[i])

print(ans)
Buggy code:
n = int(input())
list_b = list(map(int, input().split()))
list_a = [0]*n

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

print(list_a)
print(sum(list_a))

Fixed code:
n = int(input())
list_b = list(map(int, input().split()))
list_a = [0]*n

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

print(sum(list_a))
Buggy code:
n = int(input())
a = [int(a) for a in input().split()]
aaa=[]
if n==2:
  print(a[0]*2)
else:
  for i in range (n-2):
    aa = min(a[i],a[i+1])
    aaa.append(aa)
  aaa.append(a[n-2])
  print(sum(aaa))

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

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]*(len(B)+1)
A[0] = B[0]
A[1] = B[0]
cnt = 0
for i, x in enumerate(B):
    if i != 0:
        A[i + 1] = B[i]
        A[i] = min(A[i], B[i])
        cnt += A[i]
cnt += A[-1]
# print(A)
print(cnt)

Fixed code:
N = int(input())
B = list(map(int, input().split()))
A = [0]*(len(B)+1)
A[0] = B[0]
A[1] = B[0]
cnt = 0
for i, x in enumerate(B):
    if i != 0:
        A[i + 1] = B[i]
        A[i] = min(A[i], B[i])
    cnt += A[i]
cnt += A[-1]
print(cnt)
Buggy code:
N = int(input())
B = list(int,input().split())

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

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

print(answer)


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

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

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

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

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

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

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

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

result = B[0]

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

print(result)

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

result = B[0]

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

print(result)
Buggy code:
N = int(input())
B = list(map(int, input().split()))

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


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

A=[0 for i in range(N)] 
A[0]=B[0]
A[N-1]=B[N-2]
if 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())
l = map(int, input().split())

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

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

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

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


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

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

Fixed code:
def maximal():
    N = int(input())
    B = input()
    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())
Buggy code:
import sys


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

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

    A.append(B[len(B)-1])
    print(sum(A))


if __name__ == '__main__':
    main()


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

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

    A.append(B[-1])
    print(sum(A))


if __name__ == '__main__':
    main()
Buggy code:
N=int(input())
B=list(map(int,input().split()))
A=0

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

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

B_lst = list(map(int,input().split()))
A_lst = [0] * n

for i in range(n-2):
    if B_lst[i+1] > B_lst[i]:
        A_lst[i] = B_lst[i]
    else:
        A_lst[i] = B_lst[i+1]

if B_lst[n-3] > B_lst[n-2]:
    A_lst[n-2] = B_lst[n-2]
else:
    A_lst[n-2] = B_lst[n-3]

A_lst[n-1] = B_lst[n-2]
print(A_lst)
print(sum(A_lst))


Fixed code:
n = int(input())

B_lst = list(map(int,input().split()))
A_lst = [0] * n

A_lst[0] = B_lst[0]
A_lst[n-1] = B_lst[n-2]

if n >= 3:
    for i in range(1,n-1):

        if B_lst[i-1] > B_lst[i]:
            A_lst[i] = B_lst[i]
        else:
            A_lst[i] = B_lst[i-1]

print(sum(A_lst))
Buggy code:
n = int(input())
b = [int(i) for i in input().split()]
a = [0]*n
a[0] = b[0]
a[-1] = b[-1]
print(b)
if n==2:
  print(sum(a))
  exit()
i=0
while i<n-1:
  a[i]=min(b[i-1],b[i])
  i+=1
print(sum(a))

Fixed code:
n = int(input())
b = [int(i) for i in input().split()]
a = [0]*n
a[0] = b[0]
a[-1] = b[-1]
if n==2:
  print(sum(a))
  exit()
i=1
while i<n-1:
  a[i]=min(b[i-1],b[i])
  i+=1
print(sum(a))
Buggy code:
n=int(input())
b=list(map(int,input().split()))

x=b[1]

i=0
while n-1>i:
  if b[i]<=b[i+1]:
    x+=b[i]
    i+=1
  else:
    x+=b[i+1]
    i+=1
    
print(x)

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

x=b[0]+b[n-2]

i=1
while n-1>i:
  if b[i-1]<=b[i]:
    x+=b[i-1]
    i+=1
  else:
    x+=b[i]
    i+=1
    
print(x)
Buggy 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(1,n-2):
        A[i+1]=min(B[i],B[i+1])
print(sum(A))

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(1,n-1):
        A[i]=min(B[i],B[i-1])
print(sum(A))
Buggy 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)

Fixed code:
N = int(input())
B = list(map(int,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)
Buggy 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)

Fixed 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[N-2])

print(sum(A))
Buggy code:
n = int(input())
b_list = [int(i) for i in input().split()]
a_list = [0] * n
before_val = 0
for i in range(n-1):
    target = b_list[i]
    if a_list[i] == before_val:
        a_list[i], a_list[i+1] = b_list[i], b_list[i]
    else:
        a_list[i+1] = b_list[i]
print(sum(a_list))

Fixed code:
n = int(input())
b_list = [int(i) for i in input().split()]
a_list = [0] * n
before_val = 0
for i in range(n-1):
    target = b_list[i]
    if i == 0:
        a_list[i], a_list[i+1] = target, target
    elif before_val >= target:
        a_list[i], a_list[i+1] = target, target
    else:
        a_list[i], a_list[i+1] = before_val, target
    before_val = target
print(sum(a_list))
Buggy code:
N=int(input())

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

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

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

print(sum)

Fixed code:
N=int(input())

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

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

sum+=B[len(B)-1]
print(sum)