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

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

goukei=0
if mynas % 2 ==0:
    for j in range(n):
        goukei+=abs(a[j])
else:
    a=np.array(a)
    np.abs(a)
    a=np.sort(a)
    for k in range(n):
        goukei+=a[i]
    goukei-=a[0]*2

print(goukei)


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

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

a=np.array(a)
a=np.abs(a)
a=np.sort(a)
goukei=0

if mynas % 2 ==0:
    for j in range(n):
        goukei += a[j]
else:
    for k in range(n):
        goukei+=a[k]
    goukei-=a[0]*2

print(goukei)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
s = 0
c = 0
m = 10 ** 10

for x in a:
    if x < 0:
        c += 1
    
    s += abs(x)
    m = min(m, abs(x))
    
if c % 2 != 0:
    s -= m
    
print(s)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
s = 0
c = 0
m = 10 ** 10

for x in a:
    if x < 0:
        c += 1
    
    s += abs(x)
    m = min(m, abs(x))
    
if c % 2 != 0:
    s -= 2 * m
    
print(s)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
neg = 0
for i in a:
  r = r + abs(i)
  if i < 0 :
     neg = neg + 1
if neg % 2 != 0:
  s = 10000000000
  for i in a:
    s = min(s,abs(i))
  r = r - 2*s
  
print(r)

  

Fixed code:
n = int(input())
a = list(map(int,input().split()))
neg = 0
r=0
for i in a:
  r = r + abs(i)
  if i < 0 :
     neg = neg + 1
if neg % 2 != 0:
  s = 10000000000
  for i in a:
    s = min(s,abs(i))
  r = r - 2*s
  
print(r)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
count=0
a_abs=[0 for j in range(n)]
min_abs=abs(a[0])
for i in range(n):
    a_abs[i]=abs(a[i])
    if a[i]<0:
        count+=1
    if abs(a[i])<min_abs:
        min_abs=abs(a[i])
        

if count%2==0:
    ans=sum(a_abs)
else:
    ans=sum(a_abs)-2*min_abs
    
print(count)
print(min_abs)
print(ans)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
count=0
a_abs=[0 for j in range(n)]
min_abs=abs(a[0])
for i in range(n):
    a_abs[i]=abs(a[i])
    if a[i]<0:
        count+=1
    if abs(a[i])<min_abs:
        min_abs=abs(a[i])
        

if count%2==0:
    ans=sum(a_abs)
else:
    ans=sum(a_abs)-2*min_abs
    
print(ans)
Buggy code:
N = int(input())
A = list(map(int,input().split()))
isMinus = False
for i in range(N):
    if A[i] < 0:
        isMinus = not isMinus
        A[i] = A[i]*-1
if isMinus:
    print(sum(A))
else:
    print(sum(A)-min(A)*2)

Fixed code:
N = int(input())
A = list(map(int,input().split()))
isMinus = False
for i in range(N):
    if A[i] < 0:
        isMinus = not isMinus
        A[i] = A[i]*-1

if isMinus:
    print(sum(A)-min(A)*2)
else:
    print(sum(A))
Buggy code:
import sys
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
c=0
ans=0
for i in range(N):
  if num[i]<0:
    c+=1 
ans = list(map(lambda x: abs(x),num))
if c%2==0:
  print(ans)
else:
  print(sum(ans) - min(num,key=lambda x: abs(x))*2)

Fixed code:
import sys
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
c=0
ans=0
for i in range(N):
  if num[i]<0:
    c+=1 
ans = list(map(lambda x: abs(x),num))
if c%2==0:
  print(sum(ans))
else:
  print(sum(ans) - min(ans,key=lambda x: abs(x))*2)
Buggy code:
import sys
input = sys.stdin.read

n=int(input())
lsta=list(map(int,input().split()))

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

for i in range(n-1):
    if lsta[i]<0:
        lsta[i]=lsta[i]*(-1)
        lsta[i+1]=lsta[i+1]*(-1)
        print(lsta)


if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))

Fixed code:
#import sys
#input = sys.stdin.read

n=int(input())
lsta=list(map(int, input().split()))

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

