qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N = int(input())
inp2 = int(input())
a = inp2.split()
count = 0
for i in range(int(N)):
	b = int(a[i])
	flag = True
	while flag:
		c = b/2
		if c.isinstance(c,int):
			count+=1
		else:
			flag = False

print(count) 

Fixed code:
N = int(input())
inp2 = input()
a = inp2.split()
count = 0
for i in range(int(N)):
	b = int(a[i])
	flag = True
	c = b
	while flag:
		c = c/2
		if c.is_integer():
			count+=1
		else:
			flag = False

print(count)
Buggy code:
l=list(map(int,input().split()) 
dd=[]                                                                  
for i in l: 
	if i % 2==0: 
		dd.append(i)       
cnt_lst=[]                                                             
for i in dd: 
	cnt1=0 
	while(i % 2==0): 
		i//= 2 
		cnt1+=1 
		if i %2==1: 
			cnt=cnt1 
			cnt_lst.append(cnt)             
			break 
print(sum(cnt_lst)) 

Fixed code:
n=int(input())
l=list(map(int,input().split()))
dd=[]                                                                  
for i in l: 
	if i % 2==0:
		dd.append(i)       
cnt_lst=[]                                                             
for i in dd: 
	cnt1=0 
	while(i % 2==0): 
		i//= 2 
		cnt1+=1 
		if i %2==1: 
			cnt=cnt1 
			cnt_lst.append(cnt)             
			break 
print(sum(cnt_lst))
Buggy code:
n=int(input())
l=list(map(int,input().split()))
cnt=0
for i in range(n):
  c=0
  while l[i]!=1:
    if l[i]%2==0:
      l[i]=l[i]//2
      c+=1
  cnt+=c
print(cnt)

Fixed code:
n=int(input())
l=list(map(int,input().split()))
cnt=0
for i in range(n):
  c=0
  while l[i]%2==0:
    l[i]=l[i]//2
    c+=1
  cnt+=c
print(cnt)
Buggy code:
n = int(input())
lis = list(map(int,input().split()))
num = 0
for i in range(n):
  while lis[i] % 2 == 0:
    num += 1
    lis[i] // 2
print(num)

Fixed code:
n = int(input())

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

ans = 0
for i in range(n):
  while lis[i]%2 == 0:
    lis[i] //= 2
    ans+=1

print(ans)
Buggy code:
li = list(map(int, input().split()))
m = 0
for i in range(len(li)):
  n = li[i]
  while not n % 2:
    m += 1
    n /= 2
else:
  print(m)

Fixed code:
l = int(input())
li = list(map(int, input().split()))
m = 0
for i in range(l):
  n = li[i]
  while not n % 2:
    m += 1
    n /= 2
else:
  print(m)
Buggy code:
N=int(input())
arr=[int(a) for a in input().split()]
ans=0
for i in range(i):
   c=0
   while arr[i]%2 ==0:
      arr[i]=arr[i]//2
      c=c+1
   ans=ans+c

print(ans)


Fixed code:
N=int(input())
arr=[int(a) for a in input().split()]
ans=0
for i in range(N):
   c=0
   while arr[i]%2 ==0:
      arr[i]=arr[i]//2
      c=c+1
   ans=ans+c

print(ans)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(30):
        if a[i]%2 == 0:
            a[i] %= 2
            ans += 1
        else:
            break
print(ans)

Fixed code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(30):
        if a[i]%2 == 0:
            a[i] /= 2
            ans += 1
        else:
            break
print(ans)
Buggy code:
n = int(input())
a_list = list(map(int, input().split()))

ans = 0
for i in range(1, 21):
    s = len([x for x in a_list if x % (2**i) == 0])
    if s == 0:
        break
    ans += s
    print(ans)

print(ans)


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

ans = 0
for i in range(1, 100):
    s = len([x for x in a_list if x % (2**i) == 0])
    if s == 0:
        break
    ans += s

print(ans)
Buggy code:
n = int(input())
f = lambda x: 0 if x % 2 > 0 else 1 + f(x // 2)
print((f(int(x)) for x in input().split()))

Fixed code:
n = int(input())
f = lambda x: 0 if x % 2 > 0 else 1 + f(x // 2)
print(sum(f(int(x)) for x in input().split()))
Buggy code:
N = int(input())
a = list(map(int, input().split()))

SUM = 0
for i in range(N):
  while a[i] >= 2 and a % 2 == 0:
    SUM += 1
    a[i] //= 2
    
print(SUM)






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

SUM = 0
for i in range(N):
  while a[i] >= 2 and a[i] % 2 == 0:
    SUM += 1
    a[i] //= 2
    
print(SUM)
Buggy code:
n = int(input())
a = list(map(int, input().split()))
b = []
cnt = 0

for x in a:
    if x % 2 == 0:
        b.append(x)
print(b)
for j in range(len(b)):
    while(b[j] % 2 == 0):
        cnt += 1
        b[j] /= 2

print(cnt)


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

for x in a:
    if x % 2 == 0:
        b.append(x)

for j in range(len(b)):
    while(b[j] % 2 == 0):
        cnt += 1
        b[j] /= 2

print(cnt)
Buggy code:
import math

N = int(input())
lists = [ int(v) for v in input().split(" ") ]

total = 0

print(math.log2(10))

for l in lists:
  if l % 2 == 0:
    while True:
      if l % 2 == 0:
        l = int(l/2)
        total += 1      
      else:
        break
print(total)

Fixed code:
import math

N = int(input())
lists = [ int(v) for v in input().split(" ") ]

total = 0

for l in lists:
  if l % 2 == 0:
    while True:
      if l % 2 == 0:
        l = int(l/2)
        total += 1      
      else:
        break
print(total)
Buggy code:
N = int(input())
A = list(map(int, input().split()))

sum_div = 0
for i in range(N):
  temp_div = A[i]
  while True:
    if temp_div%2 == 0:
      sum_div += 1
      temp_div = A[i]//2
    else:
      break
print(sum_div)

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

sum_div = 0
for i in range(N):
  temp_div = A[i]
  while True:
    if temp_div%2 == 0:
      sum_div += 1
      temp_div = temp_div//2
    else:
      break
print(sum_div)
Buggy code:
v=map(int,input().split())
v=sorted(v)[::-1]
c=0
cnt=0
while 1:
    while 1:
        if v[c]%2:break
        cnt+=1
        v[c]/=2
    c+=1 
    if c>=len(v):break
print(cnt)


Fixed code:
n=int(input())
v=map(int,input().split())
v=sorted(v)[::-1]
c=0
cnt=0
while 1:
    while 1:
        if v[c]%2:break
        cnt+=1
        v[c]/=2
    c+=1 
    if c>=n:break
print(cnt)
Buggy code:
def divisionCnt(n):
    cnt = 0
    while n % 2 == 0:
        n = n / 2
        cnt += 1
    return cnt

numbers = [int(i) for i in input().split() if int(i) % 2 == 0]

cnt = 0
for n in numbers:
    cnt += divisionCnt(n)

print(cnt)

Fixed code:
def divisionCnt(n):
    cnt = 0
    while n % 2 == 0:
        n = n / 2
        cnt += 1
    return cnt

N = int(input())
numbers = [int(i) for i in input().split() if int(i) % 2 == 0]

cnt = 0
for n in numbers:
    cnt += divisionCnt(n)

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

count = 0
for i in a:
  b = bin(i).rfind("1") - 1
  count += b

print(count)

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

count = 0
for i in a:
  count += len(bin(i)) - bin(i).rfind("1") - 1

print(count)
Buggy code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def make_cumulative(A):
    C = [0] * (len(A) + 1)
    for i, a in enumerate(A):
        i += 1
        C[i] = C[i - 1] + a
    return C


def main():
    N, M = NMI()
    cakes = [[] for _ in range(8)]
    for i in range(N):
        x, y, z = NMI()
        cakes[0].append(sum([x, y, z]))
        cakes[1].append(sum([x, y, -z]))
        cakes[2].append(sum([x, -y, z]))
        cakes[3].append(sum([x, -y, -z]))
        cakes[4].append(sum([-x, y, z]))
        cakes[5].append(sum([-x, y, -z]))
        cakes[6].append(sum([-x, -y, z]))
        cakes[7].append(sum([-x, -y, -z]))
    for i in range(8):
        cakes[i] = sorted(cakes[i], reverse=True)
        cakes[i] = max(make_cumulative(cakes[i][:M+1]))
    print(max(cakes))


if __name__ == "__main__":
    main()

Fixed code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def make_cumulative(A):
    C = [0] * (len(A) + 1)
    for i, a in enumerate(A):
        i += 1
        C[i] = C[i - 1] + a
    return C


def main():
    N, M = NMI()
    cakes = [[] for _ in range(8)]
    for i in range(N):
        x, y, z = NMI()
        cakes[0].append(sum([x, y, z]))
        cakes[1].append(sum([x, y, -z]))
        cakes[2].append(sum([x, -y, z]))
        cakes[3].append(sum([x, -y, -z]))
        cakes[4].append(sum([-x, y, z]))
        cakes[5].append(sum([-x, y, -z]))
        cakes[6].append(sum([-x, -y, z]))
        cakes[7].append(sum([-x, -y, -z]))
    for i in range(8):
        cakes[i] = sorted(cakes[i], reverse=True)
        cakes[i] = sum(cakes[i][:M])
    print(max(cakes))


if __name__ == "__main__":
    main()
Buggy code:
N,M=map(int,input().split())
c=[list(map(int,input().split())) for i in range(N)]

bit=[[] for i in range(2**3)]
for k in range(N):
    for i in range(2**3):
        t=c[k].copy()
        for j in range(3):
            if(i>>j&1):
                t[j]*=-1
        bit[i].append(t)
for i in range(2**3):
    bit[i].sort(key=lambda x:(x[0],x[1],x[2]),reverse=True)
res=0
for i in range(2**3):
    p=[1,1,1]
    for j in range(3):
        if(i>>j&1):
            p[j]*=-1
    z,o,t=0,0,0
    for k in range(M):
        z+=bit[i][k][0]*p[0]
        o+=bit[i][k][1]*p[1]
        t+=bit[i][k][2]*p[2]
    res=max(res,abs(z)+abs(o)+abs(t))
print(res)

Fixed code:
N,M=map(int,input().split())
c=[list(map(int,input().split())) for i in range(N)]

bit=[[] for i in range(2**3)]
for k in range(N):
    for i in range(2**3):
        t=c[k].copy()
        for j in range(3):
            if(i>>j&1):
                t[j]*=-1
        bit[i].append(t)
for i in range(2**3):
    bit[i].sort(key=lambda x:(x[0]+x[1]+x[2]),reverse=True)
res=0
for i in range(2**3):
    p=[1,1,1]
    for j in range(3):
        if(i>>j&1):
            p[j]*=-1
    z,o,t=0,0,0
    for k in range(M):
        z+=bit[i][k][0]*p[0]
        o+=bit[i][k][1]*p[1]
        t+=bit[i][k][2]*p[2]
    res=max(res,abs(z)+abs(o)+abs(t))
print(res)
Buggy code:
def main():
    N, M = map(int, input().split())
    for _ in range(N):
        x, y, z = map(int, input().split())
        l.append((x,y,z))
    r = 0
    l2 = [i+j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i+j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i-j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i-j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i+j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i+j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i-j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i-j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    return r
print(main())


Fixed code:
def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(N):
        x, y, z = map(int, input().split())
        l.append((x,y,z))
    r = 0
    l2 = [i+j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i+j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i-j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [i-j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i+j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i+j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i-j+k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    l2 = [-i-j-k for i, j, k in l]
    l2.sort(reverse=True)
    r = max(r, sum(l2[:M]))
    return r
print(main())
Buggy code:
n,m = map(int,input().split())
xyz = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(8):
    s = [0 for i in range(n)]
    for j in range(n):
        a = 0
        for k in range(3):
            if i>>k&1:
                a += xyz[j][k]
            else:
                a -= xyz[j][k]
        s[i] = a
    s.sort()
    ans = max(ans,sum(s[n-m:]))
print(ans)

Fixed code:
n,m = map(int,input().split())
xyz = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(8):
    s = []
    for j in range(n):
        a = 0
        for k in range(3):
            if i>>k&1:
                a += xyz[j][k]
            else:
                a -= xyz[j][k]
        s.append(a)
    s.sort()
    ans = max(ans,sum(s[n-m:]))
print(ans)
Buggy code:
n,m=map(int,input().split())
print(max([sum(sorted([i*l[0]+j*l[1]+k*l[2] for l in [list(map(int,input().split())) for i in range(n)]],reverse=True)[:m]) for i in [-1,1] for j in [-1,1] for k in [-1,1]]))

Fixed code:
n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for i in range(n)]
print(max([sum(sorted([i*l[0]+j*l[1]+k*l[2] for l in xyz],reverse=True)[:m]) for i in [-1,1] for j in [-1,1] for k in [-1,1]]))
Buggy code:
n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(8):
    a=[0]*n
    for j in range(n):
        for k in range(3):
            if i>>k&1:
                a[j]+=x[j][k]
            else:
                a[j]-=x[j][k]
    ans=max(ans,abs(sorted(a)[-m:].sum()))
print(ans)


Fixed code:
n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(8):
    a=[0]*n
    for j in range(n):
        for k in range(3):
            if i>>k&1:
                a[j]+=x[j][k]
            else:
                a[j]-=x[j][k]
    ans=max(ans,abs(sum(sorted(a,reverse=1)[:m])))
print(ans)
Buggy code:
import numpy as np
N, M, *L = map(int, open('0').read().split())
L = [np.array(m) for m in zip(*[iter(L)]*3)]
ans = 0
for i in range(8):
  X = []
  c = []
  for j in range(3):
    if i%2==1:
      c.append(-1)
    else:
      c.append(1)
    i >>= 1
  c = np.array(c)
  X = list(map(lambda x:sum(x*c), L))
  X.sort(reverse=True)
  ans = max(ans, sum(X[:M]))
print(ans)

Fixed code:
import numpy as np
N, M, *L = map(int, open(0).read().split())
L = [np.array(m) for m in zip(*[iter(L)]*3)]
ans = 0
for i in range(8):
  X = []
  c = []
  for j in range(3):
    if i%2==1:
      c.append(-1)
    else:
      c.append(1)
    i >>= 1
  c = np.array(c)
  X = list(map(lambda x:sum(x*c), L))
  X.sort(reverse=True)
  ans = max(ans, sum(X[:M]))
print(ans)
Buggy code:
N, M = map(int, input().split())
xs = [[] for _ in range(N)]
for j in range(N):
    a, b, c = map(int, input().split())
    for i in range(2**3):
        t = []
        for k in range(3):
            t.append(1-2*((i>>k)%2))
        xs[i].append(a*t[0] +b*t[1]+c*t[2])
print(max(sum(sorted(xs[i])[-M:]) for i in range(2**3)))


Fixed code:
N, M = map(int, input().split())
xs = [[] for _ in range(8)]
for j in range(N):
    a, b, c = map(int, input().split())
    for i in range(2**3):
        t = []
        for k in range(3):
            t.append(1-2*((i>>k)%2))
        xs[i].append(a*t[0] +b*t[1]+c*t[2])
print(max(sum(sorted(xs[i])[-M:]) for i in range(2**3))*(M!=0))
Buggy code:
N,M=map(int,input().split())
cake=[list(map(int,input().split())) for _ in range(N)]
ans=0
if M=0:
    print(ans)
    exit()
for i in range(1<<3):
    point=[0]*N
    for j in range(N):
        for k in range(3):
            point[j]+=(-1+(i>>k & 1)*2)*cake[j][k]
    point.sort()
    ans=max(ans,sum(point[-M:]))
print(ans)


Fixed code:
N,M=map(int,input().split())
cake=[list(map(int,input().split())) for _ in range(N)]
ans=0
for i in range(1<<3):
    point=[0]*N
    for j in range(N):
        for k in range(3):
            point[j]+=(-1+(i>>k & 1)*2)*cake[j][k]
    point.sort()
    ans=max(ans,sum(point[-M:]))
    if M==0:
        ans=0
print(ans)
Buggy code:
n, m = map(int, input().split())
cakes = []
for i in range(n):
    x, y, z = map(int, input().split())
    cakes.append([x, y, z])

ans = []
for sign in range(8):
    check = [0, 0, 0]
    for i in range(3):
        if (sign >> i) & 1:
            check[i] = 1
        else:
            check[i] = -1

    cakes.sort(reverse=True, key=lambda x: x[0]*check[0] + x[1]*check[1] + x[2]*check[2])
    value = [0, 0, 0]
    for i in range(m):
        a, b, c = cakes[i]
        value[0] += a
        value[1] += b
        value[2] += c

    ans.append(sum(value))

print(max(ans))


Fixed code:
n, m = map(int, input().split())
cakes = []
for i in range(n):
    x, y, z = map(int, input().split())
    cakes.append([x, y, z])

ans = []
for sign in range(8):
    check = [0, 0, 0]
    for i in range(3):
        if (sign >> i) & 1:
            check[i] = 1
        else:
            check[i] = -1

    cakes.sort(reverse=True, key=lambda x: x[0]*check[0] + x[1]*check[1] + x[2]*check[2])
    value = [0, 0, 0]
    for i in range(m):
        a, b, c = cakes[i]
        value[0] += a
        value[1] += b
        value[2] += c
        
    candidate = 0
    for i in range(3):
        candidate += abs(value[i])

    ans.append(candidate)

print(max(ans))
Buggy code:
N, M, *XYZ = map(int, open(0).read().split())

P = tuple(product((1, -1), repeat=3))

A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    A[0].append(sum((x, y, z)))
    A[1].append(sum((x, y, -z)))
    A[2].append(sum((x, -y, z)))
    A[3].append(sum((x, -y, -z)))
    A[4].append(sum((-x, y, z)))
    A[5].append(sum((-x, y, -z)))
    A[6].append(sum((-x, -y, z)))
    A[7].append(sum((-x, -y, -z)))

cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))

print(max(cand))


Fixed code:
N, M, *XYZ = map(int, open(0).read().split())

A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    A[0].append(sum((x, y, z)))
    A[1].append(sum((x, y, -z)))
    A[2].append(sum((x, -y, z)))
    A[3].append(sum((x, -y, -z)))
    A[4].append(sum((-x, y, z)))
    A[5].append(sum((-x, y, -z)))
    A[6].append(sum((-x, -y, z)))
    A[7].append(sum((-x, -y, -z)))

cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))

print(max(cand))
Buggy code:
# ABC100D - Patisserie ABC
def calc(func: "func") -> int:
    cakes = [func(x, y, z) for x, y, z in zip(*[iter(XYZ)] * 3)]
    cakes.sort()
    return max(sum(cakes[:M]), sum(cakes[-M:]))


def main():
    global M, XYZ
    N, M, *XYZ = map(int, open(0).read().split())
    ans = max(
        calc(lambda x, y, z: x + y + z),
        calc(lambda x, y, z: x + y - z),
        calc(lambda x, y, z: x - y + z),
        calc(lambda x, y, z: x - y - z),
    )
    print(ans)


if __name__ == "__main__":
    main()

Fixed code:
# ABC100D - Patisserie ABC
def calc(func: "func") -> int:
    cakes = [func(x, y, z) for x, y, z in zip(*[iter(XYZ)] * 3)]
    cakes.sort(reverse=1)
    return sum(cakes[:M])


def main():
    global M, XYZ
    N, M, *XYZ = map(int, open(0).read().split())
    ans = max(
        calc(lambda x, y, z: x + y + z),
        calc(lambda x, y, z: x + y - z),
        calc(lambda x, y, z: x - y + z),
        calc(lambda x, y, z: x - y - z),
        calc(lambda x, y, z: -x + y + z),
        calc(lambda x, y, z: -x + y - z),
        calc(lambda x, y, z: -x - y + z),
        calc(lambda x, y, z: -x - y - z),
    )
    print(ans)


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

c = n[0]
d = n[1]
e = [1, -1]
f = []
for i in e:
    for j in e:
        for k in e:
         f.append([i,j,k])

ans = []
for i in f:
    g = []
    for j in a:
        g.append(sum([j[k]*i[k] for k in range(3)]))
    g.sort()
    g.reverse()
    ans.append(sum(g[:3]))

print(max(ans))

Fixed code:
n = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n[0])]

