qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys

input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
m = 0
zero = 0
ans = 0
odd = 10**9
for i in A:
    if i < 0:
        m += 1
    if i == 0:
        zero = 1
    ans += abs(i)
    if odd > abs(i):
        odd = abs(i)
if m %2 == 0 or zero:
    print(ans)
else:
    print(ans-odd)

Fixed code:
import sys

input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
m = 0
zero = 0
ans = 0
odd = 10**9
for i in A:
    if i < 0:
        m += 1
    if i == 0:
        zero = 1
    ans += abs(i)
    if odd > abs(i):
        odd = abs(i)
if m %2 == 0 or zero:
    print(ans)
else:
    print(ans-odd*2)
Buggy code:
N = int(input())
A = list(map(int,input().split()))

B = [abs(i) for i in A]
if N%2 == 0:
    print(sum(B))
else:
    print(sum(B)-min(B))

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

B = [abs(i) for i in A]
minus = [int(i<0) for i in A]
if sum(minus)%2 == 0:
    print(sum(B))
else:
    print(sum(B)-2*min(B))
Buggy code:
N=int(input())
l=list(map(int,input().split()))
l2=sorted([num for num in l if num<0])
l3=sorted([num for num in l if num>=0])
if len(l2)%2==0:
  ans=sum([abs(n) for n in l])

else:
  if abs(l2[-1]) < l3[1]:
    x=l2.pop()
  else:
    x=l3.pop(0)
  ans=sum([abs(n) for n in l2])+sum(l3)-abs(x)
print(ans)

Fixed code:
N=int(input())
l=list(map(int,input().split()))
l2=sorted([num for num in l if num<0])
l3=sorted([num for num in l if num>=0])
if len(l2)%2==0:
  ans=sum([abs(n) for n in l])

elif l3!=[]:
  if abs(l2[-1]) < l3[0]:
    x=l2.pop()
  else:
    x=l3.pop(0)
  ans=sum([abs(n) for n in l2])+sum(l3)-abs(x)
else:
  x=l2.pop()
  ans=sum([abs(n) for n in l2])-abs(x)
print(ans)
Buggy code:
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
ind=bisect.bisect_left(a,0)
print(ind)

if ind==0:
  print(sum(a))

elif ind%2==0 or a[ind]==0:

  print(-sum(a[:ind])+sum(a[ind:]))
else:
  print(-sum(a[:ind])+sum(a[ind:])-2*min(abs(a[ind]),abs(a[ind-1])))

Fixed code:
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
ind=bisect.bisect_left(a,0)


if ind==0 :
  print(sum(a))
  
elif ind==n:
  if ind%2==1:
    print(-sum(a)+2*a[-1])
  else:
    print(abs(sum(a)))

elif ind%2==0:

  print(-sum(a[:ind])+sum(a[ind:]))
else:
  print(-sum(a[:ind])+sum(a[ind:])-2*min(abs(a[ind]),abs(a[ind-1])))
Buggy code:
N = int(input())
nums = [int(i) for i in input().split(' ')]

count = 0
m = 0
target = -1
for i in range(N):
    if nums[i] < 0:
        count += 1
        if nums[i] > m or target == -1:
            target = i
            m = nums[i]
pos = [abs(i) for i in nums]
if count % 2 != 0:
    pos[target] *= -1

print(sum(pos))


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

count = 0
m = 0
target = -1
for i in range(N):
    if nums[i] < 0:
        count += 1
    if abs(nums[i]) < m or target == -1:
        target = i
        m = abs(nums[i])
pos = [abs(i) for i in nums]
if count % 2 != 0:
    pos[target] = -abs(pos[target])

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

for i in range(n):
    if a[i] < 0:
        b += 1
        
if (0 in a) or ((b % 2) == 0):
    pass
else:
    ans -= min(a)

print(ans)

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

for i in range(n):
    if a[i] < 0:
        b += 1
        a[i] = abs(a[i])
        
if (0 in a) or ((b % 2) == 0):
    pass
else:
    ans -= min(a) * 2

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

Fixed code:
input()
a = list(map(int, input().split()))
cnt = sum([i < 0 for i in a])
s = [abs(i) for i in a]
if cnt % 2 == 0:
    print(sum(s))
else:
    print(sum(s) - min(s) * 2)
Buggy code:
import numpy as np
N = int(input())
A_list = list(map(int,input().split()))
neg_num = len([x for x in A_list if x<0])
zero_num = len([x for x in A_list if x==0])
abs_list = [abs(x) for x in A_list]

