qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n=int(input())
A=list(map(int,input().split()))
B=[abs(i) for i in A]
P=0
for i in A:
    if i<0:P +=1
    elif i==0:print(sum(B));exit()

print(B if P%2==0 else sum(B)-2*min(B))

Fixed code:
n=int(input())
A=list(map(int,input().split()))
B=[abs(i) for i in A]
P=0
for i in A:
    if i<0:P +=1
    elif i==0:print(sum(B));exit()

print(sum(B) if P%2==0 else sum(B)-2*min(B))
Buggy code:
def main():
    _ = input()
    A = map(int, input())
 
    B = tuple(map(abs, A))
    C = tuple(a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()


Fixed code:
def main():
    _ = input()
    A = tuple(map(int, input().split()))
 
    B = tuple(map(abs, A))
    C = tuple(a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()
Buggy code:
from sys import stdin

readline = stdin.readline

def main():
    _, *A = map(int, open(0).read().split())
 
    B = map(abs, A)
    C = [a for a in A if a < 0]
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()

Fixed code:
from sys import stdin
 
readline = stdin.readline
 
def main():
    _, *A = map(int, open(0).read().split())
 
    B = tuple(map(abs, A))
    C = tuple(a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()
Buggy code:
from sys import stdin

readline = stdin.readline

_ = readline()
aa = map(int, open(0).read().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    if b < mi:
        mi = b
print(r - mi * 2 * (m % 2))


Fixed code:
from sys import stdin

readline = stdin.readline

_, *aa = map(int, open(0).read().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    mi = min(b, mi)
print(r - mi * 2 * (m % 2))
Buggy code:

N = int(input())
An = map(int, input().split())

total = 0
minim = 1000000000
num_negs = 0

for a in An:
    is_neg = int(a < 0)
    num_negs += is_neg
    a *= (is_neg * -2 + 1)
    total += a
    minim = ((minim < a) and minim) or a
    pass

if num_negs % 2:
    print(total - 2*minim)
else:
    print(total)
    pass


Fixed code:

N = int(input())
An = map(int, input().split())

total = 0
minim = 1000000000
num_negs = 0

for a in An:
    if a < 0:
        num_negs += 1
        a *= -1
        pass
    total += a
    minim = minim if minim < a else a
    pass

if num_negs % 2:
    print(total - 2*minim)
else:
    print(total)
    pass
Buggy code:
from itertools import *
from collections import *

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

An_pos, An_neg = deque(), deque()
for a in An:
    if a >= 0:
        An_pos.append(a)
    else:
        An_neg.append(a)
        pass
    pass

ans = sum(chain(An_pos, An_neg))

if len(An_neg) % 2 == 1:
    ans -= 2 * min(chain(An_pos, An_neg))
    pass

print(ans)


Fixed code:
from itertools import *
from collections import *

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

An_pos, An_neg = deque(), deque()
for a in An:
    if a >= 0:
        An_pos.append(a)
    else:
        An_neg.append(-a)
        pass
    pass

ans = sum(chain(An_pos, An_neg))

if len(An_neg) % 2 == 1:
    ans -= 2 * min(chain(An_pos, An_neg))
    pass

print(ans)
Buggy code:
def solve(n, a_list):
    total = [abs(item) for item in a_list]
    negative = [abs(item) for item in a_list if item < 0]
    print(negative)
    if len(negative) % 2 == 0:
        return sum([abs(item) for item in a_list])
    else:
        minimum = sorted(total)[0]
        return sum([abs(item) for item in a_list]) - 2 * minimum


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()


Fixed code:
def solve(n, a_list):
    total = [abs(item) for item in a_list]
    negative = [abs(item) for item in a_list if item < 0]
    # print(negative)
    if len(negative) % 2 == 0:
        return sum([abs(item) for item in a_list])
    else:
        minimum = sorted(total)[0]
        return sum([abs(item) for item in a_list]) - 2 * minimum


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()
Buggy code:

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

y = [abs(v) for v in X]
if N % 2 == 0:
    print(sum(y))
else:
    print(sum(y) - 2 * min(y))


Fixed code:

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

y = [abs(v) for v in X]
if sum(v < 0 for v in X) % 2 == 0:
    print(sum(y))
else:
    print(sum(y) - 2 * min(y))
Buggy code:
n=int(input())
l=list(map(int,input().split()))
b=False
sum=0
count=0
absmin=10000000
for i in l:
  if i==0:
    b=True
  elif i<0:
    count+=1
  if absmin>abs(i):
    absmin=abs(i)
  sum+=abs(i)
if b:
  print(sum)
else:
  if count%2==1:
    print(sum-absmin)
  else:
    print(sum)  

Fixed code:
n=int(input())
l=list(map(int,input().split()))
b=False
sum=0
count=0
absmin=10000000
for i in l:
  if i==0:
    b=True
  elif i<0:
    count+=1
  if absmin>abs(i):
    absmin=abs(i)
  sum+=abs(i)
if b:
  print(sum)
else:
  if count%2==1:
    print(sum-2*absmin)
  else:
    print(sum)
Buggy code:
N=int(input())
ans = 0
min_chk = 10**10
minus_chk = 0
for i in input().split():
    i = int(i)
    if i < 0 :
        minus_chk += 1
    num = abs(i)
    min_chk = min(num,min_chk)
    ans += num
if minus_chk%2 == 1:
    print(ans-2*num)
else:
    print(ans)

Fixed code:
N=int(input())
ans = 0
min_chk = 10**10
minus_chk = 0
for i in input().split():
    i = int(i)
    if i < 0 :
        minus_chk += 1
    num = abs(i)
    min_chk = min(num,min_chk)
    ans += num
if min_chk != 0:
    if minus_chk%2 == 1:
        print(ans-2*min_chk)
    else:
        print(ans)
else:
    print(ans)
Buggy code:
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if N == 2:
        print(max(A[0]+A[1], (-A[0])+(-A[1])))
        return

    a_sum, a1, a2 = 0, A[0], A[1]
    b_sum, b1, b2 = 0, -A[0], -A[1]
    for i in range(2, N):
        #print(a_sum, a1, a2)
        #print(b_sum, b1, b2)
        #print(A[i])


        if (a_sum + a1 + a2 + A[i]) > (b_sum + b1 + b2 + A[i]):
            new_a_sum = a_sum + a1
            new_a1 = a2
            new_a2 = A[i]
        else:
            new_a_sum = b_sum + b1
            new_a1 = b2
            new_a2 = A[i]
        a_sum, a1, a2 = new_a_sum, new_a1, new_a2
        b_sum, b1, b2 = new_b_sum, new_b1, new_b2

    print(max(a_sum+a1+a2, b_sum+b1+b2))

main()


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

    if N == 2:
        print(max(A[0]+A[1], (-A[0])+(-A[1])))
        return

    a_sum, a1, a2 = 0, A[0], A[1]
    b_sum, b1, b2 = 0, -A[0], -A[1]
    for i in range(2, N):
        #print(a_sum, a1, a2)
        #print(b_sum, b1, b2)
        #print(A[i])
        

        if (a_sum + a1 + a2 + A[i]) > (b_sum + b1 + b2 + A[i]):
            new_a_sum = a_sum + a1
            new_a1 = a2
            new_a2 = A[i]
        else:
            new_a_sum = b_sum + b1
            new_a1 = b2
            new_a2 = A[i]

        if (a_sum + a1 - a2 - A[i]) > (b_sum + b1 - b2 - A[i]):
            new_b_sum = a_sum + a1
            new_b1 = -a2
            new_b2 = -A[i]
        else:
            new_b_sum = b_sum + b1
            new_b1 = -b2
            new_b2 = -A[i]

        a_sum, a1, a2 = new_a_sum, new_a1, new_a2
        b_sum, b1, b2 = new_b_sum, new_b1, new_b2
        
    print(max(a_sum+a1+a2, b_sum+b1+b2))

main()
Buggy code:
n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
d=0
z=0
for i in range(n):
  if l[i]<0:
    d+=1
  elif l[i]=0:
    z+=1
if d%2==0 or (d+z)%2==0:
  for i in range(n):
    s+=abs(l[i])
  print(s)
else:
  for i in range(1,n):
    if a>=abs(l[i]):
      a=abs(l[i])
      m=i
  s=0
  for i in range(m):
    s+=abs(l[i])
  s+=-abs(l[m])
  for i in range(m+1,n):
    s+=abs(l[i])
  print(s)
    


Fixed code:
n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
d=0
z=0
s=0
for i in range(n):
  if l[i]<0:
    d+=1
  elif l[i]==0:
    z+=1
if d%2==0 or (d+z)%2==0:
  for i in range(n):
    s+=abs(l[i])
  print(s)
else:
  for i in range(1,n):
    if a>=abs(l[i]):
      a=abs(l[i])
      m=i
  s=0
  for i in range(m):
    s+=abs(l[i])
  s+=-abs(l[m])
  for i in range(m+1,n):
    s+=abs(l[i])
  print(s)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

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

if cnt%2==0 or 0 in A:
	print(sum(A))
else:
	print(sum(A)-min(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] = -A[i]
		cnt = (cnt+1)%2

if 0 in A:
	print(sum(A))
elif cnt==0:
	print(sum(A))
else:
	print(sum(A)-min(A)*2)
Buggy code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

count = 0
for i, x in enumerate(A):
	if x < 0:
		count += 1
		A[i] *= -1
print(count)
if count % 2 == 0:
	print(sum(A))
else:
	print(A)
	print(sum(A)-2*min(A))


Fixed code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

count = 0
for i, x in enumerate(A):
	if x < 0:
		count += 1
		A[i] *= -1
# print(count)
if count % 2 == 0:
	print(sum(A))
else:
	# print(A)
	print(sum(A)-2*min(A))
Buggy code:
N = int(input())
A = list(map(int, input().split()))

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

print(sum(A))

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

A.sort()
for i in range(N-1):
    if A[i] <= 0 and A[i+1] <= 0:
        A[i] *= -1
        A[i+1] *= -1
    elif A[i] < A[i+1]*(-1):
        A[i] *= -1
        A[i+1] *= -1

print(sum(A))
Buggy code:
import bisect
n = int(input())
A = [int(a) for a in input().split()]
A.sort()
A_abs = [abs(ab) for ab in A]

sum_abs = sum(A_abs)

wh = bisect.bisect_left(A, 0)
dev2 = wh % 2
if dev2 == 0:
  print(sum_abs)
else:
  print(sum_abs - 2 * A_abs[0])

Fixed code:
import bisect
n = int(input())
A = [int(a) for a in input().split()]
A.sort()
A_abs = [abs(ab) for ab in A]
A_abs.sort()
sum_abs = sum(A_abs)

wh = bisect.bisect_left(A, 0)
dev2 = wh % 2
if dev2 == 0:
  print(sum_abs)
else:
  print(sum_abs - 2 * A_abs[0])
Buggy code:
N=int(input())
A=list(map(int,input().split()))
check=sum([a<0 for a in A]) #the number of positive number in A
if check%2==0:
    print(sum([abs(a) for a in A]))
else:
    dust=min([abs(a) for a in A if a<0])
    print(sum([abs(a) for a in A])-2*dust)

Fixed code:
N=int(input())
A=list(map(int,input().split()))
check=sum([a<0 for a in A]) #the number of negative in A
if check%2==0:
    print(sum([abs(a) for a in A]))
else:
    dust=min([abs(a) for a in A])
    print(sum([abs(a) for a in A])-2*dust)
Buggy code:
def d_flipping_signs_dp(N, A):
    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])
    return dp[N][0]

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

Fixed code:
def d_flipping_signs_dp(N, A):
    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])
    return dp[N][0]

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs_dp(N, A))
Buggy code:
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
print(A)

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

Fixed code:
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

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

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

B = map(abs, A)
if len([a for a in A if a < 0]) % 2 == 1:
    print(sum(B) - min(B))
else:
    print(sum(B))


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

B = [abs(a) for a in A]
if len([a for a in A if a < 0]) % 2 == 1:
    print(sum(B) - 2 * min(B))
else:
    print(sum(B))
Buggy code:
n = int(input())
As = [int(i) for i in input().split()]
absl = [abs(a) for a in As]

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

# print(neg)

if neg // 2 == 0:
    print(sum(absl))
else:
    print(sum(absl) - min(absl) * 2)

Fixed code:
n = int(input())
As = [int(i) for i in input().split()]
absl = [abs(a) for a in As]

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

# print(neg)

if neg % 2 == 0:
    print(sum(absl))
else:
    print(sum(absl) - min(absl) * 2)
Buggy code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
mn = 10**10
cnt =0
for i in a:
    mn = min(mn,abs(i))
    ans += abs(i)
    if i<0:
        cnt+=1
        cnt%=2
if cnt:
    print(ans-mn)
else:
    print(ans)

Fixed code:
n = int(input())
a = list(map(int,input().split()))
ans = 0
mn = 10**10
cnt =0
for i in a:
    mn = min(mn,abs(i))
    ans += abs(i)
    if i<0:
        cnt+=1
        cnt%=2
if cnt:
    print(ans-mn*2)
else:
    print(ans)
Buggy code:
from bisect import bisect_left,bisect,bisect_right
import sys

icase=1
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

print(asum)

Fixed code:
from bisect import bisect_left,bisect,bisect_right
import sys

icase=0
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

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

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

mina = abs(aa[0])
nm = 0
for i in range(n):
    mina = min(mina, abs(aa[i]))
    if aa[i] < 0:
        nm += 1

if nm % 2 == 1 and mina == 0:
    print(sum(map(abs, aa)) - 2 * mina)
else:
    print(sum(map(abs, aa)))

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

mina = abs(aa[0])
nm = 0
for i in range(n):
    mina = min(mina, abs(aa[i]))
    if aa[i] < 0:
        nm += 1

if nm % 2 == 1 and mina > 0:
    print(sum(map(abs, aa)) - 2 * mina)
else:
    print(sum(map(abs, aa)))
Buggy code:
N=int(input())
A=list(map(int,input().split()))

if 0 in A:
	print(sum(abs(a) for a in A))

cnt=sum([1 for a in A if a<0])
if cnt%2==0:
	print(sum(abs(a) for a in A))
else:
	A=[abs(a) for a in A]
	print(sum(A) -2*min(A))

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

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

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, a)


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    pritn(law_ans)


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

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, abs(a))


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    print(law_ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))

