qyliang/CodeNanoFix huggingface dataset:
Buggy code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    for i in range(N-1):
        if A[i] < 0:
            A[i] *= -1
            A[i+1] *= -1
    print(A)

    return sum(A)


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Fixed code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    for i in range(N-1):
        if A[i] < 0:
            A[i] *= -1
            A[i+1] *= -1
    a_sum =sum(A)

    aa = list(map(abs, A))
    return max(a_sum, sum(aa) - 2*min(aa))


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()
Buggy code:
from itertools import accumulate
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

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

Fixed code:
from itertools import accumulate
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n = int(input())
a = list(map(int,input().split()))
dp = [[0]*2 for i in range(n+1)]
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())
a = list(map(int, input().split()))
print(sum(map(abs, a)) if len([i for i in a if i < 0]) % 2 == 0 else sum(a) - 2 * min(a))


Fixed code:
n = int(input())
a = list(map(int, input().split()))
abs_a = list(map(abs, a))
print(sum(abs_a) if len([i for i in a if i < 0]) % 2 == 0 else sum(abs_a) - 2 * min(abs_a))
Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
m = sum(1 for i in a if i < 0)
z = any(i==0 for i in a)
if m%2 == 0 or z:
    print(sum(abs(i) for i in a))
else:
    print(sum(abs(i) for i in a)-abs(min(a)))


Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
m = sum(1 for i in a if i < 0)
z = any(i==0 for i in a)
if m%2 == 0 or z:
    print(sum(abs(i) for i in a))
else:
    # print(sum(abs(i) for i in a),min(abs(i) for i in a))
    print(sum(abs(i) for i in a)-2*abs(min(abs(i) for i in a)))
Buggy code:
N = int(input())
A = [int(x) for x in input().split(' ')]

s = 0
mc = 0
for i in A:
  if i < 0:
    mc += 1
  s += abs(i)

if (mc % 2 == 1):
  mv = min(A[0],A[-1])
  #print('mv',mv)
  s -= mv*2
print(s)

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

s = 0
mc = 0
mh = 1e10
for i in A:
  if i <= 0:
    mc += 1
  if abs(i) <= mh:
    mh = abs(i)
  s += abs(i)

if (mc % 2 == 1):
  mv = min(A[0],A[-1])
  #print('mv',mv)
  s -= mh*2
print(s)
Buggy code:
import numpy as np

n = int(input())
l = np.array([int(x) for x in input().split()])
ans = 0
if 0 in l:
  for i in range(n):
    ans += abs(l[i])
  sys.exit()
m = abs(l[0])
for i in range(n):
  if l[i] < 0:
    p += 1
  if m < abs(l[i])
for i in range(n):
  ans += abs(l[i])
if p % 2 == 0:
  print(ans)
else:
  print(ans - m*2)

Fixed code:
import numpy as np
import sys
 
n = int(input())
l = np.array([int(x) for x in input().split()])
ans = 0
if 0 in l:
  for i in range(n):
    ans += abs(l[i])
  print(ans)
  sys.exit()
m = abs(l[0])
p = 0
for i in range(n):
  if l[i] < 0:
    p += 1
  if m > abs(l[i]):
    m = abs(l[i])
for i in range(n):
  ans += abs(l[i])
if p % 2 == 0:
  print(ans)
else:
  print(ans - m*2)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(a):
    if a[i]<0:
        c+=1
        a[i]=-1*a[i]
aa=list(map(abs,a))
if c%2==0:
    print(sum(aa))
else:
    print(sum(aa)-2*min(aa))


Fixed code:
n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    if a[i]<0:
        c+=1
        a[i]=-1*a[i]
aa=list(map(abs,a))
if c%2==0:
    print(sum(aa))
else:
    print(sum(aa)-2*min(aa))
Buggy code:
n = int(input())
lis = list(map(int,input().split()))
numm = 0
ans = 0
nu = 10 ** 9
for num in lis:
  nu = min(nu,num)
  ans += abs(num)
  if num < 0:
    numm += 1
if numm % 2 == 1:
  print(ans-nu*2)
else:
  print(ans)

Fixed code:
n = int(input())
lis = list(map(int,input().split()))
numm = 0
ans = 0
nu = 10 ** 9
for num in lis:
  nu = min(nu,abs(num))
  ans += abs(num)
  if num < 0:
    numm += 1
if numm % 2 == 1:
  print(ans-nu*2)
else:
  print(ans)