for i in range(n-1):
    if lsta[i]<0:
        lsta[i]=lsta[i]*(-1)
        lsta[i+1]=lsta[i+1]*(-1)

if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))
Buggy code:

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

B = False
if all(A):
    print("not contain")
    M = 0
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
            M += 1
    print(M)
    if M%2 == 0:
        B = True
    else:
        B = False

else:
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
    B = True

if B:
    print(sum(A))
else:
    print("else")
    print(min(A))
    print(str(sum(A)-2*min(A)))

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

B = False
if all(A):
    # print("not contain")
    M = 0
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
            M += 1
    # print(M)
    if M%2 == 0:
        B = True
    else:
        B = False

else:
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
    B = True

if B:
    print(sum(A))
else:
    print(str(sum(A)-2*min(A)))
Buggy code:
N = int(input())

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

cnt = 0

for n in array:
    if n < 0:
        cnt += 1
    calc_array.append(abs(n))
        
if cnt % 2 == 1:
    output = sum(calc_array) - min(calc_array)
else :
    output = sum(calc_array)
    
print(output)

Fixed code:
N = int(input())

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

cnt = 0

for n in array:
    if n < 0:
        cnt += 1
    calc_array.append(abs(n))
        
if cnt % 2 == 0 or 0 in calc_array:
    output = sum(calc_array)
else :
    output = sum(calc_array) - (2*min(calc_array))
    
print(output)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
s = sum(l)
print(s  if t == 1 or len(b)%2==0 else s - 2*min(l))


Fixed code:

n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
k  = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
    k+=1
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
s = sum(l)
print(s  if t == 1 or k%2==0 else s - 2*min(l))
Buggy code:
#https://atcoder.jp/contests/abc125
# -*- coding: utf-8 -*-

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

total = 0
minus = 0
minimum = abs(a[0])

for v in a:
        total += abs(v)
        if v < 0 :
                minus += 1
        if abs(v) < minimum:
                minimum = abs(v)

if minus%2 is 1:
        total -= minimum

print(total)

Fixed code:
#https://atcoder.jp/contests/abc125
# -*- coding: utf-8 -*-

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

total = 0
minus = 0
minimum = abs(a[0])

for v in a:
        total += abs(v)
        if v < 0 :
                minus += 1
        if abs(v) < minimum:
                minimum = abs(v)

if minus%2 is 1:
        total -= minimum*2

print(total)
Buggy code:
n = int(input())
aList = [int(x) for x in input().split(" ")]

for x in range(0, len(aList)):
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]

aMin = min(aList)

print(sum(aList) - ((aMin if len(aList)%2 == 1 else 0)*2))




Fixed code:
n = int(input())
aList = [int(x) for x in input().split(" ")]

minNum = 0

for x in range(0, len(aList)):
	minNum += 1 if aList[x] < 0 else 0
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]

aMin = min(aList)


even = minNum%2==0

if even:
	print(sum(aList))
else:
	print(sum(aList) - (aMin*2))
Buggy code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():






    n = I()
    a = LI()

    ans = 0
    mn = 0

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

    if (mn %2 == 0):
        ans = sum(a)
    else:
        ans = sum(a)-min(a)

    print(ans)

                    


main()


Fixed code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():






    n = I()
    a = LI()

    ans = 0
    mn = 0

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

    if (mn %2 == 0):
        ans = sum(a)
    else:
        ans = sum(a)-min(a)*2

    print(ans)

                    


main()
Buggy code:
N = int(input())
A = [int(i) for i in input().split()]
n = [a for a in A if a < 0]
S = sum([abs(a) for a in A])
if len(n) == 0:
    print(S)
else:
    print(S - 2 * abs(min(n)))

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

cnt = 0
for i in a:
    if i < 0:
        cnt += 1

total = sum(a)

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


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

cnt = 0
for i in a:
    if i < 0:
        cnt += 1

a = list(map(abs, a))
total = sum(a)

if cnt % 2 ==  0:
    print(total)
else:
    print(total - 2 * min(a))
Buggy code:
n = int(input())

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

ans = 0
cost = float('inf')
count = 0