count = 0
m = 10**9
sum = 0
for i in a:
    i = abs(i)
    m = min(m,i)
    sum += i
    count += 1
    
if count % 2 == 1:
    sum -= m * 2
    
print(sum)

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

count = 0
m = 10**9
sum = 0
for i in a:
    if i < 0:
        count += 1
    i = abs(i)
    m = min(m,i)
    sum += i


if count % 2 == 1:
    sum -= m * 2

print(sum)
Buggy code:
N = int(input())
x = [int(x) for x in input().split()]
dp = [[0 for _ in range(2)] for _ in range(N+1)]
dp[0][0] = 0
dp[0][1] = -10**9
for i in range(N-1):
  dp[i+1][0] = max(dp[i][0]+x[i],dp[i][1]-x[i])
  dp[i+1][1] = max(dp[i][0]-x[i],dp[i][1]+x[i])
print(max(dp[N][0],dp[N][1]))

Fixed code:
N = int(input())
x = [int(x) for x in input().split()]
dp = [[0 for _ in range(2)] for _ in range(N+1)]
dp[0][0] = 0
dp[0][1] = -10**9
for i in range(N):
  dp[i+1][0] = max(dp[i][0]+x[i],dp[i][1]-x[i])
  dp[i+1][1] = max(dp[i][0]-x[i],dp[i][1]+x[i])