Buggy code:
n = int(input())
a_list = list(map(int,input().split()))
dp = [[0] * 2 for _ in range(n-1)]
dp[0][0] = a_list[0] + a_list[1]
dp[0][1] = -1*(a_list[0] + a_list[1])

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

Fixed code:
n = int(input())
a_list = list(map(int,input().split()))
dp = [[0] * 2 for _ in range(n-1)]
dp[0][0] = a_list[0] + a_list[1]
dp[0][1] = -1*(a_list[0] + a_list[1])

for i in range(1,n-1):
    dp[i][0] = max(dp[i-1][0] + a_list[i+1] , dp[i-1][1] + a_list[i+1])
    dp[i][1] = max(dp[i-1][0] - a_list[i+1] -2*a_list[i], dp[i-1][1] - a_list[i+1]+2*a_list[i])
    
print(max(dp[n-2][0] ,dp[n-2][1]))
Buggy code:
N = int(input())
A = list(map(int, input().split()))
neg = sum([1 for i in range(N)  if A[i] < 0])
s = [abs(A[i]) for i in range(N)]
ans = sum(s)
if neg % 2 == 0:
  print(ans)
else:
  print(ans - min(s))

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

abs_sum = 0
minus = 0
abs_list = []
for i in range(n):
    if A[i] < 0:
        minus += 1
    abs_list.append(abs(A[i]))
    abs_sum += abs_list[i]

if minus % 2 != 0:
    abs_sum -= min(abs_list)
print(abs_sum)


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

abs_sum = 0
minus = 0
abs_list = []
for i in range(n):
    if A[i] < 0:
        minus += 1
    abs_list.append(abs(A[i]))
    abs_sum += abs_list[i]

if minus % 2 != 0:
    abs_sum -= min(abs_list)*2
print(abs_sum)
Buggy code:
N = int(input())
An = list(map(int, input().split()))
An = [abs(a) for a in An]
if N % 2 == 0:
  print(sum(An))
else:
  print(sum(An) - 2*min(An))

Fixed code:
N = int(input())
An = list(map(int, input().split()))
M = sum([0 if a >=0 else 1 for a in An])
An = [abs(a) for a in An]
if M % 2 == 0:
  print(sum(An))
else:
  print(sum(An) - 2*min(An))
Buggy code:
## https://atcoder.jp/contests/abc125/tasks/abc125_d

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

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

dp[1][False] = N_List[0] + N_List[1]
dp[1][True] = (N_List[0] + N_List[1])*-1

for i in range(2,N):
    dp[i][False] = max(dp[i-1][True] + N_List[i],dp[i-1][False] + N_List[i])
    dp[i][True] = max(dp[i-1][True] + N_List[i-1]*2 + N_List[i]*-1 ,dp[i-1][False] + N_List[i]*-2 + N_List[i]*-1)

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

Fixed code:
## https://atcoder.jp/contests/abc125/tasks/abc125_d

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

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

dp[1][False] = N_List[0] + N_List[1]
dp[1][True] = (N_List[0] + N_List[1])*(-1)

for i in range(2,N):
    dp[i][False] = max(dp[i-1][True] + N_List[i],dp[i-1][False] + N_List[i])
    dp[i][True] = max(dp[i-1][True] + N_List[i-1]*2 + N_List[i]*(-1) ,
                      dp[i-1][False] + N_List[i-1]*(-2) + N_List[i]*(-1))

print(max(dp[N-1]))
Buggy code:
N = int(input())
A = list(map(int, input().split()))

A_tmp = sorted(A, key=abs, reverse=True,)
total = 0
for i,v in enumerate(A_tmp):
    if (v <= 0) and (i < len(A_tmp)-1):
        A_tmp[i+1] = (-1) * A_tmp[i+1]
    total += abs(v)
print(total)

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

A_tmp = sorted(A, key=abs, reverse=True,)
total = 0
for i,v in enumerate(A_tmp):
    if (v <= 0) and (i < len(A_tmp)-1):
        A_tmp[i] = (-1) * A_tmp[i]
        A_tmp[i+1] = (-1) * A_tmp[i+1]
        total += A_tmp[i]
    else:
        total += v
print(total)
Buggy code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
if 0 in A:
    s = 0
    for i in A:
        s += abs(i)
    print(s)
c = 0
for i in range(N):
    if A[i] < 0:
        c += 1
        A[i] *= -1
Min = min(A)
s = 0
for i in A:
    s += i
