qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def input_ints():
    return list(map(int, input().split()))

def main():
    n = int(input())
    a = input_ints()
    c = 0
    for i in range(n):
        if a[i] < 0:
            c += 1
            a[i] *= -1
    ans = sum(a)
    if c % 2:
        ans -= min(a)
    print(ans)

if __name__ == '__main__':
    main()


Fixed code:
def input_ints():
    return list(map(int, input().split()))

def main():
    n = int(input())
    a = input_ints()
    c = 0
    for i in range(n):
        if a[i] < 0:
            c += 1
            a[i] *= -1
    ans = sum(a)
    if c % 2:
        ans -= 2 * min(a)
    print(ans)

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

dp = [[0 for i in range(2)] for i in range(N+1)]

dp[0][0] = 0
dp[0][1] = -100000

for i in range(N):
    dp[i+1][0] = max(dp[i][0] + A[i],dp[i][1] - A[i])
    dp[i+1][1] = max(dp[i][0] - A[i],dp[i][1] + A[i])
print(max(dp[N]))

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

dp = [[0 for i in range(2)] for i in range(N+1)]

dp[0][0] = 0
dp[0][1] = -10000000

for i in range(N):
    dp[i+1][0] = max(dp[i][0] + A[i],dp[i][1] - A[i])
    dp[i+1][1] = max(dp[i][0] - A[i],dp[i][1] + A[i])
print(dp[N][0])
Buggy code:
import sys

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


ans = 0
for a in A:
    ans += abs(a)

c = 0
m = A[0]
for a in A:
    if a < 0:
        c += 1
    elif a == 0:
        print(ans)
        sys.exit()

    if abs(a) < m:
        m = abs(a)

if c % 2 == 0:
    print(ans)
else:
    # print(ans - 2 * m)
    print('h')


Fixed code:
import sys

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


ans = 0
for a in A:
    ans += abs(a)

c = 0
m = abs(A[0])
for a in A:
    if a < 0:
        c += 1
    elif a == 0:
        print(ans)
        sys.exit()

    if abs(a) < m:
        m = abs(a)

if c % 2 == 0:
    print(ans)
else:
    print(ans - 2 * m)
Buggy code:
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))

    count = 0
    ans = 0
    _min = 10**9

    for a in a_s:
        if a <= 0:
            count += 1
        ans += abs(a)
        _min = min(_min, abs(a))
    if count % 2 == 1:
        ans -= _min
    print(ans)



if __name__ == '__main__':
    main()


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

    count = 0
    ans = 0
    _min = 10**9

    for a in a_s:
        if a <= 0:
            count += 1
        ans += abs(a)
        _min = min(_min, abs(a))
    if count % 2 == 1:
        ans -= 2*_min
    print(ans)



if __name__ == '__main__':
    main()
Buggy code:
N=input()
A=map(int,input().split())
B=list(map(abs,A))
print(sum(B)-min(B)*(1-(-1)**sum([1 for i in A if i<0])))

Fixed code:
N=input()
A=list(map(int,input().split()))
c=sum([1 for i in A if i<0])
A=list(map(abs,A))
print(sum(A)-min(A)*(1-(-1)**c))
Buggy code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0
abs_sum = 0
for i in A:
    abs_sum += abs(i)
    if i < 0:
        cnt += 1
mi = min([abs(i) for i in A])
if cnt % 2 == 0:
    print(abs_sum)
else:
    print(abs_sum-mi)

Fixed code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0
abs_sum = 0
for i in A:
    abs_sum += abs(i)
    if i < 0:
        cnt += 1
mi = min([abs(i) for i in A])
if cnt % 2 == 0:
    print(abs_sum)
else:
    print(abs_sum-(mi*2))
Buggy code:
N = int(input())
A = list(map(int, input().split()))

dp = np.zeros((N+1, 2), dtype=int)
dp[0, 1] = -10**9