print(dp[N][0])
Buggy code:
x=int(input())
y=list(map(int, input().split()))
t=1
for i in range(x):
	if y[i]<0:
		t=t*-1
	y[i]=abs(y[i])

if y==1:
	print(sum(y))
else:
	print(sum(y)-(min(y)*2))

Fixed code:
x=int(input())
y=list(map(int, input().split()))
t=1
for i in range(x):
	if y[i]<0:
		t=t*-1
	y[i]=abs(y[i])

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

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

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

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

flg=1
for num in A:
    if num < 0:
        flg*(-1)
        
B=[abs(i) for i in A]

if flg==1:
    print(sum(B))
else:
    print(sum(B)-2*sorted(B)[0])

Fixed code:
n=int(input())

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

flg=1
for num in A:
    if num < 0:
        flg*=(-1)
        
B=[abs(i) for i in A]

if flg==1:
    print(sum(B))
else:
    print(sum(B)-2*sorted(B)[0])
Buggy code:
n = int(input())
a = [int(x) for x in input().split()]
abs_a = [abs(x) for x in a]
parity_a = len([x for x in a if x < 0]) % 2

if parity_a == 0:
  print(sum(abs_a))
else:
  print(sum(abs_a) - min(abs_a))

Fixed code:
n = int(input())
a = [int(x) for x in input().split()]
abs_a = [abs(x) for x in a]
parity_a = len([x for x in a if x < 0]) % 2