if c % 2 == 1:
    s -= Min * 2
print(s)

Fixed code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
if 0 in A:
    s = 0
    for i in A:
        s += abs(i)
    print(s)
c = 0
for i in range(N):
    if A[i] < 0:
        c += 1
        A[i] *= -1
Min = min(A)
s = 0
for i in A:
    s += i
if c % 2 == 1:
    s -= Min * 2
if 0 not in A:
    print(s)
Buggy code:
import math

n = int(input())
a_list = [int(i) for i in input().split()]
sum = 0
ans = 0
mini = 10000000000
count = 0
for i in range(n):
    if a_list[i]<0:
        count += 1
    mini = min(mini,abs(a_list[i]))
    sum += abs(a_list[i])

if count%2==1:
    print(sum - mini)
else:
    print(sum)


Fixed code:
import math

n = int(input())
a_list = [int(i) for i in input().split()]
sum = 0
ans = 0
mini = 10000000000
count = 0
for i in range(n):
    if a_list[i]<0:
        count += 1
    mini = min(mini,abs(a_list[i]))
    sum += abs(a_list[i])

if count%2==1:
    print(sum - 2*mini)
else:
    print(sum)
Buggy code:
N = int(input())
A = [int(i) for i in input().split()]

count = 0

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

if count%2 == 1:
  ans = sum(A)
else:
  ans = sum(A) - 2*min(A)

print(ans)


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

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

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

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

Fixed code:
n=int(input())
a=list(map(int,input().split()))
dp=[[0,0]for _ in range(n)]
dp[0]=[a[0],-a[0]]
for i in range(1,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]-a[i],dp[i-1][1]+a[i])
print(dp[n-1][0])
Buggy code:
N = int(input())
A = list(map(int, input().split()))
cnt = 1
ans = 0
for i in range(N):
  if(A[i] < 0):
    cnt = cnt * (-1)
  elif(A[i] == 0):
    cnt = cnt * 0
if(cnt >= 0):
  for i in range(N):
    ans += abs(A[i])
else:
  for i in range(N):
    A[i] = abs(A[i])
  A.sort()
  for i in range(N):
    ans = A[i]
  ans -= A[0] * 2
print(ans)

Fixed code:
N = int(input())
A = list(map(int, input().split()))
cnt = 1
ans = 0
for i in range(N):
  if(A[i] < 0):
    cnt = cnt * (-1)
  elif(A[i] == 0):
    cnt = cnt * 0
if(cnt >= 0):
  for i in range(N):
    ans += abs(A[i])
else:
  for i in range(N):
    A[i] = abs(A[i])
  A.sort()
  for i in range(N):
    ans += A[i]
  ans -= A[0] * 2
print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
count = 0
ans, mina = a[0], abs(a[0])
flag = False
for i in range(1, n):
    ans += abs(a[i])
    mina = min(mina, abs(a[i]))
    if a[i]<0: count += 1
if count%2 or a.count(0): print(ans-mina*2)
else: print(ans)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
if a[0]<0: count=1
else: count = 0
ans, mina = abs(a[0]), abs(a[0])
flag = False
for i in range(1, n):
    ans += abs(a[i])
    mina = min(mina, abs(a[i]))
    if a[i]<0: count += 1
if count%2 or a.count(0): print(ans-mina*2)
else: print(ans)
Buggy code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
abs_A = [abs(a) for a in A]
count = sum([1 if a < 0 else 0 for a in A])
if (count % 2 == 0):
    print(sum(A))
else:
    print(sum(abs_A) - min(abs_A))


Fixed code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
abs_A = [abs(a) for a in A]
count = sum([1 if a < 0 else 0 for a in A])
if (count % 2 == 0):
    print(sum(abs_A))
else:
    print(sum(abs_A) - 2 * min(abs_A))
Buggy code:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])

if n//2==0: print(sum(abs(a)))
else: print(sum(abs(a))-2*abs(a[(np.argmin(abs(a)))]))

Fixed code:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])

if sum(a<0)%2==0: print(sum(abs(a)))
else: print(sum(abs(a))-2*abs(a[(np.argmin(abs(a)))]))
Buggy code:
n = int(input())
aa = list(map(int, input().split()))
abs_aa = [abs(a) for a in aa]
minus_count = sum([1 for a in aa if a < 0])
if minus_count % 2:
    abs_aa[0] *= -1
print(sum(abs_aa))