c = n[0]
d = n[1]
e = [1, -1]
f = []
for i in e:
    for j in e:
        for k in e:
         f.append([i,j,k])

ans = []
for i in f:
    g = []
    for j in a:
        g.append(sum([j[k]*i[k] for k in range(3)]))
    g.sort()
    g.reverse()
    ans.append(sum(g[:d]))

print(max(ans))
Buggy code:
n, m = map(int, input().split())

x = []
y = []
z = []
for i in range(n):
  _x, _y, _z = map(int, input().split())
  x.append(_x)
  y.append(_y)
  z.append(_z)

pm = [1, -1]

ans = 0
for i_x in pm:
  for i_y in pm:
    for i_z in pm:
      values = []
      for i in range(n):
        values.append(x * i_x + y * i_y + z * i_z)
      s = 0
      for value in sorted(values, reverse=True)[:m]:
        s += value
      ans = max(ans, s)
      
print(ans)

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

x = []
y = []
z = []
for i in range(n):
  _x, _y, _z = map(int, input().split())
  x.append(_x)
  y.append(_y)
  z.append(_z)

pm = [1, -1]

ans = 0
for i_x in pm:
  for i_y in pm:
    for i_z in pm:
      values = []
      for i in range(n):
        values.append(x[i] * i_x + y[i] * i_y + z[i] * i_z)
      s = 0
      for value in sorted(values, reverse=True)[:m]:
        s += value
      ans = max(ans, s)
      