ans = np.sum(abs_list)
if neg_num%2==0 or zero_num>0:
    ans = ans
elif n%2!=0:
    ans = ans - min(abs_list)
print(ans)

Fixed code:
import numpy as np
N = int(input())
A_list = list(map(int,input().split()))
neg_num = len([x for x in A_list if x<0])
zero_num = len([x for x in A_list if x==0])
abs_list = [abs(x) for x in A_list]

ans = np.sum(abs_list)
if neg_num%2==0 or zero_num>0:
    ans = ans
elif neg_num%2!=0:
    ans = ans - 2*min([x for x in abs_list if x!=0])
print(ans)
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
na = [abs(i) for i in a]
m = min(na)
s = sum(na)

if m == 0:
    ans = s
else:
    cnt = 0
    for i in a:
        if i < 0:
            cnt += 1
    if cnt%2 == 0:
        ans = s
    else:
        ans = s-m

print(ans)

Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
na = [abs(i) for i in a]
m = min(na)
s = sum(na)

if m == 0:
    ans = s
else:
    cnt = 0
    for i in a:
        if i < 0:
            cnt += 1
    if cnt%2 == 0:
        ans = s
    else:
        ans = s-2*m

print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
min_abs_a = -float('inf')
sum_abs_A = 0
include_zero = False
for a in A:
  sum_abs_A += abs(a)
  if a == 0: include_zero = True
  if a < 0 :
    neg_num += 0
    min_abs_a = min(abs(a),min_abs_a)
print(sum_abs_A if neg_num%2==0 or include_zero is True else sum_abs_A + 2*min_abs_a)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
min_abs_a = float('inf')
sum_abs_A = 0
include_zero = False
for a in A:
  sum_abs_A += abs(a)
  min_abs_a = min(abs(a),min_abs_a)
  if a == 0: include_zero = True
  if a < 0 : neg_num += 1
print(sum_abs_A if neg_num%2==0 or include_zero is True else sum_abs_A - 2*min_abs_a)
Buggy code:
N = int(input())
a =list(map(int, input().split()))

cnt = 0
min_val = a[0]
for it in a:
    if abs(it) < min_val:
        min_val = abs(it)
    
    if it < 0:
        cnt+=1
        
abs_list = list(map(abs, a))
if cnt%2 == 0:
    print(sum(abs_list))
else:
    print(sum(abs_list) - 2*min_val)

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

cnt = 0
min_val = abs(a[0])
for it in a:
    if abs(it) < min_val:
        min_val = abs(it)
    
    if it < 0:
        cnt+=1
        
abs_list = list(map(abs, a))
if cnt%2 == 0:
    print(sum(abs_list))
else:
    print(sum(abs_list) - 2*min_val)
Buggy code:
N = int(input())
a = input().split()
num=[]
numabs=[]
tex=[]
count=0
for i in range(N):
	num.append(int(a[i]))
	numabs.append(abs(num[i]))
	if num[i] < 0 :
		count +=1
	elif num[i] == 0:
		count2 +=1
if count%2 ==0 or count2 > 0:
	res = sum(num)
else:
	res =sum(num)-2*min(numabs)
print(res)
             

Fixed code:
N = int(input())
a = input().split()
num=[]
numabs=[]
tex=[]
count=0
count2=0
for i in range(N):
	num.append(int(a[i]))
	numabs.append(abs(num[i]))
	if num[i] < 0 :
		count +=1
	elif num[i] == 0:
		count2 +=1
if count%2 ==0 or count2 > 0:
	res = sum(numabs)
else:
	res =sum(numabs)-2*min(numabs)
print(res)
Buggy code:
import heapq
n=int(input())
a=list(map(int,input().split()))

zero_count=0
minus_count=0
for i in range(n):
    if a[i]<0:
        minus_count+=1
    if a[i]==0:
        zero_count+=1
        break

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

if zero_count==1 or minus_count%2==0:
    ans=sum(a)
else:
    heapq.heapify(a)
    mn=heapq.heappop(a)
    print(a)
    print(mn)
    ans=sum(a)-mn

print(ans)


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

zero_count=0
minus_count=0
for i in range(n):
    if a[i]<0:
        minus_count+=1
    if a[i]==0:
        zero_count+=1
        break

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

if zero_count==1 or minus_count%2==0:
    ans=sum(a)
else:
    heapq.heapify(a)
    mn=heapq.heappop(a)
    ans=sum(a)-mn