Fixed code:
n = int(input())
aa = list(map(int, input().split()))
abs_aa = sorted([abs(a) for a in aa])
minus_count = sum([1 for a in aa if a < 0])
if minus_count % 2:
    abs_aa[0] *= -1
print(sum(abs_aa))
Buggy code:
n=int(input())
A=list(map(int,input().split()))
Aabs=map(abs,A)

fu=0
for i in range(N):
  if A[i]<0:
    fu+=1
if fu % 2 == 0:
  print(sum(Aabs))
else:
  print(sum(Aabs)-2*min(Aabs))

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

fu=0
for i in range(N):
  if A[i]<0:
    fu+=1
if fu % 2 == 0:
  print(sum(Aabs))
else:
  print(sum(Aabs)-2*min(Aabs))
Buggy code:
n=int(input())
n-=1
a=list(map(int,input().split()))
cnt=0
ans=0
for i in range(n):
    if cnt>0:
        a[i]=a[i]*(-1)
    if a[i]<0:
        cnt=2
        a[i]=a[i]*(-1)
    else:
        pass
    ans+=a[i]
    cnt-=1
if cnt>0:
    a[n]=abs(a[n])
    m=min(a)
    if m==a[n]:
        ans-=m
    else:
        ans=ans+a[n]-m
else:
    ans+=a[n]
print(ans)

Fixed code:
n=int(input())
n-=1
a=list(map(int,input().split()))
cnt=0
ans=0
for i in range(n):
    if cnt>0:
        a[i]=a[i]*(-1)
    if a[i]<0:
        cnt=2
        a[i]=a[i]*(-1)
    else:
        pass
    ans+=a[i]
    cnt-=1
if cnt>0:
    a[n]=a[n]*(-1)
if a[n]<0:
    a[n]=a[n]*(-1)
    m=min(a)
    ans=ans+a[n]-m*2
else:
    ans+=a[n]
print(ans)
Buggy code:
n = int(input())
l = list(map(int, input().split()))
m = 0
low = l[0]
s = 0
for i in range(n):
  if l[i] < 0:
    l[i] = abs(l[i])
    m += 1
  if low > l[i]:
    low = l[i]
  s += l[i]
if m%2:
  s -= low*2
print(s)

Fixed code:
n = int(input())
l = list(map(int, input().split()))
m = 0
low = abs(l[0])
s = 0
for i in range(n):
  if l[i] < 0:
    l[i] = abs(l[i])
    m += 1
  if low > l[i]:
    low = l[i]
  s += l[i]
if m%2:
  s -= low*2
print(s)
Buggy code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N = int(input())
A = np.array(list(map(int, input().split())))
ans = 0
# print(len(A < 0))
if (len(A[A < 0]) % 2) == 0:
    for a in A:
        ans += abs(a)
    print(ans)
else:
    abs_min = A[0]
    for a in A:
        ans += abs(a)  # aaa
        abs_min = min(abs_min, abs(a))
    print(ans-abs(abs_min)*2)

# print(A)


Fixed code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N = int(input())
A = np.array(list(map(int, input().split())), dtype=np.int64)
lis = []
ans = 0
# print(len(A < 0))
if (len(A[A < 0]) % 2) == 0:
    abs_min = 0
    for a in A:
        ans += abs(a)
    print(ans)
else:
    abs_min = A[0]
    for a in A:
        ans += abs(a)  # aaa
        abs_min = min(abs(abs_min), abs(a))
    print(ans-abs(abs_min)*2)
# print(np.sum(lis) - abs_min*2)
# print(A)
Buggy code:
n = int(input())

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

neg = sum(1 for x in a if x<0)

ans = 0

if neg%2:
	for i in range(len(a)):
		if i == 0:
			exc = abs(a[i])
		else:
			exc = min(exc, abs(a[i]))
	ans = sum(abs(x) for x in a)-exc
else:
	ans = sum(abs(x) for x in a)

print(ans)

Fixed code:
n = int(input())

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

neg = sum(1 for x in a if x<0)

ans = 0

if neg%2:
	for i in range(len(a)):
		if i == 0:
			exc = abs(a[i])
		else:
			exc = min(exc, abs(a[i]))
	ans = sum(abs(x) for x in a)-exc*2
else:
	ans = sum(abs(x) for x in a)

print(ans)
Buggy code:
from sys import stdin

N = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

abs_sum = 0
negative_elements = []
zero_exist = False