for i in a:
    ans += abs(i)
    cost = min(cost,abs(i))
    if i < 0:
        count += 1

if 0 not in a:
    # count = max(count,n-count)
    if count % 2 != 0:
        ans -= cost

print(ans)

Fixed code:
n = int(input())

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

ans = 0
cost = float('inf')
count = 0

for i in a:
    ans += abs(i)
    cost = min(cost,abs(i))
    if i < 0:
        count += 1

if 0 not in a:
    # count = max(count,n-count)
    if count % 2 != 0:
        ans -= 2*cost

print(ans)
Buggy code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
minus = []
for i in range(N):
  if A[i] < 0:
    minus.append(A[i])
if len(minus) % 2 == 0:
  print(sum(abs(i) for i in A))
else:
  print(sum(abs(i) for i in A)-min(minus)*2)

Fixed code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
minus = []
for i in range(N):
  if A[i] < 0:
    minus.append(A[i])
abs_A = [abs(i) for i in A]
if len(minus) % 2 == 0:
  print(sum(abs_A))
else:
  print(sum(abs_A)-min(abs_A)*2)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

count = len([i for i in A if i < 0])

if count % 2 == 0: 
  print(sum(A)-2*min(A))
else:
  print(sum(A))

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

Fixed code:
n=int(input())
a=list(map(int,input().split()))
c=0
k=0
for i in range(0,n):
  if a[i]<0:
    c=c+1
  k=k+abs(a[i])
  a[i]=abs(a[i])
a.sort()
if c%2==1:
  k=k-2*a[0]
  print(k)
else:
  print(k)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
dp = [[0,0]]*(n+1)
dp[0][0] = 0
dp[0][1] = -float('inf')

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:
n=int(input())
a=list(map(int,input().split()))

dp=[[0]*2 for _ in range (n+1)]
dp[0][0]=0
dp[0][1]=-float('inf')

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:
n = int(input())
a = list(map(int,input().split()))
dp = [[0]*2 for _ in range(n+1)]
dp[0][1] = -10**9
for i in range(n):
    for j in range(2):
        dp[i+1][1-j] = max(dp[i+1][1-j],dp[i][j]+(-1)**(j+1)*a[i])
        dp[i+1][j] = max(dp[i+1][j],dp[i][j]+(-1)**j*a[i])
print(dp[n][0])

Fixed code:
n = int(input())
a =  list(map(int,input().split()))
dp = [[0]*2 for i in range(n+1)]
dp[0][0] = 0
INF = -10**9
dp[0][1] = INF
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:
n = int(input())
nums = list(map(int,input().split()))
cnt = 0
for num in nums:
  if num < 0:
    cnt += 1
    
if cnt % 2 == 0:
  ans = sum(nums)
else:
  ans = sum(nums) - min([abs(i) for i in nums])*2
print(ans)

Fixed code:

n = int(input())
nums = list(map(int,input().split()))
cnt = 0
for num in nums:
  if num < 0:
    cnt += 1
    
abnums = [abs(i) for i in nums]
if cnt % 2 == 0:
  ans = sum(abnums)
else:
  ans = sum(abnums) - min(abnums)*2
print(ans)
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
m = len(list(filter(lambda x: x < 0, a)))
s = sum(map(abs, a))
if m % 2 == 0 or a in 0:
    print(s)
else:
    print(s - 2 * min(a))


Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
m = len(list(filter(lambda x: x < 0, a)))
s = [abs(i) for i in a]
if m % 2 == 0 or 0 in a:
    print(sum(s))
else:
    print(sum(s) - 2 * min(s))
Buggy code:
N = int(input())
A = map(int, input().split())
plus_count = 0
total = 0
minimum = 999999999999999999

for a in A:
	total += abs(a)
	if abs(a) < minimum:
		minimum = abs(a)
	if a > 0:
		plus_count += 1
			
if plus_count % 2 == 0:
	print(total)
else:
	print(total - 2 * minimum)

Fixed code:
N = int(input())
A = map(int, input().split())
minus_count = 0
total = 0
minimum = 999999999999999999