print(ans)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
negative=[]
positive=[]
for ele in a:
    if ele<0:
        negative.append(ele)
    else:
        positive.append(ele)
if len(negative)==0:
    print(sum(a))
else:
    if len(negative)%2==0:
        print(-sum(negative)+sum(positive))
    else:
        if -negative.back()>positive[0]:
            print(-sum(negative)+sum(positive[1:])-positive[0])
        else:
            print(-sum(negative[:-2])+sum(positive)+negative.back())


Fixed code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
negative=[]
positive=[]
for ele in a:
    if ele<0:
        negative.append(ele)
    else:
        positive.append(ele)
if len(negative)==0:
    print(sum(a))
else:
    if len(negative)%2==0:
        print(-sum(negative)+sum(positive))
    else:
        if len(positive)==0:
            print(-sum(negative)+2*negative[-1])
        elif -negative[-1]>positive[0]:
            print(-sum(negative)+sum(positive[1:])-positive[0])
        else:
            print(-sum(negative[:-1])+sum(positive)+negative[-1])
Buggy code:
N = int(input())
A= list(map(int, input().split()))
minus = 0
A_abs = []
for i in range(N):
    A_abs.append(abs(int(A[i])))
    if(A_abs[i] < 0):
        minus += 0

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

Fixed code:
N = int(input())
A= list(map(int, input().split()))
minus = 0
A_abs = []
for i in range(N):
    A_abs.append(abs(int(A[i])))
    if(A[i] < 0):
        minus += 1

if minus % 2 == 0:
    print(sum(A_abs))
else:
    print(sum(A_abs) - 2*min(A_abs))
Buggy code:
N = int(input())
A = list(map(int, input().split()))
B = A.copy()

count = 0
for i in range(N):
    if B[i] < 0:
        count += 1
        B[i] *= -1
  
res = 0
if count%2 == 1:
    B.sort()
    for i in range(1, N):
        res += abs(B[i])

    res += B[0]
else:
    for i in range(N):
        res += abs(B[i])
        
print(res)

            

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

count = 0
for i in range(N):
    if B[i] < 0:
        count += 1
        B[i] *= -1
  
res = 0
if count%2 == 1:
    B.sort()
    for i in range(1, N):
        res += abs(B[i])

    res -= B[0]
else:
    for i in range(N):
        res += abs(B[i])
        
print(res)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
if 0 in A:
  A = list(map(abs,A))
  print(sum(A))
else:
  count=0
  min_A =100000000000000000
  for i in range(N):
    if A[i]<0:
      count=count+1
    if abs(A[i])<min_A:
      min_A = abs(A[i])
  A = list(map(abs,A))
  print(sum(A)-min_A*2)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
if 0 in A:
  A = list(map(abs,A))
  print(sum(A))
else:
  count=0
  min_A =100000000000000000
  for i in range(N):
    if A[i]<0:
      count=count+1
    if abs(A[i])<min_A:
      min_A = abs(A[i])
  A = list(map(abs,A))
  if count%2==0:
    print(sum(A))
  else:
    print(sum(A)-min_A*2)
Buggy code:
DEBUG = False

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

index_max_abs_val = N-1
flag_zero = not A[N-1]
for i in range(N-1):
    if not A[i]:
        flag_zero = True
    if index_max_abs_val < abs(A[i]):
        index_max_abs_val = i
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1
    if DEBUG:
        print("A: {}".format(A))
        print("index_max_abs_val: {}, flag_zero: {}".format(index_max_abs_val, flag_zero))

if flag_zero:
    A[N-1] = abs(A[N-1])
elif A[N-1] < 0:
    A[N-1] *= -1
    A[index_max_abs_val] *= -1

if DEBUG:
    print("A: {}".format(A))
print(sum(A))


Fixed code:
DEBUG = False

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

index_min_abs_val = N-1
flag_zero = not A[N-1]
if DEBUG:
    print("index_max_abs_val: {}, flag_zero: {}".format(index_min_abs_val, flag_zero))
for i in range(N-1):
    if not A[i]:
        flag_zero = True
    if abs(A[index_min_abs_val]) > abs(A[i]):
        index_min_abs_val = i
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1
    if DEBUG:
        print("i: {}, A: {}".format(i, A))
        print("index_max_abs_val: {}, flag_zero: {}".format(index_min_abs_val, flag_zero))

if flag_zero:
    A[N-1] = abs(A[N-1])
elif A[N-1] < 0:
    A[N-1] *= -1
    A[index_min_abs_val] *= -1