for i in range(N):
    dp[i+1, 0] = max(dp[i, 0] + A[i], dp[i, 1] - A[i])
    dp[i+1, 1] = max(dp[i, 0] - A[i], dp[i, 1] + A[i])
print(dp[N, 0])

Fixed code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))

dp = np.zeros((N+1, 2), dtype=int)
dp[0, 1] = -10**9

for i in range(N):
    dp[i+1, 0] = max(dp[i, 0] + A[i], dp[i, 1] - A[i])
    dp[i+1, 1] = max(dp[i, 0] - A[i], dp[i, 1] + A[i])
print(dp[N, 0])
Buggy code:
def main():
  n=int(input())
  a=list(map(int,input().split()))
  dp=[0]*2
  for i in range(n):
    dp2=[max(dp[0]+a[i],dp[1]-a[i]),max(dp[0]-a[i],dp[1]+a[i])]
    dp=dp2
  print(max(dp))
main()

Fixed code:
def main():
  n=int(input())
  a=list(map(int,input().split()))
  dp=[0,-10**18]
  for i in range(n-1):
    dp2=[max(dp[0]+a[i],dp[1]-a[i]),max(dp[0]-a[i],dp[1]+a[i])]
    dp=dp2
  print(max(dp[0]+a[-1],dp[1]-a[-1]))
main()
Buggy code:

def main():
    _ = input()
    A = list(map(int, input().split()))
    A_list = []
    count = 0
    for a in A:
        if a < 0:
            count += 1
            A_list.append(a * -1)
        else:
            A_list.append(a)
    if count % 2 == 0:
        print(sum(A_list))
    else:
        print(sum(A_list))
        print(min(A_list))
        print(sum(A_list)-min(A_list) * 2)


if __name__ == "__main__":
    main()


Fixed code:

def main():
    _ = input()
    A = list(map(int, input().split()))
    A_list = []
    count = 0
    for a in A:
        if a < 0:
            count += 1
            A_list.append(a * -1)
        else:
            A_list.append(a)
    if count % 2 == 0:
        print(sum(A_list))
    else:
        print(sum(A_list)-min(A_list) * 2)


if __name__ == "__main__":
    main()
Buggy code:
n = int(input())
a = [int(x) for x in map(int, input().split())]

cnt = 0
for i in range(len(a)):
    if a[i] < 0:
       cnt += 1

b = []
for j in range(len(a)):
    b.append(abs(a[j]))

if cnt % 2 != 0:
        b.append(2*min(b))

print(sum(b))

Fixed code:
n = int(input())
a = [int(x) for x in map(int, input().split())]

cnt = 0
for i in range(len(a)):
    if a[i] < 0:
       cnt += 1

b = []
for j in range(len(a)):
    b.append(abs(a[j]))

if cnt % 2 != 0:
        b.append(-2*min(b))

print(sum(b))
Buggy code:
input()
A=list(map(int,input()))
s=0
for a in A:
  if a < 0:
    s += 1
if s % 2 == 0:
  S = sum([abs(a) for a in A])
else:
  B = [abs(a) for a in A]
  m = min(B)
  S = sum(B) - 2*m
print(S)

Fixed code:
input()
A=list(map(int,input().split()))
s=0
for a in A:
  if a < 0:
    s += 1
S=0
if s % 2 == 0:
  S = sum([abs(a) for a in A])
else:
  B = [abs(a) for a in A]
  m = min(B)
  S = sum(B) - 2*m
print(S)
Buggy code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	A = input().split()
	A = [int(s) for s in A]

	ans = 0
	dels = 0
	naiCounts = 0
	lasts = -1
	for i, val in enumerate(A):
		if val < 0:
			lasts = i
			naiCounts += 1
		if val == 0:
			lasts = -1
			naiCounts = 0

	if naiCounts % 2 == 0 or naiCounts == 0:
		for i, val in enumerate(A):
			if val < 0:
				ans = ans + (val * -1)
			else:
				ans += val
		print(ans)
		sys.exit()

	tmp = -1
	for i, val in enumerate(A):
		if i < lasts:
			continue

		if tmp -1 or tmp > abs(val):
			dels = i
	
	print(dels)
	for i, val in enumerate(A):
		if i == dels:
			if val < 0:
				ans += val
			else:
				ans -= val
		else:
			if val < 0:
				ans = ans + (val * -1)
			else:
				ans += val


	print(ans)