print(ans)
Buggy code:
n,m = map(int,input().split())
x,y,z = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    z.append(c)
def solve(x,y,z,m):
    ans = 0
    for bit in range(8):
        print(bit>>2)
        w = []
        for i in range(n):
            t = x[i]*(-1)**((bit>>2)&1)+y[i]*(-1)**((bit>>1)&1)+z[i]*(-1)**((bit>>0)&1)
            w.append(t)
        w.sort(reverse=True)
        ans = max(ans,sum(w[:m]))
    return ans

ans = solve(x,y,z,m)
print(ans)


Fixed code:
n,m = map(int,input().split())
x,y,z = [],[],[]
for i in range(n):
    a,b,c = map(int,input().split())
    x.append(a)
    y.append(b)
    z.append(c)
def solve(x,y,z,m):
    ans = 0
    for bit in range(8):
        #print((bit>>2)&1,(bit>>1)&1,(bit>>0)&1)
        w = []
        for i in range(n):
            t = x[i]*(-1)**((bit>>2)&1)+y[i]*(-1)**((bit>>1)&1)+z[i]*(-1)**((bit>>0)&1)
            w.append(t)
        w.sort(reverse=True)
        ans = max(ans,sum(w[:m]))
    return ans

ans = solve(x,y,z,m)
print(ans)
Buggy code:
[N,M]=list(map(int,input().split()
              )
          )