if DEBUG:
    print("A: {}".format(A))
print(sum(A))
Buggy code:
N=int(input())
LA=list(map(int,input().split()))

Minus=0
Zero=0
L_absolute=[]

for i in LA:
    if i<0:
        L_absolute.append(i*(-1))
        Minus+=1
    elif i==0:
        Zero=1
    else:
        L_absolute.append(i)
        
L_absolute.sort()

if Zero==0:
    ans=sum(L_absolute)
if Minus%2==1:
    ans=sum(L_absolute)-2*L_absolute[0]
else:
    ans=sum(L_absolute)
    
print(ans)

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

Minus=0
Zero=0
L_absolute=[]

for i in LA:
    if i<0:
        L_absolute.append(i*(-1))
        Minus+=1
    elif i==0:
        Zero=1
    else:
        L_absolute.append(i)
        
L_absolute.sort()

if Zero==1:
    ans=sum(L_absolute)
elif Minus%2==1:
    ans=sum(L_absolute)-2*L_absolute[0]
else:
    ans=sum(L_absolute)
    
print(ans)
Buggy code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

if 0 in a:
  b = list(map(abs, a))
  print(sum(b))
  
else:
  if (a[a<0].size % 2) == 0:
    b = list(map(abs, a))
    print(sum(b))
  else:
    b = list(map(abs, a))
    c = sorted(b).reverse()
    d = c.pop()
    print(sum(c))

    

Fixed code:
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

if 0 in a:
  b = list(map(abs, a))
  print(sum(b))
  
else:
  if (a[a<0].size % 2) == 0:
    b = list(map(abs, a))
    print(sum(b))
  else:
    b = list(map(abs, a))
    b = sorted(b)
    b.reverse()
    c = b.pop()
    print(sum(b)-c)
Buggy code:
import numpy as np
n = int(input())
*a, = map(int, input().split())
b = np.abs(a)
#print(b)
print(np.sum(b)-2*np.min(b) if (i<0 for i in a) else np.sum(b)) 

Fixed code:
import numpy as np
n = int(input())
*a, = map(int, input().split())
b = np.abs(a)
#print(b)
print(np.sum(b)-2*np.min(b) if (np.sum(i<0 for i in a)%2) else np.sum(b))
Buggy code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

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

for i in range(1, N - 1):
    bidx = i - 1
    nidx = i + 1
    for j in range(2):
        dp[i][0] = max(dp[bidx][0] + A[nidx],
                       dp[bidx][1] + A[nidx])
        dp[i][1] = max(dp[bidx][0] - 2 * A[i] - A[nidx],
                       dp[bidx][1] - 2 * A[i] - A[nidx])

print(max(dp[N - 2]))

Fixed code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

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

for i in range(1, N - 1):
    bidx = i - 1
    nidx = i + 1
    dp[i][0] = max(dp[bidx][0] + A[nidx],
                   dp[bidx][1] + A[nidx])
    dp[i][1] = max(dp[bidx][0] - 2 * A[i] - A[nidx],
                   dp[bidx][1] + 2 * A[i] - A[nidx])

print(max(dp[N - 2]))
Buggy code:
n = int(input())
a = list(map(int, input().split(" ")))
dp = [[0 for i in range(2)] for i in range(n)]

dp[1][0] = a[0] + a[1]
dp[1][1] = -(a[0] + a[1])

for i in range(2, n):
    dp[i][0] = max(dp[i-1][0]+a[i], dp[i-1][1]+a[i])
    dp[i][1] = max(dp[i-1][0]+(-2*a[i-1])+(-a[i]), dp[i-1][1]+2*a[i-1]+(-a[i]))

for i in range(2):
    for j in range(n):
        print(dp[j][i], end=" ")
    print()

print(max(dp[n-1][0], dp[n-1][1]))


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

dp = [[0] * 2 for i in range(n)]
dp[0] = [a[0], -a[0]]

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

print(dp[n - 1][0])
Buggy code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

ans = 0
count = 0
for i in range(n):
    if a[i] < 0:
        a[i] = -a[i]
        ans += a[i]
        count += 1

if count % 2 == 0:
    print(ans)
else:
    print(ans - min(a) * 2)


Fixed code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

ans = 0
count = 0
for i in range(n):
    if a[i] < 0:
        a[i] = -a[i]
        count += 1

ans = sum(a)
if count % 2 == 0:
    print(ans)
else:
    print(ans - min(a) * 2)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(abs,a))
C = [a for a in A if a < 0]