if parity_a == 0:
  print(sum(abs_a))
else:
  print(sum(abs_a) - 2 * min(abs_a))
Buggy code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
zero=0
ans=0
mn=1000000001
for x in a:
  mn=min(mn,abs(x))
  if x<0:
    cnt+=1
    ans-=x
  else:
    ans+=x
  print(ans)
cnt%=2
if cnt==0:
  print(ans)
else:
  print(ans-mn*2)
  
  
  
  
  
#print(ans,cnt,mn)

Fixed code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
zero=0
ans=0
mn=1000000001
for x in a:
  mn=min(mn,abs(x))
  if x<0:
    cnt+=1
    ans-=x
  else:
    ans+=x
  #print(ans)
cnt%=2
if cnt==0:
  print(ans)
else:
  print(ans-mn*2)
  
  
  
  
  
#print(ans,cnt,mn)
Buggy code:
n = int(input())
w = input().split(' ')

a = []
k = False
for i in range(n):
    a.append(int(w[i]))
    if a[i] < 0:
       a[i] *= -1
       k = not(k)
    if i == 1:
        min = a[i]
    if a[i] < min:
        min = a[i]

sum = sum(a)
if k:
    sum -= min
print(sum)

Fixed code:
n = int(input())
w = input().split(" ")

a = []
m = 0
k = False
for i in range(n):
    a.append(int(w[i]))
    if a[i] < 0:
        a[i] *= -1
        k = not (k)
    if i == 0:
        m = a[i]
    if a[i] < m:
        m = a[i]