def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
if __name__ == "__main__":
	main()
	

Fixed code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline

# bisect_left(lists, 3)
# bisect_right(lists, 3)

def main():
	N = int(input())
	A = input().split()
	A = [int(s) for s in A]

	ans = 0
	dels = 0
	naiCounts = 0
	lasts = -1
	for i, val in enumerate(A):
		if val < 0:
			lasts = i
			naiCounts += 1
		if val == 0:
			lasts = -1
			naiCounts = 0
			break

	if naiCounts % 2 == 0 or naiCounts == 0:
		for i, val in enumerate(A):
			if val < 0:
				ans = ans + (val * -1)
			else:
				ans += val
		print(ans)
		sys.exit()

	tmp = -1
	for i, val in enumerate(A):
		if tmp == -1 or tmp > abs(val):
			tmp = abs(val)
			dels = i
	
	#print(dels)
	for i, val in enumerate(A):
		if i == dels:
			#print(val)
			if val < 0:
				ans += val
			else:
				ans -= val
		else:
			if val < 0:
				ans = ans + (val * -1)
			else:
				ans += val


	print(ans)



def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
if __name__ == "__main__":
	main()
Buggy code:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*min(B))
           

Fixed code:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
        if C==[]:
            print(sum(B)+sum(C)-2*min(B))
        else:
            print(sum(B)+sum(C)-2*min(min(B),min(C)))
Buggy code:
N=int(input())
A=list(map(int,input().split()))
pbox=[]
nbox=[]
if 0 in A:
  count=0
  for i in A:
    count += abs(i)
  print(count)
else:
  for i in a:
    if i > 0:
      pbox.append(i)
    else:
      nbox.append(i)
  if len(nbox)%2==0:
    count=0
    for i in a:
      count += abs(i)
    print(count)
  else:
    box=[]
    for i in a:
      box.append(abs(i))
    mi=min(box)
    count=0
    for i in a:
      count += abs(i)
    print(count-2*mi)

Fixed code:
N=int(input())
A=list(map(int,input().split()))
pbox=[]
nbox=[]
if 0 in A:
  count=0
  for i in A:
    count += abs(i)
  print(count)
else:
  for i in A:
    if i > 0:
      pbox.append(i)
    else:
      nbox.append(i)
  if len(nbox)%2==0:
    count=0
    for i in A:
      count += abs(i)
    print(count)
  else:
    box=[]
    for i in A:
      box.append(abs(i))
    mi=min(box)
    count=0
    for i in A:
      count += abs(i)
    print(count-2*mi)
Buggy code:
def getNumNeg(L):
    return sum([i<0 for i in L])
  
def findmax2(L):
    numNeg = getNumNeg(L)
    absL = list(map(abs, L))
    if numNeg % 2 == 0:
        print(sum(absL))
    else:
        print(sum(absL)-min(absL))
        
n = int(input())
a = list(map(abs, input().split()))
findmax2(a)

Fixed code:
def getNumNeg(L):
  return sum([i<0 for i in L])
  
def findmax2(L):
  numNeg = getNumNeg(L)
  absL = list(map(abs, L))
  if numNeg % 2 == 0:
    print(sum(absL))
  else:
    print(sum(absL)-2*min(absL))
        
n = int(input())
a = list(map(int, input().split()))
findmax2(a)
Buggy code:
import numpy

N = int( input() )
A = list( map( int ,input().split()) )
cnt = sum( lop < 0 for lop in A)

nA = numpy.array(A)
nA = numpy.abs(nA)