if len(C) % 2 == 0:
    print((sum(B)))
else:
    print((sum(B)-min(B)*2))

Fixed code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(abs, A))
C = [a for a in A if a < 0]
if len(C) % 2 == 0:
    print((sum(B)))
else:
    print((sum(B) - min(B)*2))
Buggy code:
import sys,collections as cl
import fractions
from functools import reduce
import copy
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
　　

n = int(input())
su = 0

a = l()

co = 0
k = 0
a.sort()
f = 0
for i in range(n):
	if a[i] < 0:
		co += 1
if co % 2 == 0:
	for i in range(n):
		su += abs(a[i])
	print(su)
else:
	for i in range(n):
		if f == 2 or a[i] == 0:
			break
		if a[i] >= 0 and f == 0:
			kk = a[i-1]
			f = 1
		if a[i] >= 0:
			if abs(a[0]) >= a[i]:
				k = a[i]*(-2)
			else:
				k = kk*2
			f = 2
		elif i == n-1:
			k = a[i]*2
	for i in range(n):
		su += abs(a[i])
	su += k
	print(su)



Fixed code:
import sys,collections as cl
import fractions
from functools import reduce
import copy
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

n = int(input())
su = 0

a = l()

co = 0
k = 0
a.sort()
f = 0
for i in range(n):
	if a[i] <= 0:
		co += 1
if co % 2 == 0:
	for i in range(n):
		su += abs(a[i])
	print(su)
else:
	for i in range(n):
		if a[i] == 0:
			break
		if a[i] > 0:
			kk = a[i-1]
		if a[i] > 0:
			if abs(a[i-1]) >= a[i]:
				k = a[i]*(-2)
			else:
				k = kk*2
			break
		elif i == n-1:
			k = a[i]*2
	for i in range(n):
		su += abs(a[i])
	su += k
	print(su)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

count = 0

for i in range(N):
    if A[i] < 0:
        A[i] *= -1
        count += 1

print(A)     

if count % 2 == 0:
    print(sum(A))
else:
    A.sort()
    print(sum(A) - 2 * A[0])

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

count = 0

for i in range(N):
    if A[i] < 0:
        A[i] *= -1
        count += 1

if count % 2 == 0:
    print(sum(A))
else:
    A.sort()
    print(sum(A) - 2 * A[0])
Buggy code:
n = int(input())
lst_a = list(map(int,input().split()))
num_minus = sum(i<0 for i in lst_a)
lst_abs = [abs(i) for i in lst_a]
if num_minus%2 == 0:print(sum(lst_abs))
else:print(sum(lst_abs)-min(lst_abs))

Fixed code:
n = int(input())
lst_a = list(map(int,input().split()))
num_minus = sum(i<0 for i in lst_a)
lst_abs = [abs(i) for i in lst_a]
if num_minus%2 == 0:print(sum(lst_abs))
else:print(sum(lst_abs)-2*min(lst_abs))
Buggy code:
N=int(input())
A=list(map(int,input().split()))
ans=0
c=0
tmp=10**9
for a in A:
    if a<0:
        c+=1
    ans+=abs(a)
    tmp=min(tmp,abs(a))
print(tmp)
if c%2==0:
    print(ans)
else:
    print(ans-tmp*2)

Fixed code:
N=int(input())
A=list(map(int,input().split()))
ans=0
c=0
tmp=10**9
for a in A:
    if a<0:
        c+=1
    ans+=abs(a)
    tmp=min(tmp,abs(a))
if c%2==0:
    print(ans)
else:
    print(ans-tmp*2)
Buggy code:
n = int(input())
a = list(map(int, input().split()))

a.sort()
minus = n
for i in range(n):
  if a[i] >= 0:
    s = i
    break

a = list(map(abs, a))
a.sort()

if minus % 2 == 0:
  print(sum(a))
else:
  print(sum(a) - 2 * a[0])


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

a.sort()
minus = n
for i in range(n):
  if a[i] >= 0:
    minus = i
    break

a = list(map(abs, a))
a.sort()

if minus % 2 == 0:
  print(sum(a))
else:
  print(sum(a) - 2 * a[0])
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
sum_abs, min_abs, cnt_minus = 0, 10**9, 0
for ai in a:
    if ai < 0:
        cnt_minus += 1
    abs_ai = abs(ai)
    sum_abs += abs_ai
    if abs_ai < min_abs:
        min_abs = abs_ai
if cnt_minus % 2 == 0 or a in 0:
    print(sum_abs)