XYZ=[[int(i) for i in input().split()] for i in range(N)] 
maxabs=0

for i in range(8):
  pm=list(map(int,format(i, 'b')))
  pm=[0,]*(3-len(pm))+pm

  newXYZ=sorted([[item[0]*(-1)**pm[0],item[1]*(-1)**pm[1],item[2]*(-1)**pm[2]] for item in XYZ],
               reverse=True)
  
  maxabs=max(sum([abs(sum([newXYZ[m][j] for m in range(M)]
                             )
                         ) for j in range(3)
                 ]
                ),
             maxabs
            )


print(maxabs)

Fixed code:
[N,M]=list(map(int,input().split()
              )
          )
XYZ=[[int(i) for i in input().split()] for i in range(N)] 
maxabs=0

for i in range(8):
  pm=list(map(int,format(i, 'b')))
  pm=[0,]*(3-len(pm))+pm
  pm=[(-1)**item for item in pm]
  
  newXYZ=sorted([[item[0]*pm[0],item[1]*pm[1],item[2]*pm[2]] for item in XYZ],
                key=lambda x:sum(x),
                reverse=True)
  
  maxabs=max(sum([abs(sum([newXYZ[m][j] for m in range(M)]
                             )
                         ) for j in range(3)
                 ]
                ),
             maxabs
            )


print(maxabs)
Buggy code:
n,m=map(int, input().split())
import numpy as np
xyz=np.array([list(map(int,input().split())) for i in range(n)])
ans=0
if m>0:
    for i in range(8):
        a=np.dot(xyz,np.array(((-1)**i,(-1)**(i//2),(-1)**(i//4))))
        print(np.sort(a)[-m:])
        ans=max(ans,np.sum(np.sort(a)[-m:]))
print(ans)

Fixed code:
n,m=map(int, input().split())
import numpy as np
xyz=np.array([list(map(int,input().split())) for i in range(n)])
ans=0
if m>0:
    for i in range(8):
        a=np.dot(xyz,np.array(((-1)**i,(-1)**(i//2),(-1)**(i//4))))
        ans=max(ans,np.sum(np.sort(a)[-m:]))
print(ans)