lA = nA.tolist()
if min(lA) == 0 or cnt % 2 == 0:
    print(sum(lA))
else :
    print(sum(lA)-min(lA))



Fixed code:
import numpy

N = int( input() )
A = list( map( int ,input().split()) )
cnt = sum( lop < 0 for lop in A)

nA = numpy.array(A)
nA = numpy.abs(nA)

lA = nA.tolist()
if min(lA) == 0 or cnt % 2 == 0:
    print(sum(lA))
else :
    print(sum(lA)-min(lA)*2)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
aabs = [i if i>=0 else i*(-1) for i in a]
MIN = min(aabs)
ans = 0
mcount = 0

for i in range(n):
  if a[i] < 0:
    mcount += 1
    
if mcount%2 == 0:
  for i in a:
    ans += abs(i)
    print(ans)
else:
  for i in a:
    ans += abs(i)
  print(ans - 2*MIN)
  

Fixed code:
n = int(input())
a = list(map(int,input().split()))
aabs = [i if i>=0 else i*(-1) for i in a]
MIN = min(aabs)
ans = 0
mcount = 0

for i in range(n):
  if a[i] < 0:
    mcount += 1
    
if mcount%2 == 0:
  for i in a:
    ans += abs(i)
  print(ans)
else:
  for i in a:
    ans += abs(i)
  print(ans - 2*MIN)
Buggy code:
n = int(input())
a = list(map(int,input().split()))

if cnt_minus % 2 == 0:
    print(sum([abs(a[i]) for i in range(n)]))
else:
    mi = min([abs(a[i]) for i in range(n)])
    print(sum([abs(a[i]) for i in range(n)]) - 2 * mi)

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

cnt_minus = len([a[i] for i in range(n) if a[i] < 0])

if cnt_minus % 2 == 0:
    print(sum([abs(a[i]) for i in range(n)]))
else:
    mi = min([abs(a[i]) for i in range(n)])
    print(sum([abs(a[i]) for i in range(n)]) - 2 * mi)
Buggy code:
import collections

N =int(input())

As = [int(item) for item in input().split()]

cnt = 0

Bs = collections.deque()

min1 = 1000000000000

for i in As:

	if As < 0:		cnt +=1

	Bs.append(abs(i))

	mim1=min(min1, abd(i))

	

if cnt % 2 =0:

	print(sum(list(Bs)))

else:

	print(sum(list(Bs))-min1*2)
    

Fixed code:
import collections
N =int(input())
As = [int(item) for item in input().split()]

cnt = 0
Bs = collections.deque()
min1 = 1000000000000

for i in As:
	if i < 0:
		cnt +=1
	Bs.append(abs(i))
	min1=min(min1, abs(i))
	
if cnt % 2 ==0:
	print(sum(list(Bs)))
else:
	print(sum(list(Bs))-min1*2)
Buggy code:
N=int(input())
a=list(map(int,input().split()))
total=0
minloss=100000000000
zeroflag=0
for i in range(N):
  total+=abs(a[i])
  if a[i]==0:
    zeroflag=1
  if abs(a[i])<minloss:
    minloss=abs(a[i])
if N%2==0 or zeroflag==1:
  print(total)
else:
  print(total-2*minloss)

Fixed code:
N=int(input())
a=list(map(int,input().split()))
total=0
minloss=100000000000
zeroflag=0
minus=0
for i in range(N):
  total+=abs(a[i])
  if a[i]==0:
    zeroflag=1
  if a[i]<0:
    minus+=1
  if abs(a[i])<minloss:
    minloss=abs(a[i])
if minus%2==0 or zeroflag==1:
  print(total)
else:
  print(total-2*minloss)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    pos.append(0)
    neg = [0]+neg
    b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)


Fixed code:
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    if pos == []:
      print(-sum(neg[:-1])+neg[-1])
      exit()
    else:
      b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
import bisect
a.sort()

idx = bisect.bisect_left(a, 0)

