Buggy python submission (verdict: Time Limit Exceeded):
import itertools


N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
num = [i for i in range(N)]
maximum = -float("inf")
for p in itertools.combinations(num, M):
    m = sum(abs(sum(lst[n][i] for n in p)) for i in range(3))
    maximum = max(maximum, m)

print(maximum)


Fixed submission:
N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            sum_lst = []
            for n in range(N):
                num = lst[n][0] * i + lst[n][1] * j + lst[n][2] * k
                sum_lst.append(num)
            maximum = max(abs(sum(sorted(sum_lst)[:M])), maximum)
            
print(maximum)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools


N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for pickup in itertools.combinations(lst, M):
    m = sum(abs(sum([pickup[n][i] for n in range(M)])) for i in range(3))
    maximum = max(maximum, m)

print(maximum)


Fixed submission:
N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            sum_lst = []
            for n in range(N):
                num = lst[n][0] * i + lst[n][1] * j + lst[n][2] * k
                sum_lst.append(num)
            maximum = max(abs(sum(sorted(sum_lst)[:M])), maximum)
            
print(maximum)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools


N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for pickup in itertools.combinations(lst, M):
    m = abs(sum([pickup[n][0] for n in range(M)])) + abs(sum([pickup[n][1] for n in range(M)])) + abs(sum([pickup[n][2] for n in range(M)]))
    maximum = max(maximum, m)

print(maximum)


Fixed submission:
N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            sum_lst = []
            for n in range(N):
                num = lst[n][0] * i + lst[n][1] * j + lst[n][2] * k
                sum_lst.append(num)
            maximum = max(abs(sum(sorted(sum_lst)[:M])), maximum)
            
print(maximum)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools


N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = 0
for pickup in itertools.permutations(lst, M):
    for q in range(M):
        m = abs(sum([pickup[n][0] for n in range(M)])) + abs(sum([pickup[n][1] for n in range(M)])) + abs(sum([pickup[n][2] for n in range(M)]))
        if m >= maximum:
            maximum = m

print(maximum)


Fixed submission:
N, M = map(int, input().split())
lst = [list(map(int, input().rstrip().split())) for n in range(N)]
maximum = -float("inf")
for i in [-1, 1]:
    for j in [-1, 1]:
        for k in [-1, 1]:
            sum_lst = []
            for n in range(N):
                num = lst[n][0] * i + lst[n][1] * j + lst[n][2] * k
                sum_lst.append(num)
            maximum = max(abs(sum(sorted(sum_lst)[:M])), maximum)
            
print(maximum)