for number in data:
    num = int(number)
    abs_sum += abs(num)
    if num == 0:
        zero_exist = True
    elif num < 0:
        negative_elements.append(int(num))

if len(negative_elements) % 2 == 0 or zero_exist:
    print(abs_sum)
else:
    print(abs_sum - 2 * min(negative_elements))

Fixed code:
from sys import stdin

N = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

abs_sum = 0
negative_elements = []
zero_exist = False

for number in data:
    num = int(number)
    abs_sum += abs(num)
    if num == 0:
        zero_exist = True
    elif num < 0:
        negative_elements.append(int(num))

if len(negative_elements) % 2 == 0 or zero_exist:
    print(abs_sum)
else:
    print(abs_sum - (2 * min([abs(int(x)) for x in data])))
Buggy code:
import numpy as np
     
N = input()
A = np.array([int(x) for x in input().split(" ")])
     
if len(np.where(A>0)[0])%2 == 0:
  print(np.abs(A).sum())
else:
  print(np.abs(A).sum() - np.abs(A).min()*2)

Fixed code:
import numpy as np
       
N = input()
A = np.array([int(x) for x in input().split(" ")])

if len(np.where(A<0)[0])%2 == 0:
  print(np.abs(A).sum())
else:
  print(np.abs(A).sum() - np.abs(A).min()*2)
Buggy code:
import sys
input = sys.stdin.readline

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

ans = 0
m = 10 ** 9 + 1
for i in range(N - 1):
    if A[i] < 0:
        A[i] = -A[i]
        A[i + 1] = -A[i + 1]
    ans += A[i]
    if A[i] < m:
        m = A[i]

if A[N - 1] < 0:
    m = min(m, abs(A[N - 1]))
    ans += A[N - 1]
    ans -= m
else:
    ans += A[N - 1]
print(ans)

Fixed code:
import sys
input = sys.stdin.readline

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

ans = 0
m = 10 ** 9 + 1
for i in range(N - 1):
    if A[i] < 0:
        A[i] = -A[i]
        A[i + 1] = -A[i + 1]
    ans += A[i]
    if A[i] < m:
        m = A[i]

if A[N - 1] < 0:
    m = min(m, abs(A[N - 1]))
    ans += abs(A[N - 1])
    ans -= 2 * m
else:
    ans += A[N - 1]
print(ans)
Buggy code:
import numpy as np
import sys
n = int(input())
a = np.array([int(x) for x in input().split()])
dp = np.zeros((n + 1, 2))
dp[0][1] = -2000000001
for i in range(n):
	dp[i + 1][0] = dp[i][0] + a[i]
	dp[i + 1][1] = dp[i][0] - a[i]
print(int(dp[n][0]))

Fixed code:
import numpy as np
import sys
n = int(input())
a = np.array([int(x) for x in input().split()])
dp = np.zeros((n + 1, 2))
dp[0][1] = -2000000001
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(int(dp[n][0]))
Buggy code:
n=int(input())
a=list(int,input())
sum=0
c=0
for i in range(n):
  if a[i]<0:
    a[i]=a[i]*-1:
      c=c+1
  sum=sum+a[i]
  if c%2==0:
    print(sum)
  else:
    print(sum-min(a*2))

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

if(flag):
    print(sum(A))
else:
    m = min(B)
    print(sum(B))

Fixed code:
N = int(input())
A = [int(i) for i in input().split()]
B = [abs(i) for i in A]
for i in range(N-1):
    if(A[i]<0):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
if(A[N-1]<0):
    flag = False
else:
    flag = True

if(flag):
    print(sum(A))
else:
    m = min(B)
    print(sum(B)-2*m)
Buggy code:
n=int(input())
a=list(map(int,input().split()))
cnt = 0
allsei = False
for i in range(n):
    if a[i] == 0:
        allsei = True
        break
    if a[i] < 0:
        cnt += 1
if cnt%2 == 0:
    allsei = True

ans = 0
mini =12345678901
for i in range(n):
    ans += abs(a[i])
    mini = min(mini,abs(a[i]))
if not allsei:
    ans -= mini
print(ans)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
cnt = 0
allsei = False
for i in range(n):
    if a[i] == 0:
        allsei = True
        break
    if a[i] < 0:
        cnt += 1
if cnt%2 == 0:
    allsei = True

ans = 0
mini =12345678901
for i in range(n):
    ans += abs(a[i])
    mini = min(mini,abs(a[i]))
if not allsei:
    ans -= 2*mini
print(ans)