if idx % 2 == 0:
    print(sum(abs(a)))
else:
    sm = [abs(x) for x in a]
    print(sum(sm) - 2*min(abs(a[idx]), abs(a[idx-1])))

Fixed code:
n = int(input())
a = list(map(int,input().split()))
import bisect
a.sort()

idx = bisect.bisect_left(a, 0)
sm = [abs(x) for x in a]
if idx % 2 == 0:
    print(sum(sm))
else:
    print(sum(sm) - 2*min(sm))
Buggy code:
N=int(input())
A=list(map(int,input().split(" ")))
A_p = [ a for a in A if a > 0 ]
A_n = [ -1*a for a in A if a < 0 ]
A_0 = [ a for a in A if a == 0 ]

l_p = len(A_p)
l_n = len(A_n)
l_0 = len(A_0)

if l_p == 0:
    if l_n%2 == 0:
        print(sum(A_n.append(0)))
    if l_0 > 0:
        print(sum(A_n.append(0)))
    else:
        tmp_n=min(A_n)
        A_n.remove(tmp_n)
        print(sum(A_n.append(0))-tmp_n)

elif l_n == 0:
    print(sum(A_p.append(0)))

    

if l_n%2 == 0:
    print(sum(A_p)+sum(A_n))
else:
    if l_0 > 0:
        print(sum(A_p)+sum(A_n))
    else:
        if min(A_n) > min(A_p):
            tmp_n=min(A_p)
            A_p.remove(tmp_n)
            print(sum(A_p.append(0))+sum(A_n)-tmp_n)    
        else:
            tmp_n=min(A_n)
            A_n.remove(tmp_n)
            print(sum(A_p)+sum(A_n.append(0))-tmp_n)

Fixed code:
N=int(input())
A=list(map(int,input().split(" ")))
A_p = [ a for a in A if a > 0 ]
A_n = [ -1*a for a in A if a < 0 ]
A_0 = [ a for a in A if a == 0 ]

l_p = len(A_p)
l_n = len(A_n)
l_0 = len(A_0)

if l_p == 0:
    if l_n%2 == 0:
        print(sum(A_n+[0]))
    elif l_0 > 0:
        print(sum(A_n+[0]))
    else:
        tmp_n=min(A_n)
        A_n.remove(tmp_n)
        print(sum(A_n+[0])-tmp_n)
elif l_n == 0:
    print(sum(A_p+[0]))

elif l_n%2 == 0:
    print(sum(A_p)+sum(A_n))
else:
    if l_0 > 0:
        print(sum(A_p)+sum(A_n))
    else:
        if min(A_n) > min(A_p):
            tmp_n=min(A_p)
            A_p.remove(tmp_n)
            print(sum(A_p)+sum(A_n)-tmp_n)    
        else:
            tmp_n=min(A_n)
            A_n.remove(tmp_n)
            print(sum(A_p)+sum(A_n)-tmp_n)
Buggy code:
n=int(input())
lists=list(map(int,input().split()))


if 0 in lists:
    ans=0
    for _ in lists:
        ans+=abs(_)
    
    
else:
    abslists=[]
    for j in lists:
        abslists.append(abs(j))
        
    ans=0
    count=0
    
    for inner in lists:
        if inner<0:
            count+=1
        
        else:
            continue
            
    if count%2==0:
        for _ in lists:
            ans+=abs(_)
        print(ans)
        
    else:
        for _ in lists:
            ans+=abs(_)
            
        min1=min(abslists)
        
        print(ans-2*min1)

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


if 0 in lists:
    ans=0
    for _ in lists:
        ans+=abs(_)
    print(ans)
        #ok
    
    
else:
    abslists=[]
    for j in lists:
        abslists.append(abs(j))
        
    ans=0
    count=0
    
    for inner in lists:
        if inner<0:
            count+=1
        
        else:
            continue
            
    if count%2==0:
        for _ in lists:
            ans+=abs(_)
        print(ans)
        
    else:
        for _ in lists: 
            ans+=abs(_)  
        min1=min(abslists)
        print(ans-2*min1)