sum = sum(a)
if k:
    sum -= m*2
print(sum)
Buggy code:
import numpy as np

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

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(A))
else:
  print(sum(A[1 :] - A[0]))

Fixed code:
import numpy as np

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

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(B))
else:
  print(sum(B[1 :]) - B[0])
Buggy code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    [n, s, k] = [str(readline().rstrip()) for _ in range(3)]
    print(s)
    s = list(s)
    strS = ""
    target = s[int(k) - 1]
    for i in range(int(n)):
        if s[i] == target:
            strS += s[i]
        else:
            strS += "*"
    print(strS)


if __name__ == '__main__':
    main()


Fixed code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    [n, s, k] = [str(readline().rstrip()) for _ in range(3)]
    s = list(s)
    strS = ""
    target = s[int(k) - 1]
    for i in range(int(n)):
        if s[i] == target:
            strS += s[i]
        else:
            strS += "*"
    print(strS)


if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
s = str(input())
k = int(input())

char = s[k]
result = ""
for x in s:
    if x == char:
        result += char
    else:
        result += "*"
print(result)


Fixed code:
n = int(input())
s = str(input())
k = int(input())
 
char = s[k-1]
result = ""
for x in s:
    if x == char:
        result += char
    else:
        result += "*"
print(result)
Buggy code:
N = int(input())
S = input()
K = int(input())
for i in range(N):
    if S[i] != S[K]:
        S = S[:i] + '*' + S[(i+1):]
print(S)

Fixed code:
N = int(input())
S = input()
K = int(input())
for i in range(N):
    if S[i] != S[K-1]:
        S = S[:i] + '*' + S[(i+1):]
print(S)