else:
    print(sum_abs - 2*min_abs)

Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
sum_abs, min_abs, cnt_minus = 0, 10**9, 0
for ai in a:
    if ai < 0:
        cnt_minus += 1
    abs_ai = abs(ai)
    sum_abs += abs_ai
    if abs_ai < min_abs:
        min_abs = abs_ai
if cnt_minus % 2 == 0 or 0 in a:
    print(sum_abs)
else:
    print(sum_abs - 2*min_abs)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[i]<0:
    cnt+=1
if min(a)>=0 or cnt%2==0:
  print(sum(a))
  exit()
b=[abs(a[i]) for i in range(n)]
s=sum(b)
ans=-10**18
for i in range(n):
  ans=max(ans,s-2*b[i])
print(ans)


Fixed code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[i]<0:
    cnt+=1
if min(a)>=0:
  print(sum(a))
  exit()
b=[abs(a[i]) for i in range(n)]
s=sum(b)
if cnt%2==0:
  print(s)
  exit()
ans=-10**18
for i in range(n):
  ans=max(ans,s-2*b[i])
print(ans)
Buggy code:
N = int(input())
lst_A =list(map(int, input().split()))
neg_count = 0
zero_count = 0
total = 0

if lst_A[0] < 0:
    neg_count += 1
elif lst_A[0] == 0:
    zero_count +=1
total += abs(lst_A[0])
print (total)
memo = abs(lst_A[0])
i = 1
while i < N:
    if lst_A[i] < 0:
        neg_count += 1
    elif lst_A[i] == 0:
        zero_count +=1
    total += abs(lst_A[i])
    print (total)
    memo = min(memo, abs(lst_A[i]))
    i += 1
if zero_count > 0:
    total = total
elif neg_count % 2 == 1:
    total = total - memo *2
else:
    total = total
print (total)

Fixed code:
N = int(input())
lst_A =list(map(int, input().split()))
neg_count = 0
zero_count = 0
total = 0

if lst_A[0] < 0:
    neg_count += 1
elif lst_A[0] == 0:
    zero_count +=1
total += abs(lst_A[0])
memo = abs(lst_A[0])
i = 1
while i < N:
    if lst_A[i] < 0:
        neg_count += 1
    elif lst_A[i] == 0:
        zero_count +=1
    total += abs(lst_A[i])
    memo = min(memo, abs(lst_A[i]))
    i += 1
if zero_count > 0:
    total = total
elif neg_count % 2 == 1:
    total = total - memo *2
else:
    total = total
print (total)
Buggy code:
n=int(input())
a=[int(i) for i in input().split()]
x=0
b=[]
for i in a:
  if i<0: x=(x+1)%2
  b.append(abs(i))
b.sort()
print(sum(b)-b[0] if  x else sum(b))

Fixed code:
n=int(input())
a=[int(i) for i in input().split()]
x=0
b=[]
for i in a:
  if i<0: x=x+1
  b.append(abs(i))
b.sort()
print(sum(b)-b[0]*2 if  x%2 else sum(b))
Buggy code:
N = int(input())
A = list(map(int,input().split()))
ans = sum(map(abs,A))
flag = False
sign = 0
mi = 10 ** 9
for a in A:
    if a == 0:
        flag = True
        break
    if a < 0:
        sign += 1
        if abs(a) < mi: mi = abs(a)
if flag:
    print(ans)
else:
    if sign % 2 == 0:
        print(ans)
    else:
        print(ans-2*mi)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
ans = sum(map(abs,A))
flag = False
sign = 0
mi = 10 ** 9
for a in A:
    if a == 0:
        flag = True
        break
    if a < 0:
        sign += 1
    if abs(a) < mi: mi = abs(a)
if flag:
    print(ans)
else:
    if sign % 2 == 0:
        print(ans)
    else:
        print(ans-2*mi)
Buggy code:
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  A = readInts()
  minus = 0
  m = abs(A[0])
  s = 0
  for a in A:
    if a < 0:
      minus += 1
    if abs(a) < m:
      m = abs(a)
    s += abs(a)

  if minus % 2 == 0:
    print(s)
  else:
    print(s - m)

if __name__ == "__main__":
  main()


Fixed code:
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  A = readInts()
  minus = 0
  m = abs(A[0])
  s = 0
  for a in A:
    if a < 0:
      minus += 1
    if abs(a) < m:
      m = abs(a)
    s += abs(a)

  if minus % 2 == 0:
    print(s)
  else:
    print(s - 2 * m)

if __name__ == "__main__":
  main()