for a in A:
	total += abs(a)
	if abs(a) < minimum:
		minimum = abs(a)
	if a < 0:
		minus_count += 1
			
if minus_count % 2 == 0:
	print(total)
else:
	print(total - 2 * minimum)
Buggy code:
N = int(input())
A = [int(x) for x in input().split()]
count = 0
ab_sum = 0
min = A[0]

for i in range(N):
    ab = 0

    if A[i] >= 0:
        ab_sum += A[i]
        ab = A[i]
    else:
        count += 1
        ab_sum -= A[i]
        ab = -A[i]
    if ab < min:
        min = ab

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

Fixed code:
N = int(input())
A = [int(x) for x in input().split()]
count = 0
ab_sum = 0
min = 1000000000

for i in range(N):
    ab = 0

    if A[i] >= 0:
        ab_sum += A[i]
        ab = A[i]
    else:
        count += 1
        ab_sum -= A[i]
        ab = -A[i]
    if ab < min:
        min = ab

if(count % 2 == 0):
    print(ab_sum)
else:
    print(ab_sum-2*min)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
i = 10**9
s = 0
z = 0
c = 0
for b in a:
  if b < 0:
    s += 1
  elif b == 0:
    z += 1
    break
  if abs(b) < i:
    i = abs(b)
  c += abs(b)
if z > 0 or s%2 == 0:
  print(c)
else:
  print(c-2*i)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
i = 10**9
s = 0
z = 0
c = 0
for b in a:
  if b < 0:
    s += 1
  elif b == 0:
    z += 1
  if abs(b) < i:
    i = abs(b)
  c += abs(b)
if z > 0 or s%2 == 0:
  print(c)
else:
  print(c-2*i)
Buggy code:
def flipping(n,a):
    c = list(filter(lambda x:x<0,a))
    b = list(map(lambda x:abs(x),a))
    if len(c)%2==0:
        return sum(b)
    if len(c)%2!=0:
        return sum(b)-min(b)
    return b
n = int(input())
a=list(map(int, input().split()))
print(flipping(n,a))

Fixed code:
def flipping(n,a):
    c = list(filter(lambda x:x<0,a))
    b = list(map(lambda x:abs(x),a))
    if len(c)%2==0:
        return sum(b)
    if len(c)%2!=0:
        return sum(b)-2*min(b)
    return b
n = int(input())
a=list(map(int, input().split()))
print(flipping(n,a))
Buggy code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

b = np.sort(np.abs(a))
c = np.sum(b < 0)

if c % 2 == 0:
  total = np.sum(b)
else:
  total = np.sum(b[1:]) - b[0]

print(total)

Fixed code:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

b = np.sort(np.abs(a))
c = np.sum(a < 0)

if c % 2 == 0:
  total = np.sum(b)
else:
  total = np.sum(b[1:]) - b[0]
  
print(total)
Buggy code:
N = int(input())
A = list(map(int, input().split()))



signA = sum([1 for a in A if a<0])

absA = [abs(a) for a in A]
absA.sort()

sumA = sum(absA)
      
         
if any([a==0 for a in A]):
  print(sumA)
if signA%2==0:
  print(sumA)
if signA%2!=0:
  print(sumA - 2*absA[0])

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



signA = sum([1 for a in A if a<0])

absA = [abs(a) for a in A]
absA.sort()

sumA = sum(absA)
      
         
if any([a==0 for a in A]):
  print(sumA)
elif signA%2==0:
  print(sumA)
elif signA%2!=0:
  print(sumA - 2*absA[0])
Buggy code:
n=int(input())
a=list(map(int,input().split()))

cnt=0
ans=0

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

print(a)



if cnt%2==0:
    ans=sum(a)

else:
    ans=sum(a)-2*min(a)

print(ans)


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

cnt=0
ans=0

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



if cnt%2==0:
    ans=sum(a)

else:
    ans=sum(a)-2*min(a)

print(ans)
Buggy code:
n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
if n%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min

print(ans)

Fixed code:
n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
a_neg=sum([1 if i<0 else 0 for i in a])
if a_neg%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min
print(ans)
Buggy code:
import sys
stdin = sys.stdin
 
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()
a = na()
c=0
for i in a:
    if i < 0:
        c+=1