Buggy code:
N=int(input())
A=list(map(int,input().split()))
l=(abs(i)  for i in A)
cnt=0
for i in A:
    if(i<0):
        cnt+=1
if cnt%2==0:
    print(sum(l))
else:
    print(sum(l)-2*min(l))

Fixed code:
N=int(input())
A=list(map(int,input().split()))
l=[abs(i)  for i in A]
cnt=0
for i in A:
    if(i<0):
        cnt+=1
if cnt%2==0:
    print(sum(l))
else:
    print(sum(l)-2*min(l))
Buggy code:
n=int(input())
A=list(map(int,input().split()))

ans,cnt,mini=[],0,float('inf')
for a in A:
  if abs(a)!=a: cnt+=1
  ans.append(abs(a))
  mini=min(mini,abs(a))
if cnt%2==0:
  print(sum(ans))
else:
  print(sum(ans)-mini)

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

ans,cnt,mini=[],0,float('inf')
for a in A:
  if abs(a)!=a: cnt+=1
  ans.append(abs(a))
  mini=min(mini,abs(a))
if cnt%2==0:
  print(sum(ans))
else:
  print(sum(ans)-(mini*2))
Buggy code:
import sys
sys.setrecursionlimit(10**5)

n = int(input())
a = list(map(int, input().split()))
dp = [[None]*(2) for _ in range(n+1)]

dp[n-1][0] = a[n-1]
dp[n-1][1] = -a[n-1]

for i in reversed(range(n-1)):
    for j in range(2):
        print('\n# i: ' + str(i))
        # Unexe
        unexe_unexe = a[i] + dp[i+1][0]
        exe_unexe = -a[i] + dp[i+1][0]
        dp[i][0] = max(unexe_unexe, exe_unexe)

        # Exe
        unexe_exe = a[i] + dp[i+1][1]
        exe_exe = -a[i] + dp[i+1][1]
        dp[i][1] = max(unexe_exe, exe_exe)

#print(dp)
#print(max(dp[0][0], dp[0][1]))
print(dp[0][1])



Fixed code:
import sys
sys.setrecursionlimit(10**5)

n = int(input())
a = list(map(int, input().split()))
dp = [[None]*(2) for _ in range(n+1)]

dp[n-1][0] = a[n-1]
dp[n-1][1] = -a[n-1]

for i in reversed(range(n-1)):
    for j in range(2):
        #print('\n# i: ' + str(i))
        # Unexe
        unexe_unexe = a[i] + dp[i+1][0]
        exe_unexe = -a[i] + dp[i+1][1]
        dp[i][0] = max(unexe_unexe, exe_unexe)

        # Exe
        unexe_exe = a[i] + dp[i+1][1]
        exe_exe = -a[i] + dp[i+1][0]
        dp[i][1] = max(unexe_exe, exe_exe)

#print(dp)
#print(max(dp[0][0], dp[0][1]))
print(dp[0][0])
Buggy code:
N = int(input())
A = [int(n) for n in input().split()]

sum = 0
minus = 0
minn = 10 ** 10
for a in A:
    b = abs(a)
    sum += b
    if b < minn:
        minn = b
    if a < 0:
        minus += 1

print(sum)
print(minn)
print(minus)

if minus % 2 == 0:
    print(sum)
else:
    print(sum - 2*minn)


Fixed code:
N = int(input())
A = [int(n) for n in input().split()]

sum = 0
minus = 0
minn = -1
for a in A:
    b = abs(a)
    sum += b
    if minn == -1 or b < minn:
        minn = b
    if a < 0:
        minus += 1

if minus % 2 == 0:
    print(sum)
else:
    print(sum - 2*minn)
Buggy code:
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

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

neg_cnt = 0
minimum = 10**10
for num in A:
    minimum = min(minimum, abs(num))
    if num < 0:
        neg_cnt += 1
        