b = [abs(i) for i in a]

if c%2 == 0:
    print(b)
    exit()

b.sort()
print(sum(b)-2*b[0])

Fixed code:
import sys
stdin = sys.stdin
 
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()
a = na()
c=0
for i in a:
    if i < 0:
        c+=1

b = [abs(i) for i in a]

if c%2 == 0:
    print(sum(b))
    exit()

b.sort()
print(sum(b)-2*b[0])
Buggy code:
import numpy as np

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

fu = np.sum(A < 0)

if fu == 0:
    print(np.sum(A))
elif fu%2 == 0:
    print(np.sum(abs(A)))
else:
    b = min(abs(A))
    print(np.sum(abs(A)) - b)

Fixed code:
import numpy as np

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

fu = np.sum(A < 0)

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

Fixed code:
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
  if A[i] < 0:
    A[i] = abs(A[i])
    cnt += 1
if cnt %2 == 1:
  print(sum(A)-2*min(A))
else:
  print(sum(A))
Buggy code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

cnt = 0
for i, x in enumerate(A):
	if x < 0:
		cnt += 1
		A[i] *= -1

if cnt%2:
	print(sum(A) - min(A))
else:
	print(sum(A))






Fixed code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

cnt = 0
for i, x in enumerate(A):
	if x < 0:
		cnt += 1
		A[i] *= -1

if cnt%2:
	print(sum(A) - 2*min(A))
else:
	print(sum(A))
Buggy code:
N = int(input())
A = list(map(int, input().split(" ")))

negCount = 0

#sum of A
sum = 0

#min of A
min = A[0]

for i in A:
    
    if i < 0:
        negCount += 1
        i *= -1

    sum += i
    
    print(negCount)
    if i < min:
        min = i


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

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

negCount = 0

#sum of A
sum = 0

#min of A
min = 0
if A[0] < 0:
    min = A[0] * -1
else:
    min = A[0]

for i in A:
    
    if i < 0:
        negCount += 1
        i *= -1

    sum += i

    if i < min:
        min = i

if negCount % 2 == 0:
    print(sum)
    
else:
    print(sum - (min*2))
Buggy code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
n = sum(1 for x in A if x<0)
print(n)
B = np.abs(A)
if n % 2 == 1:
  print(sum(B) - 2*min(B))
else:
  print(sum(B))

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

l_minus = [i for i in a if i <= 0]
l_plus = [i for i in a if i > 0]
ans = 0
if len(l_minus) % 2 == 0:
    l_minus_edit = [-i for i in l_minus]
else:
    l_minus_edit = [-i for i in l_minus]
    plus = l_plus.extend(l_minus_edit)
    l_minus_edit.append(-min(plus) * 2)
    
ans = sum(l_plus) + sum(l_minus_edit)
print(ans)

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

l_minus = [i for i in a if i <= 0]
l_plus = [i for i in a if i > 0]

ans = 0
if len(l_minus) % 2 == 0:
    l_minus_edit = [-i for i in l_minus]
else:
    l_minus_edit = [-i for i in l_minus]
    temp = l_plus[:]
    temp.extend(l_minus_edit)
    l_minus_edit.append(-min(temp) * 2)

ans = sum(l_plus) + sum(l_minus_edit)
print(ans)
Buggy code:
n=int(input())
l=[int(i) for i in input().split()]
num=0
for i in l:
    if i<0:
        num+=1
res=0
for i in l:
    if i>0:
        res+=i
    else:
        res+=-1*i
p=10**10
for i in l:
    p=min(abs(i),p)
if num%2==0:
    A=True
else:
    A=False
if A:
    print(res)
else:
    print(res-p)

Fixed code:
n=int(input())
l=[int(i) for i in input().split()]
num=0
for i in l:
    if i<0:
        num+=1
res=0
for i in l:
    if i>0:
        res+=i
    else:
        res+=-1*i
p=10**10
for i in l:
    p=min(abs(i),p)
if num%2==0:
    A=True
else:
    A=False

if A:
    print(res)
else:
    print(res-2*p)