print(minimum)
ans = 0
for num in A:
    if num < 0:
        ans += -num
    else:
        ans += num 

print(ans)
print(neg_cnt)
if neg_cnt % 2 == 0:
    print(ans)               
else:
    print(ans - minimum * 2)

Fixed code:
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

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

neg_cnt = 0
minimum = 10**10
for num in A:
    minimum = min(minimum, abs(num))
    if num < 0:
        neg_cnt += 1
        
ans = 0
for num in A:
    if num < 0:
        ans += -num
    else:
        ans += num 

if neg_cnt % 2 == 0:
    print(ans)               
else:
    print(ans - minimum * 2)
Buggy code:
N = int(input())
a = list(map(int, input().split()))

dp = [[0] * 2 for _ in range(N+1)]
dp[0][0] = 0
dp[0][1] = -10**18

for i in range(1, N):
    dp[i][0] = max(dp[i-1][0]+a[i-1], dp[i-1][1]-a[i-1])
    dp[i][1] = max(dp[i-1][0]-a[i-1], dp[i-1][1]+a[i-1])
print(max(dp[N-1][0], dp[N-1][0]))

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

dp = [[0] * 2 for _ in range(N+1)]
dp[0][0] = 0
dp[0][1] = -10**18

for i in range(1, N+1):
    dp[i][0] = max(dp[i-1][0]+a[i-1], dp[i-1][1]-a[i-1])
    dp[i][1] = max(dp[i-1][0]-a[i-1], dp[i-1][1]+a[i-1])
print(dp[N][0])
Buggy code:
a = int(input())
b = [int(i) for i in input().split()]
c = 0
d = []

for i in b:
    if i < 0:
        c += 1
    d.append(abs(i))

if c % 2 == 0:
    print(sum(d))
else:
    print(sum(d) - min(d))

Fixed code:
a = int(input())
b = [int(i) for i in input().split()]
c = 0
d = []

for i in b:
    if i < 0:
        c += 1
    d.append(abs(i))

if c % 2 == 0:
    print(sum(d))
else:
    print(sum(d) - (min(d) * 2))
Buggy code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s, cnt = [0]*n, 0
    for i in a:
        s[i] = abs(i)
        if i < 0:
            cnt += 1
    if cnt%2:
        print(sum(s) - 2*min(s))
    else:
        print(sum(s))

if __name__ == "__main__":
    main()

Fixed code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s, cnt = [0]*n, 0
    for i in range(n):
        s[i] = abs(a[i])
        if a[i] < 0:
            cnt += 1
    if cnt%2:
        print(sum(s) - 2*min(s))
    else:
        print(sum(s))

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

minusList = [i for i in A if i < 0]
absList = list(map(abs,A))
ans = sum(absList)
if len(minusList) % 2 != 0:
	minimum = min(absList)
	ans = ans - minimum

print(ans)

Fixed code:
N = int(input())
A = list(map(int,input().split(" ")))
ans = 0

minusList = [i for i in A if i < 0]
absList = list(map(abs,A))
ans = sum(absList)
if len(minusList) % 2 != 0:
	minimum = min(absList)
	ans = ans - minimum*2

print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))

cnt = 0
flag = False
for i in range(n):
    if a[i] < 0:
        a[i] = -a[i]
        cnt += 1
    elif a[i] == 0:
        flag = True
        exit()
    else:
        continue

if flag:
    print(sum(a))
    exit()
    
if cnt % 2 == 0:
    print(sum(a))
else:
    print(sum(a) - 2*min(a))

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

cnt = 0
flag = False

for i in range(n):
    if a[i] < 0:
        a[i] = -a[i]
        cnt += 1
    elif a[i] == 0:
        flag = True
    else:
        continue

if flag:
    print(sum(a))
    exit()
    
if cnt % 2 == 0:
    print(sum(a))
else:
    print(sum(a) - 2*min(a))